@antv/g2 4.1.47 → 4.1.50

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 (62) hide show
  1. package/dist/g2.min.js +3 -3
  2. package/dist/g2.min.js.map +1 -1
  3. package/esm/chart/chart.js +1 -1
  4. package/esm/chart/chart.js.map +1 -1
  5. package/esm/core.d.ts +1 -1
  6. package/esm/core.js +1 -1
  7. package/esm/core.js.map +1 -1
  8. package/esm/geometry/label/layout/pie/spider.js +7 -6
  9. package/esm/geometry/label/layout/pie/spider.js.map +1 -1
  10. package/esm/geometry/shape/interval/util.js +8 -6
  11. package/esm/geometry/shape/interval/util.js.map +1 -1
  12. package/esm/index.js +7 -0
  13. package/esm/index.js.map +1 -1
  14. package/esm/interaction/action/component/axis/axis-description.d.ts +9 -0
  15. package/esm/interaction/action/component/axis/axis-description.js +77 -0
  16. package/esm/interaction/action/component/axis/axis-description.js.map +1 -0
  17. package/esm/interface.d.ts +7 -3
  18. package/esm/interface.js.map +1 -1
  19. package/esm/theme/style-sheet/dark.d.ts +144 -424
  20. package/esm/theme/style-sheet/dark.js +14 -10
  21. package/esm/theme/style-sheet/dark.js.map +1 -1
  22. package/esm/theme/style-sheet/light.d.ts +144 -420
  23. package/esm/theme/style-sheet/light.js +14 -10
  24. package/esm/theme/style-sheet/light.js.map +1 -1
  25. package/esm/theme/util/create-by-style-sheet.js +3 -0
  26. package/esm/theme/util/create-by-style-sheet.js.map +1 -1
  27. package/lib/chart/chart.js +1 -1
  28. package/lib/chart/chart.js.map +1 -1
  29. package/lib/core.d.ts +1 -1
  30. package/lib/core.js +1 -1
  31. package/lib/core.js.map +1 -1
  32. package/lib/geometry/label/layout/pie/spider.js +7 -6
  33. package/lib/geometry/label/layout/pie/spider.js.map +1 -1
  34. package/lib/geometry/shape/interval/util.js +8 -6
  35. package/lib/geometry/shape/interval/util.js.map +1 -1
  36. package/lib/index.js +7 -0
  37. package/lib/index.js.map +1 -1
  38. package/lib/interaction/action/component/axis/axis-description.d.ts +9 -0
  39. package/lib/interaction/action/component/axis/axis-description.js +79 -0
  40. package/lib/interaction/action/component/axis/axis-description.js.map +1 -0
  41. package/lib/interface.d.ts +7 -3
  42. package/lib/interface.js.map +1 -1
  43. package/lib/theme/style-sheet/dark.d.ts +144 -424
  44. package/lib/theme/style-sheet/dark.js +14 -10
  45. package/lib/theme/style-sheet/dark.js.map +1 -1
  46. package/lib/theme/style-sheet/light.d.ts +144 -420
  47. package/lib/theme/style-sheet/light.js +14 -10
  48. package/lib/theme/style-sheet/light.js.map +1 -1
  49. package/lib/theme/util/create-by-style-sheet.js +3 -0
  50. package/lib/theme/util/create-by-style-sheet.js.map +1 -1
  51. package/package.json +2 -2
  52. package/src/chart/chart.ts +1 -1
  53. package/src/core.ts +1 -1
  54. package/src/geometry/label/layout/pie/spider.ts +6 -7
  55. package/src/geometry/shape/interval/util.ts +4 -1
  56. package/src/index.ts +8 -0
  57. package/src/interaction/action/component/axis/axis-description.ts +86 -0
  58. package/src/interface.ts +7 -16
  59. package/src/theme/style-sheet/dark.ts +15 -21
  60. package/src/theme/style-sheet/light.ts +15 -21
  61. package/src/theme/util/create-by-style-sheet.ts +3 -0
  62. package/CHANGELOG.md +0 -1306
