@visactor/vchart 2.1.0-alpha.3 → 2.1.0-alpha.4

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.
@@ -127,6 +127,9 @@ export declare class BaseChart<T extends IChartSpec> extends CompilableBase impl
127
127
  componentOnlyUpdatedComponents: IComponent[];
128
128
  hasNonComponentOnlyUpdate: boolean;
129
129
  };
130
+ private _canChangeMarkerComponentsWithoutRemake;
131
+ private _canAddMarkerComponentsWithoutRemake;
132
+ private _isMarkerAdditionSpecSafeWithoutRemake;
130
133
  private _canRemoveMarkerComponentsWithoutRemake;
131
134
  private _isOnlyMarkerComponentsRemoved;
132
135
  private _isComponentSpecKey;
@@ -134,6 +137,10 @@ export declare class BaseChart<T extends IChartSpec> extends CompilableBase impl
134
137
  private _isOnlySeriesSpecsChanged;
135
138
  private _canSkipChartDataStages;
136
139
  private _isComponentScaleDomainOnlyUpdate;
140
+ private _reRunStackDataFlow;
141
+ private _getModelSpecIndex;
142
+ private _hasComponentForSpecInfo;
143
+ private _createMissingMarkerComponentsForSpecs;
137
144
  private _removeMarkerComponentsForEmptySpecs;
138
145
  private _removeComponent;
139
146
  updateSeriesSpec(result: IUpdateSpecResult): void;
@@ -18,6 +18,20 @@ const data_1 = require("../chart-meta/data"), global_scale_1 = require("../../sc
18
18
  [interface_1.ComponentTypeEnum.markPoint]: !0,
19
19
  [interface_1.ComponentTypeEnum.markLine]: !0,
20
20
  [interface_1.ComponentTypeEnum.markArea]: !0
21
+ }, MARKER_ADDITION_REMAKE_SPEC_KEYS = {
22
+ autoRange: !0,
23
+ regionId: !0,
24
+ regionIndex: !0,
25
+ seriesId: !0,
26
+ seriesIndex: !0,
27
+ relativeSeriesId: !0,
28
+ relativeSeriesIndex: !0,
29
+ startRelativeSeriesId: !0,
30
+ startRelativeSeriesIndex: !0,
31
+ endRelativeSeriesId: !0,
32
+ endRelativeSeriesIndex: !0,
33
+ specifiedDataSeriesId: !0,
34
+ specifiedDataSeriesIndex: !0
21
35
  };
22
36
 
