@visactor/vrender-components 1.1.7 → 1.1.8-alpha.1

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,
@@ -4887,14 +4887,17 @@ class GraphicImpl extends Node {
4887
4887
  }
4888
4888
  return null === (_a = this.stage) || void 0 === _a ? void 0 : _a.rootSharedStateScope;
4889
4889
  }
4890
- syncSharedStateScopeBindingFromTree(markDirty = !0) {
4890
+ syncSharedStateScopeBinding(nextScope, markDirty = !0) {
4891
4891
  var _a;
4892
- const nextScope = this.resolveBoundSharedStateScope();
4893
4892
  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);
4894
4893
  }
4895
- syncSharedStateScopeBindingOnTreeChange(markDirty = !0) {
4894
+ syncSharedStateScopeBindingFromTree(markDirty = !0, inheritedSharedStateScope) {
4895
+ const nextScope = void 0 === inheritedSharedStateScope ? this.resolveBoundSharedStateScope() : null != inheritedSharedStateScope ? inheritedSharedStateScope : void 0;
4896
+ return this.syncSharedStateScopeBinding(nextScope, markDirty);
4897
+ }
4898
+ syncSharedStateScopeBindingOnTreeChange(markDirty = !0, inheritedSharedStateScope) {
4896
4899
  var _a, _b;
4897
- 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);
4900
+ 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);
4898
4901
  }
