frappe-charts 2.0.0-rc9 → 2.1.0
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.
- package/README.md +78 -138
- package/dist/frappe-charts.cjs.js +1 -1
- package/dist/frappe-charts.cjs.js.map +1 -1
- package/dist/frappe-charts.esm.js +1 -1
- package/dist/frappe-charts.esm.js.map +1 -1
- package/dist/frappe-charts.min.css +197 -99
- package/dist/frappe-charts.umd.js +1 -1
- package/dist/frappe-charts.umd.js.map +1 -1
- package/package.json +33 -5
- package/src/css/charts.scss +115 -27
- package/src/js/chart.js +6 -1
- package/src/js/charts/AggregationChart.js +47 -3
- package/src/js/charts/AxisChart.js +235 -73
- package/src/js/charts/BaseChart.js +51 -24
- package/src/js/charts/DonutChart.js +280 -12
- package/src/js/charts/Heatmap.js +28 -20
- package/src/js/charts/HorizontalBarChart.js +318 -0
- package/src/js/charts/PercentageChart.js +7 -3
- package/src/js/charts/PieChart.js +30 -7
- package/src/js/index.js +1 -1
- package/src/js/objects/ChartComponents.js +90 -28
- package/src/js/objects/SvgTip.js +28 -6
- package/src/js/utils/animate.js +20 -23
- package/src/js/utils/axis-chart-utils.js +19 -9
- package/src/js/utils/colors.js +2 -1
- package/src/js/utils/constants.js +26 -1
- package/src/js/utils/date-utils.js +18 -6
- package/src/js/utils/dom.js +10 -2
- package/src/js/utils/draw-utils.js +30 -1
- package/src/js/utils/draw.js +198 -95
- package/src/js/utils/export.js +8 -1
- package/src/js/utils/helpers.js +55 -0
- package/src/js/utils/intervals.js +32 -41
package/README.md
CHANGED
|
@@ -1,155 +1,95 @@
|
|
|
1
|
-
<div align="center">
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
<div align="center" markdown="1">
|
|
2
|
+
|
|
3
|
+
<img width="80" alt="Frappe Charts logo" src="https://github.com/user-attachments/assets/37b7ffaf-8354-48f2-8b9c-fa04fae0135b">
|
|
4
|
+
|
|
5
|
+
<h1>Frappe Charts</h1>
|
|
6
|
+
|
|
7
|
+
**Simple, modern SVG charts for the web, with zero dependencies**
|
|
8
|
+
|
|
9
|
+
[](https://github.com/frappe/charts/actions/workflows/publish.yml)
|
|
10
|
+
[](https://www.npmjs.com/package/frappe-charts)
|
|
11
|
+
|
|
12
|
+
[Live demos](https://frappe.io/charts)
|
|
13
|
+
|
|
14
|
+
<img alt="Frappe Charts: mixed axis, line with a today marker, horizontal bar and donut charts" src=".github/charts.png">
|
|
15
|
+
|
|
15
16
|
</div>
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
<a href="https://travis-ci.org/frappe/charts">
|
|
19
|
-
<img src="https://img.shields.io/travis/frappe/charts.svg?style=flat-square">
|
|
20
|
-
</a>
|
|
21
|
-
<a href="http://github.com/frappe/charts/tree/master/dist/js/frappe-charts.min.iife.js">
|
|
22
|
-
<img src="http://img.badgesize.io/frappe/charts/master/dist/frappe-charts.min.iife.js.svg?compression=gzip">
|
|
23
|
-
</a>
|
|
24
|
-
</p>
|
|
25
|
-
|
|
26
|
-
<p align="center">
|
|
27
|
-
<a href="https://frappe.github.io/charts">
|
|
28
|
-
<img src=".github/example.gif">
|
|
29
|
-
</a>
|
|
30
|
-
</p>
|
|
31
|
-
|
|
32
|
-
### Contents
|
|
33
|
-
* [Installation](#installation)
|
|
34
|
-
* [Usage](#usage)
|
|
35
|
-
* [Contribute](https://frappe.io/charts/docs/contributing)
|
|
36
|
-
* [Updates](#updates)
|
|
37
|
-
* [License](#license)
|
|
38
|
-
|
|
39
|
-
#### Installation
|
|
40
|
-
* Install via [`npm`](https://www.npmjs.com/get-npm):
|
|
41
|
-
|
|
42
|
-
```sh
|
|
43
|
-
$ npm install frappe-charts
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
and include in your project:
|
|
47
|
-
```js
|
|
48
|
-
import { Chart } from "frappe-charts"
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
...or include following for es-modules(eg:vuejs):
|
|
52
|
-
```js
|
|
53
|
-
import { Chart } from 'frappe-charts/dist/frappe-charts.esm.js'
|
|
54
|
-
// import css
|
|
55
|
-
import 'frappe-charts/dist/frappe-charts.min.css'
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
* ...or include within your HTML
|
|
59
|
-
|
|
60
|
-
```html
|
|
61
|
-
<script src="https://cdn.jsdelivr.net/npm/frappe-charts@1.1.0/dist/frappe-charts.min.iife.js"></script>
|
|
62
|
-
<!-- or -->
|
|
63
|
-
<script src="https://unpkg.com/frappe-charts@1.1.0/dist/frappe-charts.min.iife.js"></script>
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
#### Usage
|
|
67
|
-
```js
|
|
68
|
-
const data = {
|
|
69
|
-
labels: ["12am-3am", "3am-6pm", "6am-9am", "9am-12am",
|
|
70
|
-
"12pm-3pm", "3pm-6pm", "6pm-9pm", "9am-12am"
|
|
71
|
-
],
|
|
72
|
-
datasets: [
|
|
73
|
-
{
|
|
74
|
-
name: "Some Data", type: "bar",
|
|
75
|
-
values: [25, 40, 30, 35, 8, 52, 17, -4]
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
name: "Another Set", type: "line",
|
|
79
|
-
values: [25, 50, -10, 15, 18, 32, 27, 14]
|
|
80
|
-
}
|
|
81
|
-
]
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const chart = new frappe.Chart("#chart", { // or a DOM element,
|
|
85
|
-
// new Chart() in case of ES6 module with above usage
|
|
86
|
-
title: "My Awesome Chart",
|
|
87
|
-
data: data,
|
|
88
|
-
type: 'axis-mixed', // or 'bar', 'line', 'scatter', 'pie', 'percentage'
|
|
89
|
-
height: 250,
|
|
90
|
-
colors: ['#7cd6fd', '#743ee2']
|
|
91
|
-
})
|
|
92
|
-
```
|
|
18
|
+
## Frappe Charts
|
|
93
19
|
|
|
94
|
-
|
|
95
|
-
```diff
|
|
96
|
-
- const chart = new frappe.Chart("#chart", {
|
|
97
|
-
+ const chart = new Chart("#chart", { // or a DOM element,
|
|
98
|
-
// new Chart() in case of ES6 module with above usage
|
|
99
|
-
title: "My Awesome Chart",
|
|
100
|
-
data: data,
|
|
101
|
-
type: 'axis-mixed', // or 'bar', 'line', 'scatter', 'pie', 'percentage'
|
|
102
|
-
height: 250,
|
|
103
|
-
colors: ['#7cd6fd', '#743ee2']
|
|
104
|
-
})
|
|
105
|
-
```
|
|
20
|
+
Frappe Charts is a small charting library with a simple API. It started as the sales graph in [ERPNext](https://github.com/frappe/erpnext) and is now used for charts across the [Frappe Framework](https://github.com/frappe/frappe).
|
|
106
21
|
|
|
22
|
+
### Key Features
|
|
107
23
|
|
|
108
|
-
|
|
24
|
+
- **Chart types**: bar, horizontal bar, line, mixed axis, donut, pie, percentage and heatmap.
|
|
25
|
+
- **Axis charts**: stacked bars, rounded bars, smooth or dashed lines, gaps in lines, region fill, X and Y markers and Y regions.
|
|
26
|
+
- **Tooltips**: one tooltip per column with every series in it, with your own number format.
|
|
27
|
+
- **Donut**: a total or your own value in the center, and `onClick` for slices and legend items.
|
|
28
|
+
- **Live data**: add, remove or replace data points, and the chart animates to the new shape.
|
|
29
|
+
- **Theming**: colors and lines come from CSS variables such as `--charts-label-color`, so dark mode is a few lines of CSS.
|
|
30
|
+
- **Export**: save any chart as an SVG file.
|
|
109
31
|
|
|
110
|
-
|
|
111
|
-
2. `cd` into project directory
|
|
112
|
-
3. `npm install`
|
|
113
|
-
4. `npm run dev`
|
|
32
|
+
## Usage
|
|
114
33
|
|
|
115
|
-
|
|
34
|
+
```bash
|
|
35
|
+
npm install frappe-charts
|
|
36
|
+
```
|
|
116
37
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
- Value over data points
|
|
122
|
-
- Y Markers and regions
|
|
123
|
-
- Dot size, Bar space size, and other options
|
|
124
|
-
- Legend for axis charts
|
|
125
|
-
- We would be looking to incorporate existing PRs and issues in the meantime.
|
|
38
|
+
```js
|
|
39
|
+
import { Chart } from 'frappe-charts';
|
|
40
|
+
import 'frappe-charts/dist/frappe-charts.min.css';
|
|
41
|
+
```
|
|
126
42
|
|
|
127
|
-
|
|
43
|
+
Or load it in the browser:
|
|
128
44
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
45
|
+
```html
|
|
46
|
+
<link rel="stylesheet" href="https://unpkg.com/frappe-charts/dist/frappe-charts.min.css">
|
|
47
|
+
<script src="https://unpkg.com/frappe-charts/dist/frappe-charts.umd.js"></script>
|
|
48
|
+
<!-- the browser build exposes window['frappe-charts'].Chart -->
|
|
49
|
+
```
|
|
132
50
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
-
|
|
51
|
+
```js
|
|
52
|
+
const chart = new Chart('#chart', {
|
|
53
|
+
title: 'Sales by channel',
|
|
54
|
+
type: 'axis-mixed', // or 'bar', 'line', 'donut', 'pie', 'percentage', 'heatmap'
|
|
55
|
+
height: 250,
|
|
56
|
+
colors: ['#318ad8', '#30a66d'],
|
|
57
|
+
data: {
|
|
58
|
+
labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'],
|
|
59
|
+
datasets: [
|
|
60
|
+
{ name: 'Online', chartType: 'bar', values: [42, 48, 39, 55, 61, 58] },
|
|
61
|
+
{ name: 'Target', chartType: 'line', values: [60, 62, 64, 68, 72, 76] }
|
|
62
|
+
],
|
|
63
|
+
yMarkers: [{ label: 'Goal', value: 70 }]
|
|
64
|
+
}
|
|
65
|
+
});
|
|
137
66
|
|
|
138
|
-
|
|
139
|
-
|
|
67
|
+
chart.addDataPoint('Jul', [66, 80]);
|
|
68
|
+
chart.export();
|
|
69
|
+
```
|
|
140
70
|
|
|
141
|
-
|
|
142
|
-
- We have an animated [Pie Chart](https://github.com/frappe/charts/issues/29)! Thanks [@sheweichun](https://github.com/sheweichun).
|
|
143
|
-
- [@tobiaslins](https://github.com/tobiaslins) contributed tweaks for his quest to make these easy to use with React. Check out his [repo](https://github.com/tobiaslins/frappe-charts-react-example) and updates at [#24](https://github.com/frappe/charts/issues/24) to learn more :)
|
|
144
|
-
- A new logo.
|
|
71
|
+
For a horizontal bar chart, use `type: 'bar'` with `barOptions: { horizontal: 1 }`.
|
|
145
72
|
|
|
146
|
-
|
|
147
|
-
- The very first version out, with animatable bars and lines, a percentage chart and a heatmap. GitHub-style.
|
|
73
|
+
## Development Setup
|
|
148
74
|
|
|
149
|
-
|
|
150
|
-
|
|
75
|
+
* `yarn install`
|
|
76
|
+
* `yarn watch` - Build on every change
|
|
77
|
+
* `yarn build` - Build `dist`
|
|
78
|
+
* `yarn test` - Run the Playwright tests (run `yarn playwright install chromium` once first)
|
|
79
|
+
* Commit messages follow [Conventional Commits](https://www.conventionalcommits.org). A merge to `master` runs the tests and publishes a new version to npm.
|
|
151
80
|
|
|
152
|
-
|
|
153
|
-
Project maintained by [Frappe](https://frappe.io).
|
|
154
|
-
Used in [ERPNext](https://erpnext.com). Read the [blog post](https://medium.com/@pratu16x7/so-we-decided-to-create-our-own-charts-a95cb5032c97).
|
|
81
|
+
## Links
|
|
155
82
|
|
|
83
|
+
- [Release notes](https://github.com/frappe/charts/releases), and [older updates](CHANGELOG.md)
|
|
84
|
+
- [So we decided to create our own charts](https://medium.com/@pratu16x7/so-we-decided-to-create-our-own-charts-a95cb5032c97)
|
|
85
|
+
|
|
86
|
+
<br>
|
|
87
|
+
<br>
|
|
88
|
+
<div align="center" style="padding-top: 0.75rem;">
|
|
89
|
+
<a href="https://frappe.io" target="_blank">
|
|
90
|
+
<picture>
|
|
91
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://frappe.io/files/Frappe-white.png">
|
|
92
|
+
<img src="https://frappe.io/files/Frappe-black.png" alt="Frappe Technologies" height="28"/>
|
|
93
|
+
</picture>
|
|
94
|
+
</a>
|
|
95
|
+
</div>
|