@visactor/vrender-components 1.1.5 → 1.1.6-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js CHANGED
@@ -208,7 +208,7 @@ class Node extends EventEmitter {
208
208
  constructor() {
209
209
  super(), this._uid = Generator.GenAutoIncrementId(), this._firstChild = null, this._lastChild = null, this.parent = null, this._count = 1;
210
210
  }
211
- onParentSharedStateTreeChanged(_stage, _layer) {}
211
+ onParentSharedStateTreeChanged(_stage, _layer, _inheritedSharedStateScope) {}
212
212
  forEachChildren(cb, reverse = !1) {
213
213
  if (reverse) {
214
214
  let child = this._lastChild,
@@ -4875,14 +4875,17 @@ class GraphicImpl extends Node {
4875
4875
  }
4876
4876
  return null === (_a = this.stage) || void 0 === _a ? void 0 : _a.rootSharedStateScope;
4877
4877
  }
4878
- syncSharedStateScopeBindingFromTree(markDirty = !0) {
4878
+ syncSharedStateScopeBinding(nextScope, markDirty = !0) {
4879
4879
  var _a;
4880
- const nextScope = this.resolveBoundSharedStateScope();
4881
4880
  return this.boundSharedStateScope === nextScope ? (this.syncSharedStateActiveRegistrations(), !1) : (this.boundSharedStateScope = nextScope, this.boundSharedStateRevision = void 0, this.compiledStateDefinitions = void 0, this.compiledStateDefinitionsCacheKey = void 0, this.stateEngine = void 0, this.stateEngineCompiledDefinitions = void 0, this.syncSharedStateActiveRegistrations(), markDirty && (null === (_a = this.currentStates) || void 0 === _a ? void 0 : _a.length) && this.markSharedStateDirty(), !0);
4882
4881
  }
4883
- syncSharedStateScopeBindingOnTreeChange(markDirty = !0) {
4882
+ syncSharedStateScopeBindingFromTree(markDirty = !0, inheritedSharedStateScope) {
4883
+ const nextScope = void 0 === inheritedSharedStateScope ? this.resolveBoundSharedStateScope() : null != inheritedSharedStateScope ? inheritedSharedStateScope : void 0;
4884
+ return this.syncSharedStateScopeBinding(nextScope, markDirty);
4885
+ }
4886
+ syncSharedStateScopeBindingOnTreeChange(markDirty = !0, inheritedSharedStateScope) {
4884
4887
  var _a, _b;
4885
- return !!((null === (_a = this.currentStates) || void 0 === _a ? void 0 : _a.length) || this.boundSharedStateScope || (null === (_b = this.registeredActiveScopes) || void 0 === _b ? void 0 : _b.size) || this.sharedStateDirty) && this.syncSharedStateScopeBindingFromTree(markDirty);
4888
+ return !!((null === (_a = this.currentStates) || void 0 === _a ? void 0 : _a.length) || this.boundSharedStateScope || (null === (_b = this.registeredActiveScopes) || void 0 === _b ? void 0 : _b.size) || this.sharedStateDirty) && this.syncSharedStateScopeBindingFromTree(markDirty, inheritedSharedStateScope);
4886
4889
  }
4887
4890
  syncSharedStateActiveRegistrations() {
4888
4891
  var _a;
@@ -4890,6 +4893,7 @@ class GraphicImpl extends Node {
4890
4893
  if (!(null === (_a = this.currentStates) || void 0 === _a ? void 0 : _a.length) || !this.boundSharedStateScope) return (null == previousScopes ? void 0 : previousScopes.size) && (previousScopes.forEach(scope => {
4891
4894
  scope.subtreeActiveDescendants.delete(this);
4892
4895
  }), previousScopes.clear()), void (this.registeredActiveScopes = void 0);
4896
+ if ((null == previousScopes ? void 0 : previousScopes.size) && this.isSharedStateScopeChainRegistered(previousScopes)) return;
4893
4897
  const nextScopes = new Set(collectSharedStateScopeChain(this.boundSharedStateScope));
4894
4898
  null == previousScopes || previousScopes.forEach(scope => {
4895
4899
  nextScopes.has(scope) || scope.subtreeActiveDescendants.delete(this);
@@ -4897,6 +4901,15 @@ class GraphicImpl extends Node {
4897
4901
  scope.subtreeActiveDescendants.add(this);
4898
4902
  }), this.registeredActiveScopes = nextScopes;
4899
4903
  }
4904
+ isSharedStateScopeChainRegistered(previousScopes) {
4905
+ let scope = this.boundSharedStateScope,
4906
+ scopeCount = 0;
4907
+ for (; scope;) {
4908
+ if (!previousScopes.has(scope)) return !1;
4909
+ scopeCount += 1, scope = scope.parentScope;
4910
+ }
4911
+ return scopeCount === previousScopes.size;
4912
+ }
4900
4913
  clearSharedStateActiveRegistrations() {
4901
4914
  const previousScopes = this.registeredActiveScopes;
4902
4915
  previousScopes && (previousScopes.forEach(scope => {
@@ -4906,8 +4919,8 @@ class GraphicImpl extends Node {
4906
4919
  markSharedStateDirty() {
4907
4920
  this.sharedStateDirty = !0, enqueueGraphicSharedStateRefresh(this.stage, this), scheduleStageSharedStateRefresh(this.stage);
4908
4921
  }
4909
- onParentSharedStateTreeChanged(stage, layer) {
4910
- this.stage === stage && this.layer === layer ? this.syncSharedStateScopeBindingOnTreeChange() : this.setStage(stage, layer);
4922
+ onParentSharedStateTreeChanged(stage, layer, inheritedSharedStateScope) {
4923
+ this.stage === stage && this.layer === layer ? this.syncSharedStateScopeBindingOnTreeChange(!0, inheritedSharedStateScope) : this.setStage(stage, layer, inheritedSharedStateScope);
4911
4924
  }
4912
4925
  refreshSharedStateBeforeRender() {
4913
4926
  var _a;
@@ -5558,6 +5571,10 @@ class GraphicImpl extends Node {
5558
5571
  var _a;
5559
5572
  return null === (_a = this.states) || void 0 === _a ? void 0 : _a[stateName];
5560
5573
  }
5574
+ setStateDefinitionsWithCompiled(definitions, compiledDefinitions) {
5575
+ var _a;
5576
+ this.states = definitions, this.localStateDefinitionsSource !== definitions && (this.localStateDefinitionsSource = definitions, this.localStateDefinitionsVersion = (null !== (_a = this.localStateDefinitionsVersion) && void 0 !== _a ? _a : 0) + 1), this.compiledStateDefinitions = compiledDefinitions, this.compiledStateDefinitionsCacheKey = `local:${this.localStateDefinitionsVersion}`;
5577
+ }
5561
5578
  getStateResolveBaseAttrs() {
5562
5579
  var _a;
5563
5580
  return null !== (_a = this.baseAttributes) && void 0 !== _a ? _a : this.attribute;
@@ -5905,12 +5922,12 @@ class GraphicImpl extends Node {
5905
5922
  this._globalTransMatrix.translate(scrollX, scrollY);
5906
5923
  }
5907
5924
  }
5908
- setStage(stage, layer) {
5925
+ setStage(stage, layer, inheritedSharedStateScope) {
5909
5926
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
5910
5927
  const graphicService = null !== (_c = null !== (_a = null == stage ? void 0 : stage.graphicService) && void 0 !== _a ? _a : null === (_b = this.stage) || void 0 === _b ? void 0 : _b.graphicService) && void 0 !== _c ? _c : application.graphicService,
5911
5928
  previousStage = this.stage;
5912
5929
  if (this.stage !== stage || this.layer !== layer) {
5913
- if (this.stage = stage, this.layer = layer, ((null === (_d = this.currentStates) || void 0 === _d ? void 0 : _d.length) || this.boundSharedStateScope || (null === (_e = this.registeredActiveScopes) || void 0 === _e ? void 0 : _e.size) || this.sharedStateDirty) && this.syncSharedStateScopeBindingOnTreeChange(!0), this.setStageToShadowRoot(stage, layer), this.mayHaveTrackedAnimates() && this.hasAnyTrackedAnimate()) {
5930
+ if (this.stage = stage, this.layer = layer, ((null === (_d = this.currentStates) || void 0 === _d ? void 0 : _d.length) || this.boundSharedStateScope || (null === (_e = this.registeredActiveScopes) || void 0 === _e ? void 0 : _e.size) || this.sharedStateDirty) && this.syncSharedStateScopeBindingOnTreeChange(!0, inheritedSharedStateScope), this.setStageToShadowRoot(stage, layer), this.mayHaveTrackedAnimates() && this.hasAnyTrackedAnimate()) {
5914
5931
  const previousTimeline = null === (_f = null == previousStage ? void 0 : previousStage.getTimeline) || void 0 === _f ? void 0 : _f.call(previousStage),
5915
5932
  nextTimeline = null === (_g = null == stage ? void 0 : stage.getTimeline) || void 0 === _g ? void 0 : _g.call(stage),
5916
5933
  detachedStageAnimates = [];
@@ -5927,7 +5944,7 @@ class GraphicImpl extends Node {
5927
5944
  }
5928
5945
  return this._onSetStage && this._onSetStage(this, stage, layer), void (null === (_h = null == graphicService ? void 0 : graphicService.onSetStage) || void 0 === _h || _h.call(graphicService, this, stage));
5929
5946
  }
5930
- ((null === (_j = this.currentStates) || void 0 === _j ? void 0 : _j.length) || this.boundSharedStateScope || (null === (_k = this.registeredActiveScopes) || void 0 === _k ? void 0 : _k.size) || this.sharedStateDirty) && this.syncSharedStateScopeBindingOnTreeChange(!0);
5947
+ ((null === (_j = this.currentStates) || void 0 === _j ? void 0 : _j.length) || this.boundSharedStateScope || (null === (_k = this.registeredActiveScopes) || void 0 === _k ? void 0 : _k.size) || this.sharedStateDirty) && this.syncSharedStateScopeBindingOnTreeChange(!0, inheritedSharedStateScope);
5931
5948
  }
5932
5949
  detachStageForRelease() {
5933
5950
  var _a, _b, _c;
@@ -6349,13 +6366,13 @@ class Group extends Graphic {
6349
6366
  child.setStage(null, null);
6350
6367
  }), this.addUpdateBoundTag();
6351
6368
  }
6352
- setStage(stage, layer) {
6369
+ setStage(stage, layer, inheritedSharedStateScope) {
6353
6370
  var _a, _b, _c, _d, _e, _f;
6354
6371
  const graphicService = null !== (_c = null !== (_a = null == stage ? void 0 : stage.graphicService) && void 0 !== _a ? _a : null === (_b = this.stage) || void 0 === _b ? void 0 : _b.graphicService) && void 0 !== _c ? _c : application.graphicService,
6355
6372
  needsSharedStateTreeSync = this.hasSharedStateDefinitions() || this.sharedStateScope || (null === (_d = this.currentStates) || void 0 === _d ? void 0 : _d.length) || this.boundSharedStateScope || (null === (_e = this.registeredActiveScopes) || void 0 === _e ? void 0 : _e.size) || this.sharedStateDirty;
6356
- if (this.stage !== stage) return this.stage = stage, this.layer = layer, needsSharedStateTreeSync && (this.ensureSharedStateScopeBound(), this.syncSharedStateScopeBindingOnTreeChange(!0)), this.setStageToShadowRoot(stage, layer), this._onSetStage && this._onSetStage(this, stage, layer), null === (_f = null == graphicService ? void 0 : graphicService.onSetStage) || void 0 === _f || _f.call(graphicService, this, stage), void this.notifyChildrenSharedStateTreeChanged();
6373
+ if (this.stage !== stage) return this.stage = stage, this.layer = layer, needsSharedStateTreeSync && (this.ensureSharedStateScopeBound(), this.syncSharedStateScopeBindingOnTreeChange(!0, inheritedSharedStateScope)), this.setStageToShadowRoot(stage, layer), this._onSetStage && this._onSetStage(this, stage, layer), null === (_f = null == graphicService ? void 0 : graphicService.onSetStage) || void 0 === _f || _f.call(graphicService, this, stage), void this.notifyChildrenSharedStateTreeChanged(inheritedSharedStateScope);
6357
6374
  const layerChanged = this.layer !== layer;
6358
- layerChanged && (this.layer = layer), needsSharedStateTreeSync ? (this.ensureSharedStateScopeBound(), this.syncSharedStateScopeBindingOnTreeChange(!0), this.notifyChildrenSharedStateTreeChanged()) : layerChanged && this.notifyChildrenSharedStateTreeChanged();
6375
+ layerChanged && (this.layer = layer), needsSharedStateTreeSync ? (this.ensureSharedStateScopeBound(), this.syncSharedStateScopeBindingOnTreeChange(!0, inheritedSharedStateScope), this.notifyChildrenSharedStateTreeChanged(inheritedSharedStateScope)) : layerChanged && this.notifyChildrenSharedStateTreeChanged(inheritedSharedStateScope);
6359
6376
  }
6360
6377
  addUpdatePositionTag() {
6361
6378
  super.addUpdatePositionTag(), this.forEachChildren(g => {
@@ -6414,17 +6431,26 @@ class Group extends Graphic {
6414
6431
  hasSharedStateDefinitions() {
6415
6432
  return !!this._sharedStateDefinitions && Object.keys(this._sharedStateDefinitions).length > 0;
6416
6433
  }
6417
- notifyChildrenSharedStateTreeChanged() {
6434
+ resolveChildSharedStateScope(inheritedSharedStateScope) {
6435
+ var _a;
6436
+ return this.sharedStateScope ? this.sharedStateScope : void 0 !== inheritedSharedStateScope ? inheritedSharedStateScope : null !== (_a = this.resolveBoundSharedStateScope()) && void 0 !== _a ? _a : null;
6437
+ }
6438
+ notifyChildrenSharedStateTreeChanged(inheritedSharedStateScope) {
6439
+ const childSharedStateScope = this.resolveChildSharedStateScope(inheritedSharedStateScope);
6418
6440
  this.forEachChildren(item => {
6419
- this.syncChildSharedStateTreeBinding(item);
6441
+ this.setStageToChild(item, childSharedStateScope);
6420
6442
  });
6421
6443
  }
6422
- syncChildSharedStateTreeBinding(child) {
6423
- child.onParentSharedStateTreeChanged(this.stage, this.layer);
6444
+ setStageToChild(child, inheritedSharedStateScope) {
6445
+ const graphic = child;
6446
+ "function" != typeof graphic.setStage || child.onParentSharedStateTreeChanged !== Graphic.prototype.onParentSharedStateTreeChanged && child.onParentSharedStateTreeChanged !== Group.prototype.onParentSharedStateTreeChanged || graphic.stage === this.stage && graphic.layer === this.layer ? child.onParentSharedStateTreeChanged(this.stage, this.layer, inheritedSharedStateScope) : graphic.setStage(this.stage, this.layer, inheritedSharedStateScope);
6424
6447
  }
6425
- onParentSharedStateTreeChanged(stage, layer) {
6448
+ syncChildSharedStateTreeBinding(child, inheritedSharedStateScope) {
6449
+ void 0 === inheritedSharedStateScope && (inheritedSharedStateScope = this.resolveChildSharedStateScope()), this.setStageToChild(child, inheritedSharedStateScope);
6450
+ }
6451
+ onParentSharedStateTreeChanged(stage, layer, inheritedSharedStateScope) {
6426
6452
  var _a;
6427
- this.stage === stage && this.layer === layer ? (this.ensureSharedStateScopeBound(), this.syncSharedStateScopeBindingOnTreeChange(!!(null === (_a = this.currentStates) || void 0 === _a ? void 0 : _a.length)), this.notifyChildrenSharedStateTreeChanged()) : this.setStage(stage, layer);
6453
+ this.stage === stage && this.layer === layer ? (this.ensureSharedStateScopeBound(), this.syncSharedStateScopeBindingOnTreeChange(!!(null === (_a = this.currentStates) || void 0 === _a ? void 0 : _a.length), inheritedSharedStateScope), this.notifyChildrenSharedStateTreeChanged(inheritedSharedStateScope)) : this.setStage(stage, layer, inheritedSharedStateScope);
6428
6454
  }
6429
6455
  }
6430
6456
  Group.NOWORK_ANIMATE_ATTR = NOWORK_ANIMATE_ATTR;
@@ -9027,8 +9053,8 @@ class RichText extends Graphic {
9027
9053
  clone() {
9028
9054
  return new RichText(Object.assign({}, this.attribute));
9029
9055
  }
9030
- setStage(stage, layer) {
9031
- super.setStage(stage, layer);
9056
+ setStage(stage, layer, inheritedSharedStateScope) {
9057
+ super.setStage(stage, layer, inheritedSharedStateScope);
9032
9058
  this.getFrameCache().icons.forEach(icon => {
9033
9059
  icon.setStage(stage, layer);
9034
9060
  });
@@ -30004,6 +30030,7 @@ class DiscreteLegend extends LegendBase {
30004
30030
  this._itemHeight = 0;
30005
30031
  this._itemMaxWidth = 0;
30006
30032
  this._contentMaxHeight = 0;
30033
+ this._stateDefinitionsCache = new WeakMap();
30007
30034
  this._onHover = (e) => {
30008
30035
  const target = e.target;
30009
30036
  if (target && target.name && target.name.startsWith(LEGEND_ELEMENT_NAME.item)) {
@@ -30090,6 +30117,7 @@ class DiscreteLegend extends LegendBase {
30090
30117
  };
30091
30118
  }
30092
30119
  render() {
30120
+ this._stateDefinitionsCache = new WeakMap();
30093
30121
  super.render();
30094
30122
  this._lastActiveItem = null;
30095
30123
  }
@@ -30368,7 +30396,7 @@ class DiscreteLegend extends LegendBase {
30368
30396
  }
30369
30397
  else {
30370
30398
  itemGroup = graphicCreator.group(Object.assign({ x: 0, y: 0 }, backgroundStyle.style));
30371
- this._appendDataToShape(itemGroup, LEGEND_ELEMENT_NAME.item, item, itemGroup, backgroundStyle.state);
30399
+ this._appendDataToShape(itemGroup, LEGEND_ELEMENT_NAME.item, item, itemGroup, backgroundStyle.state, backgroundStyle.reuseStateDefinitions);
30372
30400
  }
30373
30401
  itemGroup.id = `${id !== null && id !== void 0 ? id : label}-${index}`;
30374
30402
  itemGroup.addState(isSelected ? LegendStateValue.selected : LegendStateValue.unSelected);
@@ -30401,7 +30429,7 @@ class DiscreteLegend extends LegendBase {
30401
30429
  shapeStyle.state[key].stroke = color;
30402
30430
  }
30403
30431
  });
30404
- this._appendDataToShape(itemShape, LEGEND_ELEMENT_NAME.itemShape, item, itemGroup, shapeStyle.state);
30432
+ this._appendDataToShape(itemShape, LEGEND_ELEMENT_NAME.itemShape, item, itemGroup, shapeStyle.state, false);
30405
30433
  itemShape.addState(isSelected ? LegendStateValue.selected : LegendStateValue.unSelected);
30406
30434
  innerGroup.add(itemShape);
30407
30435
  }
@@ -30416,7 +30444,7 @@ class DiscreteLegend extends LegendBase {
30416
30444
  const text = labelAttr.formatMethod ? labelAttr.formatMethod(label, item, index) : label;
30417
30445
  const labelAttributes = Object.assign(Object.assign({ x: shapeSize / 2 + shapeSpace, y: 0, textAlign: 'start', textBaseline: 'middle', lineHeight: (_b = labelStyle.style) === null || _b === void 0 ? void 0 : _b.fontSize }, labelStyle.style), { text, _originText: labelAttr.formatMethod ? label : undefined });
30418
30446
  const labelShape = createTextGraphicByType(labelAttributes);
30419
- this._appendDataToShape(labelShape, LEGEND_ELEMENT_NAME.itemLabel, item, itemGroup, labelStyle.state);
30447
+ this._appendDataToShape(labelShape, LEGEND_ELEMENT_NAME.itemLabel, item, itemGroup, labelStyle.state, labelStyle.reuseStateDefinitions);
30420
30448
  labelShape.addState(isSelected ? LegendStateValue.selected : LegendStateValue.unSelected);
30421
30449
  innerGroup.add(labelShape);
30422
30450
  const labelSpace = get(labelAttr, 'space', DEFAULT_LABEL_SPACE);
@@ -30425,7 +30453,7 @@ class DiscreteLegend extends LegendBase {
30425
30453
  const valueText = valueAttr.formatMethod ? valueAttr.formatMethod(value, item, index) : value;
30426
30454
  const valueAttributes = Object.assign(Object.assign({ x: 0, y: 0, textAlign: 'start', textBaseline: 'middle', lineHeight: valueStyle.style.fontSize }, valueStyle.style), { text: valueText, _originText: valueAttr.formatMethod ? value : undefined });
30427
30455
  const valueShape = createTextGraphicByType(valueAttributes);
30428
- this._appendDataToShape(valueShape, LEGEND_ELEMENT_NAME.itemValue, item, itemGroup, valueStyle.state);
30456
+ this._appendDataToShape(valueShape, LEGEND_ELEMENT_NAME.itemValue, item, itemGroup, valueStyle.state, valueStyle.reuseStateDefinitions);
30429
30457
  valueShape.addState(isSelected ? LegendStateValue.selected : LegendStateValue.unSelected);
30430
30458
  if (this._itemWidthByUser) {
30431
30459
  const layoutWidth = this._itemWidthByUser -
@@ -31077,11 +31105,29 @@ class DiscreteLegend extends LegendBase {
31077
31105
  });
31078
31106
  return selectedData;
31079
31107
  }
31080
- _appendDataToShape(shape, name, data, delegateShape, states = {}) {
31108
+ _appendDataToShape(shape, name, data, delegateShape, states, reuseStateDefinitions = true) {
31081
31109
  shape.name = name;
31082
31110
  shape.data = data;
31083
31111
  shape.delegate = delegateShape;
31084
- shape.states = merge({}, DEFAULT_STATES, states);
31112
+ if (!reuseStateDefinitions) {
31113
+ shape.states = merge({}, DEFAULT_STATES, states);
31114
+ return;
31115
+ }
31116
+ const source = states !== null && states !== void 0 ? states : DEFAULT_STATES;
31117
+ const cached = this._stateDefinitionsCache.get(source);
31118
+ if (cached) {
31119
+ shape.states = cached.definitions;
31120
+ shape.setStateDefinitionsWithCompiled(cached.definitions, cached.compiledDefinitions);
31121
+ return;
31122
+ }
31123
+ const definitions = states ? merge({}, DEFAULT_STATES, states) : DEFAULT_STATES;
31124
+ const entry = {
31125
+ definitions,
31126
+ compiledDefinitions: new StateDefinitionCompiler().compile(definitions)
31127
+ };
31128
+ this._stateDefinitionsCache.set(source, entry);
31129
+ shape.states = entry.definitions;
31130
+ shape.setStateDefinitionsWithCompiled(entry.definitions, entry.compiledDefinitions);
31085
31131
  }
31086
31132
  _dispatchLegendEvent(eventName, legendItem, event) {
31087
31133
  const currentSelectedItems = this._getSelectedLegends();
@@ -31107,21 +31153,27 @@ class DiscreteLegend extends LegendBase {
31107
31153
  }
31108
31154
  }
31109
31155
  if (config.state) {
31110
- newConfig.state = {};
31111
- Object.keys(config.state).forEach(key => {
31112
- if (config.state[key]) {
31113
- if (isFunction(config.state[key])) {
31114
- newConfig.state[key] = config.state[key](item, isSelected, index, items);
31115
- }
31116
- else {
31117
- newConfig.state[key] = config.state[key];
31156
+ const stateKeys = Object.keys(config.state);
31157
+ const hasStateFunction = stateKeys.some(key => isFunction(config.state[key]));
31158
+ newConfig.reuseStateDefinitions = !hasStateFunction;
31159
+ if (!hasStateFunction) {
31160
+ newConfig.state = config.state;
31161
+ }
31162
+ else {
31163
+ newConfig.state = {};
31164
+ stateKeys.forEach(key => {
31165
+ if (config.state[key]) {
31166
+ newConfig.state[key] = isFunction(config.state[key])
31167
+ ? config.state[key](item, isSelected, index, items)
31168
+ : config.state[key];
31118
31169
  }
31119
- }
31120
- });
31170
+ });
31171
+ }
31121
31172
  }
31122
31173
  return newConfig;
31123
31174
  }
31124
31175
  release() {
31176
+ this._stateDefinitionsCache = new WeakMap();
31125
31177
  super.release();
31126
31178
  this.removeAllEventListeners();
31127
31179
  }
@@ -36624,6 +36676,6 @@ TableSeriesNumber.defaultAttributes = {
36624
36676
  select: true
36625
36677
  };
36626
36678
 
36627
- const version = "1.1.5";
36679
+ const version = "1.1.6-alpha.0";
36628
36680
 
36629
36681
  export { AXIS_ELEMENT_NAME, AbstractComponent, ArcInfo, ArcLabel, ArcSegment, AxisStateValue, BasePlayer, Brush, CheckBox, CircleAxis, CircleAxisGrid, CircleCrosshair, ColorContinuousLegend, ContinuousPlayer, DEFAULT_ITEM_SPACE_COL, DEFAULT_ITEM_SPACE_ROW, DEFAULT_LABEL_SPACE, DEFAULT_PAGER_SPACE, DEFAULT_SHAPE_SIZE, DEFAULT_SHAPE_SPACE, DEFAULT_STATES$1 as DEFAULT_STATES, DEFAULT_TITLE_SPACE, DEFAULT_VALUE_SPACE, DataLabel, DataZoom, DataZoomActiveTag, DirectionEnum, DiscreteLegend, DiscretePlayer, EmptyTip, GroupTransition, IDataZoomEvent, IDataZoomInteractiveEvent, IMarkAreaLabelPosition, IMarkCommonArcLabelPosition, IMarkLineLabelPosition, IMarkPointItemPosition, IOperateType, Indicator, LEGEND_ELEMENT_NAME, LabelBase, LegendEvent, LegendStateValue, LineAxis, LineAxisGrid, LineCrosshair, LineLabel, LinkPath, MarkArcArea, MarkArcLine, MarkArea, MarkLine, MarkPoint, Pager, PlayerEventEnum, PolygonCrosshair, PolygonSectorCrosshair, PopTip, Radio, RectCrosshair, RectLabel, SLIDER_ELEMENT_NAME, ScrollBar, SectorCrosshair, Segment, SeriesNumberCellStateValue, SeriesNumberEvent, SizeContinuousLegend, Slider, StoryLabelItem, Switch, SymbolLabel, TableSeriesNumber, Tag, Timeline, Title, Tooltip, TopZIndex, VTag, WeatherBox, alignTextInLine, angle, angleLabelOrientAttribute, angleTo, cartesianTicks, clampRadian, computeOffsetForlimit, continuousTicks, contrastAccessibilityChecker, convertDomainToTickData, createTextGraphicByType, deltaXYToAngle, fuzzyEqualNumber, getAxisBreakSymbolAttrs, getCircleLabelPosition, getCirclePoints, getCircleVerticalVector, getElMap, getHorizontalPath, getMarksByName, getNoneGroupMarksByName, getPolarAngleLabelPosition, getPolygonPath, getSizeHandlerPath, getTextAlignAttrOfVerticalDir, getTextType, getVerticalCoord, getVerticalPath, hasOverlap, htmlAttributeTransform, initTextMeasure, installPoptipToApp, installScrollbarToApp, isInRange, isPostiveXAxis, isRichText, isVisible, labelSmartInvert, length, limitShapeInBounds, linearDiscreteTicks, loadPoptip, loadScrollbar, measureTextSize, normalize, polarAngleAxisDiscreteTicks, polarTicks, reactAttributeTransform, registerArcDataLabel, registerLineDataLabel, registerMarkArcAreaAnimate, registerMarkArcLineAnimate, registerMarkAreaAnimate, registerMarkLineAnimate, registerMarkPointAnimate, registerRectDataLabel, registerSymbolDataLabel, removeRepeatPoint, richTextAttributeTransform, scale, setPoptipTheme, smartInvertStrategy, tan2AngleToAngle, textIntersect, ticks, traverseGroup, version };
package/es/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare const version = "1.1.5";
1
+ export declare const version = "1.1.6-alpha.0";
2
2
  export * from './core/base';
3
3
  export { AbstractComponent } from './core/base';
4
4
  export * from './core/type';
package/es/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export const version = "1.1.5";
1
+ export const version = "1.1.6-alpha.0";
2
2
 
3
3
  export * from "./core/base";
4
4
 
package/es/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":"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","file":"index.js","sourcesContent":["// 导出版本号\nexport const version = \"1.1.5\";\n\nexport * from './core/base';\nexport { AbstractComponent } from './core/base';\nexport * from './core/type';\nexport * from './scrollbar';\nexport { ScrollBar } from './scrollbar/scrollbar';\nexport { loadScrollbar } from './scrollbar/module';\nexport * from './tag';\nexport * from './poptip';\nexport { loadPoptip } from './poptip/module';\nexport * from './crosshair';\nexport { LineCrosshair } from './crosshair/line';\nexport { CircleCrosshair } from './crosshair/circle';\nexport { SectorCrosshair } from './crosshair/sector';\nexport { PolygonCrosshair } from './crosshair/polygon';\nexport * from './label';\nexport { DataLabel } from './label/dataLabel';\nexport { registerSymbolDataLabel } from './label/symbol';\nexport * from './axis';\nexport { LineAxis } from './axis/line';\nexport { CircleAxis } from './axis/circle';\nexport { continuousTicks } from './axis/tick-data/continuous';\nexport { polarAngleAxisDiscreteTicks } from './axis/tick-data/discrete/polar-angle';\nexport * from './axis/grid';\nexport { LineAxisGrid } from './axis/grid/line';\nexport { CircleAxisGrid } from './axis/grid/circle';\nexport * from './segment';\nexport { Segment } from './segment/segment';\nexport * from './data-zoom';\nexport { DataZoom } from './data-zoom/data-zoom';\nexport * from './marker';\nexport { MarkLine, registerMarkLineAnimate } from './marker/line';\nexport { MarkArea, registerMarkAreaAnimate } from './marker/area';\nexport { MarkArcLine, registerMarkArcLineAnimate } from './marker/arc-line';\nexport { MarkArcArea, registerMarkArcAreaAnimate } from './marker/arc-area';\nexport { MarkPoint, registerMarkPointAnimate } from './marker/point';\nexport * from './pager';\nexport * from './legend';\nexport { ColorContinuousLegend } from './legend/color/color';\nexport { SizeContinuousLegend } from './legend/size/size';\nexport * from './title';\nexport { Title } from './title/title';\nexport * from './indicator';\nexport { Indicator } from './indicator/indicator';\nexport * from './slider';\nexport * from './link-path';\nexport * from './player';\nexport { DiscretePlayer } from './player/discrete-player';\nexport { ContinuousPlayer } from './player/continuous-player';\nexport { PlayerEventEnum } from './player/type/event';\nexport * from './brush';\nexport { Brush } from './brush/brush';\nexport { IOperateType } from './brush/type';\nexport * from './tooltip';\nexport * from './timeline';\nexport * from './interface';\nexport * from './jsx';\nexport * from './checkbox';\nexport * from './radio';\nexport * from './empty-tip';\nexport * from './weather';\nexport * from './util';\nexport { labelSmartInvert } from './util/label-smartInvert';\nexport * from './switch';\nexport * from './label-item';\nexport * from './table-series-number';\n"]}
1
+ {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":"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","file":"index.js","sourcesContent":["// 导出版本号\nexport const version = \"1.1.6-alpha.0\";\n\nexport * from './core/base';\nexport { AbstractComponent } from './core/base';\nexport * from './core/type';\nexport * from './scrollbar';\nexport { ScrollBar } from './scrollbar/scrollbar';\nexport { loadScrollbar } from './scrollbar/module';\nexport * from './tag';\nexport * from './poptip';\nexport { loadPoptip } from './poptip/module';\nexport * from './crosshair';\nexport { LineCrosshair } from './crosshair/line';\nexport { CircleCrosshair } from './crosshair/circle';\nexport { SectorCrosshair } from './crosshair/sector';\nexport { PolygonCrosshair } from './crosshair/polygon';\nexport * from './label';\nexport { DataLabel } from './label/dataLabel';\nexport { registerSymbolDataLabel } from './label/symbol';\nexport * from './axis';\nexport { LineAxis } from './axis/line';\nexport { CircleAxis } from './axis/circle';\nexport { continuousTicks } from './axis/tick-data/continuous';\nexport { polarAngleAxisDiscreteTicks } from './axis/tick-data/discrete/polar-angle';\nexport * from './axis/grid';\nexport { LineAxisGrid } from './axis/grid/line';\nexport { CircleAxisGrid } from './axis/grid/circle';\nexport * from './segment';\nexport { Segment } from './segment/segment';\nexport * from './data-zoom';\nexport { DataZoom } from './data-zoom/data-zoom';\nexport * from './marker';\nexport { MarkLine, registerMarkLineAnimate } from './marker/line';\nexport { MarkArea, registerMarkAreaAnimate } from './marker/area';\nexport { MarkArcLine, registerMarkArcLineAnimate } from './marker/arc-line';\nexport { MarkArcArea, registerMarkArcAreaAnimate } from './marker/arc-area';\nexport { MarkPoint, registerMarkPointAnimate } from './marker/point';\nexport * from './pager';\nexport * from './legend';\nexport { ColorContinuousLegend } from './legend/color/color';\nexport { SizeContinuousLegend } from './legend/size/size';\nexport * from './title';\nexport { Title } from './title/title';\nexport * from './indicator';\nexport { Indicator } from './indicator/indicator';\nexport * from './slider';\nexport * from './link-path';\nexport * from './player';\nexport { DiscretePlayer } from './player/discrete-player';\nexport { ContinuousPlayer } from './player/continuous-player';\nexport { PlayerEventEnum } from './player/type/event';\nexport * from './brush';\nexport { Brush } from './brush/brush';\nexport { IOperateType } from './brush/type';\nexport * from './tooltip';\nexport * from './timeline';\nexport * from './interface';\nexport * from './jsx';\nexport * from './checkbox';\nexport * from './radio';\nexport * from './empty-tip';\nexport * from './weather';\nexport * from './util';\nexport { labelSmartInvert } from './util/label-smartInvert';\nexport * from './switch';\nexport * from './label-item';\nexport * from './table-series-number';\n"]}
@@ -15,6 +15,7 @@ export declare class DiscreteLegend extends LegendBase<DiscreteLegendAttrs> {
15
15
  private _itemContext;
16
16
  private _scrollMask;
17
17
  private _scrollMaskContext;
18
+ private _stateDefinitionsCache;
18
19
  static defaultAttributes: Partial<DiscreteLegendAttrs>;
19
20
  constructor(attributes: DiscreteLegendAttrs, options?: ComponentOptions);
20
21
  render(): void;
@@ -10,6 +10,8 @@ var __rest = this && this.__rest || function(s, e) {
10
10
 
11
11
  import { merge, isEmpty, normalizePadding, get, isValid, isNil, isFunction, isArray, minInArray, throttle, isNumberClose, clamp, isObject } from "@visactor/vutils";
12
12
 
13
+ import { StateDefinitionCompiler } from "@visactor/vrender-core";
14
+
13
15
  import { graphicCreator } from "../../util/graphic-creator";
14
16
 
15
17
  import { LegendBase } from "../base";
@@ -40,7 +42,8 @@ export class DiscreteLegend extends LegendBase {
40
42
  constructor(attributes, options) {
41
43
  super((null == options ? void 0 : options.skipDefault) ? attributes : merge({}, DiscreteLegend.defaultAttributes, attributes)),
42
44
  this.name = "discreteLegend", this._itemsContainer = null, this._itemHeightByUser = void 0,
43
- this._itemHeight = 0, this._itemMaxWidth = 0, this._contentMaxHeight = 0, this._onHover = e => {
45
+ this._itemHeight = 0, this._itemMaxWidth = 0, this._contentMaxHeight = 0, this._stateDefinitionsCache = new WeakMap,
46
+ this._onHover = e => {
44
47
  const target = e.target;
45
48
  if (target && target.name && target.name.startsWith(LEGEND_ELEMENT_NAME.item)) {
46
49
  const legendItem = target.delegate;
@@ -88,7 +91,7 @@ export class DiscreteLegend extends LegendBase {
88
91
  };
89
92
  }
90
93
  render() {
91
- super.render(), this._lastActiveItem = null;
94
+ this._stateDefinitionsCache = new WeakMap, super.render(), this._lastActiveItem = null;
92
95
  }
93
96
  setSelected(selectedData) {
94
97
  var _a;
@@ -206,7 +209,7 @@ export class DiscreteLegend extends LegendBase {
206
209
  }), this._appendDataToShape(itemGroup, LEGEND_ELEMENT_NAME.item, item, itemGroup)) : (itemGroup = graphicCreator.group(Object.assign({
207
210
  x: 0,
208
211
  y: 0
209
- }, backgroundStyle.style)), this._appendDataToShape(itemGroup, LEGEND_ELEMENT_NAME.item, item, itemGroup, backgroundStyle.state)),
212
+ }, backgroundStyle.style)), this._appendDataToShape(itemGroup, LEGEND_ELEMENT_NAME.item, item, itemGroup, backgroundStyle.state, backgroundStyle.reuseStateDefinitions)),
210
213
  itemGroup.id = `${null != id ? id : label}-${index}`, itemGroup.addState(isSelected ? LegendStateValue.selected : LegendStateValue.unSelected);
211
214
  const innerGroup = graphicCreator.group({
212
215
  x: 0,
@@ -228,7 +231,7 @@ export class DiscreteLegend extends LegendBase {
228
231
  const color = shapeStyle.state[key].fill || shapeStyle.state[key].stroke;
229
232
  shape.fill && isNil(shapeStyle.state[key].fill) && color && (shapeStyle.state[key].fill = color),
230
233
  shape.stroke && isNil(shapeStyle.state[key].stroke) && color && (shapeStyle.state[key].stroke = color);
231
- })), this._appendDataToShape(itemShape, LEGEND_ELEMENT_NAME.itemShape, item, itemGroup, shapeStyle.state),
234
+ })), this._appendDataToShape(itemShape, LEGEND_ELEMENT_NAME.itemShape, item, itemGroup, shapeStyle.state, !1),
232
235
  itemShape.addState(isSelected ? LegendStateValue.selected : LegendStateValue.unSelected),
233
236
  innerGroup.add(itemShape);
234
237
  }
@@ -256,7 +259,7 @@ export class DiscreteLegend extends LegendBase {
256
259
  text: text,
257
260
  _originText: labelAttr.formatMethod ? label : void 0
258
261
  }), labelShape = createTextGraphicByType(labelAttributes);
259
- this._appendDataToShape(labelShape, LEGEND_ELEMENT_NAME.itemLabel, item, itemGroup, labelStyle.state),
262
+ this._appendDataToShape(labelShape, LEGEND_ELEMENT_NAME.itemLabel, item, itemGroup, labelStyle.state, labelStyle.reuseStateDefinitions),
260
263
  labelShape.addState(isSelected ? LegendStateValue.selected : LegendStateValue.unSelected),
261
264
  innerGroup.add(labelShape);
262
265
  const labelSpace = get(labelAttr, "space", DEFAULT_LABEL_SPACE);
@@ -271,7 +274,7 @@ export class DiscreteLegend extends LegendBase {
271
274
  text: valueText,
272
275
  _originText: valueAttr.formatMethod ? value : void 0
273
276
  }), valueShape = createTextGraphicByType(valueAttributes);
274
- if (this._appendDataToShape(valueShape, LEGEND_ELEMENT_NAME.itemValue, item, itemGroup, valueStyle.state),
277
+ if (this._appendDataToShape(valueShape, LEGEND_ELEMENT_NAME.itemValue, item, itemGroup, valueStyle.state, valueStyle.reuseStateDefinitions),
275
278
  valueShape.addState(isSelected ? LegendStateValue.selected : LegendStateValue.unSelected),
276
279
  this._itemWidthByUser) {
277
280
  const layoutWidth = this._itemWidthByUser - parsedPadding[1] - parsedPadding[3] - shapeSize - shapeSpace - labelSpace - focusSpace - valueSpace;
@@ -614,8 +617,16 @@ export class DiscreteLegend extends LegendBase {
614
617
  item.hasState(LegendStateValue.selected) && selectedData.push(item.data);
615
618
  })), selectedData;
616
619
  }
617
- _appendDataToShape(shape, name, data, delegateShape, states = {}) {
618
- shape.name = name, shape.data = data, shape.delegate = delegateShape, shape.states = merge({}, DEFAULT_STATES, states);
620
+ _appendDataToShape(shape, name, data, delegateShape, states, reuseStateDefinitions = !0) {
621
+ if (shape.name = name, shape.data = data, shape.delegate = delegateShape, !reuseStateDefinitions) return void (shape.states = merge({}, DEFAULT_STATES, states));
622
+ const source = null != states ? states : DEFAULT_STATES, cached = this._stateDefinitionsCache.get(source);
623
+ if (cached) return shape.states = cached.definitions, void shape.setStateDefinitionsWithCompiled(cached.definitions, cached.compiledDefinitions);
624
+ const definitions = states ? merge({}, DEFAULT_STATES, states) : DEFAULT_STATES, entry = {
625
+ definitions: definitions,
626
+ compiledDefinitions: (new StateDefinitionCompiler).compile(definitions)
627
+ };
628
+ this._stateDefinitionsCache.set(source, entry), shape.states = entry.definitions,
629
+ shape.setStateDefinitionsWithCompiled(entry.definitions, entry.compiledDefinitions);
619
630
  }
620
631
  _dispatchLegendEvent(eventName, legendItem, event) {
621
632
  const currentSelectedItems = this._getSelectedLegends();
@@ -632,13 +643,18 @@ export class DiscreteLegend extends LegendBase {
632
643
  }
633
644
  _handleStyle(config, item, isSelected, index, items) {
634
645
  const newConfig = {};
635
- return config.style && (isFunction(config.style) ? newConfig.style = config.style(item, isSelected, index, items) : newConfig.style = config.style),
636
- config.state && (newConfig.state = {}, Object.keys(config.state).forEach((key => {
637
- config.state[key] && (isFunction(config.state[key]) ? newConfig.state[key] = config.state[key](item, isSelected, index, items) : newConfig.state[key] = config.state[key]);
638
- }))), newConfig;
646
+ if (config.style && (isFunction(config.style) ? newConfig.style = config.style(item, isSelected, index, items) : newConfig.style = config.style),
647
+ config.state) {
648
+ const stateKeys = Object.keys(config.state), hasStateFunction = stateKeys.some((key => isFunction(config.state[key])));
649
+ newConfig.reuseStateDefinitions = !hasStateFunction, hasStateFunction ? (newConfig.state = {},
650
+ stateKeys.forEach((key => {
651
+ config.state[key] && (newConfig.state[key] = isFunction(config.state[key]) ? config.state[key](item, isSelected, index, items) : config.state[key]);
652
+ }))) : newConfig.state = config.state;
653
+ }
654
+ return newConfig;
639
655
  }
640
656
  release() {
641
- super.release(), this.removeAllEventListeners();
657
+ this._stateDefinitionsCache = new WeakMap, super.release(), this.removeAllEventListeners();
642
658
  }
643
659
  }
644
660