@@ -112,10 +112,9 @@ export function pieSpiderLabelLayout(items: LabelItem[], labels: IGroup[], shape
112
112
 
113
113
  // step 1: adjust items to spider
114
114
  each(items, (item) => {
115
+ if (!item) return;
115
116
  const label = get(labelsMap, [item.id]);
116
- if (!label) {
117
- return;
118
- }
117
+ if (!label) return;
119
118
 
120
119
  const inRight = item.x > center.x || (item.x === center.x && item.y > center.y);
121
120
  const offsetX = !isNil(item.offsetX) ? item.offsetX : LABEL_OFFSET_X;
@@ -130,12 +129,12 @@ export function pieSpiderLabelLayout(items: LabelItem[], labels: IGroup[], shape
130
129
  const LEFT_HALF_KEY = 'left';
131
130
  const RIGHT_HALF_KEY = 'right';
132
131
  // step 1: separate labels
133
- const seperateLabels = groupBy(items, (item) => (item.x < center.x ? LEFT_HALF_KEY : RIGHT_HALF_KEY));
132
+ const separateLabels = groupBy(items, (item) => (item.x < center.x ? LEFT_HALF_KEY : RIGHT_HALF_KEY));
134
133
 
135
134
  // step2: calculate totalHeight
136
135
  let totalHeight = (radius + labelOffset) * 2 + labelHeight;
137
136
 
138
- each(seperateLabels, (half: PolarLabelItem[]) => {
137
+ each(separateLabels, (half: PolarLabelItem[]) => {
139
138
  const halfHeight = half.length * labelHeight;
140
139
  if (halfHeight > totalHeight) {
141
140
  totalHeight = Math.min(halfHeight, Math.abs(start.y - end.y));
@@ -151,7 +150,7 @@ export function pieSpiderLabelLayout(items: LabelItem[], labels: IGroup[], shape
151
150
  };
152
151
 
153
152
  // step 3: antiCollision
154
- each(seperateLabels, (half, key) => {
153
+ each(separateLabels, (half, key) => {
155
154
  const maxLabelsCountForOneSide = totalHeight / labelHeight;
156
155
  if (half.length > maxLabelsCountForOneSide) {
157
156
  half.sort((a, b) => {
@@ -173,7 +172,7 @@ export function pieSpiderLabelLayout(items: LabelItem[], labels: IGroup[], shape
173
172
  const endY = labelsContainerRange.maxY;
174
173
 
175
174
  // step4: applyTo labels and adjust labelLines
176
- each(seperateLabels, (half, key) => {
175
+ each(separateLabels, (half, key) => {
177
176
  const inRight = key === RIGHT_HALF_KEY;
178
177
 
179
178
  each(half, (item) => {
@@ -269,7 +269,6 @@ export function getRectWithCornerRadius(points: Point[], coordinate: Coordinate,
269
269
 
270
270
  if (coordinate.isTransposed) {
271
271
  [p1, p3] = swap(p1, p3);
272
- [r1, r2, r3, r4] = [r4, r1, r2, r3]
273
272
  }
274
273
 
275
274
  /**
@@ -301,6 +300,10 @@ export function getRectWithCornerRadius(points: Point[], coordinate: Coordinate,
301
300
  const abs = v => Math.abs(v);
302
301
  [r1, r2, r3, r4] = parseRadius([r1, r2, r3, r4], Math.min(abs(p3.x - p0.x), abs(p1.y - p0.y))).map(d => abs(d));
303
302
 
303
+ if (coordinate.isTransposed) {
304
+ [r1, r2, r3, r4] = [r4, r1, r2, r3]
305
+ }
306
+
304
307
  if (p0.y < p1.y /** 负数情况 */) {
305
308
  path.push(['M', p3.x, p3.y + r3]);
306
309
  r3 !== 0 && path.push(['A', r3, r3, 0, 0, 0, p3.x - r3, p3.y]);
package/src/index.ts CHANGED
@@ -220,6 +220,7 @@ import ViewMove from './interaction/action/view/move';
220
220
  import ScaleTranslate from './interaction/action/view/scale-translate';
221
221
  import ScaleZoom from './interaction/action/view/scale-zoom';
222
222
  import MousewheelScroll from './interaction/action/view/mousewheel-scroll';
223
+ import AxisDescription from './interaction/action/component/axis/axis-description'
223
224
 
224
225
  registerAction('tooltip', TooltipAction);
225
226
  registerAction('sibling-tooltip', SiblingTooltip);
@@ -260,6 +261,7 @@ registerAction('legend-item-highlight', ListHighlight, {
260
261
  registerAction('axis-label-highlight', ListHighlight, {
261
262
  componentNames: ['axis'],
262
263
  });
264
+ registerAction('axis-description', AxisDescription)
263
265
 
264
266
  registerAction('rect-mask', RectMask);
265
267
  registerAction('x-rect-mask', DimMask, { dim: 'x' });
@@ -615,6 +617,12 @@ registerInteraction('active-region', {
615
617
  end: [{ trigger: 'plot:mouseleave', action: 'active-region:hide' }],
616
618
  });
617
619
 
620
+ // 显示坐标轴标题详情信息
621
+ registerInteraction('axis-description', {
622
+ start: [{ trigger: 'axis-description:mousemove', action: 'axis-description:show' }],
623
+ end: [{ trigger: 'axis-description:mouseleave', action: 'axis-description:hide' }]
624
+ })
625
+
618
626
  function isWheelDown(event) {
619
627
  event.gEvent.preventDefault();
620
628
  return event.gEvent.originalEvent.deltaY > 0;
@@ -0,0 +1,86 @@
1
+ import { TOOLTIP_CSS_CONST } from "@antv/component";
2
+ import { deepMix } from "@antv/util";
3
+ import { HtmlTooltip } from "../../../../dependents";
4
+ import Action from "../../base";
5
+ import { getDelegationObject } from "../../util";
6
+
7
+ const AXIS_DESCRIPTION_TOOLTIP = 'aixs-description-tooltip'
8
+
9
+ class AxisDescription extends Action {
10
+ private tooltip;
11
+
12
+ public show() {
13
+ const context = this.context;
14
+ const { axis } = getDelegationObject(context);
15
+ const { description, text } = axis.cfg.title;
16
+ const { x, y } = context.event;
17
+ if(!this.tooltip) {
18
+ this.renderTooltip()
19
+ };
20
+ this.tooltip.update({
21
+ title: text || '',
22
+ customContent: () => {
23
+ return (`
24
+ <div class="${TOOLTIP_CSS_CONST.CONTAINER_CLASS}">
25
+ <div class="${TOOLTIP_CSS_CONST.TITLE_CLASS}">
26
+ ${text}
27
+ </div>
28
+ <div class="${TOOLTIP_CSS_CONST.LIST_CLASS}">
29
+ ${description}
30
+ </div>
31
+ </div>
32
+ `)
33
+ },
34
+ x,
35
+ y
36
+ });
37
+ this.tooltip.show()
38
+ }
39
+
40
+ public destroy() {
41
+ super.destroy();
42
+ this.tooltip && this.tooltip.destroy();
43
+ }
44
+
45
+ public hide() {
46
+ this.tooltip && this.tooltip.hide()
47
+ }
48
+
49
+ public renderTooltip() {
50
+ const view = this.context.view;
51
+ const canvas = view.canvas;
52
+ const region = {
53
+ start: { x: 0, y: 0 },
54
+ end: { x: canvas.get('width'), y: canvas.get('height') },
55
+ };
56
+ const tooltip = new HtmlTooltip({
57
+ parent: canvas.get('el').parentNode,
58
+ region,
59
+ visible: false,
60
+ containerId: AXIS_DESCRIPTION_TOOLTIP,
61
+ domStyles: {
62
+ ...deepMix({}, {
63
+ // 超长的时候,tooltip tip 最大宽度为 50%,然后可以换行
64
+ [TOOLTIP_CSS_CONST.CONTAINER_CLASS]: {
65
+ 'max-width': '50%',
66
+ 'padding': '5px',
67
+ 'line-height': '15px'
68
+ },
69
+ [TOOLTIP_CSS_CONST.TITLE_CLASS]: {
70
+ 'word-break': 'break-all',
71
+ 'font-size': '14px',
72
+ 'margin-bottom': '3px'
73
+ },
74
+ [TOOLTIP_CSS_CONST.LIST_CLASS]: {
75
+ 'word-break': 'break-all',
76
+ 'opacity': '.5'
77
+ }
78
+ }),
79
+ },
80
+ });
81
+ tooltip.init();
82
+ tooltip.setCapture(false);
83
+ this.tooltip = tooltip
84
+ }
85
+ }
86
+ export default AxisDescription
package/src/interface.ts CHANGED
@@ -1066,8 +1066,8 @@ export interface ScaleOption extends ScaleConfig {
1066
1066
  */
1067
1067
  sync?: boolean | string;
1068
1068
  /**
1069
- * @title 是否显示最后日期
1070
- * @description 只对 type: 'time' 的 scale 生效,强制显示最后的日期 tick。
1069
+ * @title 是否显示最后的 tick
1070
+ * @description 只对 `type: 'cat'` 以及 `type: 'time-cat'` 的 scale 生效,强制显示最后的日期 tick。
1071
1071
  */
1072
1072
  showLast?: boolean;
1073
1073
  /**
@@ -2768,7 +2768,10 @@ export interface StyleSheet {
2768
2768
  * @title 坐标轴标题距离坐标轴文本的间距
2769
2769
  */
2770
2770
  axisTitleSpacing?: number;
2771
-
2771
+ /**
2772
+ * @title 坐标轴详细说明icon颜色
2773
+ */
2774
+ axisDescriptionIconFillColor?: string;
2772
2775
  /**
2773
2776
  * @title 坐标轴刻度线颜色
2774
2777
  */
@@ -3831,19 +3834,7 @@ export interface StyleSheet {
3831
3834
  /**
3832
3835
  * @title createTheme 主题样式表配置
3833
3836
  */
3834
- export type StyleSheetCfg = Pick<
3835
- StyleSheet,
3836
- | 'backgroundColor'
3837
- | 'subColor'
3838
- | 'brandColor'
3839
- | 'paletteQualitative10'
3840
- | 'paletteQualitative20'
3841
- | 'paletteSemanticRed'
3842
- | 'paletteSemanticGreen'
3843
- | 'paletteSemanticYellow'
3844
- | 'paletteSequence'
3845
- | 'fontFamily'
3846
- >;
3837
+ export type StyleSheetCfg = Partial<StyleSheet>;
3847
3838
 
3848
3839
  // ============================ 交互相关的类型定义 ============================
3849
3840
  /**
@@ -72,42 +72,32 @@ const SINGLE_SEQUENCE = [
72
72
  ];
73
73
 
74
74
  export const createDarkStyleSheet = (cfg: StyleSheetCfg = {}) => {
75
- const {
76
- backgroundColor = '#141414',
77
- subColor = 'rgba(255,255,255,0.05)',
78
- paletteQualitative10 = QUALITATIVE_10,
79
- paletteQualitative20 = QUALITATIVE_20,
80
- paletteSemanticRed = '#F4664A',
81
- paletteSemanticGreen = '#30BF78',
82
- paletteSemanticYellow = '#FAAD14',
83
- paletteSequence = SINGLE_SEQUENCE,
84
- fontFamily = `"Segoe UI", Roboto, "Helvetica Neue", Arial,
85
- "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol",
86
- "Noto Color Emoji"`,
87
- } = cfg;
75
+ const { paletteQualitative10 = QUALITATIVE_10, paletteQualitative20 = QUALITATIVE_20 } = cfg;
88
76
  const { brandColor = paletteQualitative10[0] } = cfg;
89
77
 
90
- return {
78
+ const token = {
91
79
  /** 图表背景色 */
92
- backgroundColor,
80
+ backgroundColor: '#141414',
93
81
  /** 主题色 */
94
82
  brandColor,
95
83
  /** 图表辅助色 */
96
- subColor,
84
+ subColor: 'rgba(255,255,255,0.05)',
97
85
  /** 分类色板 1,在数据量小于等于 10 时使用 */
98
86
  paletteQualitative10,
99
87
  /** 分类色板 2,在数据量大于 10 时使用 */
100
88
  paletteQualitative20,
101
89
  /** 语义色 */
102
- paletteSemanticRed,
90
+ paletteSemanticRed: '#F4664A',
103
91
  /** 语义色 */
104
- paletteSemanticGreen,
92
+ paletteSemanticGreen: '#30BF78',
105
93
  /** 语义色 */
106
- paletteSemanticYellow,
94
+ paletteSemanticYellow: '#FAAD14',
107
95
  /** (单色)顺序色板 */
108
- paletteSequence,
96
+ paletteSequence: SINGLE_SEQUENCE,
109
97
  /** 字体 */
110
- fontFamily,
98
+ fontFamily: `"Segoe UI", Roboto, "Helvetica Neue", Arial,
99
+ "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol",
100
+ "Noto Color Emoji"`,
111
101
 
112
102
  // -------------------- 坐标轴 --------------------
113
103
  /** 坐标轴线颜色 */
@@ -127,6 +117,8 @@ export const createDarkStyleSheet = (cfg: StyleSheetCfg = {}) => {
127
117
  axisTitleTextFontWeight: 'normal',
128
118
  /** 坐标轴标题距离坐标轴文本的间距 */
129
119
  axisTitleSpacing: 12,
120
+ /** 坐标轴标题详细说明icon颜色 */
121
+ axisDescriptionIconFillColor: WHITE_COLORS[85],
130
122
 
131
123
  /** 坐标轴刻度线颜色 */
132
124
  axisTickLineBorderColor: BLACK_COLORS[25],
@@ -565,6 +557,8 @@ export const createDarkStyleSheet = (cfg: StyleSheetCfg = {}) => {
565
557
  /** hollowInterval inactive 状态下边框透明度 */
566
558
  hollowIntervalInactiveBorderOpacity: 0.3,
567
559
  };
560
+
561
+ return { ...token, ...cfg };
568
562
  };
569
563
 
570
564
  export const antvDark = createDarkStyleSheet();
@@ -72,42 +72,32 @@ const SINGLE_SEQUENCE = [
72
72
  ];
73
73
 
74
74
  export const createLightStyleSheet = (cfg: StyleSheetCfg = {}) => {
75
- const {
76
- backgroundColor = 'transparent',
77
- subColor = 'rgba(0,0,0,0.05)',
78
- paletteQualitative10 = QUALITATIVE_10,
79
- paletteQualitative20 = QUALITATIVE_20,
80
- paletteSemanticRed = '#F4664A',
81
- paletteSemanticGreen = '#30BF78',
82
- paletteSemanticYellow = '#FAAD14',
83
- paletteSequence = SINGLE_SEQUENCE,
84
- fontFamily = `"Segoe UI", Roboto, "Helvetica Neue", Arial,
85
- "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol",
86
- "Noto Color Emoji"`,
87
- } = cfg;
75
+ const { paletteQualitative10 = QUALITATIVE_10, paletteQualitative20 = QUALITATIVE_20 } = cfg;
88
76
  const { brandColor = paletteQualitative10[0] } = cfg;
89
77
 
90
- return {
78
+ const token = {
91
79
  /** 图表背景色 */
92
- backgroundColor,
80
+ backgroundColor: 'transparent',
93
81
  /** 主题色 */
94
82
  brandColor,
95
83
  /** 图表辅助色 */
96
- subColor,
84
+ subColor: 'rgba(0,0,0,0.05)',
97
85
  /** 分类色板 1,在数据量小于等于 10 时使用 */
98
86
  paletteQualitative10,
99
87
  /** 分类色板 2,在数据量大于 10 时使用 */
100
88
  paletteQualitative20,
101
89
  /** 语义色 */
102
- paletteSemanticRed,
90
+ paletteSemanticRed: '#F4664A',
103
91
  /** 语义色 */
104
- paletteSemanticGreen,
92
+ paletteSemanticGreen: '#30BF78',
105
93
  /** 语义色 */
106
- paletteSemanticYellow,
94
+ paletteSemanticYellow: '#FAAD14',
107
95
  /** (单色)顺序色板 */
108
- paletteSequence,
96
+ paletteSequence: SINGLE_SEQUENCE,
109
97
  /** 字体 */
110
- fontFamily,
98
+ fontFamily: `"Segoe UI", Roboto, "Helvetica Neue", Arial,
99
+ "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol",
100
+ "Noto Color Emoji"`,
111
101
 
112
102
  // -------------------- 坐标轴 --------------------
113
103
  /** 坐标轴线颜色 */
@@ -127,6 +117,8 @@ export const createLightStyleSheet = (cfg: StyleSheetCfg = {}) => {
127
117
  axisTitleTextFontWeight: 'normal',
128
118
  /** 坐标轴标题距离坐标轴文本的间距 */
129
119
  axisTitleSpacing: 12,
120
+ /** 坐标轴标题详细说明icon颜色 */
121
+ axisDescriptionIconFillColor: WHITE_COLORS[85],
130
122
 
131
123
  /** 坐标轴刻度线颜色 */
132
124
  axisTickLineBorderColor: BLACK_COLORS[25],
@@ -561,6 +553,8 @@ export const createLightStyleSheet = (cfg: StyleSheetCfg = {}) => {
561
553
  /** hollowInterval inactive 状态下边框透明度 */
562
554
  hollowIntervalInactiveBorderOpacity: 0.3,
563
555
  };
556
+
557
+ return { ...token, ...cfg };
564
558
  };
565
559
 
566
560
  export const antvLight = createLightStyleSheet();
@@ -22,6 +22,9 @@ function createAxisStyles(styleSheet: StyleSheet): LooseObject {
22
22
  textBaseline: 'middle',
23
23
  fontFamily: styleSheet.fontFamily,
24
24
  },
25
+ iconStyle: {
26
+ fill: styleSheet.axisDescriptionIconFillColor
27
+ }
25
28
  },
26
29
  label: {
27
30
  autoRotate: false,