You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by ov...@apache.org on 2019/10/24 07:22:07 UTC

[incubator-echarts] branch fix-11145 created (now 779bd11)

This is an automated email from the ASF dual-hosted git repository.

ovilia pushed a change to branch fix-11145
in repository https://gitbox.apache.org/repos/asf/incubator-echarts.git.


      at 779bd11  test(time): add test for #11145

This branch includes the following new commits:

     new 1869232  fix(time): bar bandWidth with time axis #11145
     new 779bd11  test(time): add test for #11145

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org


[incubator-echarts] 01/02: fix(time): bar bandWidth with time axis #11145

Posted by ov...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ovilia pushed a commit to branch fix-11145
in repository https://gitbox.apache.org/repos/asf/incubator-echarts.git

commit 1869232f59ffc0cd4adb0ee57b0d0a142ba12915
Author: Ovilia <zw...@gmail.com>
AuthorDate: Thu Oct 24 15:16:47 2019 +0800

    fix(time): bar bandWidth with time axis #11145
---
 src/layout/barGrid.js | 81 +++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 78 insertions(+), 3 deletions(-)

diff --git a/src/layout/barGrid.js b/src/layout/barGrid.js
index b5c998b..f74bb6f 100644
--- a/src/layout/barGrid.js
+++ b/src/layout/barGrid.js
@@ -87,16 +87,91 @@ export function prepareLayoutBarSeries(seriesType, ecModel) {
     return seriesModels;
 }
 
