Skip to content

Commit

Permalink
Merge pull request apache#15686 from apache/fix/dataset-perf
Browse files Browse the repository at this point in the history
fix: Fix MarkLine/MarkPoint/MarkArea do not work on time axis if input string time format
  • Loading branch information
100pah authored Sep 7, 2021
2 parents eb42349 + ef1d850 commit babc67d
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 44 deletions.
42 changes: 20 additions & 22 deletions src/component/marker/MarkAreaView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { enableHoverEmphasis, setStatesStylesFromModel } from '../../util/states
import * as markerHelper from './markerHelper';
import MarkerView from './MarkerView';
import { retrieve, mergeAll, map, curry, filter, HashMap, extend } from 'zrender/src/core/util';
import { ScaleDataValue, ParsedValue, ZRColor } from '../../util/types';
import { ParsedValue, ScaleDataValue, ZRColor } from '../../util/types';
import { CoordinateSystem, isCoordinateSystemType } from '../../coord/CoordinateSystem';
import MarkAreaModel, { MarkArea2DDataItemOption } from './MarkAreaModel';
import SeriesModel from '../../model/Series';
Expand All @@ -41,6 +41,7 @@ import { getVisualFromData } from '../../visual/helper';
import { setLabelStyle, getLabelStatesModels } from '../../label/labelStyle';
import { getECData } from '../../util/innerStore';
import Axis2D from '../../coord/cartesian/Axis2D';
import { parseDataValue } from '../../data/helper/dataValueHelper';

