@antv/component 0.8.32 → 0.9.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.
Files changed (81) hide show
  1. package/esm/abstract/html-component.js +1 -9
  2. package/esm/abstract/html-component.js.map +1 -1
  3. package/esm/legend/category.js +12 -3
  4. package/esm/legend/category.js.map +1 -1
  5. package/esm/slider/constant.d.ts +46 -1
  6. package/esm/slider/constant.js +50 -4
  7. package/esm/slider/constant.js.map +1 -1
  8. package/esm/slider/foreground.d.ts +78 -0
  9. package/esm/slider/foreground.js +102 -0
  10. package/esm/slider/foreground.js.map +1 -0
  11. package/esm/slider/handler.d.ts +3 -8
  12. package/esm/slider/handler.js +8 -15
  13. package/esm/slider/handler.js.map +1 -1
  14. package/esm/slider/slider.d.ts +29 -4
  15. package/esm/slider/slider.js +243 -46
  16. package/esm/slider/slider.js.map +1 -1
  17. package/esm/tooltip/css-const.d.ts +0 -1
  18. package/esm/tooltip/css-const.js +0 -1
  19. package/esm/tooltip/css-const.js.map +1 -1
  20. package/esm/tooltip/html-theme.d.ts +0 -22
  21. package/esm/tooltip/html-theme.js +0 -7
  22. package/esm/tooltip/html-theme.js.map +1 -1
  23. package/esm/tooltip/html.d.ts +0 -23
  24. package/esm/tooltip/html.js +11 -27
  25. package/esm/tooltip/html.js.map +1 -1
  26. package/esm/util/event.d.ts +8 -0
  27. package/esm/util/event.js +11 -0
  28. package/esm/util/event.js.map +1 -1
  29. package/esm/util/mask.d.ts +9 -0
  30. package/esm/util/mask.js +26 -0
  31. package/esm/util/mask.js.map +1 -0
  32. package/esm/util/util.d.ts +10 -0
  33. package/esm/util/util.js +62 -1
  34. package/esm/util/util.js.map +1 -1
  35. package/lib/abstract/html-component.js +1 -9
  36. package/lib/abstract/html-component.js.map +1 -1
  37. package/lib/legend/category.js +12 -3
  38. package/lib/legend/category.js.map +1 -1
  39. package/lib/slider/constant.d.ts +46 -1
  40. package/lib/slider/constant.js +51 -5
  41. package/lib/slider/constant.js.map +1 -1
  42. package/lib/slider/foreground.d.ts +78 -0
  43. package/lib/slider/foreground.js +105 -0
  44. package/lib/slider/foreground.js.map +1 -0
  45. package/lib/slider/handler.d.ts +3 -8
  46. package/lib/slider/handler.js +9 -16
  47. package/lib/slider/handler.js.map +1 -1
  48. package/lib/slider/slider.d.ts +29 -4
  49. package/lib/slider/slider.js +240 -43
  50. package/lib/slider/slider.js.map +1 -1
  51. package/lib/tooltip/css-const.d.ts +0 -1
  52. package/lib/tooltip/css-const.js +1 -2
  53. package/lib/tooltip/css-const.js.map +1 -1
  54. package/lib/tooltip/html-theme.d.ts +0 -22
  55. package/lib/tooltip/html-theme.js +0 -7
  56. package/lib/tooltip/html-theme.js.map +1 -1
  57. package/lib/tooltip/html.d.ts +0 -23
  58. package/lib/tooltip/html.js +11 -27
  59. package/lib/tooltip/html.js.map +1 -1
  60. package/lib/util/event.d.ts +8 -0
  61. package/lib/util/event.js +13 -1
  62. package/lib/util/event.js.map +1 -1
  63. package/lib/util/mask.d.ts +9 -0
  64. package/lib/util/mask.js +32 -0
  65. package/lib/util/mask.js.map +1 -0
  66. package/lib/util/util.d.ts +10 -0
  67. package/lib/util/util.js +64 -1
  68. package/lib/util/util.js.map +1 -1
  69. package/package.json +6 -18
  70. package/src/abstract/html-component.ts +1 -12
  71. package/src/legend/category.ts +21 -12
  72. package/src/slider/constant.ts +54 -4
  73. package/src/slider/foreground.ts +158 -0
  74. package/src/slider/handler.ts +10 -20
  75. package/src/slider/slider.ts +275 -60
  76. package/src/tooltip/css-const.ts +0 -1
  77. package/src/tooltip/html-theme.ts +0 -8
  78. package/src/tooltip/html.ts +11 -29
  79. package/src/util/event.ts +12 -0
  80. package/src/util/mask.ts +32 -0
  81. package/src/util/util.ts +67 -2
