@visactor/vchart 1.1.0-beta.6 → 1.1.0-beta.7

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.
Files changed (69) hide show
  1. package/build/index.js +104 -75
  2. package/build/index.min.js +2 -2
  3. package/cjs/chart/base-chart.d.ts +1 -1
  4. package/cjs/chart/base-chart.js +2 -2
  5. package/cjs/chart/base-chart.js.map +1 -1
  6. package/cjs/chart/interface/chart.d.ts +1 -0
  7. package/cjs/chart/interface/chart.js.map +1 -1
  8. package/cjs/component/legend/discrete/legend.js +2 -2
  9. package/cjs/component/legend/discrete/legend.js.map +1 -1
  10. package/cjs/component/tooltip/handler/base.d.ts +2 -1
  11. package/cjs/component/tooltip/handler/base.js +30 -36
  12. package/cjs/component/tooltip/handler/base.js.map +1 -1
  13. package/cjs/component/tooltip/interface/spec.d.ts +1 -1
  14. package/cjs/component/tooltip/interface/spec.js.map +1 -1
  15. package/cjs/component/tooltip/tooltip.js +6 -7
  16. package/cjs/component/tooltip/tooltip.js.map +1 -1
  17. package/cjs/constant/index.d.ts +6 -5
  18. package/cjs/constant/index.js +4 -4
  19. package/cjs/constant/index.js.map +1 -1
  20. package/cjs/core/index.d.ts +1 -1
  21. package/cjs/core/index.js +1 -1
  22. package/cjs/core/index.js.map +1 -1
  23. package/cjs/core/interface.d.ts +6 -1
  24. package/cjs/core/interface.js.map +1 -1
  25. package/cjs/core/vchart.d.ts +3 -2
  26. package/cjs/core/vchart.js +14 -0
  27. package/cjs/core/vchart.js.map +1 -1
  28. package/cjs/mark/path.js +1 -0
  29. package/cjs/mark/path.js.map +1 -1
  30. package/cjs/mark/polygon/polygon.d.ts +2 -1
  31. package/cjs/mark/polygon/polygon.js +5 -0
  32. package/cjs/mark/polygon/polygon.js.map +1 -1
  33. package/cjs/series/base/base-series.d.ts +2 -2
  34. package/cjs/series/base/base-series.js +1 -1
  35. package/cjs/series/base/base-series.js.map +1 -1
  36. package/esm/chart/base-chart.d.ts +1 -1
  37. package/esm/chart/base-chart.js +2 -2
  38. package/esm/chart/base-chart.js.map +1 -1
  39. package/esm/chart/interface/chart.d.ts +1 -0
  40. package/esm/chart/interface/chart.js.map +1 -1
  41. package/esm/component/legend/discrete/legend.js +2 -2
  42. package/esm/component/legend/discrete/legend.js.map +1 -1
  43. package/esm/component/tooltip/handler/base.d.ts +2 -1
  44. package/esm/component/tooltip/handler/base.js +27 -34
  45. package/esm/component/tooltip/handler/base.js.map +1 -1
  46. package/esm/component/tooltip/interface/spec.d.ts +1 -1
  47. package/esm/component/tooltip/interface/spec.js.map +1 -1
  48. package/esm/component/tooltip/tooltip.js +7 -6
  49. package/esm/component/tooltip/tooltip.js.map +1 -1
  50. package/esm/constant/index.d.ts +6 -5
  51. package/esm/constant/index.js +4 -4
  52. package/esm/constant/index.js.map +1 -1
  53. package/esm/core/index.d.ts +1 -1
  54. package/esm/core/index.js +1 -1
  55. package/esm/core/index.js.map +1 -1
  56. package/esm/core/interface.d.ts +6 -1
  57. package/esm/core/interface.js.map +1 -1
  58. package/esm/core/vchart.d.ts +3 -2
  59. package/esm/core/vchart.js +14 -1
  60. package/esm/core/vchart.js.map +1 -1
  61. package/esm/mark/path.js +1 -0
  62. package/esm/mark/path.js.map +1 -1
  63. package/esm/mark/polygon/polygon.d.ts +2 -1
  64. package/esm/mark/polygon/polygon.js +5 -0
  65. package/esm/mark/polygon/polygon.js.map +1 -1
  66. package/esm/series/base/base-series.d.ts +2 -2
  67. package/esm/series/base/base-series.js +1 -1
  68. package/esm/series/base/base-series.js.map +1 -1
  69. package/package.json +3 -3
