@visactor/vchart 1.1.1-beta.1 → 1.1.2

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
@@ -41365,24 +41365,6 @@
41365
41365
  function defaultLabelPosition(type) {
41366
41366
  return "rect" === type ? DefaultRectPositions : DefaultPositions;
41367
41367
  }
41368
- function clampText(text, width, height) {
41369
- const {
41370
- x1: x1,
41371
- x2: x2,
41372
- y1: y1,
41373
- y2: y2
41374
- } = text.AABBBounds,
41375
- minX = Math.min(x1, x2),
41376
- maxX = Math.max(x1, x2),
41377
- minY = Math.min(y1, y2),
41378
- maxY = Math.max(y1, y2);
41379
- let dx = 0,
41380
- dy = 0;
41381
- return minX < 0 && maxX - minX <= width ? dx = -minX : maxX > width && minX - (maxX - width) >= 0 && (dx = width - maxX), minY < 0 && maxY - minY <= height ? dy = -minY : maxY > height && minY - (maxY - height) >= 0 && (dy = height - maxY), {
41382
- dx: dx,
41383
- dy: dy
41384
- };
41385
- }
41386
41368
 
41387
41369
  const fadeIn = function () {
41388
41370
  let textAttribute = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
@@ -41461,17 +41443,9 @@
41461
41443
  this._bmpTool = bmpTool;
41462
41444
  }
41463
41445
  render() {
41464
- this._prepare();
41465
- const {
41466
- overlap: overlap,
41467
- smartInvert: smartInvert,
41468
- dataFilter: dataFilter,
41469
- customLayoutFunc: customLayoutFunc,
41470
- customOverlapFunc: customOverlapFunc
41471
- } = this.attribute;
41472
- let labels,
41473
- data = this.attribute.data;
41474
- isFunction(dataFilter) && (data = dataFilter(data)), isFunction(customLayoutFunc) ? labels = customLayoutFunc(data, d => this._idToGraphic.get(d.id)) : (labels = this.layout(data), isFunction(customOverlapFunc) ? labels = customOverlapFunc(labels, d => this._idToGraphic.get(d.id)) : !1 !== overlap && (labels = this._overlapping(labels))), !1 !== smartInvert && this._smartInvert(labels), this._renderLabels(labels);
41446
+ const currentBaseMarks = this._checkMarks(),
41447
+ labels = this.layout(currentBaseMarks);
41448
+ this._smartInvert(labels), this._renderLabels(labels);
41475
41449
  }
41476
41450
  _bindEvent(target) {
41477
41451
  if (!target) return;
@@ -41490,53 +41464,52 @@
41490
41464
  const text = createText(attributes);
41491
41465
  return this._bindEvent(text), this._setStates(text), text;
41492
41466
  }