@@ -0,0 +1,158 @@
1
+ import { IGroup, LooseObject } from '@antv/g-base';
2
+ import { omit } from '@antv/util';
3
+ import GroupComponent from '../abstract/group-component';
4
+ import { GroupComponentCfg } from '../types';
5
+ import { BAR_STYLE, FOREGROUND_STYLE, SLIDER_BAR_LINE_GAP } from './constant';
6
+
7
+ interface IStyle {
8
+ fill?: string;
9
+ stroke?: string;
10
+ radius?: number;
11
+ opacity?: number;
12
+ cursor?: string;
13
+ highLightFill?: string;
14
+ }
15
+
16
+ export interface ForegroundCfg extends GroupComponentCfg {
17
+ // position size
18
+ readonly x: number;
19
+ readonly y: number;
20
+ readonly width: number;
21
+ readonly height: number;
22
+ // style
23
+ readonly foregroundStyle?: IStyle;
24
+ }
25
+
26
+ export class Foreground extends GroupComponent<ForegroundCfg> {
27
+ public getDefaultCfg() {
28
+ const cfg = super.getDefaultCfg();
29
+ return {
30
+ ...cfg,
31
+ name: 'foreground',
32
+ width: 100,
33
+ height: 16,
34
+ foregroundStyle: FOREGROUND_STYLE,
35
+ barStyle: BAR_STYLE,
36
+ };
37
+ }
38
+
39
+ protected renderInner(group: IGroup) {
40
+ const { x, height, width, foregroundStyle, barStyle } = this.cfg;
41
+
42
+ // 上方brush区域
43
+ this.addShape(group, {
44
+ id: this.getElementId('foreground-brush'),
45
+ name: 'foreground-brush',
46
+ type: 'rect',
47
+ attrs: {
48
+ x,
49
+ y: 0,
50
+ width,
51
+ height: (height * 3) / 5,
52
+ cursor: 'crosshair',
53
+ ...omit(foregroundStyle, ['stroke']),
54
+ },
55
+ });
56
+
57
+ // 下方移动区域
58
+ this.addShape(group, {
59
+ id: this.getElementId('foreground-scroll'),
60
+ name: 'foreground-scroll',
61
+ type: 'rect',
62
+ attrs: {
63
+ x,
64
+ y: (height * 3) / 5,
65
+ width,
66
+ height: (height * 2) / 5,
67
+ cursor: 'move',
68
+ ...omit(foregroundStyle, ['stroke']),
69
+ },
70
+ });
71
+
72
+ // 下方Bar区域
73
+ const barGroup = this.addGroup(group, {
74
+ id: this.getElementId('foreground-bar'),
75
+ name: 'foreground-bar',
76
+ });
77
+ // 外层矩形
78
+ this.addShape(barGroup, {
79
+ id: this.getElementId('foreground-bar-rect'),
80
+ name: 'foreground-bar-rect',
81
+ type: 'rect',
82
+ attrs: {
83
+ x,
84
+ y: height,
85
+ width,
86
+ height: barStyle.height,
87
+ cursor: 'move',
88
+ ...barStyle,
89
+ },
90
+ });
91
+ // 三条小竖线
92
+ const centerX = width / 2 + x;
93
+ const leftX = centerX - SLIDER_BAR_LINE_GAP;
94
+ const rightX = centerX + SLIDER_BAR_LINE_GAP;
95
+ const y1 = height + (1 / 4) * barStyle.height;
96
+ const y2 = height + (3 / 4) * barStyle.height;
97
+ const publicAttrs = {
98
+ y1,
99
+ y2,
100
+ ...barStyle,
101
+ };
102
+ [leftX, centerX, rightX].forEach((x) => {
103
+ this.drawBarLine(group, x, publicAttrs);
104
+ });
105
+
106
+ this.addShape(group, {
107
+ id: this.getElementId('foreground-border'),
108
+ name: 'foreground-border',
109
+ type: 'rect',
110
+ attrs: {
111
+ x,
112
+ y: 0,
113
+ width,
114
+ height,
115
+ stroke: foregroundStyle?.stroke,
116
+ opacity: foregroundStyle?.strokeOpacity,
117
+ lineWidth: foregroundStyle?.lineWidth,
118
+ },
119
+ });
120
+ }
121
+
122
+ private drawBarLine(group: IGroup, x: number, attrs: LooseObject) {
123
+ this.addShape(group, {
124
+ id: this.getElementId(`line-${x}`),
125
+ name: `line-${x}`,
126
+ type: 'line',
127
+ attrs: {
128
+ x1: x,
129
+ x2: x,
130
+ ...attrs,
131
+ },
132
+ });
133
+ }
134
+
135
+ protected initEvent() {
136
+ this.bindEvents();
137
+ }
138
+
139
+ private bindEvents() {
140
+ const { highLightFill, fill } = this.get('barStyle');
141
+ const barRectShape = this.get('group').findById(this.getElementId('foreground-bar-rect'));
142
+ this.get('group').on('foreground-bar:mouseenter', () => {
143
+ barRectShape.attr('fill', highLightFill);
144
+ this.draw();
145
+ });
146
+ this.get('group').on('foreground-bar:mouseleave', () => {
147
+ barRectShape.attr('fill', fill);
148
+ this.draw();
149
+ });
150
+ }
151
+
152
+ private draw() {
153
+ const canvas = this.get('container').get('canvas');
154
+ if (canvas) {
155
+ canvas.draw();
156
+ }
157
+ }
158
+ }
@@ -1,6 +1,7 @@
1
1
  import { IGroup } from '@antv/g-base';
