You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by wa...@apache.org on 2022/01/22 18:43:46 UTC

[echarts] branch fix-heatmap-gap created (now a5ad5de)

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

wangzx pushed a change to branch fix-heatmap-gap
in repository https://gitbox.apache.org/repos/asf/echarts.git.


      at a5ad5de  fix(heatmap): add 0.5px to avoid the gaps in Cartesian 2D coordinate system when dpr is not an integer.

This branch includes the following new commits:

     new a5ad5de  fix(heatmap): add 0.5px to avoid the gaps in Cartesian 2D coordinate system when dpr is not an integer.

The 1 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


[echarts] 01/01: fix(heatmap): add 0.5px to avoid the gaps in Cartesian 2D coordinate system when dpr is not an integer.

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

wangzx pushed a commit to branch fix-heatmap-gap
in repository https://gitbox.apache.org/repos/asf/echarts.git

commit a5ad5debafffeea84ae8d246f15aa303b297782c
Author: plainheart <yh...@all-my-life.cn>
AuthorDate: Sun Jan 23 01:49:08 2022 +0800

    fix(heatmap): add 0.5px to avoid the gaps in Cartesian 2D coordinate system when dpr is not an integer.
---
 src/chart/heatmap/HeatmapView.ts          | 20 +++++++++++---------
 test/heatmap-gap-bug.html                 |  6 +++++-
 test/heatmap-large.html                   |  8 ++++++--
 test/runTest/actions/__meta__.json        |  1 +
 test/runTest/actions/heatmap-gap-bug.json |  1 +
 5 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/src/chart/heatmap/HeatmapView.ts b/src/chart/heatmap/HeatmapView.ts
index 253fe50..f366905 100644
--- a/src/chart/heatmap/HeatmapView.ts
+++ b/src/chart/heatmap/HeatmapView.ts
@@ -175,12 +175,13 @@ class HeatmapView extends ChartView {
     ) {
 
         const coordSys = seriesModel.coordinateSystem as Cartesian2D | Calendar;
+        const isCartesian2d = isCoordinateSystemType<Cartesian2D>(coordSys, 'cartesian2d');
         let width;
         let height;
         let xAxisExtent;
         let yAxisExtent;
 
-        if (isCoordinateSystemType<Cartesian2D>(coordSys, 'cartesian2d')) {
+        if (isCartesian2d) {
             const xAxis = coordSys.getAxis('x');
             const yAxis = coordSys.getAxis('y');
 
@@ -193,8 +194,9 @@ class HeatmapView extends ChartView {
                 }
             }
 
-            width = xAxis.getBandWidth();
-            height = yAxis.getBandWidth();
+            // add 0.5px to avoid the gaps
+            width = xAxis.getBandWidth() + .5;
+            height = yAxis.getBandWidth() + .5;
             xAxisExtent = xAxis.scale.getExtent();
             yAxisExtent = yAxis.scale.getExtent();
         }
@@ -211,7 +213,7 @@ class HeatmapView extends ChartView {
         let blurScope = emphasisModel.get('blurScope');
         let emphasisDisabled = emphasisModel.get('disabled');
 
-        const dataDims = isCoordinateSystemType<Cartesian2D>(coordSys, 'cartesian2d')
+        const dataDims = isCartesian2d
             ? [
                 data.mapDimension('x'),
                 data.mapDimension('y'),
@@ -226,7 +228,7 @@ class HeatmapView extends ChartView {
             let rect;
             const style = data.getItemVisual(idx, 'style');
 
-            if (isCoordinateSystemType<Cartesian2D>(coordSys, 'cartesian2d')) {
+            if (isCartesian2d) {
                 const dataDimX = data.get(dataDims[0], idx);
                 const dataDimY = data.get(dataDims[1], idx);
 
@@ -247,10 +249,10 @@ class HeatmapView extends ChartView {
 
                 rect = new graphic.Rect({
                     shape: {
-                        x: Math.floor(Math.round(point[0]) - width / 2),
-                        y: Math.floor(Math.round(point[1]) - height / 2),
-                        width: Math.ceil(width),
-                        height: Math.ceil(height)
+                        x: point[0] - width / 2,
+                        y: point[1] - height / 2,
+                        width,
+                        height
                     },
                     style
                 });
diff --git a/test/heatmap-gap-bug.html b/test/heatmap-gap-bug.html
index a6793b0..1fd6b73 100644
--- a/test/heatmap-gap-bug.html
+++ b/test/heatmap-gap-bug.html
@@ -97,7 +97,11 @@ under the License.
             </div>
         </div>
         <script>
-
+            // gap usually appears when dpr is not an integer
+            Object.defineProperty(window, 'devicePixelRatio', {
+                value: 2.5,
+                writable: false
+            });
             require([
                 'echarts'
             ], function (echarts) {
diff --git a/test/heatmap-large.html b/test/heatmap-large.html
index d0be16b..9271ad2 100644
--- a/test/heatmap-large.html
+++ b/test/heatmap-large.html
@@ -36,7 +36,11 @@ under the License.
         </style>
         <div id="main"></div>
         <script>
-
+            // gap usually appears when dpr is not an integer
+            Object.defineProperty(window, 'devicePixelRatio', {
+                value: 2.5,
+                writable: false
+            });
             require([
                 'echarts'
             ], function (echarts) {
@@ -111,4 +115,4 @@ under the License.
 
         </script>
     </body>
-</html>
\ No newline at end of file
+</html>
diff --git a/test/runTest/actions/__meta__.json b/test/runTest/actions/__meta__.json
index a20b553..8133605 100644
--- a/test/runTest/actions/__meta__.json
+++ b/test/runTest/actions/__meta__.json
@@ -103,6 +103,7 @@
   "graphic-draggable": 1,
   "graphic-transition": 3,
   "heatmap": 1,
+  "heatmap-gap-bug": 1,
   "heatmap-map": 1,
   "homepage3": 1,
   "hoverFocus": 12,
diff --git a/test/runTest/actions/heatmap-gap-bug.json b/test/runTest/actions/heatmap-gap-bug.json
new file mode 100644
index 0000000..5a3cfca
--- /dev/null
+++ b/test/runTest/actions/heatmap-gap-bug.json
@@ -0,0 +1 @@
+[{"name":"Action 1","ops":[{"type":"mousedown","time":482,"x":413,"y":595},{"type":"mouseup","time":1742,"x":454,"y":595},{"time":1743,"delay":400,"type":"screenshot-auto"},{"type":"mousemove","time":1772,"x":454,"y":595}],"scrollY":0,"scrollX":0,"timestamp":1642876188713}]
\ 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