@visactor/react-vchart 2.1.3 → 2.1.4-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/build/index.js CHANGED
@@ -33773,6 +33773,24 @@
33773
33773
  },
33774
33774
  textBaseline: "middle"
33775
33775
  }
33776
+ },
33777
+ conversionArrow: {
33778
+ line: {
33779
+ style: {
33780
+ stroke: "black"
33781
+ }
33782
+ },
33783
+ symbol: {
33784
+ style: {
33785
+ fill: "black"
33786
+ }
33787
+ },
33788
+ text: {
33789
+ style: {
33790
+ fontSize: 12,
33791
+ fill: "#606773"
33792
+ }
33793
+ }
33776
33794
  }
33777
33795
  };
33778
33796
  return res[is3d ? "transform3d" : "transform"] = {
@@ -33890,20 +33908,16 @@
33890
33908
  }
33891
33909
  return isArray$1(spec) ? spec.map(s => specTransform(s, special)) : spec;
33892
33910
  }
33893
- function functionTransform(spec, VChart) {
33894
- if (!spec) return spec;
33895
- if (isPlainObject$3(spec)) {
33911
+ function functionTransform(value, registry) {
33912
+ var _a;
33913
+ if (!value) return value;
33914
+ if (isString$1(value)) return null !== (_a = registry.getFunction(value)) && void 0 !== _a ? _a : value;
33915
+ if (isPlainObject$3(value)) {
33896
33916
  const result = {};
33897
- for (const key in spec) if (Object.prototype.hasOwnProperty.call(spec, key)) {
33898
- if (isString$1(spec[key]) && VChart.getFunction(spec[key])) {
33899
- result[key] = VChart.getFunction(spec[key]);
33900
- continue;
33901
- }
33902
- result[key] = functionTransform(spec[key], VChart);
33903
- }
33917
+ for (const key in value) Object.prototype.hasOwnProperty.call(value, key) && (result[key] = functionTransform(value[key], registry));
33904
33918
  return result;
33905
33919
  }
33906
- return isArray$1(spec) ? spec.map(s => functionTransform(s, VChart)) : spec;
33920
+ return isArray$1(value) ? value.map(item => functionTransform(item, registry)) : value;
33907
33921
  }
33908
33922
  function transformFunctionAttribute(att, ...args) {
33909
33923
  return isFunction$1(att) ? att(...args) : att;
@@ -48939,13 +48953,14 @@
48939
48953
  if (this._cachedProcessedTheme[cacheKey]) return this._cachedProcessedTheme[cacheKey];
48940
48954
  let theme = this._currentTheme;
48941
48955
  return keys.forEach((key, index) => {
48956
+ var _a;
48942
48957
  if (1 !== index || "series" !== keys[0] && "component" !== keys[0]) theme = null == theme ? void 0 : theme[key];else {
48943
48958
  const buildInTheme = "series" === keys[0] ? Factory.getSeriesBuiltInTheme(key) : Factory.getComponentBuiltInTheme(key);
48944
48959
  theme = theme ? mergeSpec({}, buildInTheme, theme[key]) : buildInTheme;
48945
48960
  }
48946
48961
  index === keys.length - 1 && isValid$1(theme) && (theme = preprocessTheme({
48947
48962
  [key]: theme
48948
- }, this._currentTheme.colorScheme, this._currentTheme.token)[key]);
48963
+ }, this._currentTheme.colorScheme, this._currentTheme.token)[key], (null === (_a = this.getFunctionList()) || void 0 === _a ? void 0 : _a.length) && (theme = functionTransform(theme, this)));
48949
48964
  }), this._cachedProcessedTheme[cacheKey] = theme, theme;
48950
48965
  }, removeUndefined(options), this._option = Object.assign(Object.assign({}, this._option), options), (null == options ? void 0 : options.optimize) && (this._option.optimize = Object.assign(Object.assign({}, this._option.optimize), options.optimize)), this._onError = null === (_a = this._option) || void 0 === _a ? void 0 : _a.onError;
48951
48966
  const _k = this._option,
@@ -54559,7 +54574,7 @@
54559
54574
  animationEnter: this._animationConfig.enter ? Array.isArray(this._animationConfig.enter) ? this._animationConfig.enter[0] : this._animationConfig.enter : void 0,
