@antv/component 0.9.1 → 0.9.3

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 (48) hide show
  1. package/esm/slider/constant.d.ts +8 -5
  2. package/esm/slider/constant.js +8 -5
  3. package/esm/slider/constant.js.map +1 -1
  4. package/esm/slider/foreground.d.ts +9 -1
  5. package/esm/slider/foreground.js +30 -23
  6. package/esm/slider/foreground.js.map +1 -1
  7. package/esm/slider/handler.d.ts +1 -0
  8. package/esm/slider/handler.js +2 -0
  9. package/esm/slider/handler.js.map +1 -1
  10. package/esm/slider/slider.d.ts +14 -0
  11. package/esm/slider/slider.js +86 -40
  12. package/esm/slider/slider.js.map +1 -1
  13. package/esm/util/event.d.ts +2 -2
  14. package/esm/util/event.js +1 -2
  15. package/esm/util/event.js.map +1 -1
  16. package/esm/util/mask.js +0 -8
  17. package/esm/util/mask.js.map +1 -1
  18. package/esm/util/util.d.ts +4 -1
  19. package/esm/util/util.js +5 -2
  20. package/esm/util/util.js.map +1 -1
  21. package/lib/slider/constant.d.ts +8 -5
  22. package/lib/slider/constant.js +9 -6
  23. package/lib/slider/constant.js.map +1 -1
  24. package/lib/slider/foreground.d.ts +9 -1
  25. package/lib/slider/foreground.js +29 -22
  26. package/lib/slider/foreground.js.map +1 -1
  27. package/lib/slider/handler.d.ts +1 -0
  28. package/lib/slider/handler.js +2 -0
  29. package/lib/slider/handler.js.map +1 -1
  30. package/lib/slider/slider.d.ts +14 -0
  31. package/lib/slider/slider.js +84 -38
  32. package/lib/slider/slider.js.map +1 -1
  33. package/lib/util/event.d.ts +2 -2
  34. package/lib/util/event.js +1 -2
  35. package/lib/util/event.js.map +1 -1
  36. package/lib/util/mask.js +0 -8
  37. package/lib/util/mask.js.map +1 -1
  38. package/lib/util/util.d.ts +4 -1
  39. package/lib/util/util.js +7 -4
  40. package/lib/util/util.js.map +1 -1
  41. package/package.json +1 -1
  42. package/src/slider/constant.ts +8 -9
  43. package/src/slider/foreground.ts +38 -36
  44. package/src/slider/handler.ts +3 -0
  45. package/src/slider/slider.ts +96 -38
  46. package/src/util/event.ts +2 -3
  47. package/src/util/mask.ts +1 -10
  48. package/src/util/util.ts +5 -2
@@ -1,13 +1,8 @@
1
1
  import { IGroup, LooseObject } from '@antv/g-base';
2
+ import { omit } from '@antv/util';
2
3
  import GroupComponent from '../abstract/group-component';
3
4
  import { GroupComponentCfg } from '../types';
4
- import {
5
- FOREGROUND_STYLE,
6
- SLICER_BAR_LINE_STYLE,
7
- SLIDER_BAR_HEIGHT,
8
- SLIDER_BAR_LINE_GAP,
9
- SLIDER_BAR_STYLE,
10
- } from './constant';
5
+ import { BAR_STYLE, FOREGROUND_STYLE, SLIDER_BAR_LINE_GAP } from './constant';
11
6
 
