Skip to content

Commit

Permalink
Merge pull request #16714 from apache/fix-heatmap-gap
Browse files Browse the repository at this point in the history
fix(heatmap): avoid the unexpected gaps when dpr is not an integer
  • Loading branch information
plainheart authored Mar 22, 2022
2 parents a4cda9f + a5ad5de commit 5c9430c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 12 deletions.
20 changes: 11 additions & 9 deletions src/chart/heatmap/HeatmapView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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();
}
Expand All @@ -212,7 +214,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'),
Expand All @@ -227,7 +229,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);

Expand All @@ -248,10 +250,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
});
Expand Down
6 changes: 5 additions & 1 deletion test/heatmap-gap-bug.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions test/heatmap-large.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/runTest/actions/__meta__.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/runTest/actions/heatmap-gap-bug.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5c9430c

Please sign in to comment.