54560
54575
  animationUpdate: this._animationConfig.update ? Array.isArray(this._animationConfig.update) ? this._animationConfig.update[0] : this._animationConfig.update : void 0,
54561
54576
  animationExit: this._animationConfig.exit ? Array.isArray(this._animationConfig.exit) ? this._animationConfig.exit[0] : this._animationConfig.exit : void 0
54562
- })), this._component ? this._component.setAttributes(attrs) : (this._component = Factory.createGraphicComponent(this._componentType, attrs, {
54577
+ })), this._component ? (this._component.setAttributes(attrs), this._product && this._component.parent !== this._product && this._product.appendChild(this._component)) : (this._component = Factory.createGraphicComponent(this._componentType, attrs, {
54563
54578
  mode: this._mode,
54564
54579
  skipDefault: this._markConfig.skipTheme
54565
54580
  }), this._component && this._product.appendChild(this._component)), this._component && (this._component.context = this._getCommonContext()), this._markConfig.support3d && this._product && this._product.setMode("3d"), this.model.event.emit(HOOK_EVENT.AFTER_ELEMENT_ENCODE, {
@@ -55133,6 +55148,8 @@
55133
55148
  specIndex: this._seriesIndex
55134
55149
  });
55135
55150
  }
55151
+ }, this._clearContinuousBarBandwidthCache = () => {
55152
+ this._continuousBarBandwidthCache = void 0;
55136
55153
  }, this._transformLayoutPosition = pos => {
55137
55154
  let {
55138
55155
  x: x,
@@ -55339,12 +55356,60 @@
55339
55356
  isContinuous: isContinuous(this._scale.type),
55340
55357
  dataToPosition: this.dataToPosition.bind(this),
55341
55358
  getScale: (depth = 0) => this._scales[depth],
55359
+ getBandwidth: (depth = 0) => this._getContinuousBarBandwidth(depth),
55342
55360
  getAxisType: () => this.type,
55343
55361
  getAxisId: () => this.id,
55344
55362
  isInverse: () => !0 === this._inverse,
55345
55363
  getSpec: () => this._spec
55346
55364
  };
55347
55365
  }
55366
+ _getContinuousBarBandwidth(depth = 0) {
55367
+ if (0 !== depth || !isContinuous(this._scale.type)) return;
55368
+ const scale = this._scales[0],
55369
+ domain = scale.domain(),
55370
+ range = scale.range(),
55371
+ domainStart = +(null == domain ? void 0 : domain[0]),
55372
+ domainEnd = +(null == domain ? void 0 : domain[domain.length - 1]),
55373
+ rangeStart = +(null == range ? void 0 : range[0]),
55374
+ rangeEnd = +(null == range ? void 0 : range[range.length - 1]);
55375
+ if (!(Number.isFinite(domainStart) && Number.isFinite(domainEnd) && Number.isFinite(rangeStart) && Number.isFinite(rangeEnd) && domainStart !== domainEnd)) return;
55376
+ const cache = this._continuousBarBandwidthCache;
55377
+ if (cache && cache.scale === scale && cache.domainStart === domainStart && cache.domainEnd === domainEnd && cache.rangeStart === rangeStart && cache.rangeEnd === rangeEnd) return cache.bandWidth;
55378
+ const valueSet = new Set(),
55379
+ orient = this.getOrient();
55380
+ eachSeries(this._regions, s => {
55381
+ var _a, _b, _c, _d;
55382
+ if (s.type !== SeriesTypeEnum.bar) return;
55383
+ const barSeries = s,
55384
+ field = isXAxis(orient) && "vertical" === barSeries.direction ? barSeries.fieldX[0] : isYAxis(orient) && "horizontal" === barSeries.direction ? barSeries.fieldY[0] : void 0,
55385
+ values = field ? null === (_d = null === (_c = null === (_b = null === (_a = s.getViewDataStatistics) || void 0 === _a ? void 0 : _a.call(s)) || void 0 === _b ? void 0 : _b.latestData) || void 0 === _c ? void 0 : _c[field]) || void 0 === _d ? void 0 : _d.values : void 0;
55386
+ null == values || values.forEach(value => {
55387
+ const numericValue = +value;
55388
+ Number.isFinite(numericValue) && valueSet.add(numericValue);
55389
+ });
55390
+ }, {
55391
+ userId: this._seriesUserId,
55392
+ specIndex: this._seriesIndex
55393
+ });
55394
+ const values = Array.from(valueSet).sort((a, b) => a - b);
55395
+ if (values.length < 2) return;
55396
+ let minStep = 1 / 0,
55397
+ lastValue = values[0];
55398
+ for (let i = 1; i < values.length; i++) {
55399
+ const value = values[i],
55400
+ step = value - lastValue;
55401
+ step > 0 && step < minStep && (minStep = step), lastValue = value;
55402
+ }
55403
+ const bandWidth = minStep < 1 / 0 ? Math.abs((rangeEnd - rangeStart) / (domainEnd - domainStart) * minStep) : void 0;
55404
+ return Number.isFinite(bandWidth) ? (this._continuousBarBandwidthCache = {
55405
+ scale: scale,
55406
+ domainStart: domainStart,
55407
+ domainEnd: domainEnd,
55408
+ rangeStart: rangeStart,
55409
+ rangeEnd: rangeEnd,
55410
+ bandWidth: bandWidth
55411
+ }, bandWidth) : void 0;
55412
+ }
55348
55413
  afterCompile() {
55349
55414
  var _a;
55350
55415
  (null === (_a = this._axisMark) || void 0 === _a ? void 0 : _a.getProduct()) && this.event.on(HOOK_EVENT.AFTER_ELEMENT_ENCODE, ({
@@ -55527,7 +55592,13 @@
55527
55592
  })] : [];
55528
55593
  }
