Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perf/pictogram #3724

Merged
merged 2 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@visactor/vchart",
"comment": "refactor: optimize performance of pictogram",
"type": "none"
}
],
"packageName": "@visactor/vchart"
}
15 changes: 12 additions & 3 deletions packages/vchart/src/series/pictogram/pictogram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type { IMatrix } from '@visactor/vutils';
import { Bounds, Matrix, isValid, merge } from '@visactor/vutils';
import type { Datum } from '../../typings';
import { createRect } from '@visactor/vrender-core';
import type { Group, IGraphic } from '@visactor/vrender-core';
import type { Group } from '@visactor/vrender-core';
import { VGRAMMAR_HOOK_EVENT } from '../../constant/event';
import type { IHoverSpec, ISelectSpec } from '../../interaction/interface';
import { STATE_VALUE_ENUM } from '../../compile/mark';
Expand Down Expand Up @@ -47,6 +47,8 @@ export class PictogramSeries<T extends IPictogramSeriesSpec = IPictogramSeriesSp
protected _parsedSvgResult: SVGParserResult;
private _labelMark: ITextMark;

private _idToMark: Map<string, IMark> = new Map();

setAttrFromSpec() {
super.setAttrFromSpec();
this.svg = this._spec.svg;
Expand Down Expand Up @@ -149,7 +151,7 @@ export class PictogramSeries<T extends IPictogramSeriesSpec = IPictogramSeriesSp
skipBeforeLayouted: true,
dataView: this._mapViewData.getDataView(),
dataProductId: this._mapViewData.getProductId(),
parent: (this._pictogramMark.getMarkInUserId(parent?._uniqueId) as IGroupMark) ?? this._pictogramMark
parent: (this._idToMark.get(parent?._uniqueId) as IGroupMark) ?? this._pictogramMark
},
{
morph: shouldMarkDoMorph(this._spec, PictogramSeries.mark.pictogram.name)
Expand All @@ -158,6 +160,7 @@ export class PictogramSeries<T extends IPictogramSeriesSpec = IPictogramSeriesSp

if (mark) {
mark.setUserId(_uniqueId); // id 必须唯一,但无法控制 svg 中元素有重复 id, 这里做一个保护
this._idToMark.set(_uniqueId, mark);
if (mark.type !== 'group') {
mark.setMarkConfig({ graphicName: mark.name });
}
Expand Down Expand Up @@ -243,7 +246,7 @@ export class PictogramSeries<T extends IPictogramSeriesSpec = IPictogramSeriesSp
}
for (const element of elements) {
const { _uniqueId, _finalAttributes: attributes } = element as SVGParsedElementExtend;
const mark = this._pictogramMark.getMarkInUserId(_uniqueId);
const mark = this._idToMark.get(_uniqueId);
const valid = this._validElement(element);
if (mark) {
// 描边粗细跟随缩放倍数
Expand Down Expand Up @@ -476,6 +479,12 @@ export class PictogramSeries<T extends IPictogramSeriesSpec = IPictogramSeriesSp
} as ISeriesSeriesInfo;
});
}

release(): void {
this._parsedSvgResult = null;
this._idToMark.clear();
this._idToMark = null;
}
}

export const registerPictogramSeries = () => {
Expand Down
Loading