4899
4902
  syncSharedStateActiveRegistrations() {
4900
4903
  var _a;
@@ -4902,6 +4905,7 @@ class GraphicImpl extends Node {
4902
4905
  if (!(null === (_a = this.currentStates) || void 0 === _a ? void 0 : _a.length) || !this.boundSharedStateScope) return (null == previousScopes ? void 0 : previousScopes.size) && (previousScopes.forEach(scope => {
4903
4906
  scope.subtreeActiveDescendants.delete(this);
4904
4907
  }), previousScopes.clear()), void (this.registeredActiveScopes = void 0);
4908
+ if ((null == previousScopes ? void 0 : previousScopes.size) && this.isSharedStateScopeChainRegistered(previousScopes)) return;
4905
4909
  const nextScopes = new Set(collectSharedStateScopeChain(this.boundSharedStateScope));
4906
4910
  null == previousScopes || previousScopes.forEach(scope => {
4907
4911
  nextScopes.has(scope) || scope.subtreeActiveDescendants.delete(this);
@@ -4909,6 +4913,15 @@ class GraphicImpl extends Node {
4909
4913
  scope.subtreeActiveDescendants.add(this);
4910
4914
  }), this.registeredActiveScopes = nextScopes;
4911
4915
  }
4916
+ isSharedStateScopeChainRegistered(previousScopes) {
4917
+ let scope = this.boundSharedStateScope,
4918
+ scopeCount = 0;
4919
+ for (; scope;) {
4920
+ if (!previousScopes.has(scope)) return !1;
4921
+ scopeCount += 1, scope = scope.parentScope;
4922
+ }
4923
+ return scopeCount === previousScopes.size;
4924
+ }
4912
4925
  clearSharedStateActiveRegistrations() {
4913
4926
  const previousScopes = this.registeredActiveScopes;
4914
4927
  previousScopes && (previousScopes.forEach(scope => {
@@ -4918,8 +4931,8 @@ class GraphicImpl extends Node {
4918
4931
  markSharedStateDirty() {
4919
4932
  this.sharedStateDirty = !0, enqueueGraphicSharedStateRefresh(this.stage, this), scheduleStageSharedStateRefresh(this.stage);
4920
4933
  }
4921
- onParentSharedStateTreeChanged(stage, layer) {
4922
- this.stage === stage && this.layer === layer ? this.syncSharedStateScopeBindingOnTreeChange() : this.setStage(stage, layer);
4934
+ onParentSharedStateTreeChanged(stage, layer, inheritedSharedStateScope) {
4935
+ this.stage === stage && this.layer === layer ? this.syncSharedStateScopeBindingOnTreeChange(!0, inheritedSharedStateScope) : this.setStage(stage, layer, inheritedSharedStateScope);
4923
4936
  }
4924
4937
  refreshSharedStateBeforeRender() {
4925
4938
  var _a;
@@ -5569,6 +5582,10 @@ class GraphicImpl extends Node {
5569
5582
  var _a;
5570
5583
  return null === (_a = this.states) || void 0 === _a ? void 0 : _a[stateName];
5571
5584
  }
5585
+ setStateDefinitionsWithCompiled(definitions, compiledDefinitions) {
5586
+ var _a;
5587
+ 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}`;
5588
+ }
5572
5589
  getStateResolveBaseAttrs() {
5573
5590
  var _a;
5574
5591
  return null !== (_a = this.baseAttributes) && void 0 !== _a ? _a : this.attribute;
@@ -5932,12 +5949,12 @@ class GraphicImpl extends Node {
5932
5949
  this._globalTransMatrix.translate(scrollX, scrollY);
5933
5950
  }
5934
5951
  }
5935
- setStage(stage, layer) {
5952
+ setStage(stage, layer, inheritedSharedStateScope) {
5936
5953
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
5937
5954
  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,
5938
5955
  previousStage = this.stage;
5939
5956
  if (this.stage !== stage || this.layer !== layer) {
5940
- 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()) {
5957
+ 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()) {
5941
5958
  const previousTimeline = null === (_f = null == previousStage ? void 0 : previousStage.getTimeline) || void 0 === _f ? void 0 : _f.call(previousStage),
5942
5959
  nextTimeline = null === (_g = null == stage ? void 0 : stage.getTimeline) || void 0 === _g ? void 0 : _g.call(stage),
5943
5960
  detachedStageAnimates = [];
@@ -5954,7 +5971,7 @@ class GraphicImpl extends Node {
5954
5971
  }
5955
5972
  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));
5956
5973
  }
5957
- ((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);
5974
+ ((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);
5958
5975
  }
5959
5976
  detachStageForRelease() {
5960
5977
  var _a, _b, _c;
@@ -6376,13 +6393,13 @@ class Group extends Graphic {
6376
6393
  child.setStage(null, null);
6377
6394
  }), this.addUpdateBoundTag();
6378
6395
  }
6379
- setStage(stage, layer) {
6396
+ setStage(stage, layer, inheritedSharedStateScope) {
6380
6397
  var _a, _b, _c, _d, _e, _f;
6381
6398
  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,
6382
6399
  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;
6383
- 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();
6400
+ 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);
6384
6401
  const layerChanged = this.layer !== layer;
6385
- layerChanged && (this.layer = layer), needsSharedStateTreeSync ? (this.ensureSharedStateScopeBound(), this.syncSharedStateScopeBindingOnTreeChange(!0), this.notifyChildrenSharedStateTreeChanged()) : layerChanged && this.notifyChildrenSharedStateTreeChanged();
6402
+ layerChanged && (this.layer = layer), needsSharedStateTreeSync ? (this.ensureSharedStateScopeBound(), this.syncSharedStateScopeBindingOnTreeChange(!0, inheritedSharedStateScope), this.notifyChildrenSharedStateTreeChanged(inheritedSharedStateScope)) : layerChanged && this.notifyChildrenSharedStateTreeChanged(inheritedSharedStateScope);
6386
6403
  }
6387
6404
  addUpdatePositionTag() {
6388
6405
  super.addUpdatePositionTag(), this.forEachChildren(g => {
@@ -6441,17 +6458,26 @@ class Group extends Graphic {
6441
6458
  hasSharedStateDefinitions() {
6442
6459
  return !!this._sharedStateDefinitions && Object.keys(this._sharedStateDefinitions).length > 0;
6443
6460
  }
6444
- notifyChildrenSharedStateTreeChanged() {
6461
+ resolveChildSharedStateScope(inheritedSharedStateScope) {
6462
+ var _a;
6463
+ return this.sharedStateScope ? this.sharedStateScope : void 0 !== inheritedSharedStateScope ? inheritedSharedStateScope : null !== (_a = this.resolveBoundSharedStateScope()) && void 0 !== _a ? _a : null;
6464
+ }
6465
+ notifyChildrenSharedStateTreeChanged(inheritedSharedStateScope) {
6466
+ const childSharedStateScope = this.resolveChildSharedStateScope(inheritedSharedStateScope);
6445
6467
  this.forEachChildren(item => {
6446
- this.syncChildSharedStateTreeBinding(item);
6468
+ this.setStageToChild(item, childSharedStateScope);
6447
6469
  });
6448
6470
  }
6449
- syncChildSharedStateTreeBinding(child) {
6450
- child.onParentSharedStateTreeChanged(this.stage, this.layer);
6471
+ setStageToChild(child, inheritedSharedStateScope) {
6472
+ const graphic = child;
6473
+ "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);
6451
6474
  }
6452
- onParentSharedStateTreeChanged(stage, layer) {
6475
+ syncChildSharedStateTreeBinding(child, inheritedSharedStateScope) {
6476
+ void 0 === inheritedSharedStateScope && (inheritedSharedStateScope = this.resolveChildSharedStateScope()), this.setStageToChild(child, inheritedSharedStateScope);
6477
+ }
6478
+ onParentSharedStateTreeChanged(stage, layer, inheritedSharedStateScope) {
6453
6479
  var _a;
6454
- 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);
6480
+ 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);
6455
6481
  }
6456
6482
  }
6457
6483
  Group.NOWORK_ANIMATE_ATTR = NOWORK_ANIMATE_ATTR;
@@ -9061,8 +9087,8 @@ class RichText extends Graphic {
9061
9087
  clone() {
9062
9088
  return new RichText(Object.assign({}, this.attribute));
9063
9089
  }
9064
- setStage(stage, layer) {
9065
- super.setStage(stage, layer);
9090
+ setStage(stage, layer, inheritedSharedStateScope) {
9091
+ super.setStage(stage, layer, inheritedSharedStateScope);
9066
9092
  this.getFrameCache().icons.forEach(icon => {
9067
9093
  icon.setStage(stage, layer);
9068
9094
  });
@@ -30266,6 +30292,7 @@ class DiscreteLegend extends LegendBase {
30266
30292
  this._itemHeight = 0;
30267
30293
  this._itemMaxWidth = 0;
30268
30294
  this._contentMaxHeight = 0;
30295
+ this._stateDefinitionsCache = new WeakMap();
30269
30296
  this._onHover = (e) => {
30270
30297
  const target = e.target;
30271
30298
  if (target && target.name && target.name.startsWith(LEGEND_ELEMENT_NAME.item)) {
@@ -30352,6 +30379,7 @@ class DiscreteLegend extends LegendBase {
30352
30379
  };
30353
30380
  }
30354
30381
  render() {
30382
+ this._stateDefinitionsCache = new WeakMap();
30355
30383
  super.render();
30356
30384
  this._lastActiveItem = null;
30357
30385
  }
@@ -30630,7 +30658,7 @@ class DiscreteLegend extends LegendBase {
30630
30658
  }
30631
30659
  else {
30632
30660
  itemGroup = graphicCreator.group(Object.assign({ x: 0, y: 0 }, backgroundStyle.style));
30633
- this._appendDataToShape(itemGroup, LEGEND_ELEMENT_NAME.item, item, itemGroup, backgroundStyle.state);
30661
+ this._appendDataToShape(itemGroup, LEGEND_ELEMENT_NAME.item, item, itemGroup, backgroundStyle.state, backgroundStyle.reuseStateDefinitions);
30634
30662
  }
30635
30663
  itemGroup.id = `${id !== null && id !== void 0 ? id : label}-${index}`;
30636
30664
  itemGroup.addState(isSelected ? LegendStateValue.selected : LegendStateValue.unSelected);
@@ -30663,7 +30691,7 @@ class DiscreteLegend extends LegendBase {
30663
30691
  shapeStyle.state[key].stroke = color;
30664
30692
  }
30665
30693
  });
30666
- this._appendDataToShape(itemShape, LEGEND_ELEMENT_NAME.itemShape, item, itemGroup, shapeStyle.state);
30694
+ this._appendDataToShape(itemShape, LEGEND_ELEMENT_NAME.itemShape, item, itemGroup, shapeStyle.state, false);
30667
30695
  itemShape.addState(isSelected ? LegendStateValue.selected : LegendStateValue.unSelected);
30668
30696
  innerGroup.add(itemShape);
30669
30697
  }
@@ -30678,7 +30706,7 @@ class DiscreteLegend extends LegendBase {
30678
30706
  const text = labelAttr.formatMethod ? labelAttr.formatMethod(label, item, index) : label;
30679
30707
  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 });
30680
30708
  const labelShape = createTextGraphicByType(labelAttributes);
30681
- this._appendDataToShape(labelShape, LEGEND_ELEMENT_NAME.itemLabel, item, itemGroup, labelStyle.state);
30709
+ this._appendDataToShape(labelShape, LEGEND_ELEMENT_NAME.itemLabel, item, itemGroup, labelStyle.state, labelStyle.reuseStateDefinitions);
30682
30710
  labelShape.addState(isSelected ? LegendStateValue.selected : LegendStateValue.unSelected);
30683
30711
  innerGroup.add(labelShape);
30684
30712
  const labelSpace = get(labelAttr, 'space', DEFAULT_LABEL_SPACE);
@@ -30687,7 +30715,7 @@ class DiscreteLegend extends LegendBase {
30687
30715
  const valueText = valueAttr.formatMethod ? valueAttr.formatMethod(value, item, index) : value;
30688
30716
  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 });
30689
30717
  const valueShape = createTextGraphicByType(valueAttributes);
30690
- this._appendDataToShape(valueShape, LEGEND_ELEMENT_NAME.itemValue, item, itemGroup, valueStyle.state);
30718
+ this._appendDataToShape(valueShape, LEGEND_ELEMENT_NAME.itemValue, item, itemGroup, valueStyle.state, valueStyle.reuseStateDefinitions);
30691
30719
  valueShape.addState(isSelected ? LegendStateValue.selected : LegendStateValue.unSelected);
30692
30720
  if (this._itemWidthByUser) {
30693
30721
  const layoutWidth = this._itemWidthByUser -
@@ -31339,11 +31367,29 @@ class DiscreteLegend extends LegendBase {
31339
31367
  });
31340
31368
  return selectedData;
31341
31369
  }
31342
- _appendDataToShape(shape, name, data, delegateShape, states = {}) {
31370
+ _appendDataToShape(shape, name, data, delegateShape, states, reuseStateDefinitions = true) {
31343
31371
  shape.name = name;
31344
31372
  shape.data = data;
31345
31373
  shape.delegate = delegateShape;
31346
- shape.states = merge({}, DEFAULT_STATES, states);
31374
+ if (!reuseStateDefinitions) {
31375
+ shape.states = merge({}, DEFAULT_STATES, states);
31376
+ return;
31377
+ }
31378
+ const source = states !== null && states !== void 0 ? states : DEFAULT_STATES;
31379
+ const cached = this._stateDefinitionsCache.get(source);
31380
+ if (cached) {
31381
+ shape.states = cached.definitions;
31382
+ shape.setStateDefinitionsWithCompiled(cached.definitions, cached.compiledDefinitions);
31383
+ return;
31384
+ }
31385
+ const definitions = states ? merge({}, DEFAULT_STATES, states) : DEFAULT_STATES;
31386
+ const entry = {
31387
+ definitions,
31388
+ compiledDefinitions: new StateDefinitionCompiler().compile(definitions)
31389
+ };
31390
+ this._stateDefinitionsCache.set(source, entry);
31391
+ shape.states = entry.definitions;
31392
+ shape.setStateDefinitionsWithCompiled(entry.definitions, entry.compiledDefinitions);
31347
31393
  }
31348
31394
  _dispatchLegendEvent(eventName, legendItem, event) {
31349
31395
  const currentSelectedItems = this._getSelectedLegends();
@@ -31369,21 +31415,27 @@ class DiscreteLegend extends LegendBase {
31369
31415
  }
31370
31416
  }
31371
31417
  if (config.state) {
31372
- newConfig.state = {};
31373
- Object.keys(config.state).forEach(key => {
31374
- if (config.state[key]) {
31375
- if (isFunction(config.state[key])) {
31376
- newConfig.state[key] = config.state[key](item, isSelected, index, items);
31377
- }
31378
- else {
31379
- newConfig.state[key] = config.state[key];
31418
+ const stateKeys = Object.keys(config.state);
31419
+ const hasStateFunction = stateKeys.some(key => isFunction(config.state[key]));
31420
+ newConfig.reuseStateDefinitions = !hasStateFunction;
31421
+ if (!hasStateFunction) {
31422
+ newConfig.state = config.state;
31423
+ }
31424
+ else {
31425
+ newConfig.state = {};
31426
+ stateKeys.forEach(key => {
31427
+ if (config.state[key]) {
31428
+ newConfig.state[key] = isFunction(config.state[key])
31429
+ ? config.state[key](item, isSelected, index, items)
31430
+ : config.state[key];
31380
31431
  }
31381
- }
31382
- });
31432
+ });
31433
+ }
31383
31434
  }
31384
31435
  return newConfig;
31385
31436
  }
31386
31437
  release() {
31438
+ this._stateDefinitionsCache = new WeakMap();
31387
31439
  super.release();
31388
31440
  this.removeAllEventListeners();
31389
31441
  }
@@ -36886,6 +36938,6 @@ TableSeriesNumber.defaultAttributes = {
36886
36938
  select: true
36887
36939
  };
36888
36940
 
36889
- const version = "1.1.7";
36941
+ const version = "1.1.8-alpha.1";
36890
36942
 
36891
36943
  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.7";
1
+ export declare const version = "1.1.8-alpha.1";
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.7";
1
+ export const version = "1.1.8-alpha.1";
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.7\";\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.8-alpha.1\";\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