55529
55594
  initEvent() {
55530
- super.initEvent(), this._specVisible && (this.event.on(ChartEvent.layoutEnd, this._updateAxisLayout), this.event.on(ChartEvent.layoutEnd, this._fixAxisOnZero), this.event.on(ChartEvent.layoutRectUpdate, () => {
55595
+ super.initEvent(), eachSeries(this._regions, s => {
55596
+ var _a, _b;
55597
+ null === (_b = null === (_a = s.getViewDataStatistics) || void 0 === _a ? void 0 : _a.call(s)) || void 0 === _b || _b.target.addListener("change", this._clearContinuousBarBandwidthCache);
55598
+ }, {
55599
+ userId: this._seriesUserId,
55600
+ specIndex: this._seriesIndex
55601
+ }), this._specVisible && (this.event.on(ChartEvent.layoutEnd, this._updateAxisLayout), this.event.on(ChartEvent.layoutEnd, this._fixAxisOnZero), this.event.on(ChartEvent.layoutRectUpdate, () => {
55531
55602
  this._clearLayoutCache();
55532
55603
  }));
55533
55604
  }
@@ -71015,6 +71086,20 @@
71015
71086
  compileOnlyKeys: Object.assign(Object.assign({}, policy.compileOnlyKeys), BAR_SERIES_COMPILE_ONLY_KEYS)
71016
71087
  });
71017
71088
  }