41493
- _prepare() {
41467
+ _checkMarks() {
41494
41468
  var _a;
41495
41469
  const baseMarks = this.getBaseMarks(),
41496
41470
  currentBaseMarks = [];
41497
- if (baseMarks.forEach(mark => {
41471
+ return baseMarks.forEach(mark => {
41498
41472
  "willRelease" !== mark.releaseStatus && currentBaseMarks.push(mark);
41499
- }), null === (_a = this._idToGraphic) || void 0 === _a || _a.clear(), this._baseMarks = currentBaseMarks, !currentBaseMarks || 0 === currentBaseMarks.length) return;
41473
+ }), this._prevRelationMap = new Map(this._relationMap), null === (_a = this._relationMap) || void 0 === _a || _a.clear(), currentBaseMarks;
41474
+ }
41475
+ layout(currentMarks) {
41500
41476
  const {
41477
+ textStyle: textStyle,
41478
+ position: position,
41479
+ offset: offset
41480
+ } = this.attribute;
41481
+ let {
41501
41482
  data: data
41502
41483
  } = this.attribute;
41503
- if (data && 0 !== data.length) {
41504
- this._idToGraphic || (this._idToGraphic = new Map());
41505
- for (let i = 0; i < currentBaseMarks.length; i++) {
41506
- const textData = data[i],
41507
- baseMark = currentBaseMarks[i];
41508
- textData && baseMark && (isValid(textData.id) || (textData.id = `vrender-component-${this.name}-${i}`), this._idToGraphic.set(textData.id, baseMark));
41509
- }
41510
- }
41511
- }
41512
- layout() {
41513
- let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
41514
- const {
41515
- textStyle = {},
41516
- position: position,
41517
- offset: offset
41518
- } = this.attribute,
41519
- labels = [];
41484
+ if (isFunction(data) && (data = data({})), !data || 0 === data.length) return [];
41485
+ let labels = [];
41486
+ isFunction(this.attribute.sort) && currentMarks && currentMarks.length && (currentMarks = currentMarks.sort(this.attribute.sort)), this._relationMap || (this._relationMap = new Map());
41520
41487
  for (let i = 0; i < data.length; i++) {
41521
41488
  const textData = data[i],
41522
- baseMark = this._idToGraphic.get(textData.id),
41523
- labelAttribute = Object.assign(Object.assign({}, textStyle), textData),
41524
- text = this._createLabelText(labelAttribute),
41525
- textBounds = this.getGraphicBounds(text),
41526
- graphicBounds = this.getGraphicBounds(baseMark, {
41527
- x: textData.x,
41528
- y: textData.y
41529
- }),
41530
- textLocation = this.labeling(textBounds, graphicBounds, isFunction(position) ? position(textData) : position, offset);
41531
- textLocation && (labelAttribute.x = textLocation.x, labelAttribute.y = textLocation.y, text.setAttributes(textLocation), labels.push(text));
41489
+ baseMark = null == currentMarks ? void 0 : currentMarks[i],
41490
+ labelAttribute = Object.assign(Object.assign(Object.assign({}, textStyle), textData), {
41491
+ _relatedIndex: i
41492
+ });
41493
+ if (this._relationMap.set(i, baseMark), textData) {
41494
+ const text = createText(labelAttribute);
41495
+ text.update();
41496
+ const textBounds = this.getGraphicBounds(text),
41497
+ graphicBounds = this.getGraphicBounds(baseMark, {
41498
+ x: textData.x,
41499
+ y: textData.y
41500
+ }),
41501
+ textAttributes = this.labeling(textBounds, graphicBounds, isFunction(position) ? position(textData) : position, offset);
41502
+ if (!textAttributes) continue;
41503
+ labelAttribute.x = textAttributes.x, labelAttribute.y = textAttributes.y, labels.push(labelAttribute);
41504
+ }
41532
41505
  }
41533
- return labels;
41506
+ return this._baseMarks = currentMarks, !1 !== this.attribute.overlap && (labels = this.overlapping(labels, this.attribute.overlap)), labels;
41534
41507
  }
41535
- _overlapping(labels) {
41536
- var _a, _b, _c, _d;
41508
+ overlapping(labels) {
41509
+ let option = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
41510
+ var _a, _b, _c, _d, _e;
41537
41511
  if (0 === labels.length) return [];
41538
- const option = this.attribute.overlap,
41539
- result = [],
41512
+ const result = [],
41540
41513
  baseMarkGroup = this.getBaseMarkGroup(),
41541
41514
  size = null !== (_a = option.size) && void 0 !== _a ? _a : {
41542
41515
  width: null !== (_b = null == baseMarkGroup ? void 0 : baseMarkGroup.AABBBounds.width()) && void 0 !== _b ? _b : 0,
@@ -41557,45 +41530,27 @@
41557
41530
  }));
41558
41531
  for (let i = 0; i < labels.length; i++) {
41559
41532
  if (!1 === labels[i].visible) continue;
41560
- const text = labels[i],
41561
- baseMark = this._idToGraphic.get(text.attribute.id);
41533
+ const text = createText(labels[i]),
41534
+ baseMark = null === (_e = this._baseMarks) || void 0 === _e ? void 0 : _e[i];
41562
41535
  if (text.update(), canPlace(bmpTool, bitmap, text.AABBBounds, clampForce)) {
41563
41536
  if (!checkBounds) {
41564
- bitmap.setRange(boundToRange(bmpTool, text.AABBBounds, !0)), result.push(text);
41537
+ bitmap.setRange(boundToRange(bmpTool, text.AABBBounds, !0)), result.push(Object.assign({}, text.attribute));
41565
41538
  continue;
41566
41539
  }
41567
41540
  if (checkBounds && (null == baseMark ? void 0 : baseMark.AABBBounds) && canPlaceInside(text.AABBBounds, null == baseMark ? void 0 : baseMark.AABBBounds)) {
41568
- bitmap.setRange(boundToRange(bmpTool, text.AABBBounds, !0)), result.push(text);
41569
- continue;
41570
- }
41571
- }
41572
- if (clampForce) {
41573
- const {
41574
- dx = 0,
41575
- dy = 0
41576
- } = clampText(text, bmpTool.width, bmpTool.height);
41577
- if ((0 !== dx || 0 !== dy) && canPlace(bmpTool, bitmap, {
41578
- x1: text.AABBBounds.x1 + dx,
41579
- x2: text.AABBBounds.x2 + dx,
41580
- y1: text.AABBBounds.y1 + dy,
41581
- y2: text.AABBBounds.y2 + dy
41582
- })) {
41583
- text.setAttributes({
41584
- x: text.attribute.x + dx,
41585
- y: text.attribute.y + dy
41586
- }), result.push(text);
41541
+ bitmap.setRange(boundToRange(bmpTool, text.AABBBounds, !0)), result.push(Object.assign({}, text.attribute));
41587
41542
  continue;
41588
41543
  }
41589
41544
  }
41590
41545
  let hasPlace = !1;
41591
41546
  for (let j = 0; j < strategy.length; j++) if (hasPlace = place$2(bmpTool, bitmap, strategy[j], this.attribute, text, this.getGraphicBounds(baseMark, labels[i]), this.labeling), !1 !== hasPlace) {
41592
- text.setAttributes({
41547
+ result.push(Object.assign(Object.assign({}, text.attribute), {
41593
41548
  x: hasPlace.x,
41594
41549
  y: hasPlace.y
41595
- }), result.push(text);
41550
+ }));
41596
41551
  break;
41597
41552
  }
41598
- !hasPlace && !hideOnHit && result.push(text);
41553
+ !hasPlace && !hideOnHit && result.push(Object.assign({}, text.attribute));
41599
41554
  }
41600
41555
  return isFunction(this.onAfterLabelOverlap) && this.onAfterLabelOverlap(bitmap), result;
41601
41556
  }
