From 1ee8ef87ca0074e8d289a5d962f1df83e9c00961 Mon Sep 17 00:00:00 2001 From: skie1997 Date: Mon, 12 Jun 2023 15:49:34 +0800 Subject: [PATCH 1/4] refactor(marker): optimize marker performance with domain judgement --- packages/vchart/src/component/marker/utils.ts | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/packages/vchart/src/component/marker/utils.ts b/packages/vchart/src/component/marker/utils.ts index 4837a09518..43802c169d 100644 --- a/packages/vchart/src/component/marker/utils.ts +++ b/packages/vchart/src/component/marker/utils.ts @@ -17,9 +17,12 @@ export function xLayout( const lines: [IPointLike, IPointLike][] = []; const dataPoints = data.latestData[0].latestData ? data.latestData[0].latestData : data.latestData; + const xDomain = relativeSeries.getXAxisHelper().getScale(0).domain(); dataPoints.forEach((datum: IPointLike) => { if (isValid(datum.x)) { - isNumber(datum.x) && relativeSeries?.getXAxisHelper().setExtendDomain?.('marker_xAxis_extend', datum.x); + isNumber(datum.x) && + isNeedExtendDomain(xDomain, datum.x) && + relativeSeries?.getXAxisHelper().setExtendDomain?.('marker_xAxis_extend', datum.x); const x = relativeSeries.getXAxisHelper().dataToPosition([datum.x]) + regionStartLayoutStartPoint.x; const y = Math.max( regionStartLayoutStartPoint.y + regionStart.getLayoutRect().height, @@ -55,9 +58,12 @@ export function yLayout( const lines: [IPointLike, IPointLike][] = []; const dataPoints = data.latestData[0].latestData ? data.latestData[0].latestData : data.latestData; + const yDomain = relativeSeries.getYAxisHelper().getScale(0).domain(); dataPoints.forEach((datum: IPointLike) => { if (isValid(datum.y)) { - isNumber(datum.y) && relativeSeries.getYAxisHelper()?.setExtendDomain?.('marker_yAxis_extend', datum.y); + isNumber(datum.y) && + isNeedExtendDomain(yDomain, datum.y) && + relativeSeries.getYAxisHelper()?.setExtendDomain?.('marker_yAxis_extend', datum.y); const x = Math.min(regionStartLayoutStartPoint.x, regionEndLayoutStartPoint.x); const y = relativeSeries.getYAxisHelper().dataToPosition([datum.y]) + regionStartLayoutStartPoint.y; const x1 = Math.max( @@ -92,9 +98,14 @@ export function coordinateLayout(data: DataView, relativeSeries: ICartesianSerie const refRelativeSeries = datum?.getRefRelativeSeries ? datum.getRefRelativeSeries() : relativeSeries; const regionStart = refRelativeSeries.getRegion(); const regionStartLayoutStartPoint = regionStart.getLayoutStartPoint(); + const xDomain = refRelativeSeries.getXAxisHelper().getScale(0).domain(); + const yDomain = refRelativeSeries.getYAxisHelper().getScale(0).domain(); isNumber(datum.x) && + isNeedExtendDomain(xDomain, datum.x) && refRelativeSeries.getXAxisHelper()?.setExtendDomain?.('marker_xAxis_extend', datum.x as number); + isNumber(datum.y) && + isNeedExtendDomain(yDomain, datum.y) && refRelativeSeries.getYAxisHelper()?.setExtendDomain?.('marker_yAxis_extend', datum.y as number); points.push({ x: refRelativeSeries.getXAxisHelper().dataToPosition([datum.x]) + regionStartLayoutStartPoint.x, @@ -104,3 +115,12 @@ export function coordinateLayout(data: DataView, relativeSeries: ICartesianSerie ); return points; } + +function isNeedExtendDomain(domain: number[], datum: number) { + const min = Math.min(...domain); + const max = Math.max(...domain); + if (datum < min || datum > max) { + return true; + } + return false; +} From a6906bc578e3cdb8676efc5e2da852f7a109a653 Mon Sep 17 00:00:00 2001 From: skie1997 Date: Mon, 12 Jun 2023 16:41:18 +0800 Subject: [PATCH 2/4] refactor(marker): change log --- .../refactor-marker-performance_2023-06-12-08-40.json | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 common/changes/@visactor/vchart/refactor-marker-performance_2023-06-12-08-40.json diff --git a/common/changes/@visactor/vchart/refactor-marker-performance_2023-06-12-08-40.json b/common/changes/@visactor/vchart/refactor-marker-performance_2023-06-12-08-40.json new file mode 100644 index 0000000000..30b7d1b607 --- /dev/null +++ b/common/changes/@visactor/vchart/refactor-marker-performance_2023-06-12-08-40.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@visactor/vchart", + "comment": "refactor(marker): optimize performance", + "type": "none" + } + ], + "packageName": "@visactor/vchart" +} \ No newline at end of file From a1606e8308c2de87ffe08081c136f9dc609b3531 Mon Sep 17 00:00:00 2001 From: skie1997 Date: Thu, 15 Jun 2023 17:22:45 +0800 Subject: [PATCH 3/4] fix: lock file update --- common/config/rush/pnpm-lock.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index 9eec1a1571..b6cf39285a 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -20529,4 +20529,4 @@ packages: /zwitch/1.0.5: resolution: {integrity: sha512-V50KMwwzqJV0NpZIZFwfOD5/lyny3WlSzRiXgA0G7VUnRlqttta1L6UQIHzd6EuBY/cHGfwTIck7w1yH6Q5zUw==} - dev: true + dev: true \ No newline at end of file From 10901d3929965633cc8d5fe83763b2b5d028ea78 Mon Sep 17 00:00:00 2001 From: skie1997 Date: Mon, 12 Jun 2023 15:49:34 +0800 Subject: [PATCH 4/4] refactor(marker): optimize marker performance with domain judgement --- common/config/rush/pnpm-lock.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index b6cf39285a..9eec1a1571 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -20529,4 +20529,4 @@ packages: /zwitch/1.0.5: resolution: {integrity: sha512-V50KMwwzqJV0NpZIZFwfOD5/lyny3WlSzRiXgA0G7VUnRlqttta1L6UQIHzd6EuBY/cHGfwTIck7w1yH6Q5zUw==} - dev: true \ No newline at end of file + dev: true