Skip to content

Commit

Permalink
Merge pull request #3724 from VisActor/perf/pictogram
Browse files Browse the repository at this point in the history
Perf/pictogram
  • Loading branch information
xile611 authored Feb 14, 2025
2 parents b0feae0 + 30d5e13 commit ee6304d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
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

0 comments on commit ee6304d

Please sign in to comment.