package/build/index.js CHANGED
@@ -5641,25 +5641,6 @@
5641
5641
  y: actualTop
5642
5642
  };
5643
5643
  }
5644
- const getScrollLeft = element => {
5645
- var _a, _b, _c;
5646
- return element === (null === (_a = null === globalThis || void 0 === globalThis ? void 0 : globalThis.document) || void 0 === _a ? void 0 : _a.body) ? (null === (_c = null === (_b = null === globalThis || void 0 === globalThis ? void 0 : globalThis.document) || void 0 === _b ? void 0 : _b.documentElement) || void 0 === _c ? void 0 : _c.scrollLeft) || element.scrollLeft : "html" === element.tagName.toLowerCase() ? 0 : element.scrollLeft;
5647
- },
5648
- getScrollTop = element => {
5649
- var _a, _b, _c;
5650
- return element === (null === (_a = null === globalThis || void 0 === globalThis ? void 0 : globalThis.document) || void 0 === _a ? void 0 : _a.body) ? (null === (_c = null === (_b = null === globalThis || void 0 === globalThis ? void 0 : globalThis.document) || void 0 === _b ? void 0 : _b.documentElement) || void 0 === _c ? void 0 : _c.scrollTop) || element.scrollTop : "html" === element.tagName.toLowerCase() ? 0 : element.scrollTop;
5651
- };
5652
- function getElementAbsoluteScrollOffset(element) {
5653
- let actualLeft = getScrollLeft(element),
5654
- current = element.parentElement;
5655
- for (; current;) actualLeft += getScrollLeft(current), current = current.parentElement;
5656
- let actualTop = getScrollTop(element);
5657
- for (current = element.parentElement; current;) actualTop += getScrollTop(current), current = current.parentElement;
5658
- return {
5659
- x: actualLeft,
5660
- y: actualTop
5661
- };
5662
- }
5663
5644
  function hasParentElement(element, target) {
5664
5645
  let parent = element.parentNode;
5665
5646
  for (; null !== parent;) {
@@ -47972,11 +47953,12 @@
47972
47953
  AttributeLevel[AttributeLevel["Default"] = 0] = "Default";
47973
47954
  AttributeLevel[AttributeLevel["Theme"] = 1] = "Theme";
47974
47955
  AttributeLevel[AttributeLevel["Chart"] = 2] = "Chart";
47975
- AttributeLevel[AttributeLevel["Series"] = 3] = "Series";
47976
- AttributeLevel[AttributeLevel["Mark"] = 4] = "Mark";
47977
- AttributeLevel[AttributeLevel["User_Chart"] = 5] = "User_Chart";
47978
- AttributeLevel[AttributeLevel["User_Series"] = 6] = "User_Series";
47979
- AttributeLevel[AttributeLevel["User_Mark"] = 7] = "User_Mark";
47956
+ AttributeLevel[AttributeLevel["Base_Series"] = 3] = "Base_Series";
47957
+ AttributeLevel[AttributeLevel["Series"] = 4] = "Series";
47958
+ AttributeLevel[AttributeLevel["Mark"] = 5] = "Mark";
47959
+ AttributeLevel[AttributeLevel["User_Chart"] = 6] = "User_Chart";
47960
+ AttributeLevel[AttributeLevel["User_Series"] = 7] = "User_Series";
47961
+ AttributeLevel[AttributeLevel["User_Mark"] = 8] = "User_Mark";
47980
47962
  AttributeLevel[AttributeLevel["Built_In"] = 99] = "Built_In";
47981
47963
  })(AttributeLevel || (AttributeLevel = {}));