@@ -41627,16 +41582,17 @@
41627
41582
  easing = null !== (_d = animationConfig.easing) && void 0 !== _d ? _d : DefaultLabelAnimation.easing,
41628
41583
  delay = null !== (_e = animationConfig.delay) && void 0 !== _e ? _e : 0,
41629
41584
  currentTextMap = new Map(),
41630
- prevTextMap = this._graphicToText || new Map(),
41585
+ prevTextMap = this._textMap || new Map(),
41631
41586
  texts = [];
41632
- labels.forEach((text, index) => {
41633
- const relatedGraphic = this._idToGraphic.get(text.attribute.id),
41587
+ labels.forEach((label, index) => {
41588
+ const text = this._createLabelText(label),
41589
+ relatedGraphic = this._relationMap.get(label._relatedIndex),
41634
41590
  state = (null == prevTextMap ? void 0 : prevTextMap.get(relatedGraphic)) ? "update" : "enter";
41635
41591
  if ("enter" === state) if (texts.push(text), currentTextMap.set(relatedGraphic, text), !disableAnimation && relatedGraphic) {
41636
41592
  const {
41637
41593
  from: from,
41638
41594
  to: to
41639
- } = getAnimationAttributes(text.attribute, "fadeIn");
41595
+ } = getAnimationAttributes(label, "fadeIn");
41640
41596
  this.add(text), relatedGraphic.onAnimateBind = () => {
41641
41597
  text.setAttributes(from);
41642
41598
  const listener = this._afterRelatedGraphicAttributeUpdate(text, texts, index, relatedGraphic, {
@@ -41661,7 +41617,7 @@
41661
41617
  disableAnimation ? this.removeChild(label) : null == label || label.animate().to(getAnimationAttributes(label.attribute, "fadeOut").to, duration, easing).onEnd(() => {
41662
41618
  this.removeChild(label);
41663
41619
  });
41664
- }), this._graphicToText = currentTextMap;
41620
+ }), this._textMap = currentTextMap;
41665
41621
  }
41666
41622
  _afterRelatedGraphicAttributeUpdate(text, texts, index, relatedGraphic, _ref) {
41667
41623
  let {
@@ -41704,32 +41660,21 @@
41704
41660
  return listener;
41705
41661
  }
41706
41662
  _smartInvert(labels) {
41707
- const option = this.attribute.smartInvert || {},
41708
- {
41709
- textType: textType,
41710
- contrastRatiosThreshold: contrastRatiosThreshold,
41711
- alternativeColors: alternativeColors
41712
- } = option;
41713
- for (let i = 0; i < labels.length; i++) {
41714
- const label = labels[i];
41663
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
41664
+ if (!1 !== this.attribute.smartInvert) for (let i = 0; i < labels.length; i++) {
41665
+ const label = null == labels ? void 0 : labels[i];
41715
41666
  if (!label) continue;
41716
- const baseMark = this._idToGraphic.get(label.attribute.id),
41717
- isInside = canPlaceInside(label.AABBBounds, null == baseMark ? void 0 : baseMark.AABBBounds);
41718
- if (label.attribute.stroke && label.attribute.lineWidth > 0) label.setAttributes({
41719
- fill: labelSmartInvert(label.attribute.fill, label.attribute.stroke, textType, contrastRatiosThreshold, alternativeColors)
41720
- });else if (isInside) {
41721
- const backgroundColor = baseMark.attribute.fill,
41722
- foregroundColor = label.attribute.fill;
41723
- label.setAttributes({
41724
- fill: labelSmartInvert(foregroundColor, backgroundColor, textType, contrastRatiosThreshold, alternativeColors)
41725
- });
41726
- } else if (label.attribute.lineWidth > 0) {
41727
- const backgroundColor = label.attribute.stroke,
41728
- foregroundColor = label.attribute.fill;
41729
- label.setAttributes({
41730
- stroke: baseMark.attribute.fill,
41731
- fill: labelSmartInvert(foregroundColor, backgroundColor, textType, contrastRatiosThreshold, alternativeColors)
41732
- });
41667
+ const isInside = canPlaceInside(createText(label).AABBBounds, null === (_a = this._relationMap.get(label._relatedIndex)) || void 0 === _a ? void 0 : _a.AABBBounds);
41668
+ if (label.stroke && label.lineWidth > 0) label.fill = labelSmartInvert(label.fill, label.stroke, null === (_b = this.attribute.smartInvert) || void 0 === _b ? void 0 : _b.textType, null === (_c = this.attribute.smartInvert) || void 0 === _c ? void 0 : _c.contrastRatiosThreshold, null === (_d = this.attribute.smartInvert) || void 0 === _d ? void 0 : _d.alternativeColors);else if (isInside) {
41669
+ const backgroundColor = this._relationMap.get(label._relatedIndex).attribute.fill,
41670
+ foregroundColor = label.fill;
41671
+ label.fill = labelSmartInvert(foregroundColor, backgroundColor, null === (_e = this.attribute.smartInvert) || void 0 === _e ? void 0 : _e.textType, null === (_f = this.attribute.smartInvert) || void 0 === _f ? void 0 : _f.contrastRatiosThreshold, null === (_g = this.attribute.smartInvert) || void 0 === _g ? void 0 : _g.alternativeColors);
41672
+ } else if (label.lineWidth > 0) {
41673
+ const baseMark = this._relationMap.get(label._relatedIndex);
41674
+ label.stroke = baseMark.attribute.fill;
41675
+ const backgroundColor = label.stroke,
41676
+ foregroundColor = label.fill;
41677
+ label.fill = labelSmartInvert(foregroundColor, backgroundColor, null === (_h = this.attribute.smartInvert) || void 0 === _h ? void 0 : _h.textType, null === (_j = this.attribute.smartInvert) || void 0 === _j ? void 0 : _j.contrastRatiosThreshold, null === (_k = this.attribute.smartInvert) || void 0 === _k ? void 0 : _k.alternativeColors);
41733
41678
  }
41734
41679
  }
41735
41680
  }
@@ -54119,10 +54064,6 @@
54119
54064
  function getMapSource(type) {
54120
54065
  return geoSourceMap.get(type);
54121
54066
  }
54122
- function clearMapSource() {
54123
- geoSourceMap.clear();
54124
- mapDataSet = null;
54125
- }
54126
54067
 
54127
54068
  function copyOneDataView(d, deep = false) {
54128
54069
  let _deep = deep;
@@ -54917,7 +54858,6 @@
54917
54858
  this._compiler?.release();
54918
54859
  this._eventDispatcher?.release();
54919
54860
  this._unBindResizeEvent();
54920
- clearMapSource();
54921
54861
  this._releaseData();
54922
54862
  this._chart = null;
54923
54863
  this._compiler = null;
@@ -58088,7 +58028,7 @@
58088
58028
  VChart.useMark([ComponentMark, GroupMark, ImageMark]);
58089
58029
  Factory.registerRegion('region', Region);
58090
58030
  Factory.registerLayout('base', Layout);
58091
- const version = "1.1.1-beta.1";
58031
+ const version = "1.1.2";
58092
58032
  Logger.getInstance(LoggerLevel.Error);
58093
58033
 
58094
58034
  var SeriesMarkNameEnum;
@@ -66530,7 +66470,7 @@
66530
66470
  }, {
66531
66471
  morph: shouldDoMorph(this._spec.animation, this._spec.morph, userAnimationConfig(this.type, this._spec)),
66532
66472
  defaultMorphElementKey: this._seriesField,
66533
- key: this._seriesField,
66473
+ key: DEFAULT_DATA_KEY,
66534
66474
  groupKey: this._seriesField,
66535
66475
  skipBeforeLayouted: true,
66536
66476
  isSeriesMark: true
@@ -81099,8 +81039,19 @@
81099
81039
  if (!this._expand) {
81100
81040
  return;
81101
81041
  }
81102
- const domainMin = domain[0];
81103
- const domainMax = domain[domain.length - 1];
81042
+ let domainMin = domain[0];
81043
+ let domainMax = domain[domain.length - 1];
81044
+ if (domainMin === domainMax) {
81045
+ if (domainMax === 0) {
81046
+ domainMax = 1;
81047
+ }
81048
+ else if (domainMax > 0) {
81049
+ domainMin = 0;
81050
+ }
81051
+ else if (domainMax < 0) {
81052
+ domainMax = 0;
81053
+ }
81054
+ }
81104
81055
  if (isValid(this._expand.min)) {
81105
81056
  domain[0] = domainMin - (domainMax - domainMin) * this._expand.min;
81106
81057
  }
@@ -81109,6 +81060,10 @@
81109
81060
  }
81110
81061
  }
81111
81062
  niceDomain(domain) {
81063
+ const { min: userMin, max: userMax } = getLinearAxisSpecDomain(this._spec);
81064
+ if (isValid(userMin) || isValid(userMax)) {
81065
+ return domain;
81066
+ }
81112
81067
  if (Math.abs(minInArray(domain) - maxInArray(domain)) <= 1e-12) {
81113
81068
  let num = domain[0];
81114
81069
  const flag = num >= 0 ? 1 : -1;
@@ -83150,9 +83105,26 @@
83150
83105
  this._actualScale = this._spec.zoomLimit?.max;
83151
83106
  scale = this._spec.zoomLimit?.max / _lastActualScale;
83152
83107
  }
83153
- event.zoomDelta = scale;
83108
+ if (event) {
83109
+ event.zoomDelta = scale;
83110
+ }
83154
83111
  this.zoom(scale, [params.zoomX, params.zoomY]);
83112
+ return scale;
83155
83113
  };
83114
+ dispatchZoom(zoomDelta, center) {
83115
+ const scaleCenter = center || {
83116
+ x: this.getLayoutStartPoint().x + this.getLayoutRect().width / 2,
83117
+ y: this.getLayoutStartPoint().y + this.getLayoutRect().height / 2
83118
+ };
83119
+ const scale = this._handleChartZoom({ zoomDelta, zoomX: scaleCenter.x, zoomY: scaleCenter.y });
83120
+ if (scale !== 1) {
83121
+ this.event.emit('zoom', {
83122
+ scale,
83123
+ scaleCenter,
83124
+ model: this
83125
+ });
83126
+ }
83127
+ }
83156
83128
  initEvent() {
83157
83129
  this.event.on(ChartEvent.scaleUpdate, { filter: ({ model }) => model?.id === this.id }, this.effect.scaleUpdate.bind(this));
83158
83130
  if (this._spec.roam) {
@@ -88282,6 +88254,12 @@
88282
88254
  });
88283
88255
  });
88284
88256
  }
88257
+ updateSpec(spec) {
88258
+ const result = super.updateSpec(spec);
88259
+ result.reRender = true;
88260
+ result.reMake = true;
88261
+ return result;
88262
+ }
88285
88263
  onRender(ctx) {
88286
88264
  }
88287
88265
  changeRegions(regions) {