@antv/component 2.1.9 → 2.1.11

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.
@@ -6,7 +6,15 @@ import { transition } from '../../animation';
6
6
  import { Component } from '../../core';
7
7
  import { Group, Rect, Text } from '../../shapes';
8
8
  import type { Selection } from '../../util';
9
- import { getEventPos, ifShow, parseSeriesAttr, select, subStyleProps, superStyleProps, toPrecision } from '../../util';
9
+ import {
10
+ getEventViewportPos,
11
+ ifShow,
12
+ parseSeriesAttr,
13
+ select,
14
+ subStyleProps,
15
+ superStyleProps,
16
+ toPrecision,
17
+ } from '../../util';
10
18
  import type { SparklineStyleProps } from '../sparkline';
11
19
  import { Sparkline } from '../sparkline';
12
20
  import { CLASS_NAMES, HANDLE_DEFAULT_CFG, HANDLE_ICON_DEFAULT_CFG, HANDLE_LABEL_DEFAULT_CFG } from './constant';
@@ -556,7 +564,7 @@ export class Slider extends Component<SliderStyleProps> {
556
564
  private onDragStart = (target: string) => (e: any) => {
557
565
  e.stopPropagation();
558
566
  this.target = target;
559
- this.prevPos = this.getOrientVal(getEventPos(e));
567
+ this.prevPos = this.getOrientVal(getEventViewportPos(e));
560
568
  const { x, y } = this.availableSpace;
561
569
  const { x: X, y: Y } = this.getBBox();
562
570
  this.selectionStartPos = this.getRatio(this.prevPos - this.getOrientVal([x, y]) - this.getOrientVal([+X!, +Y!]));
@@ -565,11 +573,11 @@ export class Slider extends Component<SliderStyleProps> {
565
573
  document.addEventListener('pointerup', this.onDragEnd);
566
574
  };
567
575
 
568
- private onDragging = (e: any) => {
576
+ private onDragging = (e: PointerEvent) => {
569
577
  const { slidable, brushable, type } = this.attributes;
570
578
  e.stopPropagation();
571
579
 
572
- const currPos = this.getOrientVal(getEventPos(e));
580
+ const currPos = this.getOrientVal(getEventViewportPos(e));
573
581
  const diffPos = currPos - this.prevPos;
574
582
 
575
583
  if (!diffPos) return;
package/src/util/event.ts CHANGED
@@ -14,3 +14,19 @@ export function getEventPos(e: any): [number, number] {
14
14
  if (offsetX && offsetY) return [offsetX, offsetY];
15
15
  return [0, 0];
16
16
  }
17
+
18
+ /**
19
+ * 获得触发事件相对于页面 viewport 的坐标
20
+ */
21
+ export function getEventViewportPos(e: any): [number, number] {
22
+ const { nativeEvent, touches, clientX, clientY } = e;
23
+ if (nativeEvent) {
24
+ return [nativeEvent.clientX, nativeEvent.clientY];
25
+ }
26
+ if (touches) {
27
+ const { clientX, clientY } = touches[0];
28
+ return [clientX, clientY];
29
+ }
30
+ if (typeof clientX === 'number' && typeof clientY === 'number') return [clientX, clientY];
31
+ return [0, 0];
32
+ }
@@ -11,5 +11,13 @@ export function renderExtDo(el: ExtendDisplayObject): DisplayObject {
11
11
 
12
12
  export function renderHtmlExtDo(el: ExtendDisplayObject, style: Partial<HTMLStyleProps>): DisplayObject {
13
13
  if (typeof el === 'function') return el();
14
- return isString(el) || isNumber(el) ? new HTML({ style: { ...style, innerHTML: String(el) } }) : el;
14
+ return isString(el) || isNumber(el)
15
+ ? new HTML({
16
+ style: {
17
+ pointerEvents: 'auto',
18
+ ...style,
19
+ innerHTML: el as string | HTMLElement,
20
+ },
21
+ })
22
+ : el;
15
23
  }