47982
47964
  const STACK_FIELD_START = `${PREFIX}_STACK_START`;
@@ -51525,6 +51507,32 @@
51525
51507
  setDimensionIndex(value, opt = {}) {
51526
51508
  return this._chart?.setDimensionIndex(value, opt);
51527
51509
  }
51510
+ convertDatumToPosition(datum, dataLinkInfo = {}) {
51511
+ if (!this._chart) {
51512
+ return null;
51513
+ }
51514
+ if (isEmpty(datum)) {
51515
+ return null;
51516
+ }
51517
+ const { seriesId, seriesIndex = 0 } = dataLinkInfo;
51518
+ let series;
51519
+ if (isValid(seriesId)) {
51520
+ series = this._chart.getSeriesInUserId(seriesId);
51521
+ }
51522
+ else if (isValid(seriesIndex)) {
51523
+ series = this._chart.getSeriesInIndex([seriesIndex])?.[0];
51524
+ }
51525
+ if (series) {
51526
+ const keys = Object.keys(datum);
51527
+ const handledDatum = series
51528
+ .getViewData()
51529
+ .latestData.find((viewDatum) => keys.every(k => viewDatum[k] == datum[k]));
51530
+ if (handledDatum) {
51531
+ return series.dataToPosition(handledDatum);
51532
+ }
51533
+ }
51534
+ return null;
51535
+ }
51528
51536
  }
51529
51537
 
51530
51538
  var STATE_VALUE_ENUM;
@@ -54154,7 +54162,7 @@
54154
54162
  VChart.useMark([ComponentMark, GroupMark]);
54155
54163
  Factory.registerRegion('region', Region);
54156
54164
  Factory.registerLayout('base', Layout);
54157
- const version = "1.1.0-beta.6";
54165
+ const version = "1.1.0-beta.7";
54158
54166
 
54159
54167
  var SeriesMarkNameEnum;
