@antv/component 0.9.3 → 0.9.5

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.
@@ -11,6 +11,8 @@ interface IStyle {
11
11
  opacity?: number;
12
12
  cursor?: string;
13
13
  highLightFill?: string;
14
+ /** 框选占比 */
15
+ brushRatio?: number;
14
16
  }
15
17
 
16
18
  export interface ForegroundCfg extends GroupComponentCfg {
@@ -38,6 +40,7 @@ export class Foreground extends GroupComponent<ForegroundCfg> {
38
40
 
39
41
  protected renderInner(group: IGroup) {
40
42
  const { x, height, width, foregroundStyle, barStyle } = this.cfg;
43
+ const { brushRatio } = foregroundStyle;
41
44
 
42
45
  // 上方移动区域
43
46
  this.addShape(group, {
@@ -48,7 +51,7 @@ export class Foreground extends GroupComponent<ForegroundCfg> {
48
51
  x,
49
52
  y: 0,
50
53
  width,
51
- height: (height * 2) / 5,
54
+ height: height * (1 - brushRatio),
52
55
  cursor: 'move',
53
56
  ...omit(foregroundStyle, ['stroke']),
54
57
  },
@@ -61,9 +64,9 @@ export class Foreground extends GroupComponent<ForegroundCfg> {
61
64
  type: 'rect',
62
65
  attrs: {
63
66
  x,
64
- y: (height * 2) / 5,
67
+ y: height * (1 - brushRatio),
65
68
  width,
66
- height: (height * 3) / 5,
69
+ height: height * brushRatio,
67
70
  cursor: 'crosshair',
68
71
  ...omit(foregroundStyle, ['stroke']),
69
72
  },
@@ -1,4 +1,5 @@
1
1
  import { IGroup } 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
5
  import { DEFAULT_HANDLER_HEIGHT, DEFAULT_HANDLER_WIDTH, HANDLER_STYLE } from './constant';
@@ -21,6 +22,7 @@ export interface HandlerCfg extends GroupComponentCfg {
21
22
  readonly height: number;
22
23
  // style
23
24
  readonly style?: IStyle;
25
+ readonly sliderHeight?: number;
24
26
  }
25
27
 
26
28
  export class Handler extends GroupComponent<HandlerCfg> {
@@ -37,10 +39,23 @@ export class Handler extends GroupComponent<HandlerCfg> {
37
39
  };
38
40
  }
39
41
  protected renderInner(group: IGroup) {
40
- const { width, height, style } = this.cfg as HandlerCfg;
41
- const { fill, stroke, radius, opacity, cursor } = style;
42
+ const { width, height, style, sliderHeight } = this.cfg;
43
+ const { stroke, cursor } = style;
42
44
 
43
- // 按钮框框
45
+ // 滑块柄竖线
46
+ this.addShape(group, {
47
+ type: 'line',
48
+ id: this.getElementId('background-line'),
49
+ attrs: {
50
+ x1: (1 / 2) * width,
51
+ y1: -(sliderHeight - height) / 2,
52
+ x2: (1 / 2) * width,
53
+ y2: (height + sliderHeight) / 2,
54
+ stroke,
55
+ },
56
+ });
57
+
58
+ // 滑块柄框框
44
59
  this.addShape(group, {
45
60
  type: 'rect',
46
61
  id: this.getElementId('background'),
@@ -49,10 +64,7 @@ export class Handler extends GroupComponent<HandlerCfg> {
49
64
  y: 0,
50
65
  width,
51
66
  height,
52
- fill,
53
- radius,
54
- opacity,
55
- cursor,
67
+ ...omit(style, ['stroke']),
56
68
  },
57
69
  });
58
70
 
@@ -106,6 +118,7 @@ export class Handler extends GroupComponent<HandlerCfg> {
106
118
  private bindEvents() {
107
119
  this.get('group').on('mouseenter', () => {
108
120
  const { highLightStroke } = this.get('style');
121
+ this.getElementByLocalId('background-line').attr('stroke', highLightStroke);
109
122
  this.getElementByLocalId('line-left').attr('stroke', highLightStroke);
110
123
  this.getElementByLocalId('line-right').attr('stroke', highLightStroke);
111
124
  this.draw();
@@ -113,6 +126,7 @@ export class Handler extends GroupComponent<HandlerCfg> {
113
126
 
114
127
  this.get('group').on('mouseleave', () => {
115
128
  const { stroke } = this.get('style');
129
+ this.getElementByLocalId('background-line').attr('stroke', stroke);
116
130
  this.getElementByLocalId('line-left').attr('stroke', stroke);
117
131
  this.getElementByLocalId('line-right').attr('stroke', stroke);
118
132
  this.draw();
@@ -15,12 +15,11 @@ import {
15
15
  HANDLER_STYLE,
16
16
  MAX_TEXT_WIDTH,
17
17
  SLIDER_CHANGE,
18
- TEXT_PADDING,
19
18
  TEXT_SAFE_WIDTH,
20
19
  TEXT_STYLE,
21
20
  } from './constant';
22
21
  import { createMask, getRectMaskAttrs, updateMask } from '../util/mask';
23
- import { clipTextTwoLines, getTextWidth } from '../util/util';
22
+ import { clipTextTwoLines } from '../util/util';
24
23
  import { Foreground } from './foreground';
25
24
  import { getCurrentPoint } from '../util/event';
26
25
 
@@ -277,6 +276,7 @@ export class Slider extends GroupComponent<SliderCfg> implements ISlider {
277
276
  height: handlerHeight,
278
277
  cursor: 'ew-resize',
279
278
  style: handlerStyle,
279
+ sliderHeight: height,
280
280
  });
281
281
 
282
282
  this.maxHandler = this.addComponent(group, {
@@ -289,6 +289,7 @@ export class Slider extends GroupComponent<SliderCfg> implements ISlider {
289
289
  height: handlerHeight,
290
290
  cursor: 'ew-resize',
291
291
  style: handlerStyle,
292
+ sliderHeight: height,
292
293
  });
293
294
  }
294
295
 
@@ -567,7 +568,13 @@ export class Slider extends GroupComponent<SliderCfg> implements ISlider {
567
568
  * @param range
568
569
  */
569
570
  private _dodgeText(range: [number, number], minTextShape: IShape, maxTextShape: IShape): [object, object] {
571
+ const dodgeText = get(this.cfg.textStyle, 'dodgeText', null);
572
+ if (dodgeText) {
573
+ return dodgeText(this.cfg, range, minTextShape, maxTextShape);
574
+ }
575
+
570
576
  const handlerWidth = get(this.cfg.handlerStyle, 'width', DEFAULT_HANDLER_WIDTH);
577
+ const textPadding = get(this.cfg.textStyle, 'padding');
571
578
  let [min, max] = range;
572
579
  let sorted = false;
573
580
 
@@ -586,7 +593,7 @@ export class Slider extends GroupComponent<SliderCfg> implements ISlider {
586
593
  const { attrs: maxAttrs, textWidth: maxTextWidth } = this.setTextAttrs(maxBBox, maxTextShape, [min, max], 'max');
587
594
 
588
595
  // 两端文字存在安全间距为4px, 如果小于该距离则两端均不显示文字
589
- const gap = this.cfg.width - handlerWidth * 2 - TEXT_PADDING * 2 - minTextWidth - maxTextWidth;
596
+ const gap = this.cfg.width - handlerWidth * 2 - textPadding * 2 - minTextWidth - maxTextWidth;
590
597
  if (gap <= TEXT_SAFE_WIDTH) {
591
598
  // text: '' 不显示文字
592
599
  const newMinAttrs = { ...minAttrs, text: '' };
@@ -598,7 +605,7 @@ export class Slider extends GroupComponent<SliderCfg> implements ISlider {
598
605
  // 检测中间宽度是否能展示当前不滑动文字的文本,如果距离不够,则隐藏不滑动一侧的文字。
599
606
  if (minAttrs.textAlign === 'left' || maxAttrs.textAlign === 'right') {
600
607
  const foregroundWidth = this.foreground?.get('width');
601
- const gap = foregroundWidth - handlerWidth - TEXT_PADDING * 2;
608
+ const gap = foregroundWidth - handlerWidth - textPadding * 2;
602
609
  if (minAttrs.textAlign === 'left') {
603
610
  if (gap <= minTextWidth) {
604
611
  return !sorted ? [{ ...minAttrs, text: '' }, { ...maxAttrs }] : [{ ...maxAttrs }, { ...minAttrs, text: '' }];
@@ -632,7 +639,8 @@ export class Slider extends GroupComponent<SliderCfg> implements ISlider {
632
639
  textWidth: number;
633
640
  } {
634
641
  const handlerWidth = get(this.cfg.handlerStyle, 'width', DEFAULT_HANDLER_WIDTH);
635
- const gapWidth = handlerWidth / 2 + TEXT_PADDING;
642
+ const textPadding = get(this.cfg.textStyle, 'padding');
643
+ const gapWidth = handlerWidth / 2 + textPadding;
636
644
  const [min, max] = range;
637
645
  const { width } = bbox;
638
646
  const text = textShape.attr('text');
package/src/types.ts CHANGED
@@ -811,7 +811,7 @@ export interface LegendItemNameCfg {
811
811
  style?: ShapeAttrs | ShapeAttrsCallback;
812
812
  }
813
813
 
814
- type formatterCallback = (text: string, item: ListItem, index: number) => any;
814
+ type formatterCallback = (text: string, item: ListItem, index: number, items?: ListItem[]) => any;
815
815
 
816
816
  export interface LegendItemValueCfg {
817
817
  /**