1 | ![](https://img.shields.io/badge/language-react-red.svg) ![](https://img.shields.io/badge/license-MIT-000000.svg) [![NPM Package](https://img.shields.io/npm/v/bizcharts-plugin-slider.svg)](https://www.npmjs.com/package/bizcharts) [![NPM Downloads](https://img.shields.io/npm/dm/bizcharts-plugin-slider.svg)](https://npmjs.org/package/bizcharts)
|
2 |
|
3 | # bizcharts-plugin-slider
|
4 |
|
5 | A datazoom slider plugin for BizCharts base g2-plugin-slider.
|
6 |
|
7 | ## Installation
|
8 |
|
9 | Please make sure BizCharts has been already loaded.
|
10 |
|
11 | ### npm
|
12 | ```sh
|
13 | $ npm install bizcharts-plugin-slider
|
14 | ```
|
15 |
|
16 | ### html
|
17 | ```html
|
18 | <script src=https://unpkg.com/bizcharts-plugin-slider@2.0.0/umd/bizcharts-plugin-slider.js"> </script>
|
19 | ```
|
20 |
|
21 | ### dev build
|
22 | ```sh
|
23 | $ git clone https://github.com/alibaba/BizCharts.git
|
24 | $ cd BizCharts
|
25 | $ cd /plugin/slider
|
26 | $ npm install
|
27 | $ npm run build
|
28 | ```
|
29 |
|
30 | ### dev demo
|
31 |
|
32 | ```sh
|
33 | slider $ sudo vi /etc/hosts
|
34 | // add 127.0.0.1 localhost
|
35 | slider $ npm run demo
|
36 | // open in browser http://localhost:3510/
|
37 | ```
|
38 |
|
39 | ## Usage
|
40 | see [demo](https://alibaba.github.io/BizCharts/demo-detail.html?code=demo/other/rain-and-flow)
|
41 |
|
42 |
|
43 | ## API Reference
|
44 |
|
45 | ### Create an instance
|
46 |
|
47 | ```jsx
|
48 | <Slider
|
49 | width={{number} | {string}}
|
50 | height={number}
|
51 | padding={{object} | {number} | {array}}
|
52 | xAxis={string}
|
53 | yAxis={string}
|
54 | start={{string} | {number}}
|
55 | end={{string} | {number}}
|
56 | data={{array} | {dataview}}
|
57 | fillerStyle={object}
|
58 | backgroundStyle={object}
|
59 | textStyle={object}
|
60 | handleStyle={object}
|
61 | backgroundChart={object}
|
62 | />
|
63 | ```
|
64 | ### Property
|
65 |
|
66 | #### 1、 `width` *number | string*
|
67 |
|
68 | Set the width of the `slider` component, the default is `auto`, indicating the width of the adaptive container.
|
69 |
|
70 | #### 2、 `height` *number*
|
71 |
|
72 | Set the height of the `slider` component, the default is 26, the unit is '`px`'.
|
73 |
|
74 | #### 3、 `padding`
|
75 |
|
76 | Sets the padding canvas's canvas's padding to align with the chart (the default chart's canvas container is padded with padding). The default is the same padding as `BizCharts` default theme, `[20, 20, 95, 80]`.
|
77 |
|
78 | #### 4、 `xAxis` *string*
|
79 |
|
80 | **Must declare** Slider is a slider component with a background graph that is used to declare the horizontal axis mapping field of the background chart, which is also the data filtering field.
|
81 |
|
82 | #### 5、 `yAxis` *string*
|
83 |
|
84 |
|
85 | **Must declare** Slider is a slider component with a background graph that is used to declare the vertical axis of the background graph.
|
86 |
|
87 | ### 6、 `data` *array | dataview*
|
88 |
|
89 | **Must declare**,data source.
|
90 |
|
91 | #### 7、 `start` *number | string*
|
92 |
|
93 |
|
94 | The value of the slider that declares the position of the slider at the beginning of the corresponding data value, the default is the minimum value.
|
95 |
|
96 | #### 8、 `end` *number | string*
|
97 |
|
98 | The data value corresponding to the position where the slider finishes the slider is declared, and the default is the maximum value.
|
99 |
|
100 | #### 9、 `scales` *object*
|
101 |
|
102 | Used to define the columns for the `xAxis` and `yAxis` fields for the same column definitions in the action's chart.
|
103 |
|
104 | Sample code:
|
105 |
|
106 | ```jsx
|
107 | <Slider
|
108 | scales={{
|
109 | [`${xAxis}`]: {
|
110 | type: 'time',
|
111 | mask: 'MM-DD'
|
112 | }
|
113 | }}
|
114 | />
|
115 | ```
|
116 |
|
117 | #### 10、 `fillerStyle` *object*
|
118 |
|
119 | The selected area of the style configuration, the default configuration is as follows:
|
120 |
|
121 | ```jsx
|
122 | <Slider
|
123 | fillerStyle={{
|
124 | fill: '#BDCCED',
|
125 | fillOpacity: 0.3
|
126 | }}
|
127 | />
|
128 | ```
|
129 |
|
130 | Red box in the picture selected area: <img src="https://gw.alipayobjects.com/zos/rmsportal/iYFxRgDjRSiCyVPFozik.png" style="width: 59%;">
|
131 |
|
132 | #### 11、 `backgroundStyle` *object*
|
133 |
|
134 | slider background style.
|
135 |
|
136 | #### 12、 `textStyle` *object*
|
137 |
|
138 | slider auxiliary text font style configuration.
|
139 |
|
140 | #### 13、 `handleStyle` *object*
|
141 |
|
142 | The slider style configuration, configurable properties are as follows:
|
143 |
|
144 | ```jsx
|
145 | <Slider
|
146 | handleStyle={{
|
147 | img: 'https://gw.alipayobjects.com/zos/rmsportal/QXtfhORGlDuRvLXFzpsQ.png', // Can make the picture address can also be data urls
|
148 | width: 5,
|
149 | height: 26
|
150 | }}
|
151 | />
|
152 | ```
|
153 |
|
154 | #### 14、 `backgroundChart` *object*
|
155 | The slider's background chart configuration allows you to configure its chart type and color:
|
156 |
|
157 | ```jsx
|
158 | <Slider
|
159 | backgroundChart={{
|
160 | type: [ 'area' ], // The type of chart, either a string or an array
|
161 | color: '#CCD6EC'
|
162 | }}
|
163 | />
|
164 | ```
|
165 |
|
166 | #### 15、 `onChange` *function*
|
167 |
|
168 | When the slider slider changes, trigger the callback function, mainly used to update the state of `ds`. The callback function provides a parameter, which is an object that contains the following properties:
|
169 |
|
170 | ```jsx
|
171 | <Slider
|
172 | onChange = {(obj) => {
|
173 | const { startValue, endValue, startText, endText } = obj;
|
174 | }}
|
175 | />
|
176 | ```
|
177 |
|
178 | * `startValue` The current raw data value corresponding to the start slider, if the type is` time` or `timeCat`, the value is timestamp, please note.
|
179 | * `endValue` The current corresponding raw data value of the end slider, if the type is` time` or `timeCat`, the value is timestamp, please note.
|
180 | * `startText` Start slider current display text value
|
181 | * `endText` The current display text value of the end slider
|
182 |
|
183 | > NOTE: The reason for distinguishing text from value is that users will format numbers in most cases. Therefore, when setting the state quantity and updating the state quantity, you need to ensure that the value types are the same before and after.
|
184 |
|
\ | No newline at end of file |