interface MarkAreaDrawGroup {
group: graphic.Group
Expand Down Expand Up @@ -362,11 +363,11 @@ function createList(
maModel: MarkAreaModel
) {

let coordDimsInfos: SeriesDimensionDefine[];
let areaData: SeriesData<MarkAreaModel>;
let dataDims: SeriesDimensionDefine[];
const dims = ['x0', 'y0', 'x1', 'y1'];
if (coordSys) {
coordDimsInfos = map(coordSys && coordSys.dimensions, function (coordDim) {
const coordDimsInfos: SeriesDimensionDefine[] = map(coordSys && coordSys.dimensions, function (coordDim) {
const data = seriesModel.getData();
const info = data.getDimensionInfo(
data.mapDimension(coordDim)
Expand All @@ -378,19 +379,18 @@ function createList(
ordinalMeta: null
});
});
areaData = new SeriesData(map(dims, function (dim, idx) {
return {
name: dim,
type: coordDimsInfos[idx % 2].type
};
}), maModel);
dataDims = map(dims, (dim, idx) => ({
name: dim,
type: coordDimsInfos[idx % 2].type
}));
areaData = new SeriesData(dataDims, maModel);
}
else {
coordDimsInfos = [{
dataDims = [{
name: 'value',
type: 'float'
}];
areaData = new SeriesData(coordDimsInfos, maModel);
areaData = new SeriesData(dataDims, maModel);
}

let optData = map(maModel.get('data'), curry(
Expand All @@ -402,17 +402,15 @@ function createList(
);
}

const dimValueGetter = coordSys ? function (
item: MarkAreaMergedItemOption,
dimName: string,
dataIndex: number,
dimIndex: number
) {
// TODO should convert to ParsedValue?
return item.coord[Math.floor(dimIndex / 2)][dimIndex % 2] as ParsedValue;
} : function (item: MarkAreaMergedItemOption) {
return item.value;
};
const dimValueGetter: markerHelper.MarkerDimValueGetter<MarkAreaMergedItemOption> = coordSys
? function (item, dimName, dataIndex, dimIndex) {
// TODO should convert to ParsedValue?
const rawVal = item.coord[Math.floor(dimIndex / 2)][dimIndex % 2];
return parseDataValue(rawVal, dataDims[dimIndex]);
}
: function (item, dimName, dataIndex, dimIndex) {
return parseDataValue(item.value, dataDims[dimIndex]);
};
areaData.initData(optData, null, dimValueGetter);
areaData.hasItemOption = true;
return areaData;
Expand Down
9 changes: 5 additions & 4 deletions src/component/marker/MarkLineView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import { makeInner } from '../../util/model';
import { LineDataVisual } from '../../visual/commonVisualTypes';
import { getVisualFromData } from '../../visual/helper';
import Axis2D from '../../coord/cartesian/Axis2D';
import SeriesDimensionDefine from '../../data/SeriesDimensionDefine';

// Item option for configuring line and each end of symbol.
// Line option. be merged from configuration of two ends.
Expand Down Expand Up @@ -435,7 +436,7 @@ class MarkLineView extends MarkerView {

function createList(coordSys: CoordinateSystem, seriesModel: SeriesModel, mlModel: MarkLineModel) {

let coordDimsInfos;
let coordDimsInfos: SeriesDimensionDefine[];
if (coordSys) {
coordDimsInfos = map(coordSys && coordSys.dimensions, function (coordDim) {
const info = seriesModel.getData().getDimensionInfo(
Expand Down Expand Up @@ -469,9 +470,9 @@ function createList(coordSys: CoordinateSystem, seriesModel: SeriesModel, mlMode
optData, curry(markLineFilter, coordSys)
);
}
const dimValueGetter = coordSys ? markerHelper.dimValueGetter : function (item: MarkLineMergedItemOption) {
return item.value;
};

const dimValueGetter = markerHelper.createMarkerDimValueGetter(!!coordSys, coordDimsInfos);

fromData.initData(
map(optData, function (item) {
return item[0];
Expand Down
12 changes: 5 additions & 7 deletions src/component/marker/MarkPointView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ import MarkPointModel, {MarkPointDataItemOption} from './MarkPointModel';
import GlobalModel from '../../model/Global';
import MarkerModel from './MarkerModel';
import ExtensionAPI from '../../core/ExtensionAPI';
import { HashMap, isFunction, map, defaults, filter, curry, extend } from 'zrender/src/core/util';
import { HashMap, isFunction, map, filter, curry, extend } from 'zrender/src/core/util';
import { getECData } from '../../util/innerStore';
import { getVisualFromData } from '../../visual/helper';
import { ZRColor } from '../../util/types';
import SeriesDimensionDefine from '../../data/SeriesDimensionDefine';

function updateMarkerLayout(
mpData: SeriesData<MarkPointModel>,
Expand Down Expand Up @@ -180,7 +181,7 @@ function createData(
seriesModel: SeriesModel,
mpModel: MarkPointModel
) {
let coordDimsInfos;
let coordDimsInfos: SeriesDimensionDefine[];
if (coordSys) {
coordDimsInfos = map(coordSys && coordSys.dimensions, function (coordDim) {
const info = seriesModel.getData().getDimensionInfo(
Expand Down Expand Up @@ -211,11 +212,8 @@ function createData(
);
}

mpData.initData(dataOpt, null,
coordSys ? markerHelper.dimValueGetter : function (item: MarkPointDataItemOption) {
return item.value;
}
);
const dimValueGetter = markerHelper.createMarkerDimValueGetter(!!coordSys, coordDimsInfos);
mpData.initData(dataOpt, null, dimValueGetter);

return mpData;
}
Expand Down
35 changes: 24 additions & 11 deletions src/component/marker/markerHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import { indexOf, curry, clone, isArray } from 'zrender/src/core/util';
import Axis from '../../coord/Axis';
import { CoordinateSystem } from '../../coord/CoordinateSystem';
import { ScaleDataValue, ParsedValue, DimensionLoose, DimensionName } from '../../util/types';
import { parseDataValue } from '../../data/helper/dataValueHelper';
import SeriesDimensionDefine from '../../data/SeriesDimensionDefine';

interface MarkerAxisInfo {
valueDataDim: DimensionName
Expand All @@ -34,6 +36,13 @@ interface MarkerAxisInfo {
baseDataDim: DimensionName
}

export type MarkerDimValueGetter<TMarkerItemOption> = (
item: TMarkerItemOption,
dimName: string,
dataIndex: number,
dimIndex: number
) => ParsedValue;

function hasXOrY(item: MarkerPositionOption) {
return !(isNaN(parseFloat(item.x as string)) && isNaN(parseFloat(item.y as string)));
}
Expand Down Expand Up @@ -187,17 +196,21 @@ export function dataFilter(
? coordSys.containData(item.coord) : true;
}

export function dimValueGetter(
item: MarkerPositionOption,
dimName: string,
dataIndex: number,
dimIndex: number
) {
// x, y, radius, angle
if (dimIndex < 2) {
return item.coord && item.coord[dimIndex] as ParsedValue;
}
return item.value;
export function createMarkerDimValueGetter(
inCoordSys: boolean,
dims: SeriesDimensionDefine[]
): MarkerDimValueGetter<MarkerPositionOption> {
return inCoordSys
? function (item, dimName, dataIndex, dimIndex) {
const rawVal = dimIndex < 2
// x, y, radius, angle
? (item.coord && item.coord[dimIndex])
: item.value;
return parseDataValue(rawVal, dims[dimIndex]);
}
: function (item, dimName, dataIndex, dimIndex) {
return parseDataValue(item.value, dims[dimIndex]);
};
}

export function numCalculate(
Expand Down
111 changes: 111 additions & 0 deletions test/marker-case.html

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

0 comments on commit babc67d

Please sign in to comment.