Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions src/chart/heatmap/HeatmapView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import * as graphic from '../../util/graphic';
import { toggleHoverEmphasis } from '../../util/states';
import HeatmapLayer from './HeatmapLayer';
import * as zrUtil from 'zrender/src/core/util';
import tokens from '../../visual/tokens';
import ChartView from '../../view/Chart';
import HeatmapSeriesModel, { HeatmapDataItemOption } from './HeatmapSeries';
import type GlobalModel from '../../model/Global';
Expand All @@ -29,7 +30,7 @@ import type VisualMapModel from '../../component/visualMap/VisualMapModel';
import type PiecewiseModel from '../../component/visualMap/PiecewiseModel';
import type ContinuousModel from '../../component/visualMap/ContinuousModel';
import { CoordinateSystem, isCoordinateSystemType } from '../../coord/CoordinateSystem';
import { StageHandlerProgressParams, Dictionary, OptionDataValue } from '../../util/types';
import { StageHandlerProgressParams, Dictionary, OptionDataValue, ZRColor } from '../../util/types';
import type Cartesian2D from '../../coord/cartesian/Cartesian2D';
import type Calendar from '../../coord/calendar/Calendar';
import { setLabelStyle, getLabelStatesModels } from '../../label/labelStyle';
Expand Down Expand Up @@ -130,11 +131,12 @@ class HeatmapView extends ChartView {
this.group.removeAll();

const coordSys = seriesModel.coordinateSystem;
const emptyCellFill: ZRColor = ecModel.get('backgroundColor') || tokens.color.neutral00;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should probably use tokens.color.background instead.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in adb71c1 to use tokens.color.background as the fallback instead of tokens.color.neutral00.

if (coordSys.type === 'cartesian2d'
|| coordSys.type === 'calendar'
|| coordSys.type === 'matrix'
) {
this._renderOnGridLike(seriesModel, api, 0, seriesModel.getData().count());
this._renderOnGridLike(seriesModel, api, emptyCellFill, 0, seriesModel.getData().count());
}
else if (isGeoCoordSys(coordSys)) {
this._renderOnGeo(
Expand All @@ -154,14 +156,15 @@ class HeatmapView extends ChartView {
api: ExtensionAPI
) {
const coordSys = seriesModel.coordinateSystem;
const emptyCellFill: ZRColor = ecModel.get('backgroundColor') || tokens.color.neutral00;
if (coordSys) {
// geo does not support incremental rendering?
if (isGeoCoordSys(coordSys)) {
this.render(seriesModel, ecModel, api);
}
else {
this._progressiveEls = [];
this._renderOnGridLike(seriesModel, api, params.start, params.end, true);
this._renderOnGridLike(seriesModel, api, emptyCellFill, params.start, params.end, true);
}
}
}
Expand All @@ -173,6 +176,7 @@ class HeatmapView extends ChartView {
_renderOnGridLike(
seriesModel: HeatmapSeriesModel,
api: ExtensionAPI,
emptyCellFill: ZRColor,
start: number,
end: number,
incremental?: boolean
Expand Down Expand Up @@ -236,10 +240,11 @@ class HeatmapView extends ChartView {
if (isCartesian2d) {
const dataDimX = data.get(dataDims[0], idx);
const dataDimY = data.get(dataDims[1], idx);
const value = data.get(dataDims[2], idx) as number;

// Ignore empty data and out of extent data
if (isNaN(data.get(dataDims[2], idx) as number)
|| isNaN(dataDimX as number)
// Ignore out of extent data. Preserve empty cells so splitArea
// does not show through inconsistently behind them.
if (isNaN(dataDimX as number)
|| isNaN(dataDimY as number)
|| dataDimX < xAxisExtent[0]
|| dataDimX > xAxisExtent[1]
Expand All @@ -253,6 +258,7 @@ class HeatmapView extends ChartView {
dataDimX,
dataDimY
]);
const emptyCell = isNaN(value);

rect = new graphic.Rect({
shape: {
Expand All @@ -261,21 +267,31 @@ class HeatmapView extends ChartView {
width,
height
},
style
style: emptyCell
? zrUtil.extend(zrUtil.extend({}, style), {
fill: emptyCellFill
})
: style
});
}
else if (isMatrix) {
const value = data.get(dataDims[2], idx) as number;
const shape = coordSys.dataToLayout([
data.get(dataDims[0], idx),
data.get(dataDims[1], idx)
]).rect;
if (zrUtil.eqNaN(shape.x)) {
continue;
}
const emptyCell = isNaN(value);
rect = new graphic.Rect({
z2: 1,
shape,
style,
style: emptyCell
? zrUtil.extend(zrUtil.extend({}, style), {
fill: emptyCellFill
})
: style,
});
}
else { // Calendar
Expand Down
82 changes: 82 additions & 0 deletions test/ut/spec/series/heatmap.test.ts

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