+
+/**
+ * Map from axis.index to min gap of two adjacent time values.
+ * For a single time axis, return value is in the form like
+ * [[1000000]].
+ * The value of 1000000 is in milliseconds.
+ */
+function getTimeAxesMinGaps(barSeries) {
+    /**
+     * Map from axis.index to time values.
+     * For a single time axis, axisValues is in the form like
+     * [[1495555200000, 1495641600000, 1495728000000]].
+     * Items in axisValues[x], e.g. 1495555200000, are time values of all
+     * series.
+     */
+    var axisValues = [];
+    zrUtil.each(barSeries, function (seriesModel) {
+        var cartesian = seriesModel.coordinateSystem;
+        var baseAxis = cartesian.getBaseAxis();
+        if (baseAxis.type !== 'time') {
+            return;
+        }
+
+        var data = seriesModel.getData();
+        var axisId = baseAxis.index;
+        for (var i = 0, cnt = data.count(); i < cnt; ++i) {
+            var value = data.get(baseAxis.dim, i);
+            if (!axisValues[axisId]) {
+                // No time value for the time axis
+                axisValues[axisId] = [value];
+            }
+            else if (axisValues[axisId].indexOf(value) < 0) {
+                // No time value in previous series
+                axisValues[axisId].push(value);
+            }
+            // Ignore duplicated time values in the same time axis
+        }
+    });
+
+    var axisMinGaps = [];
+    for (var i = 0; i < axisValues.length; ++i) {
+        if (axisValues[i]) {
+            // Sort time values into ascending order to calculate gaps
+            axisValues[i] = axisValues[i].sort(function (a, b) {
+                return a - b;
+            });
+
+            var min = Number.MAX_VALUE;
+            for (var j = 1; j < axisValues[i].length; ++j) {
+                min = Math.min(min, axisValues[i][j] - axisValues[i][j - 1]);
+            }
+            // Set to null if only have one data
+            axisMinGaps[i] = min === Number.MAX_VALUE ? null : min;
+        }
+    }
+    return axisMinGaps;
+}
+
 export function makeColumnLayout(barSeries) {
+    var axisMinGaps = getTimeAxesMinGaps(barSeries);
+
     var seriesInfoList = [];
     zrUtil.each(barSeries, function (seriesModel) {
         var data = seriesModel.getData();
         var cartesian = seriesModel.coordinateSystem;
         var baseAxis = cartesian.getBaseAxis();
         var axisExtent = baseAxis.getExtent();
-        var bandWidth = baseAxis.type === 'category'
-            ? baseAxis.getBandWidth()
-            : (Math.abs(axisExtent[1] - axisExtent[0]) / data.count());
+
+        var bandWidth;
+        switch (baseAxis.type) {
+            case 'category':
+                bandWidth = baseAxis.getBandWidth();
+                break;
+            case 'time':
+                var minGap = axisMinGaps[baseAxis.index];
+                var extentSpan = Math.abs(axisExtent[1] - axisExtent[0]);
+                var scale = baseAxis.scale.getExtent();
+                var scaleSpan = Math.abs(scale[1] - scale[0]);
+                bandWidth = minGap
+                    ? extentSpan / scaleSpan * minGap
+                    : extentSpan; // When there is only one data value
+                break;
+            default:
+                bandWidth = Math.abs(axisExtent[1] - axisExtent[0]) / data.count();
+        }
 
         var barWidth = parsePercent(
             seriesModel.get('barWidth'), bandWidth


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org


[incubator-echarts] 02/02: test(time): add test for #11145

Posted by ov...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ovilia pushed a commit to branch fix-11145
in repository https://gitbox.apache.org/repos/asf/incubator-echarts.git

commit 779bd1181bc73af4568d07434fc6295dad5f190c
Author: Ovilia <zw...@gmail.com>
AuthorDate: Thu Oct 24 15:21:17 2019 +0800

    test(time): add test for #11145
---
 test/bar2.html                     | 56 ++++++++++++++++++++++++++++++++++++++
 test/runTest/actions/__meta__.json |  3 +-
 test/runTest/actions/bar2.json     |  1 +
 3 files changed, 59 insertions(+), 1 deletion(-)

diff --git a/test/bar2.html b/test/bar2.html
index ca870b5..956179d 100644
--- a/test/bar2.html
+++ b/test/bar2.html
@@ -51,6 +51,7 @@ under the License.
         <div class="chart" id="main3"></div>
         <div class="chart" id="main4"></div>
         <div class="chart" id="main5"></div>
+        <div class="chart" id="main6"></div>
 
 
         <script>
@@ -512,5 +513,60 @@ under the License.
         </script>
 
 
+
+
+        <script>
+            require(['echarts'], function (echarts) {
+                option = {
+                    animation: false,
+                    dataZoom: [
+                        {
+                            "type": "slider",
+                            "show": true
+                        }
+                    ],
+                    color: ['#003366', '#e5323e'],
+                    legend: {
+                        data: ['Forest', 'Desert']
+                    },
+                    xAxis: [
+                        {
+                            type: 'time'
+                        }
+                    ],
+                    yAxis: [
+                        {
+                            type: 'value'
+                        }
+                    ],
+                    series: [
+                        {
+                            name: 'Forest',
+                            type: 'bar',
+                            barGap: 0,
+                            data: [["2017-05-26", 320], ["2017-05-25", 340], ["2017-05-24", 310]]
+                        },
+                        {
+                            name: 'Desert',
+                            type: 'bar',
+                            data: [["2017-05-26", 240], ["2017-05-24", 315]]
+                        }
+                    ],
+                    grid: {
+                        left: 200,
+                        right: 200
+                    }
+                };
+
+                var chart = testHelper.create(echarts, 'main6', {
+                    title: [
+                        'Zoom in and bars should not overlap'
+                    ],
+                    option: option
+                });
+            });
+        </script>
+
+
     </body>
 </html>
\ No newline at end of file
diff --git a/test/runTest/actions/__meta__.json b/test/runTest/actions/__meta__.json
index 1f33b69..5c3688b 100644
--- a/test/runTest/actions/__meta__.json
+++ b/test/runTest/actions/__meta__.json
@@ -136,5 +136,6 @@
   "map-default": 1,
   "map-labels": 1,
   "gauge-simple": 2,
-  "polar-rounded": 2
+  "polar-rounded": 2,
+  "bar2": 2
 }
\ No newline at end of file
diff --git a/test/runTest/actions/bar2.json b/test/runTest/actions/bar2.json
new file mode 100644
index 0000000..33ed444
--- /dev/null
+++ b/test/runTest/actions/bar2.json
@@ -0,0 +1 @@
+[{"name":"Action 1","ops":[{"type":"mousemove","time":50,"x":246,"y":222},{"type":"mousemove","time":256,"x":337,"y":215},{"type":"mousemove","time":470,"x":344,"y":215},{"type":"mousedown","time":681,"x":344,"y":215},{"type":"mousemove","time":691,"x":344,"y":215},{"type":"mouseup","time":807,"x":344,"y":215},{"time":808,"delay":400,"type":"screenshot-auto"},{"type":"mousedown","time":1823,"x":344,"y":215},{"type":"mouseup","time":1958,"x":344,"y":215},{"time":1959,"delay":400,"type":"s [...]
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org