@visactor/vchart 1.2.2-alpha.0 → 1.2.2-beta.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.
Files changed (43) hide show
  1. package/build/es5/index.js +1 -1
  2. package/build/index.js +137 -95
  3. package/build/index.min.js +1 -1
  4. package/build/tsconfig.tsbuildinfo +1 -1
  5. package/cjs/compile/compiler.d.ts +2 -1
  6. package/cjs/compile/compiler.js +4 -0
  7. package/cjs/compile/compiler.js.map +1 -1
  8. package/cjs/component/title/title.js +1 -1
  9. package/cjs/component/title/title.js.map +1 -1
  10. package/cjs/component/tooltip/handler/utils/get-spec.js +71 -53
  11. package/cjs/component/tooltip/handler/utils/get-spec.js.map +1 -1
  12. package/cjs/core/index.d.ts +1 -1
  13. package/cjs/core/index.js +1 -1
  14. package/cjs/core/index.js.map +1 -1
  15. package/cjs/core/vchart.d.ts +1 -0
  16. package/cjs/core/vchart.js +13 -11
  17. package/cjs/core/vchart.js.map +1 -1
  18. package/cjs/series/base/tooltip-helper.js +1 -0
  19. package/cjs/series/base/tooltip-helper.js.map +1 -1
  20. package/cjs/typings/tooltip/line.d.ts +0 -1
  21. package/cjs/typings/tooltip/line.js.map +1 -1
  22. package/cjs/typings/tooltip/shape.d.ts +1 -0
  23. package/cjs/typings/tooltip/shape.js.map +1 -1
  24. package/esm/compile/compiler.d.ts +2 -1
  25. package/esm/compile/compiler.js +4 -0
  26. package/esm/compile/compiler.js.map +1 -1
  27. package/esm/component/title/title.js +1 -1
  28. package/esm/component/title/title.js.map +1 -1
  29. package/esm/component/tooltip/handler/utils/get-spec.js +68 -50
  30. package/esm/component/tooltip/handler/utils/get-spec.js.map +1 -1
  31. package/esm/core/index.d.ts +1 -1
  32. package/esm/core/index.js +1 -1
  33. package/esm/core/index.js.map +1 -1
  34. package/esm/core/vchart.d.ts +1 -0
  35. package/esm/core/vchart.js +13 -11
  36. package/esm/core/vchart.js.map +1 -1
  37. package/esm/series/base/tooltip-helper.js +1 -0
  38. package/esm/series/base/tooltip-helper.js.map +1 -1
  39. package/esm/typings/tooltip/line.d.ts +0 -1
  40. package/esm/typings/tooltip/line.js.map +1 -1
  41. package/esm/typings/tooltip/shape.d.ts +1 -0
  42. package/esm/typings/tooltip/shape.js.map +1 -1
  43. package/package.json +5 -5