54160
54168
  (function (SeriesMarkNameEnum) {
@@ -55540,7 +55548,7 @@
55540
55548
  if (!dimensionInfo) {
55541
55549
  return;
55542
55550
  }
55543
- if (opt.tooltip) {
55551
+ if (opt.tooltip !== false) {
55544
55552
  const tooltip = this._components.find(c => c.type === ComponentTypeEnum.tooltip);
55545
55553
  if (tooltip.getVisible()) {
55546
55554
  const dataFilter = {};
@@ -55559,7 +55567,7 @@
55559
55567
  tooltip.showTooltip(dataFilter, opt.showTooltipOption);
55560
55568
  }
55561
55569
  }
55562
- if (opt.crosshair) {
55570
+ if (opt.crosshair !== false) {
55563
55571
  const crosshair = this._components.find(c => c.type === ComponentTypeEnum.cartesianCrosshair);
55564
55572
  if (crosshair && crosshair.clearAxisValue && crosshair.setAxisValue) {
55565
55573
  dimensionInfo.forEach((d) => {
@@ -57303,8 +57311,8 @@
57303
57311
  this._rawDataStatistics?.reRunAllTransform();
57304
57312
  this.setSeriesField(this._spec.seriesField);
57305
57313
  this.getMarks().forEach(m => {
57306
- if (m.stateStyle.normal?.fill?.style) {
57307
- m.setAttribute('stroke', m.stateStyle.normal.fill.style, 'normal', AttributeLevel.Chart);
57314
+ if (m.stateStyle?.normal?.lineWidth) {
57315
+ m.setAttribute('stroke', this.getColorAttribute(), 'normal', AttributeLevel.Base_Series);
57308
57316
  }
57309
57317
  });
57310
57318
  }
@@ -63370,6 +63378,7 @@
63370
63378
  _getDefaultStyle() {
63371
63379
  const defaultStyle = {
63372
63380
  ...super._getDefaultStyle(),
63381
+ lineWidth: 0,
63373
63382
  path: ''
63374
63383
  };
63375
63384
  return defaultStyle;
@@ -69352,6 +69361,13 @@
69352
69361
  class PolygonMark extends BasePolygonMark {
69353
69362
  static type = MarkTypeEnum.polygon;
69354
69363
  type = PolygonMark.type;
69364
+ _getDefaultStyle() {
69365
+ const defaultStyle = {
69366
+ ...super._getDefaultStyle(),
69367
+ lineWidth: 0
69368
+ };
69369
+ return defaultStyle;
69370
+ }
69355
69371
  }
69356
69372
 
69357
69373
  VChart.useMark([PolygonMark, TextMark, RuleMark]);
@@ -80524,6 +80540,7 @@
80524
80540
  const originData = (this._legendData.getLatestData() || []).map((datum) => {
80525
80541
  const fill = datum.style('fill');
80526
80542
  const stroke = datum.style('stroke');
80543
+ const lineWidth = datum.style('lineWidth');
80527
80544
  const symbolType = datum.style('symbolType');
80528
80545
  const fillOpacity = datum.style('fillOpacity');
80529
80546
  const strokeOpacity = datum.style('strokeOpacity');
@@ -80537,7 +80554,7 @@
80537
80554
  shape: {
80538
80555
  fill,
80539
80556
  symbolType: symbolType ?? datum.shapeType ?? 'circle',
80540
- stroke: fill === stroke ? null : stroke,
80557
+ stroke: lineWidth === 0 || fill === stroke ? null : stroke,
80541
80558
  fillOpacity: isValidNumber(fillOpacity) ? fillOpacity : 1,
80542
80559
  strokeOpacity: isValidNumber(strokeOpacity) ? strokeOpacity : 1,
80543
80560
  opacity: isValidNumber(opacity) ? opacity : 1,
@@ -84537,7 +84554,7 @@
84537
84554
  };
84538
84555
  return actualTooltip;
84539
84556
  };
84540
- _getActualTooltipPosition = (actualTooltip, position, params, parentElement, changePositionOnly) => {
84557
+ _getActualTooltipPosition = (actualTooltip, position, params, tooltipParentElement, changePositionOnly) => {
84541
84558
  const event = params.event;
84542
84559
  const { width: tooltipBoxWidth = 0, height: tooltipBoxHeight = 0 } = this._getTooltipBoxSize(actualTooltip, changePositionOnly) ?? {};
84543
84560
  const { offsetX, offsetY } = this._option;
@@ -84546,6 +84563,7 @@
84546
84563
  const canvasRect = params?.chart?.getCanvasRect();
84547
84564
  const canvasWidth = canvasRect?.width ?? DEFAULT_CHART_WIDTH;
84548
84565
  const canvasHeight = canvasRect?.height ?? DEFAULT_CHART_HEIGHT;
84566
+ let isFixedPosition = false;
84549
84567
  let left;
84550
84568
  let top;
84551
84569
  let right;
@@ -84558,6 +84576,7 @@
84558
84576
  bottom = getActualTooltipPositionValue(posBottom, event);
84559
84577
  }
84560
84578
  else if (isValid(position) && actualTooltip.activeType === 'mark') {
84579
+ isFixedPosition = true;
84561
84580
  const element = params.item;
84562
84581
  const model = params.model;
84563
84582
  const bounds = element?.getBounds();
@@ -84598,28 +84617,24 @@
84598
84617
  width: 0,
84599
84618
  height: 0
84600
84619
  };
84601
- const getDefaultOffest = () => ({ x: 0, y: 0 });
84602
- let absolutePosOffset = getDefaultOffest();
84603
- let scrollOffset = getDefaultOffest();
84604
- let parentElementScrollOffset = getDefaultOffest();
84605
- let parentElementPosOffset = getDefaultOffest();
84620
+ const getDefaultPointValue = (defaultValue = 0) => ({ x: defaultValue, y: defaultValue });
84621
+ let relativePosOffset = getDefaultPointValue();
84622
+ let tooltipParentElementPos = getDefaultPointValue();
84623
+ let chartElementScale = 1;
84624
+ let tooltipParentElementScale = 1;
84606
84625
  if (isTrueBrowser(this._env) && !tooltipSpec.confine) {
84607
84626
  containerSize.width = window.innerWidth;
84608
84627
  containerSize.height = window.innerHeight;
84609
84628
  if (!isCanvas) {
84610
- const chartRenderer = (this._compiler.getCanvas() ?? this._chartContainer);
84611
- parentElementPosOffset = getElementAbsolutePosition(parentElement);
84612
- parentElementScrollOffset = getElementAbsoluteScrollOffset(parentElement);
84613
- const chartPosOffset = getElementAbsolutePosition(chartRenderer);
84614
- const chartScrollOffset = getElementAbsoluteScrollOffset(chartRenderer);
84615
- absolutePosOffset = {
84616
- x: chartPosOffset.x - parentElementPosOffset.x,
84617
- y: chartPosOffset.y - parentElementPosOffset.y
84618
- };
84619
- scrollOffset = {
84620
- x: chartScrollOffset.x - parentElementScrollOffset.x,
84621
- y: chartScrollOffset.y - parentElementScrollOffset.y
84629
+ const chartElement = (this._compiler.getCanvas() ?? this._chartContainer);
84630
+ tooltipParentElementPos = tooltipParentElement.getBoundingClientRect();
84631
+ const chartPosOffset = chartElement.getBoundingClientRect();
84632
+ relativePosOffset = {
84633
+ x: chartPosOffset.x - tooltipParentElementPos.x,
84634
+ y: chartPosOffset.y - tooltipParentElementPos.y
84622
84635
  };
84636
+ chartElementScale = getScale(chartElement);
84637
+ tooltipParentElementScale = getScale(tooltipParentElement);
84623
84638
  }
84624
84639
  }
84625
84640
  else {
@@ -84634,7 +84649,7 @@
84634
84649
  x = canvasWidth - tooltipBoxWidth - right;
84635
84650
  }
84636
84651
  else {
84637
- x = canvasX - scrollOffset.x + offsetX;
84652
+ x = canvasX + offsetX;
84638
84653
  }
84639
84654
  if (isValidNumber(top)) {
84640
84655
  y = top;
@@ -84643,28 +84658,38 @@
84643
84658
  y = canvasHeight - tooltipBoxHeight - bottom;
84644
84659
  }
84645
84660
  else {
84646
- y = canvasY - scrollOffset.y + offsetY;
84661
+ y = canvasY + offsetY;
84647
84662
  }
84663
+ x *= chartElementScale;
84664
+ y *= chartElementScale;
84648
84665
  if (isTrueBrowser(this._env)) {
84649
- x += absolutePosOffset.x;
84650
- y += absolutePosOffset.y;
84666
+ x += relativePosOffset.x;
84667
+ y += relativePosOffset.y;
84651
84668
  }
84669
+ x /= tooltipParentElementScale;
84670
+ y /= tooltipParentElementScale;
84652
84671
  const { width: containerWidth, height: containerHeight } = containerSize;
84653
- const parentElementTotalOffset = {
84654
- x: parentElementPosOffset.x - parentElementScrollOffset.x,
84655
- y: parentElementPosOffset.y - parentElementScrollOffset.y
84656
- };
84657
- if (x + tooltipBoxWidth + parentElementTotalOffset.x > containerWidth) {
84658
- x -= offsetX * 2 + tooltipBoxWidth;
84672
+ if ((x + tooltipBoxWidth) * tooltipParentElementScale + tooltipParentElementPos.x > containerWidth) {
84673
+ if (isFixedPosition) {
84674
+ x = (containerWidth - tooltipParentElementPos.x) / tooltipParentElementScale - tooltipBoxWidth;
84675
+ }
84676
+ else {
84677
+ x -= offsetX * 2 + tooltipBoxWidth;
84678
+ }
84659
84679
  }
84660
- if (y + tooltipBoxHeight + parentElementTotalOffset.y > containerHeight) {
84661
- y -= offsetY * 2 + tooltipBoxHeight;
84680
+ if ((y + tooltipBoxHeight) * tooltipParentElementScale + tooltipParentElementPos.y > containerHeight) {
84681
+ if (isFixedPosition) {
84682
+ y = (containerHeight - tooltipParentElementPos.y) / tooltipParentElementScale - tooltipBoxHeight;
84683
+ }
84684
+ else {
84685
+ y -= offsetY * 2 + tooltipBoxHeight;
84686
+ }
84662
84687
  }
84663
- if (x + parentElementTotalOffset.x < 0) {
84664
- x = 0 - parentElementTotalOffset.x;
84688
+ if (x * tooltipParentElementScale + tooltipParentElementPos.x < 0) {
84689
+ x = 0 - tooltipParentElementPos.x / tooltipParentElementScale;
84665
84690
  }
84666
- if (y + parentElementTotalOffset.y < 0) {
84667
- y = 0 - parentElementTotalOffset.y;
84691
+ if (y * tooltipParentElementScale + tooltipParentElementPos.y < 0) {
84692
+ y = 0 - tooltipParentElementPos.y / tooltipParentElementScale;
84668
84693
  }
84669
84694
  return { x, y };
84670
84695
  };
@@ -84735,6 +84760,12 @@
84735
84760
  this._initFromSpec();
84736
84761
  }
84737
84762
  }
84763
+ const getScale = (element) => {
84764
+ if (element.offsetWidth > 0) {
84765
+ return element.getBoundingClientRect().width / element.offsetWidth;
84766
+ }
84767
+ return element.getBoundingClientRect().height / element.offsetHeight;
84768
+ };
84738
84769
 
84739
84770
  const DEFAULT_SHAPE_SPACING = 8;
84740
84771
  const DEFAULT_KEY_SPACING = 26;
@@ -86013,7 +86044,12 @@
86013
86044
  };
86014
86045
  }
86015
86046
  if (isValid(userSpec.parentElement)) {
86016
- this._spec.parentElement = userSpec.parentElement;
86047
+ if (isString(userSpec.parentElement)) {
86048
+ this._spec.parentElement = globalThis.document?.getElementById(userSpec.parentElement);
86049
+ }
86050
+ else {
86051
+ this._spec.parentElement = userSpec.parentElement;
86052
+ }
86017
86053
  }
86018
86054
  else if (isTrueBrowser(this._option.mode)) {
86019
86055
  this._spec.parentElement = domDocument?.body;
@@ -86075,16 +86111,9 @@
86075
86111
  return false;
86076
86112
  }
86077
86113
  const { x, y } = point;
86078
- const container = globalInstance.getContainer();
86079
- const { x: chartX, y: chartY } = getElementAbsolutePosition(container);
86080
- const { x: scrollOffsetX, y: scrollOffsetY } = getElementAbsoluteScrollOffset(container);
86081
- const canvasRect = chart.getCanvasRect();
86082
- const chartWidth = canvasRect?.width;
86083
- const chartHeight = canvasRect?.height;
86084
- if (x >= chartX - scrollOffsetX &&
86085
- x <= chartX + chartWidth - scrollOffsetX &&
86086
- y >= chartY - scrollOffsetY &&
86087
- y <= chartY + chartHeight - scrollOffsetY) {
86114
+ const canvas = globalInstance.getCanvas();
86115
+ const { x: chartX, y: chartY, width: chartWidth, height: chartHeight } = canvas.getBoundingClientRect();
86116
+ if (x >= chartX && x <= chartX + chartWidth && y >= chartY && y <= chartY + chartHeight) {
86088
86117
  return true;
86089
86118
  }
86090
86119
  return false;