23
37
  class BaseChart extends compilable_base_1.CompilableBase {
@@ -107,7 +121,8 @@ class BaseChart extends compilable_base_1.CompilableBase {
107
121
  const component = this._components.find((s => s.userId === userId));
108
122
  if (component) return component;
109
123
  }, this.getComponentsByType = type => this._components.filter((c => c.type === type)),
110
- this._paddingSpec = (0, util_1.normalizeLayoutPaddingSpec)(null !== (_a = spec.padding) && void 0 !== _a ? _a : option.getTheme("padding")),
124
+ this._isMarkerAdditionSpecSafeWithoutRemake = spec => !(!spec || "object" != typeof spec || !1 === spec.visible) && !Object.keys(MARKER_ADDITION_REMAKE_SPEC_KEYS).some((key => !(0,
125
+ vutils_1.isNil)(spec[key]))), this._paddingSpec = (0, util_1.normalizeLayoutPaddingSpec)(null !== (_a = spec.padding) && void 0 !== _a ? _a : option.getTheme("padding")),
111
126
  this._event = new event_1.Event(option.eventDispatcher, option.mode), this._dataSet = option.dataSet,
112
127
  this._chartData = new data_1.ChartData(this._dataSet), this._modelOption = Object.assign(Object.assign({}, option), {
113
128
  mode: this._option.mode,
@@ -429,7 +444,7 @@ class BaseChart extends compilable_base_1.CompilableBase {
429
444
  return Object.keys(spec).filter((key => !ignoreKeys[key])).sort();
430
445
  }
431
446
  updateSpec(spec) {
432
- var _a;
447
+ var _a, _b;
433
448
  const result = {
434
449
  change: !1,
435
450
  reMake: !1,
@@ -444,7 +459,7 @@ class BaseChart extends compilable_base_1.CompilableBase {
444
459
  result;
445
460
  for (let i = 0; i < currentKeys.length; i++) {
446
461
  const key = currentKeys[i], currentSpec = this._spec[key], nextSpec = spec[key];
447
- if ((0, util_1.isArray)(currentSpec) && currentSpec.length !== (0, util_1.array)(nextSpec).length && !this._canRemoveMarkerComponentsWithoutRemake(key, currentSpec, nextSpec)) return result.reMake = !0,
462
+ if ((0, util_1.isArray)(currentSpec) && currentSpec.length !== (0, util_1.array)(nextSpec).length && !this._canChangeMarkerComponentsWithoutRemake(key, currentSpec, nextSpec)) return result.reMake = !0,
448
463
  this.setLayoutTag(!0, null, !1), result;
449
464
  }
450
465
  const oldSpec = this._spec, onlyMarkerComponentsRemoved = this._isOnlyMarkerComponentsRemoved(this._spec, spec, currentKeys), onlyComponentSpecsChanged = this._isOnlyComponentSpecsChanged(this._spec, spec, currentKeys), onlySeriesSpecsChanged = this._isOnlySeriesSpecsChanged(this._spec, spec, currentKeys);
@@ -457,13 +472,15 @@ class BaseChart extends compilable_base_1.CompilableBase {
457
472
  if (this.updateRegionSpec(result), result.reMake) return this.setLayoutTag(!0, null, !1),
458
473
  result;
459
474
  const componentUpdateResult = this.updateComponentSpec(result);
460
- return result.reMake ? (this.setLayoutTag(!0, null, !1), result) : (0, util_3.isUpdateSpecResultLocalOnly)(result) ? result : onlyComponentSpecsChanged && !componentUpdateResult.hasNonComponentOnlyUpdate && ((0,
475
+ return result.reMake ? (this.setLayoutTag(!0, null, !1), result) : (!onlyComponentSpecsChanged && (null === (_a = result.effects) || void 0 === _a ? void 0 : _a.localOnly) && delete result.effects.localOnly,
476
+ (0, util_3.isUpdateSpecResultLocalOnly)(result) ? result : onlyComponentSpecsChanged && !componentUpdateResult.hasNonComponentOnlyUpdate && ((0,
461
477
  util_3.isUpdateSpecResultComponentOnly)(result) || this._isComponentScaleDomainOnlyUpdate(result)) ? (componentUpdateResult.componentOnlyUpdatedComponents.forEach((component => {
462
478
  component.reInit(component.getSpec());
463
- })), (null === (_a = result.effects) || void 0 === _a ? void 0 : _a.layout) && this.setLayoutTag(!0, null, !1),
479
+ })), (null === (_b = result.effects) || void 0 === _b ? void 0 : _b.layout) && this.setLayoutTag(!0, null, !1),
464
480
  result) : (this.setLayoutTag(!0, null, !1), this.updateSeriesSpec(result), result.reMake || (this.reInit(),
465
481
  onlySeriesSpecsChanged && this._canSkipChartDataStages(result) || (this.updateDataSpec(),
466
- this.updateGlobalScaleDomain())), result);
482
+ this.reDataFlow(), this._reRunStackDataFlow(), this.getAllModels().forEach((model => model.onDataUpdate())))),
483
+ result));
467
484
  }
468
485
  updateChartConfig(result, oldSpec) {
469
486
  var _a, _b;
@@ -508,7 +525,7 @@ class BaseChart extends compilable_base_1.CompilableBase {
508
525
  vutils_1.isEqual)(previousComponentSpec, cmpSpec) || (hasNonComponentOnlyUpdate = !0),
509
526
  (0, util_3.mergeUpdateResult)(result, componentResult);
510
527
  }
511
- }));
528
+ })), result.reMake || this._createMissingMarkerComponentsForSpecs(result, componentCache);
512
529
  for (const key in componentCache) if (Object.prototype.hasOwnProperty.call(componentCache, key)) {
513
530
  const element = componentCache[key];
514
531
  element.componentCount !== element.specCount && (result.reMake = !0);
@@ -530,6 +547,13 @@ class BaseChart extends compilable_base_1.CompilableBase {
530
547
  hasNonComponentOnlyUpdate: hasNonComponentOnlyUpdate
531
548
  };
532
549
  }
