Skip to content

Commit

Permalink
fix(line): use ignore function to implement line symbol show between …
Browse files Browse the repository at this point in the history
…null
  • Loading branch information
linghaoSu committed Aug 8, 2023
1 parent c771fdb commit bacb997
Show file tree
Hide file tree
Showing 5 changed files with 189 additions and 92 deletions.
12 changes: 0 additions & 12 deletions src/chart/helper/SymbolDraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ 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 @@ -61,17 +60,6 @@ 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
48 changes: 44 additions & 4 deletions src/chart/line/LineView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,43 @@ function getIsIgnoreFunc(
};
}

function getIsSingleSymbolIgnore(
seriesModel: LineSeriesModel,
data: SeriesData,
coordSys: Cartesian2D
) {
const intervalAxis = coordSys.getAxesByScale('interval')[0];

if (!intervalAxis) {
return;
}

const intervalDataDim = data.mapDimension(intervalAxis.dim);

const count = data.count();

const singleDataIdxStateList: boolean[] = [];

for (let i = 0; i < count; i++) {
const intervalValue = data.get(intervalDataDim, i);

if (typeof intervalValue === 'number' && isNaN(intervalValue)) {
singleDataIdxStateList[i] = false;
}
else {
singleDataIdxStateList[i] = true;
}

}


return function (dataIndex: number) {
return singleDataIdxStateList[dataIndex - 1]
|| !singleDataIdxStateList[dataIndex]
|| singleDataIdxStateList[dataIndex + 1];
};
}

function canShowAllSymbolForCategory(
categoryAxis: Axis2D,
data: SeriesData
Expand Down Expand Up @@ -657,8 +694,13 @@ class LineView extends ChartView {

const connectNulls = seriesModel.get('connectNulls');

const isIgnoreFunc = showSymbol && !isCoordSysPolar
&& getIsIgnoreFunc(seriesModel, data, coordSys as Cartesian2D);
const isIgnoreFunc = showSymbol ? !isCoordSysPolar
&& getIsIgnoreFunc(seriesModel, data, coordSys as Cartesian2D)
: (
!isCoordSysPolar
&& !connectNulls
&& getIsSingleSymbolIgnore(seriesModel, data, coordSys as Cartesian2D)
);

// Remove temporary symbols
const oldData = this._data;
Expand Down Expand Up @@ -703,7 +745,6 @@ class LineView extends ChartView {
) {
if (showSymbol || !connectNulls) {
symbolDraw.updateData(data, {
showSingleSymbol: showSymbol === false && !connectNulls,
isIgnore: isIgnoreFunc,
clipShape: clipShapeForSymbol,
disableAnimation: true,
Expand Down Expand Up @@ -784,7 +825,6 @@ class LineView extends ChartView {
// because points are not changed.
if (showSymbol || !connectNulls) {
symbolDraw.updateData(data, {
showSingleSymbol: showSymbol === false && !connectNulls,
isIgnore: isIgnoreFunc,
clipShape: clipShapeForSymbol,
disableAnimation: true,
Expand Down
219 changes: 143 additions & 76 deletions test/lines-single-symbol.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/lines-single-symbol.json

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

0 comments on commit bacb997

Please sign in to comment.