71089
+ getStatisticFields() {
71090
+ var _a;
71091
+ const fields = super.getStatisticFields(),
71092
+ positionAxisHelper = "horizontal" === this.direction ? this.getYAxisHelper() : this.getXAxisHelper(),
71093
+ positionFields = "horizontal" === this.direction ? this._fieldY : this._fieldX,
71094
+ positionScale = null === (_a = null == positionAxisHelper ? void 0 : positionAxisHelper.getScale) || void 0 === _a ? void 0 : _a.call(positionAxisHelper, 0);
71095
+ return positionScale && isContinuous(positionScale.type) && positionFields.forEach(field => {
71096
+ const fieldStatistics = fields.find(entry => entry.key === field);
71097
+ fieldStatistics ? fieldStatistics.operations.includes("values") || fieldStatistics.operations.push("values") : fields.push({
71098
+ key: field,
71099
+ operations: ["values"]
71100
+ });
71101
+ }), fields;
71102
+ }
71018
71103
  initMark() {
71019
71104
  this._initBarBackgroundMark(), this._barMark = this._createMark(Object.assign(Object.assign({}, BarSeries.mark.bar), {
71020
71105
  name: this._barMarkName,
@@ -71345,18 +71430,19 @@
71345
71430
  this._barMark.setAnimationConfig(animationConfig(null === (_b = Factory.getAnimationInKey("bar")) || void 0 === _b ? void 0 : _b(barAnimationParams, appearPreset), userAnimationConfig(this._barMarkName, this._spec, this._markAttributeContext), animationParams));
71346
71431
  }
71347
71432
  _getBarWidth(axisHelper, scaleDepth) {
71348
- var _a, _b;
71433
+ var _a;
71349
71434
  const depthFromSpec = this._groups ? this._groups.fields.length : 1,
71350
71435
  depth = isNil$1(scaleDepth) ? depthFromSpec : Math.min(depthFromSpec, scaleDepth),
71351
- bandWidth = null !== (_b = null === (_a = axisHelper.getBandwidth) || void 0 === _a ? void 0 : _a.call(axisHelper, depth - 1)) && void 0 !== _b ? _b : 6,
71352
71436
  hasBarWidth = isValid$1(this._spec.barWidth) && depth === depthFromSpec,
71437
+ axisBandWidth = hasBarWidth && "number" == typeof this._spec.barWidth && "string" != typeof this._spec.barMinWidth && "string" != typeof this._spec.barMaxWidth || null === (_a = axisHelper.getBandwidth) || void 0 === _a ? void 0 : _a.call(axisHelper, depth - 1),
71438
+ bandWidth = null != axisBandWidth ? axisBandWidth : 6,
71353
71439
  hasBarMinWidth = isValid$1(this._spec.barMinWidth),
71354
71440
  hasBarMaxWidth = isValid$1(this._spec.barMaxWidth);
71355
- let width = bandWidth;
71441
+ let width = !axisHelper.isContinuous || isNil$1(axisBandWidth) || hasBarWidth ? bandWidth : .5 * bandWidth;
71356
71442
  return hasBarWidth && (width = getActualNumValue(this._spec.barWidth, bandWidth)), hasBarMinWidth && (width = Math.max(width, getActualNumValue(this._spec.barMinWidth, bandWidth))), hasBarMaxWidth && (width = Math.min(width, getActualNumValue(this._spec.barMaxWidth, bandWidth))), width;
71357
71443
  }
71358
71444
  _getPosition(direction, datum, scaleDepth, mark) {
71359
- var _a, _b, _c, _d, _e;
71445
+ var _a, _b, _c, _d, _e, _f;
71360
71446
  let axisHelper, sizeAttribute, dataToPosition;
71361
71447
  "horizontal" === direction ? (axisHelper = this.getYAxisHelper(), sizeAttribute = "height", dataToPosition = "barBackground" === mark ? this.dataToBarBackgroundPositionY.bind(this) : this.dataToPositionY.bind(this)) : (axisHelper = this.getXAxisHelper(), sizeAttribute = "width", dataToPosition = "barBackground" === mark ? this.dataToBarBackgroundPositionX.bind(this) : this.dataToPositionX.bind(this));
71362
71448
  const scale = axisHelper.getScale(0),
@@ -71377,7 +71463,7 @@
71377
71463
  i = groupValues.indexOf(datum[groupField]);
71378
71464
  index === groupFields.length - 1 ? (totalWidth += groupCount * size + (groupCount - 1) * gap, offSet += i * (size + gap)) : (offSet += i * (totalWidth + gap), totalWidth += totalWidth + (groupCount - 1) * gap);
71379
71465
  }
71380
- return scale.scale(datum[groupFields[0]]) + axisHelper.getBandwidth(0) / 2 - totalWidth / 2 + offSet;
71466
+ return scale.scale(datum[groupFields[0]]) + (null !== (_f = axisHelper.getBandwidth(0)) && void 0 !== _f ? _f : bandWidth) / 2 - totalWidth / 2 + offSet;
71381
71467
  }
71382
71468
  const continuous = isContinuous(scale.type || "band");
71383
71469
  return dataToPosition(datum, depth) + .5 * (bandWidth - size) + (continuous ? -bandWidth / 2 : 0);