12
7
  interface IStyle {
13
8
  fill?: string;
@@ -34,49 +29,47 @@ export class Foreground extends GroupComponent<ForegroundCfg> {
34
29
  return {
35
30
  ...cfg,
36
31
  name: 'foreground',
37
- // x: 0,
38
- // y: 0,
39
32
  width: 100,
40
33
  height: 16,
41
- style: FOREGROUND_STYLE,
42
- barStyle: SLIDER_BAR_STYLE,
34
+ foregroundStyle: FOREGROUND_STYLE,
35
+ barStyle: BAR_STYLE,
43
36
  };
44
37
  }
45
38
 
46
39
  protected renderInner(group: IGroup) {
47
- const { x, height, width, style, barStyle } = this.cfg;
40
+ const { x, height, width, foregroundStyle, barStyle } = this.cfg;
48
41
 
49
- // 上方brush区域
42
+ // 上方移动区域
50
43
  this.addShape(group, {
51
- id: this.getElementId('foreground-brush'),
52
- name: 'foreground-brush',
44
+ id: this.getElementId('foreground-scroll'),
45
+ name: 'foreground-scroll',
53
46
  type: 'rect',
54
47
  attrs: {
55
48
  x,
56
49
  y: 0,
57
50
  width,
58
- height: (height * 3) / 5,
59
- cursor: 'crosshair',
60
- ...style,
51
+ height: (height * 2) / 5,
52
+ cursor: 'move',
53
+ ...omit(foregroundStyle, ['stroke']),
61
54
  },
62
55
  });
63
56
 
64
- // 下方移动区域
57
+ // 下方brush区域
65
58
  this.addShape(group, {
66
- id: this.getElementId('foreground-scroll'),
67
- name: 'foreground-scroll',
59
+ id: this.getElementId('foreground-brush'),
60
+ name: 'foreground-brush',
68
61
  type: 'rect',
69
62
  attrs: {
70
63
  x,
71
- y: (height * 3) / 5,
64
+ y: (height * 2) / 5,
72
65
  width,
73
- height: (height * 2) / 5,
74
- cursor: 'move',
75
- ...style,
66
+ height: (height * 3) / 5,
67
+ cursor: 'crosshair',
68
+ ...omit(foregroundStyle, ['stroke']),
76
69
  },
77
70
  });
78
71
 
79
- // 下方Bar区域
72
+ // 上方Bar区域
80
73
  const barGroup = this.addGroup(group, {
81
74
  id: this.getElementId('foreground-bar'),
82
75
  name: 'foreground-bar',
@@ -88,28 +81,29 @@ export class Foreground extends GroupComponent<ForegroundCfg> {
88
81
  type: 'rect',
89
82
  attrs: {
90
83
  x,
91
- y: height,
84
+ y: -barStyle.height,
92
85
  width,
93
- height: SLIDER_BAR_HEIGHT,
86
+ height: barStyle.height,
94
87
  cursor: 'move',
95
- ...barStyle,
88
+ ...omit(barStyle, ['stroke']),
96
89
  },
97
90
  });
98
91
  // 三条小竖线
99
92
  const centerX = width / 2 + x;
100
93
  const leftX = centerX - SLIDER_BAR_LINE_GAP;
101
94
  const rightX = centerX + SLIDER_BAR_LINE_GAP;
102
- const y1 = height + (1 / 5) * 6;
103
- const y2 = height + (4 / 5) * 6;
95
+ const y1 = -(1 / 4) * barStyle.height;
96
+ const y2 = -(3 / 4) * barStyle.height;
104
97
  const publicAttrs = {
105
98
  y1,
106
99
  y2,
107
- ...SLICER_BAR_LINE_STYLE,
100
+ ...barStyle,
108
101
  };
109
102
  [leftX, centerX, rightX].forEach((x) => {
110
103
  this.drawBarLine(group, x, publicAttrs);
111
104
  });
112
105
 
106
+ // 背景边框
113
107
  this.addShape(group, {
114
108
  id: this.getElementId('foreground-border'),
115
109
  name: 'foreground-border',
@@ -119,9 +113,9 @@ export class Foreground extends GroupComponent<ForegroundCfg> {
119
113
  y: 0,
120
114
  width,
121
115
  height,
122
- stroke: '#4E83CD',
123
- opacity: 0.3,
124
- lineWidth: 0.8,
116
+ stroke: foregroundStyle?.stroke,
117
+ opacity: foregroundStyle?.strokeOpacity,
118
+ lineWidth: foregroundStyle?.lineWidth,
125
119
  },
126
120
  });
127
121
  }
@@ -129,7 +123,7 @@ export class Foreground extends GroupComponent<ForegroundCfg> {
129
123
  private drawBarLine(group: IGroup, x: number, attrs: LooseObject) {
130
124
  this.addShape(group, {
131
125
  id: this.getElementId(`line-${x}`),
132
- name: `line-${x}`,
126
+ name: `foreground-line`,
133
127
  type: 'line',
134
128
  attrs: {
135
129
  x1: x,
@@ -150,10 +144,18 @@ export class Foreground extends GroupComponent<ForegroundCfg> {
150
144
  barRectShape.attr('fill', highLightFill);
151
145
  this.draw();
152
146
  });
147
+ this.get('group').on('foreground-scroll:mouseenter', () => {
148
+ barRectShape.attr('fill', highLightFill);
149
+ this.draw();
150
+ });
153
151
  this.get('group').on('foreground-bar:mouseleave', () => {
154
152
  barRectShape.attr('fill', fill);
155
153
  this.draw();
156
154
  });
155
+ this.get('group').on('foreground-scroll:mouseleave', () => {
156
+ barRectShape.attr('fill', fill);
157
+ this.draw();
158
+ });
157
159
  }
158
160
 
159
161
  private draw() {
@@ -10,6 +10,7 @@ interface IStyle {
10
10
  opacity?: number;
11
11
  cursor?: string;
12
12
  highLightFill?: string;
13
+ highLightStroke?: string;
13
14
  }
14
15
 
15
16
  export interface HandlerCfg extends GroupComponentCfg {
@@ -64,6 +65,7 @@ export class Handler extends GroupComponent<HandlerCfg> {
64
65
 
65
66
  this.addShape(group, {
66
67
  id: this.getElementId('line-left'),
68
+ name: 'handler-line',
67
69
  type: 'line',
68
70
  attrs: {
69
71
  x1,
@@ -77,6 +79,7 @@ export class Handler extends GroupComponent<HandlerCfg> {
77
79
 
78
80
  this.addShape(group, {
79
81
  id: this.getElementId('line-right'),
82
+ name: 'handler-line',
80
83
  type: 'line',
81
84
  attrs: {
82
85
  x1: x2,
@@ -6,8 +6,8 @@ import { Trend } from '../trend/trend';
6
6
  import { Handler, HandlerCfg } from './handler';
7
7
  import { GroupComponentCfg, Range } from '../types';
8
8
  import {
9
- ACTIVE_TREND_STYLE,
10
9
  BACKGROUND_STYLE,
10
+ BAR_STYLE,
11
11
  DEFAULT_HANDLER_HEIGHT,
12
12
  DEFAULT_HANDLER_WIDTH,
13
13
  DEFAULT_TREND_STYLE,
@@ -20,8 +20,9 @@ import {
20
20
  TEXT_STYLE,
21
21
  } from './constant';
22
22
  import { createMask, getRectMaskAttrs, updateMask } from '../util/mask';
23
- import { clipText, getTextWidth } from '../util/util';
23
+ import { clipTextTwoLines, getTextWidth } from '../util/util';
24
24
  import { Foreground } from './foreground';
25
+ import { getCurrentPoint } from '../util/event';
25
26
 
26
27
  export interface TrendCfg {
27
28
  // 数据
@@ -32,6 +33,7 @@ export interface TrendCfg {
32
33
  readonly backgroundStyle?: object;
33
34
  readonly lineStyle?: object;
34
35
  readonly areaStyle?: object;
36
+ readonly barStyle?: object;
35
37
  }
36
38
 
37
39
  /**
@@ -138,11 +140,13 @@ export class Slider extends GroupComponent<SliderCfg> implements ISlider {
138
140
  foregroundStyle: {},
139
141
  handlerStyle: {},
140
142
  textStyle: {},
143
+ barStyle: {},
141
144
  defaultCfg: {
142
145
  backgroundStyle: BACKGROUND_STYLE,
143
146
  foregroundStyle: FOREGROUND_STYLE,
144
147
  handlerStyle: HANDLER_STYLE,
145
148
  textStyle: TEXT_STYLE,
149
+ barStyle: BAR_STYLE,
146
150
  },
147
151
  };
148
152
  }
@@ -187,10 +191,9 @@ export class Slider extends GroupComponent<SliderCfg> implements ISlider {
187
191
  backgroundStyle = {},
188
192
  foregroundStyle = {},
189
193
  textStyle = {},
194
+ barStyle = {},
190
195
  } = this.cfg;
191
196
 
192
- const handlerStyle = deepMix({}, HANDLER_STYLE, this.cfg.handlerStyle);
193
-
194
197
  const min = start * width;
195
198
  const max = end * width;
196
199
 
@@ -228,7 +231,8 @@ export class Slider extends GroupComponent<SliderCfg> implements ISlider {
228
231
  id: this.getElementId('foreground'),
229
232
  name: 'foreground',
230
233
  height,
231
- style: foregroundStyle,
234
+ foregroundStyle,
235
+ barStyle,
232
236
  });
233
237
 
234
238
  // 3. 左右文字
@@ -258,6 +262,7 @@ export class Slider extends GroupComponent<SliderCfg> implements ISlider {
258
262
  });
259
263
 
260
264
  // 滑块相关的大小信息
265
+ const handlerStyle = deepMix({}, HANDLER_STYLE, this.cfg.handlerStyle);
261
266
  const handlerWidth = get(handlerStyle, 'width', DEFAULT_HANDLER_WIDTH);
262
267
  const handlerHeight = get(handlerStyle, 'height', DEFAULT_HANDLER_HEIGHT);
263
268
 
@@ -299,7 +304,7 @@ export class Slider extends GroupComponent<SliderCfg> implements ISlider {
299
304
  }
300
305
 
301
306
  private updateUI(minTextShape: IShape, maxTextShape: IShape) {
302
- const { start, end, width, minText, maxText, handlerStyle, height } = this.cfg as SliderCfg;
307
+ const { start, end, width, minText, maxText, handlerStyle, height, barStyle } = this.cfg;
303
308
  const min = start * width;
304
309
  const max = end * width;
305
310
 
@@ -314,27 +319,37 @@ export class Slider extends GroupComponent<SliderCfg> implements ISlider {
314
319
  }
315
320
 
316
321
  if (this.foreground) {
322
+ const newBarStyle = ['foreground-bar', 'foreground'].includes(this.currentTarget)
323
+ ? { ...barStyle, fill: barStyle.highLightFill }
324
+ : barStyle;
317
325
  this.foreground.update({
318
326
  x: min,
319
327
  width: max - min,
328
+ barStyle: newBarStyle,
320
329
  });
321
330
  if (!this.get('updateAutoRender')) {
322
331
  this.foreground.render();
323
332
  }
324
333
  }
325
-
326
334
  // 滑块相关的大小信息
327
335
  const handlerWidth = get(handlerStyle, 'width', DEFAULT_HANDLER_WIDTH);
328
336
 
329
337
  // 设置文本
330
338
  minTextShape.attr('text', minText);
331
339
  maxTextShape.attr('text', maxText);
332
-
333
340
  const [minAttrs, maxAttrs] = this._dodgeText([min, max], minTextShape, maxTextShape);
334
341
  // 2. 左侧滑块和文字位置
335
342
  if (this.minHandler) {
343
+ const newStyle =
344
+ this.currentTarget === 'minHandler'
345
+ ? {
346
+ ...handlerStyle,
347
+ stroke: handlerStyle.highLightStroke,
348
+ }
349
+ : handlerStyle;
336
350
  this.minHandler.update({
337
351
  x: min - handlerWidth / 2,
352
+ style: newStyle,
338
353
  });
339
354
  if (!this.get('updateAutoRender')) {
340
355
  this.minHandler.render();
@@ -344,8 +359,16 @@ export class Slider extends GroupComponent<SliderCfg> implements ISlider {
344
359
 
345
360
  // 3. 右侧滑块和文字位置
346
361
  if (this.maxHandler) {
362
+ const newStyle =
363
+ this.currentTarget === 'maxHandler'
364
+ ? {
365
+ ...handlerStyle,
366
+ stroke: handlerStyle.highLightStroke,
367
+ }
368
+ : handlerStyle;
347
369
  this.maxHandler.update({
348
370
  x: max - handlerWidth / 2,
371
+ style: newStyle,
349
372
  });
350
373
  if (!this.get('updateAutoRender')) {
351
374
  this.maxHandler.render();
@@ -374,6 +397,8 @@ export class Slider extends GroupComponent<SliderCfg> implements ISlider {
374
397
  group.on('foreground-bar:mousedown', this.onMouseDown('foreground'));
375
398
  // 选中区域框选
376
399
  group.on('foreground-brush:mousedown', this.onMouseDown('foreground-brush'));
400
+ // 移动端:只允许拖拽
401
+ group.on('foreground:touchstart', this.onMouseDown('foreground'));
377
402
  }
378
403
 
379
404
  private onMouseDown = (target: string) => (e: Event) => {
@@ -386,8 +411,9 @@ export class Slider extends GroupComponent<SliderCfg> implements ISlider {
386
411
  event.preventDefault();
387
412
 
388
413
  // 兼容移动端获取数据
389
- this.prevX = get(event, 'touches.0.pageX', event.pageX);
390
- this.prevY = get(event, 'touches.0.pageY', event.pageY);
414
+ const { x, y } = getCurrentPoint(event);
415
+ this.prevX = x;
416
+ this.prevY = y;
391
417
 
392
418
  const containerDOM = this.getContainerDOM();
393
419
 
@@ -420,8 +446,7 @@ export class Slider extends GroupComponent<SliderCfg> implements ISlider {
420
446
  event.stopPropagation();
421
447
  event.preventDefault();
422
448
 
423
- const x = get(event, 'touches.0.pageX', event.pageX);
424
- const y = get(event, 'touches.0.pageY', event.pageY);
449
+ const { x, y } = getCurrentPoint(event);
425
450
 
426
451
  // 横向的 slider 只处理 x
427
452
  const offsetX = x - this.prevX;
@@ -452,6 +477,25 @@ export class Slider extends GroupComponent<SliderCfg> implements ISlider {
452
477
  this.currentTarget = undefined;
453
478
  }
454
479
 
480
+ // 清空handler的高亮状态
481
+ const { handlerStyle } = this.cfg;
482
+ if (this.minHandler && this.minHandler.cfg.style.stroke === handlerStyle.highLightStroke) {
483
+ this.minHandler.update({
484
+ style: handlerStyle,
485
+ });
486
+ if (!this.get('updateAutoRender')) {
487
+ this.minHandler.render();
488
+ }
489
+ }
490
+ if (this.maxHandler && this.maxHandler.cfg.style.stroke === handlerStyle.highLightStroke) {
491
+ this.maxHandler.update({
492
+ style: handlerStyle,
493
+ });
494
+ if (!this.get('updateAutoRender')) {
495
+ this.maxHandler.render();
496
+ }
497
+ }
498
+
455
499
  const containerDOM = this.getContainerDOM();
456
500
  if (containerDOM) {
457
501
  containerDOM.removeEventListener('mousemove', this.onMouseMove);
@@ -543,7 +587,8 @@ export class Slider extends GroupComponent<SliderCfg> implements ISlider {
543
587
 
544
588
  // 两端文字存在安全间距为4px, 如果小于该距离则两端均不显示文字
545
589
  const gap = this.cfg.width - handlerWidth * 2 - TEXT_PADDING * 2 - minTextWidth - maxTextWidth;
546
- if (gap < TEXT_SAFE_WIDTH) {
590
+ if (gap <= TEXT_SAFE_WIDTH) {
591
+ // text: '' 不显示文字
547
592
  const newMinAttrs = { ...minAttrs, text: '' };
548
593
  const newMaxAttrs = { ...maxAttrs, text: '' };
549
594
  return !sorted ? [newMinAttrs, newMaxAttrs] : [newMaxAttrs, newMinAttrs];
@@ -552,19 +597,17 @@ export class Slider extends GroupComponent<SliderCfg> implements ISlider {
552
597
  // 一侧不滑动(文字仍显示在中间),另一侧滑动的情况下。
553
598
  // 检测中间宽度是否能展示当前不滑动文字的文本,如果距离不够,则隐藏不滑动一侧的文字。
554
599
  if (minAttrs.textAlign === 'left' || maxAttrs.textAlign === 'right') {
600
+ const foregroundWidth = this.foreground?.get('width');
601
+ const gap = foregroundWidth - handlerWidth - TEXT_PADDING * 2;
555
602
  if (minAttrs.textAlign === 'left') {
556
- const foregroundWidth = this.foreground?.get('width');
557
- const gap = foregroundWidth - TEXT_PADDING;
558
- if (gap < minTextWidth) {
603
+ if (gap <= minTextWidth) {
559
604
  return !sorted ? [{ ...minAttrs, text: '' }, { ...maxAttrs }] : [{ ...maxAttrs }, { ...minAttrs, text: '' }];
560
605
  } else {
561
606
  return !sorted ? [minAttrs, maxAttrs] : [maxAttrs, minAttrs];
562
607
  }
563
608
  }
564
609
  if (maxAttrs.textAlign === 'right') {
565
- const foregroundWidth = this.foreground?.get('width');
566
- const gap = foregroundWidth - TEXT_PADDING;
567
- if (gap < maxTextWidth) {
610
+ if (gap <= maxTextWidth) {
568
611
  return !sorted ? [{ ...minAttrs }, { ...maxAttrs, text: '' }] : [{ ...maxAttrs, text: '' }, { ...minAttrs }];
569
612
  } else {
570
613
  return !sorted ? [minAttrs, maxAttrs] : [maxAttrs, minAttrs];
@@ -589,53 +632,68 @@ export class Slider extends GroupComponent<SliderCfg> implements ISlider {
589
632
  textWidth: number;
590
633
  } {
591
634
  const handlerWidth = get(this.cfg.handlerStyle, 'width', DEFAULT_HANDLER_WIDTH);
635
+ const gapWidth = handlerWidth / 2 + TEXT_PADDING;
592
636
  const [min, max] = range;
593
637
  const { width } = bbox;
594
638
  const text = textShape.attr('text');
595
639
  const font = textShape.attr('font');
596
640
  let textWidth = 0;
597
641
  let attrs = {};
642
+ // 字体长度>最大长度,换行处理
598
643
  if (width > MAX_TEXT_WIDTH) {
599
644
  textWidth = MAX_TEXT_WIDTH;
600
645
  if (direction === 'min') {
601
646
  attrs =
602
- width / 2 > min - TEXT_PADDING
647
+ // 如果 最大单行宽度 > 左侧能塞下的宽度,则放在左侧
648
+ MAX_TEXT_WIDTH > min - gapWidth
603
649
  ? {
604
- x: min + handlerWidth / 2 + TEXT_PADDING,
650
+ x: min + gapWidth,
605
651
  textAlign: 'left',
606
- text: clipText(text, MAX_TEXT_WIDTH, font),
652
+ text: clipTextTwoLines(text, MAX_TEXT_WIDTH, font),
607
653
  }
608
654
  : {
609
- x: min - handlerWidth / 2 - TEXT_PADDING,
655
+ x: min - gapWidth,
610
656
  textAlign: 'right',
611
- text: clipText(text, MAX_TEXT_WIDTH, font),
657
+ text: clipTextTwoLines(text, MAX_TEXT_WIDTH, font),
612
658
  };
613
659
  } else {
614
660
  attrs =
615
- width / 2 > this.cfg.width - max - TEXT_PADDING
661
+ MAX_TEXT_WIDTH > this.cfg.width - max - gapWidth
616
662
  ? {
617
- x: max - handlerWidth / 2 + TEXT_PADDING,
663
+ x: max - gapWidth,
618
664
  textAlign: 'right',
619
- text: clipText(text, MAX_TEXT_WIDTH, font),
665
+ text: clipTextTwoLines(text, MAX_TEXT_WIDTH, font),
620
666
  }
621
667
  : {
622
- x: max + handlerWidth / 2 - TEXT_PADDING,
668
+ x: max + gapWidth,
623
669
  textAlign: 'left',
624
- text: clipText(text, MAX_TEXT_WIDTH, font),
670
+ text: clipTextTwoLines(text, MAX_TEXT_WIDTH, font),
625
671
  };
626
672
  }
627
673
  } else {
628
- textWidth = getTextWidth(text, font);
674
+ textWidth = width;
629
675
  if (direction === 'min') {
630
676
  attrs =
631
- width > min - TEXT_PADDING
632
- ? { x: min + handlerWidth / 2 + TEXT_PADDING, textAlign: 'left' }
633
- : { x: min - handlerWidth / 2 - TEXT_PADDING, textAlign: 'right' };
677
+ width > min - gapWidth
678
+ ? {
679
+ x: min + gapWidth,
680
+ textAlign: 'left',
681
+ }
682
+ : {
683
+ x: min - gapWidth,
684
+ textAlign: 'right',
685
+ };
634
686
  } else {
635
687
  attrs =
636
- width > this.cfg.width - max - TEXT_PADDING
637
- ? { x: max - handlerWidth / 2 - TEXT_PADDING, textAlign: 'right' }
638
- : { x: max + handlerWidth / 2 + TEXT_PADDING, textAlign: 'left' };
688
+ width > this.cfg.width - max - gapWidth
689
+ ? {
690
+ x: max - gapWidth,
691
+ textAlign: 'right',
692
+ }
693
+ : {
694
+ x: max + gapWidth,
695
+ textAlign: 'left',
696
+ };
639
697
  }
640
698
  }
641
699
 
@@ -664,7 +722,7 @@ export class Slider extends GroupComponent<SliderCfg> implements ISlider {
664
722
  if (!this.enableBrush) return;
665
723
 
666
724
  const { x } = this.getBBox();
667
- const curX = get(event, 'touches.0.pageX', event.offsetX);
725
+ const curX = event.offsetX;
668
726
  // 绘制 brush mask
669
727
  if (!isNumber(this.brushPrevX)) {
670
728
  this.brushPrevX = curX;
@@ -693,7 +751,7 @@ export class Slider extends GroupComponent<SliderCfg> implements ISlider {
693
751
  if (!this.enableBrush) return;
694
752
 
695
753
  // 没有拖动偏移量时,取消框选操作
696
- const curX = get(event, 'touches.0.pageX', event.offsetX);
754
+ const curX = event.offsetX;
697
755
  if (this.brushPrevX === curX) {
698
756
  this.cancelBrush();
699
757
  return;
package/src/util/event.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Event, IGroup } from '@antv/g-base';
1
+ import { IGroup } from '@antv/g-base';
2
2
  import { Event as GraphEvent } from '@antv/g-base';
3
3
  import { get } from '@antv/util';
4
4
  import { LooseObject } from '../types';
@@ -28,8 +28,7 @@ export function propagationDelegate(group: IGroup, eventName: string, eventObjec
28
28
  *
29
29
  * @param e 事件对象
30
30
  */
31
- export function getCurrentPoint(e: Event) {
32
- const event = e.originalEvent as MouseEvent;
31
+ export function getCurrentPoint(event: MouseEvent) {
33
32
  return {
34
33
  x: get(event, 'touches.0.pageX', event.pageX),
35
34
  y: get(event, 'touches.0.pageY', event.pageY),
package/src/util/mask.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { BBox, IGroup, IShape, LooseObject, Point } from '@antv/g-base';
1
+ import { IGroup, IShape, LooseObject, Point } from '@antv/g-base';
2
2
 
3
3
  export function createMask(group: IGroup, maskType: string, maskAttrs: LooseObject) {
4
4
  const maskShape = group.addShape({
@@ -18,15 +18,6 @@ export function updateMask(shape: IShape, maskAttrs: LooseObject) {
18
18
  return shape;
19
19
  }
20
20
 
21
- // export function overBBoxLimit(bbox: BBox, curPoint: Point) {
22
- // const { minX, maxX, minY, maxY } = bbox;
23
- // const { x, y } = curPoint;
24
- // if (Math.min(minX, maxX) > x || Math.max(minX, maxX) < x || Math.min(minY, maxY) > y || Math.max(minY, maxY) < y) {
25
- // return true;
26
- // }
27
- // return false;
28
- // }
29
-
30
21
  export function getRectMaskAttrs(start: Point, end: Point) {
31
22
  const x = Math.min(start.x, end.x);
32
23
  const y = Math.min(start.y, end.y);
package/src/util/util.ts CHANGED
@@ -265,7 +265,10 @@ export function getTextWidth(text: string, font: string) {
265
265
  return width;
266
266
  }
267
267
 
268
- export function clipText(str: string, maxWidth: number, font: string) {
268
+ /**
269
+ * @description 文字超出最大宽度时,换行处理
270
+ */
271
+ export function clipTextTwoLines(str: string, maxWidth: number, font: string) {
269
272
  // 日期字段根据空格拆为两组:'2022-10-12 08:23' => ['2022-10-12', '08:23']
270
273
  if (Date.parse(str)) {
271
274
  return str.split(' ').join('\n');
@@ -274,7 +277,7 @@ export function clipText(str: string, maxWidth: number, font: string) {
274
277
  function mapStr(str: string, callback: (i: number) => void) {
275
278
  for (let i = 0; i < str.length; i++) {
276
279
  const curStr = str.slice(0, i + 1);
277
- const curWidth = getTextWidth(curStr, '12');
280
+ const curWidth = getTextWidth(curStr, font);
278
281
  if (curWidth > maxWidth) {
279
282
  callback(i);
280
283
  return;