|
| 1 | + |
1 | 2 |
|
2 | | -# React Waterfall Chart |
| 3 | + |
| 4 | + |
| 5 | +# React Waterfall Chart |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | +<a href="https://www.npmjs.com/package/react-waterfall-chart"><img src="https://badgen.net/npm/v/react-waterfall-chart?color=blue" alt="npm version"></a> <a href="https://www.npmjs.com/package/react-waterfall-chart" ><img src="https://img.shields.io/npm/dw/react-waterfall-chart?label=Downloads" /></a> <a href="https://github.com/KeyValueSoftwareSystems/react-waterfall-chart"><img src="https://github.com/KeyValueSoftwareSystems/react-waterfall-chart/actions/workflows/deploy.yml/badge.svg" alt="" /></a> |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | +<div align="center"> |
| 14 | +<img src="src/assets/waterfall-chart-example.png" alt="" width="735" height="401"/> |
| 15 | +</div> |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | +>A customizable & responsive Waterfall chart for react project |
| 20 | +
|
| 21 | + |
| 22 | + |
| 23 | +Try tweaking a waterfall chart using this codesandbox link <a href="https://codesandbox.io/s/waterfall-chart-example-uvr8jd">here</a> |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | +## Installation |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | +The easiest way to use react-waterfall-chart is to install it from npm and build it into your app with Webpack. |
| 32 | + |
| 33 | + |
| 34 | + |
| 35 | +```bash |
| 36 | + |
| 37 | +npm install @keyvaluesystems/react-waterfall-chart |
| 38 | + |
| 39 | +``` |
| 40 | + |
| 41 | +You’ll need to install React separately since it isn't included in the package. |
| 42 | + |
| 43 | +## Usage |
| 44 | + |
| 45 | +React Waterfall chart can run in a very basic mode by just providing the `transactions` like given below: |
| 46 | + |
| 47 | + |
| 48 | + |
| 49 | +```jsx |
| 50 | + |
| 51 | +import WaterfallChart from '@keyvaluesystems/react-waterfall-chart'; |
| 52 | + |
| 53 | +<WaterfallChart |
| 54 | + transactions={transactionList} |
| 55 | +/> |
| 56 | + |
| 57 | +``` |
| 58 | + |
| 59 | + |
| 60 | + |
| 61 | +The transactions prop is an array of transactions with the following keys: |
| 62 | + |
| 63 | + |
| 64 | + |
| 65 | +- `label` - a string to represent each transaction |
| 66 | + |
| 67 | +- `value` - a number that specifies the transaction quantity |
| 68 | + |
| 69 | +- `color` - the color preference for each transaction. (optional) |
| 70 | + |
| 71 | +An example for transactions array is shown below: |
| 72 | + |
| 73 | + |
| 74 | + |
| 75 | +```jsx |
| 76 | +const transactionsList = [ |
| 77 | + { |
| 78 | + label: 'Quarter 1, 2020', |
| 79 | + value: 1000, |
| 80 | + color: 'red' |
| 81 | + }, |
| 82 | + { |
| 83 | + label: 'Quarter 2, 2020', |
| 84 | + value: -500 |
| 85 | + } |
| 86 | +] |
| 87 | +``` |
| 88 | + |
| 89 | +You can use `barWidth` prop to specify the width of each bar present in the chart. The given value will be converted to pixels (px) and applied to the chart. |
| 90 | +With the help of `showBridgeLines` prop, the line connecting the adjacent bars can be shown/hidden. |
| 91 | +`showFinalSummary` can be used to display the summary as the last transaction. |
| 92 | + |
| 93 | +```jsx |
| 94 | +<WaterfallChart |
| 95 | + transactions={transactionsList} |
| 96 | + barWidth={100} |
| 97 | + showBridgeLines={true} |
| 98 | + showFinalSummary={false} |
| 99 | +/> |
| 100 | +``` |
| 101 | + |
| 102 | + |
| 103 | + |
| 104 | +You can specify whether to show or hide the scale lines in the Y axis with the help of `showYAxisScaleLines` prop. |
| 105 | + |
| 106 | +```jsx |
| 107 | +<WaterfallChart |
| 108 | + transactions={transactionsList} |
| 109 | + showYAxisScaleLines={true} |
| 110 | +/> |
| 111 | +``` |
| 112 | +## Props |
| 113 | + |
| 114 | + Props that can be passed to the component are listed below: |
| 115 | + |
| 116 | +<table> |
| 117 | +<thead> |
| 118 | +<tr> |
| 119 | +<th>Prop</th> |
| 120 | +<th>Description</th> |
| 121 | +<th>Default</th> |
| 122 | +</tr> |
| 123 | +</thead> |
| 124 | +<tbody> |
| 125 | +<tr> |
| 126 | +<td><code><b>transactions:</b> object[]</code></td> |
| 127 | +<td> |
| 128 | +An array of transaction objects to specifying the value, label and color preference |
| 129 | +</td> |
| 130 | +<td><code>[]</code></td> |
| 131 | +</tr> |
| 132 | +<tr> |
| 133 | +<td><code><b>barWidth?:</b> number</code></td> |
| 134 | +<td> |
| 135 | +A number to specify the width of each bars shown in the chart |
| 136 | +</td> |
| 137 | +<td><code>true</code></td> |
| 138 | +</tr> |
| 139 | +<tr> |
| 140 | +<td><code><b>showBridgeLines?:</b> number</code></td> |
| 141 | +<td> |
| 142 | +A boolean value to specify whether to show the connecting line between adjacent bars |
| 143 | +</td> |
| 144 | +<td><code>true</code></td> |
| 145 | +</tr> |
| 146 | +<tr> |
| 147 | +<td><code><b>showYAxisScaleLines?:</b> boolean</code></td> |
| 148 | +<td> |
| 149 | +The boolean value to control the display of scale lines in y axis |
| 150 | +</td> |
| 151 | +<td><code>true</code></td> |
| 152 | +</tr> |
| 153 | +<tr> |
| 154 | +<td><code><b>yAxisPixelsPerUnit?:</b> number</code></td> |
| 155 | +<td> |
| 156 | +The distance between each y axis scale unit. The value specified will be applied as pixels. |
| 157 | +</td> |
| 158 | +<td><code>0</code></td> |
| 159 | +</tr> |
| 160 | +<tr> |
| 161 | +<td><code><b>showFinalSummary?:</b> boolean</code></td> |
| 162 | +<td> |
| 163 | +The boolean value to control the display of summary section. The summary will be displayed as the last transaction |
| 164 | +</td> |
| 165 | +<td><code>true</code></td> |
| 166 | +</tr> |
| 167 | +<tr> |
| 168 | +<td><code><b>summaryXLabel?:</b> string</code></td> |
| 169 | +<td> |
| 170 | +The x axis label to be shown for the summary section. |
| 171 | +</td> |
| 172 | +<td><code>Summary</code></td> |
| 173 | +</tr> |
| 174 | +<tr> |
| 175 | +<td><code><b>onChartClick?:</b> function</code></td> |
| 176 | +<td> |
| 177 | +The callback function which will be triggered on clicking the bars in the waterfall chart. The current bar element will be passed as the prop in the function |
| 178 | +</td> |
| 179 | +<td><code>undefined</code></td> |
| 180 | +</tr> |
| 181 | +<tr> |
| 182 | +<td><code><b>styles?:</b> object</code></td> |
| 183 | +<td> |
| 184 | +Provides you with a bunch of callback functions to override the default styles. |
| 185 | +</td> |
| 186 | +<td><code>undefined</code></td> |
| 187 | +</tr> |
| 188 | +</tbody> |
| 189 | +</table> |
| 190 | + |
| 191 | + |
| 192 | +## Style Customizations |
| 193 | + |
| 194 | + |
| 195 | +All the default styles provided by this package are overridable using the `style` prop. |
| 196 | +the below code shows all the overridable styles: |
| 197 | + |
| 198 | +```jsx |
| 199 | +<WaterfallChart |
| 200 | + transactions={transactionsList} |
| 201 | + showYAxisScaleLines={true} |
| 202 | + styles={{ |
| 203 | + summaryBar: CSSProperties, |
| 204 | + positiveBar: CSSProperties, |
| 205 | + negativeBar: CSSProperties |
| 206 | + }} |
| 207 | +/> |
| 208 | +``` |
| 209 | +- `summaryBar` - overrides the summary bar styles |
| 210 | +- `positiveBar` - overrides the positive value bar styles |
| 211 | +- `negativeBar` - overrides the negative value bar styles |
0 commit comments