Skip to content

Commit

Permalink
feat(line): show single symbol when pre and next data is null
Browse files Browse the repository at this point in the history
  • Loading branch information
linghaoSu committed Aug 8, 2023
1 parent 586ca04 commit c771fdb
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 16 deletions.
12 changes: 12 additions & 0 deletions src/chart/helper/SymbolDraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import Element from 'zrender/src/Element';
import SeriesModel from '../../model/Series';

interface UpdateOpt {
showSingleSymbol?: boolean;
isIgnore?(idx: number): boolean
clipShape?: CoordinateSystemClipArea,
getSymbolPoint?(idx: number): number[]
Expand All @@ -60,6 +61,17 @@ interface SymbolLikeCtor {
}

function symbolNeedsDraw(data: SeriesData, point: number[], idx: number, opt: UpdateOpt) {
if (opt.showSingleSymbol) {
const dataCount = data.count();
if (
data.getRawDataItem(idx) === null
|| (idx !== 0 && data.getRawDataItem(idx - 1) !== null)
|| (idx !== dataCount - 1 && data.getRawDataItem(idx + 1) !== null)
) {
return false;
}
}

return point && !isNaN(point[0]) && !isNaN(point[1])
&& !(opt.isIgnore && opt.isIgnore(idx))
// We do not set clipShape on group, because it will cut part of
Expand Down
38 changes: 22 additions & 16 deletions src/chart/line/LineView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -701,14 +701,17 @@ class LineView extends ChartView {
if (
!(polyline && prevCoordSys.type === coordSys.type && step === this._step)
) {
showSymbol && symbolDraw.updateData(data, {
isIgnore: isIgnoreFunc,
clipShape: clipShapeForSymbol,
disableAnimation: true,
getSymbolPoint(idx) {
return [points[idx * 2], points[idx * 2 + 1]];
}
});
if (showSymbol || !connectNulls) {
symbolDraw.updateData(data, {
showSingleSymbol: showSymbol === false && !connectNulls,
isIgnore: isIgnoreFunc,
clipShape: clipShapeForSymbol,
disableAnimation: true,
getSymbolPoint(idx) {
return [points[idx * 2], points[idx * 2 + 1]];
}
});
}

hasAnimation && this._initSymbolLabelAnimation(
data,
Expand Down Expand Up @@ -779,14 +782,17 @@ class LineView extends ChartView {

// Always update, or it is wrong in the case turning on legend
// because points are not changed.
showSymbol && symbolDraw.updateData(data, {
isIgnore: isIgnoreFunc,
clipShape: clipShapeForSymbol,
disableAnimation: true,
getSymbolPoint(idx) {
return [points[idx * 2], points[idx * 2 + 1]];
}
});
if (showSymbol || !connectNulls) {
symbolDraw.updateData(data, {
showSingleSymbol: showSymbol === false && !connectNulls,
isIgnore: isIgnoreFunc,
clipShape: clipShapeForSymbol,
disableAnimation: true,
getSymbolPoint(idx) {
return [points[idx * 2], points[idx * 2 + 1]];
}
});
}

// In the case data zoom triggered refreshing frequently
// Data may not change if line has a category axis. So it should animate nothing.
Expand Down
104 changes: 104 additions & 0 deletions test/lines-single-symbol.html

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

0 comments on commit c771fdb

Please sign in to comment.