550
+ _canChangeMarkerComponentsWithoutRemake(key, currentSpec, nextSpec) {
551
+ return this._canRemoveMarkerComponentsWithoutRemake(key, currentSpec, nextSpec) || this._canAddMarkerComponentsWithoutRemake(key, currentSpec, nextSpec);
552
+ }
553
+ _canAddMarkerComponentsWithoutRemake(key, currentSpec, nextSpec) {
554
+ return !!(MARKER_COMPONENT_SPEC_KEYS[key] && (0, util_1.isArray)(currentSpec) && (0,
555
+ util_1.isArray)(nextSpec)) && (!(nextSpec.length <= currentSpec.length) && nextSpec.slice(currentSpec.length).every(this._isMarkerAdditionSpecSafeWithoutRemake));
556
+ }
533
557
  _canRemoveMarkerComponentsWithoutRemake(key, currentSpec, nextSpec) {
534
558
  return MARKER_COMPONENT_SPEC_KEYS[key] && (0, util_1.isArray)(currentSpec) && currentSpec.length > 0 && (0,
535
559
  util_1.isArray)(nextSpec) && 0 === nextSpec.length;
@@ -541,7 +565,7 @@ class BaseChart extends compilable_base_1.CompilableBase {
541
565
  return hasMarkerRemoval && onlyMarkerRemoval;
542
566
  }
543
567
  _isComponentSpecKey(key) {
544
- return this._components.some((component => (component.specKey || component.type) === key));
568
+ return !!MARKER_COMPONENT_SPEC_KEYS[key] || this._components.some((component => (component.specKey || component.type) === key));
545
569
  }
546
570
  _isOnlyComponentSpecsChanged(currentSpec, nextSpec, specKeys) {
547
571
  let hasComponentSpecChange = !1;
@@ -566,6 +590,39 @@ class BaseChart extends compilable_base_1.CompilableBase {
566
590
  const effects = result.effects;
567
591
  return !(!(null == effects ? void 0 : effects.component) || !effects.scaleDomain || result.reMake || result.reCompile || result.reSize || effects.remake || effects.compile || effects.data || effects.series || effects.animation || result.reTransformSpec || result.reAnimate || result.changeTheme || result.changeBackground);
568
592
  }
593
+ _reRunStackDataFlow() {
594
+ var _a, _b;
595
+ this._series.some((series => {
596
+ var _a;
597
+ return null === (_a = series.getStack) || void 0 === _a ? void 0 : _a.call(series);
598
+ })) && (null === (_b = null === (_a = this._stack) || void 0 === _a ? void 0 : _a.stackAll) || void 0 === _b || _b.call(_a),
599
+ this._series.forEach((series => {
600
+ series.getViewDataFilter() && series.reTransformViewData();
601
+ })));
602
+ }
603
+ _getModelSpecIndex(specInfo) {
604
+ var _a;
605
+ const specPath = null !== (_a = specInfo.specPath) && void 0 !== _a ? _a : [], specIndex = specPath[specPath.length - 1];
606
+ return "number" == typeof specIndex ? specIndex : 0;
607
+ }
608
+ _hasComponentForSpecInfo(key, specInfo) {
609
+ const specIndex = this._getModelSpecIndex(specInfo);
610
+ return this._components.some((component => (component.specKey || component.type) === key && component.getSpecIndex() === specIndex));
611
+ }
612
+ _createMissingMarkerComponentsForSpecs(result, componentCache) {
613
+ var _a;
614
+ let createdCount = 0;
615
+ null === (_a = this._specTransformer) || void 0 === _a || _a.forEachComponentInSpec(this._spec, ((constructor, specInfo) => {
616
+ if (result.reMake) return;
617
+ const compSpecKey = constructor.specKey || constructor.type;
618
+ MARKER_COMPONENT_SPEC_KEYS[compSpecKey] && !this._hasComponentForSpecInfo(compSpecKey, specInfo) && (this._isMarkerAdditionSpecSafeWithoutRemake(specInfo.spec) ? (this._createComponent(constructor, specInfo),
619
+ componentCache[compSpecKey] && componentCache[compSpecKey].componentCount++, createdCount++) : result.reMake = !0);
620
+ }), this._option.getSpecInfo()), createdCount && (result.change = !0, result.effects = Object.assign(Object.assign({}, result.effects), {
621
+ component: !0,
622
+ layout: !0,
623
+ render: !0
624
+ }));
625
+ }
569
626
  _removeMarkerComponentsForEmptySpecs(result) {
570
627
  const removedComponents = this._components.filter((component => {
571
628
  var _a;