2
2
  import GroupComponent from '../abstract/group-component';
3
3
  import { GroupComponentCfg } from '../types';
4
+ import { DEFAULT_HANDLER_HEIGHT, DEFAULT_HANDLER_WIDTH, HANDLER_STYLE } from './constant';
4
5
 
5
6
  interface IStyle {
6
7
  fill?: string;
@@ -21,16 +22,6 @@ export interface HandlerCfg extends GroupComponentCfg {
21
22
  readonly style?: IStyle;
22
23
  }
23
24
 
24
- export const DEFAULT_HANDLER_STYLE = {
25
- fill: '#F7F7F7',
26
- stroke: '#BFBFBF',
27
- radius: 2,
28
- opacity: 1,
29
- cursor: 'ew-resize',
30
- // 高亮的颜色
31
- highLightFill: '#FFF',
32
- };
33
-
34
25
  export class Handler extends GroupComponent<HandlerCfg> {
35
26
  public getDefaultCfg() {
36
27
  const cfg = super.getDefaultCfg();
@@ -39,9 +30,9 @@ export class Handler extends GroupComponent<HandlerCfg> {
39
30
  name: 'handler',
40
31
  x: 0,
41
32
  y: 0,
42
- width: 10,
43
- height: 24,
44
- style: DEFAULT_HANDLER_STYLE,
33
+ width: DEFAULT_HANDLER_WIDTH,
34
+ height: DEFAULT_HANDLER_HEIGHT,
35
+ style: HANDLER_STYLE,
45
36
  };
46
37
  }
47
38
  protected renderInner(group: IGroup) {
@@ -58,7 +49,6 @@ export class Handler extends GroupComponent<HandlerCfg> {
58
49
  width,
59
50
  height,
60
51
  fill,
61
- stroke,
62
52
  radius,
63
53
  opacity,
64
54
  cursor,
@@ -112,16 +102,16 @@ export class Handler extends GroupComponent<HandlerCfg> {
112
102
 
113
103
  private bindEvents() {
114
104
  this.get('group').on('mouseenter', () => {
115
- const { highLightFill } = this.get('style');
116
- this.getElementByLocalId('background').attr('fill', highLightFill);
117
-
105
+ const { highLightStroke } = this.get('style');
106
+ this.getElementByLocalId('line-left').attr('stroke', highLightStroke);
107
+ this.getElementByLocalId('line-right').attr('stroke', highLightStroke);
118
108
  this.draw();
119
109
  });
120
110
 
121
111
  this.get('group').on('mouseleave', () => {
122
- const { fill } = this.get('style');
123
- this.getElementByLocalId('background').attr('fill', fill);
124
-
112
+ const { stroke } = this.get('style');
113
+ this.getElementByLocalId('line-left').attr('stroke', stroke);
114
+ this.getElementByLocalId('line-right').attr('stroke', stroke);
125
115
  this.draw();
126
116
  });
127
117
  }