package/build/index.js CHANGED
@@ -26008,6 +26008,7 @@
26008
26008
  if (heightLimit > 0 && (lineCountLimit = Math.max(Math.floor(heightLimit / lineHeight), 1)), lineClamp && (lineCountLimit = Math.min(lineCountLimit, lineClamp)), "number" == typeof maxLineWidth && maxLineWidth !== 1 / 0) {
26009
26009
  if (maxLineWidth > 0) for (let i = 0; i < lines.length; i++) {
26010
26010
  const str = lines[i];
26011
+ let needCut = !0;
26011
26012
  if (i === lineCountLimit - 1) {
26012
26013
  const clip = layoutObj.textMeasure.clipTextWithSuffix(str, layoutObj.textOptions, maxLineWidth, ellipsis);
26013
26014
  linesLayout.push({
@@ -26017,14 +26018,17 @@
26017
26018
  break;
26018
26019
  }
26019
26020
  const clip = layoutObj.textMeasure.clipText(str, layoutObj.textOptions, maxLineWidth);
26020
- if ("" !== str && "" === clip.str) if (ellipsis) {
26021
- const clipEllipsis = layoutObj.textMeasure.clipTextWithSuffix(str, layoutObj.textOptions, maxLineWidth, ellipsis);
26022
- clip.str = null !== (_b = clipEllipsis.str) && void 0 !== _b ? _b : "", clip.width = null !== (_c = clipEllipsis.width) && void 0 !== _c ? _c : 0;
26023
- } else clip.str = "", clip.width = 0;
26021
+ if ("" !== str && "" === clip.str) {
26022
+ if (ellipsis) {
26023
+ const clipEllipsis = layoutObj.textMeasure.clipTextWithSuffix(str, layoutObj.textOptions, maxLineWidth, ellipsis);
26024
+ clip.str = null !== (_b = clipEllipsis.str) && void 0 !== _b ? _b : "", clip.width = null !== (_c = clipEllipsis.width) && void 0 !== _c ? _c : 0;
26025
+ } else clip.str = "", clip.width = 0;
26026
+ needCut = !1;
26027
+ }
26024
26028
  if (linesLayout.push({
26025
26029
  str: clip.str,
26026
26030
  width: clip.width
26027
- }), clip.str.length === str.length) ;else {
26031
+ }), clip.str.length === str.length) ;else if (needCut) {
26028
26032
  const newStr = str.substring(clip.str.length);
26029
26033
  lines.splice(i + 1, 0, newStr);
26030
26034
  }
@@ -54684,6 +54688,9 @@
54684
54688
  this._view.resize(width, height);
54685
54689
  return this.reRenderAsync({ morph: false });
54686
54690
  }
54691
+ setBackground(color) {
54692
+ this._view?.background(color);
54693
+ }
54687
54694
  reRenderAsync(morphConfig) {
54688
54695
  if (this.isInited) {
54689
54696
  if (this._rafId) {
@@ -54979,7 +54986,6 @@
54979
54986
  this._currentThemeName = ThemeManager.getCurrentThemeName();
54980
54987
  this._setSpec(spec);
54981
54988
  this._updateCurrentTheme();
54982
- const specBackground = typeof spec.background === 'string' ? spec.background : null;
54983
54989
  this._compiler = new Compiler({
54984
54990
  dom: this._container ?? 'none',
54985
54991
  canvas: renderCanvas
@@ -54988,7 +54994,7 @@
54988
54994
  stage,
54989
54995
  pluginList: poptip !== false ? ['poptipForText'] : [],
54990
54996
  ...restOptions,
54991
- background: specBackground || this._currentTheme.background || this._option.background,
54997
+ background: this._getBackground(),
54992
54998
  onError: this._onError
54993
54999
  });
54994
55000
  this._eventDispatcher = new EventDispatcher(this, this._compiler);
@@ -55150,10 +55156,8 @@
55150
55156
  this._compiler?.releaseGrammar();
55151
55157
  }
55152
55158
  else {
55153
- if (updateResult.reCompile) {
55154
- this.getComponents().forEach(c => c.clear());
55155
- this._compiler?.compile({ chart: this._chart, vChart: this }, {});
55156
- }
55159
+ this.getComponents().forEach(c => c.clear());
55160
+ this._compiler?.compile({ chart: this._chart, vChart: this }, {});
55157
55161
  }
55158
55162
  }
55159
55163
  renderSync(morphConfig) {
@@ -55392,6 +55396,11 @@
55392
55396
  this._currentTheme = merge$2({}, ThemeManager.getTheme(this._currentThemeName), this._spec?.theme ?? {});
55393
55397
  }
55394
55398
  setPoptipTheme(merge$2({}, this._currentTheme.component?.poptip));
55399
+ this._compiler?.setBackground(this._getBackground());
55400
+ }
55401
+ _getBackground() {
55402
+ const specBackground = typeof this._spec.background === 'string' ? this._spec.background : null;
55403
+ return specBackground || this._currentTheme.background || this._option.background;
55395
55404
  }
55396
55405
  getCurrentTheme() {
55397
55406
  return this._currentTheme;
@@ -58413,7 +58422,7 @@
58413
58422
  VChart.useMark([ComponentMark, GroupMark, ImageMark]);
58414
58423
  Factory.registerRegion('region', Region);
58415
58424
  Factory.registerLayout('base', Layout);
58416
- const version = "1.2.2-alpha.0";
58425
+ const version = "1.2.2-beta.1";
58417
58426
  Logger.getInstance(LoggerLevel.Error);
58418
58427
 
58419
58428
  var SeriesMarkNameEnum;
@@ -61013,6 +61022,7 @@
61013
61022
  },
61014
61023
  content: [
61015
61024
  {
61025
+ seriesId: this.series.id,
61016
61026
  key: this.contentKeyCallback,
61017
61027
  value: this.contentValueCallback,
61018
61028
  hasShape: true,
@@ -83771,7 +83781,7 @@
83771
83781
  };
83772
83782
  }
83773
83783
  _getTitleAttrs() {
83774
- const realWidth = this._spec.width ?? this.getLayoutRect().width;
83784
+ const realWidth = Math.max(0, this._spec.width ?? this.getLayoutRect().width);
83775
83785
  return {
83776
83786
  text: this._spec.text ?? '',
83777
83787
  subtext: this._spec.subtext ?? '',
@@ -86712,8 +86722,6 @@
86712
86722
  ...globalSpec,
86713
86723
  activeType
86714
86724
  };
86715
- let defaultPattern = {};
86716
- let userPattern = {};
86717
86725
  if (activeType === 'mark' && series) {
86718
86726
  const seriesSpec = (series.tooltipHelper?.spec ?? {});
86719
86727
  if (isValid(seriesSpec.visible) || isValid(seriesSpec.activeType)) {
@@ -86729,11 +86737,9 @@
86729
86737
  if (finalSpec.handler?.showTooltip) {
86730
86738
  return finalSpec;
86731
86739
  }
86732
- defaultPattern = makeDefaultPattern(series, 'mark') ?? {};
86733
- userPattern = merge$2({}, cloneDeep(globalSpec.mark), cloneDeep(seriesSpec.mark));
86734
86740
  }
86735
86741
  else if (activeType === 'dimension' && dimensionInfo?.length) {
86736
- const seriesList = dimensionInfo.reduce((list, cur) => list.concat(cur.data.map(data => data.series).filter(isValid)), []);
86742
+ const seriesList = getSeriesListFromDimensionInfo(dimensionInfo);
86737
86743
  if (seriesList.every(series => !getTooltipActualActiveType(series.tooltipHelper?.spec).includes('dimension'))) {
86738
86744
  finalSpec.visible = false;
86739
86745
  }
@@ -86747,6 +86753,83 @@
86747
86753
  if (finalSpec.handler?.showTooltip) {
86748
86754
  return finalSpec;
86749
86755
  }
86756
+ }
86757
+ const defaultPattern = getDefaultTooltipPattern(activeType, series, dimensionInfo);
86758
+ const seriesPattern = getSeriesTooltipPattern(activeType, series, dimensionInfo);
86759
+ const userPattern = merge$2({}, cloneDeep(globalSpec[activeType]), seriesPattern);
86760
+ const defaultPatternTitle = defaultPattern.title;
86761
+ const titleShape = getShapePattern(undefined, userPattern, undefined, defaultPatternTitle);
86762
+ if (isValid(userPattern.title)) {
86763
+ if (!isFunction(userPattern.title)) {
86764
+ userPattern.title = {
86765
+ ...defaultPattern.title,
86766
+ ...titleShape,
86767
+ ...userPattern.title
86768
+ };
86769
+ }
86770
+ else {
86771
+ const userPatternTitle = userPattern.title;
86772
+ userPattern.title = (data, params) => {
86773
+ const userResult = userPatternTitle(data, params) ?? {};
86774
+ return {
86775
+ ...titleShape,
86776
+ ...userResult
86777
+ };
86778
+ };
86779
+ }
86780
+ }
86781
+ else {
86782
+ userPattern.title = {
86783
+ ...defaultPattern.title,
86784
+ ...titleShape
86785
+ };
86786
+ }
86787
+ const defaultPatternContent = array(defaultPattern.content);
86788
+ if (isValid(userPattern.content)) {
86789
+ const shapePatternMap = getShapePatternMapOfEachSeries(defaultPatternContent);
86790
+ if (!isFunction(userPattern.content)) {
86791
+ const newPatternContent = [];
86792
+ array(userPattern.content).forEach(userLine => {
86793
+ newPatternContent.push({
86794
+ ...getShapePattern(userLine, userPattern, shapePatternMap),
86795
+ ...userLine
86796
+ });
86797
+ });
86798
+ userPattern.content = newPatternContent;
86799
+ }
86800
+ else {
86801
+ const userPatternContent = userPattern.content;
86802
+ userPattern.content = (data, params) => {
86803
+ const newPatternContent = [];
86804
+ array(userPatternContent(data, params) ?? []).forEach(userLine => {
86805
+ newPatternContent.push({
86806
+ ...getShapePattern(userLine, userPattern, shapePatternMap),
86807
+ ...userLine
86808
+ });
86809
+ });
86810
+ return newPatternContent;
86811
+ };
86812
+ }
86813
+ }
86814
+ else {
86815
+ userPattern.content = defaultPatternContent.map(line => ({
86816
+ ...line,
86817
+ ...getShapePattern(undefined, userPattern, undefined, line)
86818
+ }));
86819
+ }
86820
+ finalSpec[activeType] = {
86821
+ ...defaultPattern,
86822
+ ...userPattern,
86823
+ activeType
86824
+ };
86825
+ return finalSpec;
86826
+ };
86827
+ const getDefaultTooltipPattern = (activeType, series, dimensionInfo) => {
86828
+ let defaultPattern = {};
86829
+ if (activeType === 'mark' && series) {
86830
+ defaultPattern = makeDefaultPattern(series, 'mark') ?? {};
86831
+ }
86832
+ else if (activeType === 'dimension' && dimensionInfo?.length) {
86750
86833
  const patternList = [];
86751
86834
  dimensionInfo[0].data.forEach(data => {
86752
86835
  const { series } = data;
@@ -86774,16 +86857,23 @@
86774
86857
  ...patternList[0],
86775
86858
  content: defaultPatternContent
86776
86859
  };
86777
- let seriesDimensionPattern = {};
86860
+ }
86861
+ return defaultPattern;
86862
+ };
86863
+ const getSeriesTooltipPattern = (activeType, series, dimensionInfo) => {
86864
+ let seriesPattern = {};
86865
+ if (activeType === 'mark' && series) {
86866
+ const seriesSpec = (series.tooltipHelper?.spec ?? {});
86867
+ seriesPattern = seriesSpec.mark ? cloneDeep(seriesSpec.mark) : {};
86868
+ }
86869
+ else if (activeType === 'dimension' && dimensionInfo?.length) {
86870
+ const seriesList = getSeriesListFromDimensionInfo(dimensionInfo);
86778
86871
  const seriesPatternList = seriesList
86779
86872
  .filter(series => {
86780
86873
  const spec = series.tooltipHelper?.spec;
86781
86874
  return isValid(spec?.dimension) && getTooltipActualActiveType(spec).includes('dimension');
86782
86875
  })
86783
- .map(series => {
86784
- const pattern = series.tooltipHelper.spec.dimension;
86785
- return pattern;
86786
- });
86876
+ .map(series => series.tooltipHelper.spec.dimension);
86787
86877
  if (seriesPatternList.length) {
86788
86878
  let seriesPatternContent = [];
86789
86879
  if (seriesPatternList.every(({ content }) => isNil(content))) {
@@ -86802,86 +86892,38 @@
86802
86892
  }
86803
86893
  });
86804
86894
  }
86805
- seriesDimensionPattern = {
86895
+ seriesPattern = {
86806
86896
  ...seriesPatternList[0],
86807
86897
  content: seriesPatternContent
86808
86898
  };
86809
86899
  }
86810
- userPattern = merge$2({}, cloneDeep(globalSpec.dimension), seriesDimensionPattern);
86811
86900
  }
86812
- const defaultPatternTitle = defaultPattern.title;
86813
- const titleShape = {
86814
- hasShape: userPattern.hasShape ?? defaultPatternTitle?.hasShape,
86815
- shapeType: userPattern.shapeType ?? defaultPatternTitle?.shapeType,
86816
- shapeColor: userPattern.shapeColor ?? defaultPatternTitle?.shapeColor
86817
- };
86818
- if (isValid(userPattern.title)) {
86819
- if (!isFunction(userPattern.title)) {
86820
- userPattern.title = {
86821
- ...defaultPattern.title,
86822
- ...titleShape,
86823
- ...userPattern.title
86824
- };
86825
- }
86826
- else {
86827
- const userPatternTitle = userPattern.title;
86828
- userPattern.title = (data, params) => {
86829
- const userResult = userPatternTitle(data, params) ?? {};
86830
- return {
86831
- ...titleShape,
86832
- ...userResult
86833
- };
86834
- };
86901
+ return seriesPattern;
86902
+ };
86903
+ const getSeriesListFromDimensionInfo = (dimensionInfo) => {
86904
+ return dimensionInfo.reduce((list, cur) => list.concat(cur.data.map(data => data.series).filter(isValid)), []);
86905
+ };
86906
+ const getShapePatternMapOfEachSeries = (content) => {
86907
+ const shapePatternMap = {};
86908
+ content.forEach(line => {
86909
+ const key = line.seriesId ?? 0;
86910
+ if (!shapePatternMap[key]) {
86911
+ shapePatternMap[key] = line;
86835
86912
  }
86836
- }
86837
- else {
86838
- userPattern.title = {
86839
- ...defaultPattern.title,
86840
- ...titleShape
86841
- };
86842
- }
86843
- const getContentShape = (defaultContentLine) => ({
86844
- hasShape: userPattern.hasShape ?? defaultContentLine?.hasShape,
86845
- shapeType: userPattern.shapeType ?? defaultContentLine?.shapeType,
86846
- shapeColor: userPattern.shapeColor ?? defaultContentLine?.shapeColor
86847
86913
  });
86848
- const defaultPatternContent = array(defaultPattern.content);
86849
- if (isValid(userPattern.content)) {
86850
- if (!isFunction(userPattern.content)) {
86851
- const userPatternContent = array(userPattern.content);
86852
- userPatternContent.forEach((line, i) => {
86853
- userPatternContent[i] = {
86854
- ...getContentShape(defaultPatternContent[0]),
86855
- ...line
86856
- };
86857
- });
86858
- }
86859
- else {
86860
- const userPatternContent = userPattern.content;
86861
- userPattern.content = (data, params) => {
86862
- const userResult = array(userPatternContent(data, params) ?? []);
86863
- userResult.forEach((line, i) => {
86864
- userResult[i] = {
86865
- ...getContentShape(defaultPatternContent[0]),
86866
- ...line
86867
- };
86868
- });
86869
- return userResult;
86870
- };
86914
+ return shapePatternMap;
86915
+ };
86916
+ const getShapePattern = (userLinePattern, userPattern, shapePatternMap, defaultShapePattern) => {
86917
+ const shapePatternFromMap = shapePatternMap?.[userLinePattern?.seriesId ?? 0] ?? shapePatternMap?.[0];
86918
+ const shapeKeys = ['hasShape', 'shapeType', 'shapeColor'];
86919
+ const shapePattern = {};
86920
+ shapeKeys.forEach(key => {
86921
+ const value = userLinePattern?.[key] ?? userPattern?.[key] ?? shapePatternFromMap?.[key] ?? defaultShapePattern?.[key];
86922
+ if (value !== undefined) {
86923
+ shapePattern[key] = value;
86871
86924
  }
86872
- }
86873
- else {
86874
- userPattern.content = defaultPatternContent.map(line => ({
86875
- ...line,
86876
- ...getContentShape(line)
86877
- }));
86878
- }
86879
- finalSpec[activeType] = {
86880
- ...defaultPattern,
86881
- ...userPattern,
86882
- activeType
86883
- };
86884
- return finalSpec;
86925
+ });
86926
+ return shapePattern;
86885
86927
  };
86886
86928
 
86887
86929
  const getActualTooltipPositionValue = (position, event) => {