Skip to content

Commit aa12bfb

Browse files
committed
feat: scroll bar 样式支持可配置
1 parent 5f017cd commit aa12bfb

File tree

7 files changed

+60
-7
lines changed

7 files changed

+60
-7
lines changed

packages/f2/src/components/scrollBar/horizontal.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
import { jsx } from '@antv/f-engine';
22

33
export default (props, context) => {
4-
const { coord, range, position, layout } = props;
4+
const { coord, range, position, layout, style, background, barStyle } = props;
55
const { left, width } = coord;
66
const { top, height } = layout;
77
const [start, end] = range?.x || range?.y;
88
const barLeft = width * start;
99
const barWidth = width * (end - start);
1010
if (isNaN(barWidth)) return;
11+
1112
return (
1213
<group
1314
style={{
1415
display: 'flex',
1516
left,
1617
top: position === 'top' ? top - context.px2hd('8px') : top + height,
18+
...style,
1719
}}
1820
>
1921
<line
@@ -26,6 +28,7 @@ export default (props, context) => {
2628
stroke: 'rgba(202, 215, 239, .2)',
2729
lineCap: 'round',
2830
lineWidth: '8px',
31+
...background,
2932
}}
3033
/>
3134
<line
@@ -38,6 +41,7 @@ export default (props, context) => {
3841
stroke: 'rgba(202, 215, 239, .5)',
3942
lineCap: 'round',
4043
lineWidth: '8px',
44+
...barStyle,
4145
}}
4246
/>
4347
</group>

packages/f2/src/components/scrollBar/vertical.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { jsx } from '@antv/f-engine';
22

33
export default (props, context) => {
4-
const { coord, range, position, layout } = props;
4+
const { coord, range, position, layout, style, background, barStyle } = props;
55
const { top, height } = coord;
66
const { left, width } = layout;
77
const [start, end] = range?.y || range?.x;
@@ -15,6 +15,7 @@ export default (props, context) => {
1515
display: 'flex',
1616
top,
1717
left: position === 'left' ? left - context.px2hd('8px') : left + width,
18+
...style,
1819
}}
1920
>
2021
<line
@@ -27,6 +28,7 @@ export default (props, context) => {
2728
stroke: 'rgba(202, 215, 239, .2)',
2829
lineCap: 'round',
2930
lineWidth: '8px',
31+
...background,
3032
}}
3133
/>
3234
<line
@@ -38,6 +40,7 @@ export default (props, context) => {
3840
stroke: 'rgba(202, 215, 239, .5)',
3941
lineCap: 'round',
4042
lineWidth: '8px',
43+
...barStyle,
4144
}}
4245
/>
4346
</group>

packages/f2/src/components/scrollBar/withScrollBar.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { jsx } from '@antv/f-engine';
1+
import { jsx, ShapeProps } from '@antv/f-engine';
22
import withZoom, { ZoomProps } from '../zoom';
33
import { ChartChildProps } from '../../chart';
44

@@ -13,8 +13,22 @@ export interface ScrollBarProps extends ZoomProps {
1313
position?: 'bottom' | 'top' | 'left' | 'right';
1414
/**
1515
* 间距
16+
* @deprecated
1617
*/
1718
margin?: string;
19+
20+
/**
21+
* 滚动条父容器样式
22+
*/
23+
style?: ShapeProps;
24+
/**
25+
* 背景条样式
26+
*/
27+
background?: ShapeProps;
28+
/**
29+
* 滚动条样式
30+
*/
31+
barStyle?: ShapeProps;
1832
}
1933

2034
export default (View) => {

packages/f2/test/components/interaction/dodge-pan.test.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,22 @@ describe('dodge pan', () => {
164164
showCrosshairs
165165
crosshairsType="x"
166166
/>
167-
<ScrollBar pan pinch={false} mode="x" range={[0.5, 1]} visible />
167+
<ScrollBar
168+
pan
169+
pinch={false}
170+
mode="x"
171+
range={[0.5, 1]}
172+
visible
173+
style={{
174+
marginTop: '10px',
175+
}}
176+
background={{
177+
stroke: '#000',
178+
}}
179+
barStyle={{
180+
stroke: 'red',
181+
}}
182+
/>
168183
</Chart>
169184
</Canvas>
170185
);

site/docs/api/chart/scroll-bar.zh.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const data = [
3030

3131
### mode: string
3232

33-
滚动模式,默认为: `'x'`, 可选值: `'x' | 'y' | '['x', 'y']' `
33+
滚动模式,默认为: `'x'`, 可选值: `'x' | 'y' | '['x', 'y']'`
3434

3535
### range: [0, 1]
3636

@@ -56,9 +56,26 @@ const data = [
5656

5757
默认为 `'bottom'`, 可选值为:`'top' | 'right' | 'bottom' | 'left'`
5858

59-
### margin: number
59+
### style: ShapeProps
6060

61-
滚动条和图表内容间距,默认 `16px`
61+
滚动条和图表内容间距,比如
62+
63+
```css
64+
marign: ['10px', '20px']
65+
marignTop: '10px'
66+
```
67+
68+
### backgroud: ShapeProps
69+
70+
滚动条背景样式
71+
72+
> 类型为绘图属性:[线条属性](/zh/docs/tutorial/shape-attrs#线条属性) 线条样式
73+
74+
### barStyle: ShapeProps
75+
76+
滑块样式
77+
78+
> 类型为绘图属性:[线条属性](/zh/docs/tutorial/shape-attrs#线条属性) 线条样式
6279

6380
## demo 示例
6481

0 commit comments

Comments
 (0)