ngx-mira-charts 0.1.0 → 0.2.0-dev.2

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 CHANGED
@@ -1,31 +1,41 @@
1
1
  # ngx-mira-charts
2
2
 
3
- Composable SVG charts for Angular, built on signals.
3
+ [![npm version](https://img.shields.io/npm/v/ngx-mira-charts.svg)](https://www.npmjs.com/package/ngx-mira-charts) [![license](https://img.shields.io/npm/l/ngx-mira-charts.svg)](https://github.com/dhutaryan/ngx-mira-charts/blob/main/LICENSE) [![docs](https://img.shields.io/badge/docs-ngx--mira--charts-blue)](https://dhutaryan.github.io/ngx-mira-charts/)
4
4
 
5
- A chart is made of parts, put together in the template: the grid, the axes, the cursor and each series, a line or a set of bars, are components written inside the chart. Use the ones you need and leave out the rest. Each takes its settings as inputs, like any other component, so there's no options object to fill in.
5
+ Composable SVG charts for Angular, built on signals. A chart is put together in your template, from parts: the axes, the grid, the cursor, the tooltip, the legend, and a `<mira-line>` or a `<mira-bar>` for each series. Each part takes its settings as inputs, so there's no options object to fill in.
6
6
 
7
7
  > Early days: the versions are 0.x, and the API may change between them.
8
8
 
9
- ## What's here
9
+ ## Why this one
10
10
 
11
- - A line chart: a `<mira-line>` per key of the data, with a dot on each value, straight or along a smooth curve that never overshoots the values. A missing value breaks the line.
12
- - A bar chart: a `<mira-bar>` per key of the data, with a bar for each datum, up from zero or down below it. The bars of several keys stand side by side in each category. A missing value leaves its place empty.
13
- - Axes, a grid, and a cursor at the datum under the pointer: a vertical line, or in a bar chart a band across the category. Each `<mira-line>` marks its value there with a bigger dot.
14
- - The chart fills its container and follows its size.
15
- - Light and dark, after the page's `color-scheme`. The colors are CSS custom properties.
16
- - Signals and OnPush throughout, no zone.js needed. Nothing underneath: no d3, no chart engine.
11
+ - ðŸ§Đ **Composed in the template.** Write the parts you need and leave out the rest. A second `<mira-bar>` makes grouped bars, with nothing to set on the chart.
12
+ - 📋 **Your rows, in their own shape.** A chart takes an array of plain objects, and each series reads its values by `dataKey`. The values must be numbers: a string, even `'42'`, is left out.
13
+ - 🅰ïļ **Angular all the way down.** Standalone components with signal inputs, OnPush throughout, with zone.js or without it.
14
+ - ðŸŠķ **Small.** No d3 and no chart engine, and no runtime dependencies beyond `tslib`.
15
+
16
+ ## Features
17
+
18
+ - 📈 Line charts: straight or smooth lines, with a dot on each value
19
+ - 📊 Bar charts: one series, or several side by side
20
+ - ↕ïļ Values below zero, and gaps where a value is missing
21
+ - 🧭 Axes, a grid and a cursor at the datum under the pointer
22
+ - 💎 A tooltip with each series' value there, or a box of your own
23
+ - 🏷ïļ A legend along any edge of the chart or anywhere on the page, which can hide or show a series on a click
24
+ - 📐 A chart fills its container and follows its size, or takes a fixed width and height
25
+ - ðŸŽĻ Light and dark, with the colors as CSS custom properties
26
+ - ðŸ–Ĩïļ Server rendering, at a set size until the browser can measure the chart
17
27
 
18
28
  ## Not here (yet)
19
29
 
20
- Area and pie charts, stacked and horizontal bars, a tooltip, a legend, default series colors, animations and keyboard access. The plan is in the [issues](https://github.com/dhutaryan/ngx-mira-charts/issues).
30
+ Area and pie charts, stacked and horizontal bars, a palette of series colors, animations and keyboard access to the data. The plan is in the [issues](https://github.com/dhutaryan/ngx-mira-charts/issues).
21
31
 
22
32
  ## Installation
23
33
 
24
- ```sh
34
+ ```bash
25
35
  npm install ngx-mira-charts
26
36
  ```
27
37
 
28
- It needs Angular 20.2 or a later 20.x.
38
+ Requires **Angular 20.2** or a later 20.x (peer dependencies `@angular/core` and `@angular/common`).
29
39
 
30
40
  ## Quick start
31
41
 
@@ -36,12 +46,13 @@ import {
36
46
  MiraCursor,
37
47
  MiraLine,
38
48
  MiraLineChart,
49
+ MiraTooltip,
39
50
  MiraXAxis,
40
51
  MiraYAxis,
41
52
  } from 'ngx-mira-charts'
42
53
 
43
54
  @Component({
44
- selector: 'app-visits',
55
+ selector: 'app-solar-chart',
45
56
  imports: [
46
57
  MiraLineChart,
47
58
  MiraCartesianGrid,
@@ -49,70 +60,56 @@ import {
49
60
  MiraXAxis,
50
61
  MiraYAxis,
51
62
  MiraLine,
63
+ MiraTooltip,
52
64
  ],
53
65
  template: `
54
- <mira-line-chart [data]="visits">
66
+ <mira-line-chart [data]="day" ariaLabel="Solar output and usage, kW">
55
67
  <mira-cartesian-grid strokeDasharray="3 3" />
56
68
  <mira-cursor />
57
- <mira-x-axis dataKey="month" />
69
+ <mira-x-axis dataKey="hour" />
58
70
  <mira-y-axis />
59
- <mira-line dataKey="views" stroke="#8884d8" />
60
- <mira-line dataKey="visitors" stroke="#82ca9d" curve="monotone" />
71
+ <mira-line
72
+ dataKey="solar"
73
+ name="Solar"
74
+ stroke="#d97706"
75
+ curve="monotone"
76
+ />
77
+ <mira-line dataKey="usage" name="Usage" stroke="#3b82f6" />
78
+ <mira-tooltip />
61
79
  </mira-line-chart>
62
80
  `,
63
81
  })
64
- export class Visits {
65
- protected readonly visits = [
66
- { month: 'Jan', views: 4000, visitors: 2400 },
67
- { month: 'Feb', views: 3000, visitors: 1398 },
68
- { month: 'Mar', views: 2000, visitors: 980 },
82
+ export class SolarChart {
83
+ // What a home's solar panels make and what the home uses, in kW.
84
+ protected readonly day = [
85
+ { hour: '08:00', solar: 1.6, usage: 1.4 },
86
+ { hour: '10:00', solar: 3.2, usage: 0.8 },
87
+ { hour: '12:00', solar: 4.1, usage: 1.1 },
88
+ { hour: '14:00', solar: 3.6, usage: 0.9 },
89
+ { hour: '16:00', solar: 2.1, usage: 1.2 },
90
+ { hour: '18:00', solar: 0.6, usage: 2.3 },
69
91
  ]
70
92
  }
71
93
  ```
72
94
 
73
- What's inside the chart is drawn in the order it's written, so the first line ends up at the bottom.
74
-
75
- A bar chart takes the same parts, with a `<mira-bar>` for each key (import `MiraBarChart` and `MiraBar`):
95
+ Parts are drawn in the order they're written, so the grid goes first and the lines over it; the tooltip is laid over the svg, wherever it's written. For a bar chart, write `<mira-bar-chart>` instead, and a `<mira-bar>` for each series, with its color as `fill` (import `MiraBarChart` and `MiraBar`):
76
96
 
77
97
  ```html
78
- <mira-bar-chart [data]="visits">
98
+ <mira-bar-chart [data]="day" ariaLabel="Solar output and usage, kW">
79
99
  <mira-cartesian-grid strokeDasharray="3 3" />
80
100
  <mira-cursor />
81
- <mira-x-axis dataKey="month" />
101
+ <mira-x-axis dataKey="hour" />
82
102
  <mira-y-axis />
83
- <mira-bar dataKey="views" fill="#8884d8" />
84
- <mira-bar dataKey="visitors" fill="#82ca9d" />
103
+ <mira-bar dataKey="solar" name="Solar" fill="#d97706" />
104
+ <mira-bar dataKey="usage" name="Usage" fill="#3b82f6" />
105
+ <mira-tooltip />
85
106
  </mira-bar-chart>
86
107
  ```
87
108
 
88
- Each `<mira-bar>` draws a bar for every datum: here, two bars a month, side by side in the order they're written, views then visitors.
89
-
90
- ## Components
91
-
92
- | Component | Inputs |
93
- | --- | --- |
94
- | `<mira-line-chart>` | `data`, `width`, `height`, `margin`, `ariaLabel` |
95
- | `<mira-bar-chart>` | `data`, `width`, `height`, `margin`, `ariaLabel` |
96
- | `<mira-x-axis>` | `dataKey`, `height` |
97
- | `<mira-y-axis>` | `width`, `tickCount` |
98
- | `<mira-cartesian-grid>` | `horizontal`, `vertical`, `strokeDasharray` |
99
- | `<mira-cursor>` | — |
100
- | `<mira-line>` | `dataKey`, `stroke`, `curve` (`'linear'` or `'monotone'`), `dot`, `activeDot` |
101
- | `<mira-bar>` | `dataKey`, `fill` |
102
-
103
- Without `width` and `height`, the chart takes its container's size, with a height of 300px in a container that has none.
104
-
105
- ## Theming
106
-
107
- Set these CSS custom properties anywhere above the chart:
108
-
109
- - `--mira-axis-color`: the axes' lines and labels;
110
- - `--mira-grid-color`: the grid;
111
- - `--mira-cursor-color`: the cursor, a line or, in a bar chart, a band in this color at 25% opacity;
112
- - `--mira-background`: what's behind the chart, for the ring around the dot under the pointer. The page's by default: set it where the chart sits on a card of another color.
109
+ ## Documentation
113
110
 
114
- Unset, they follow the page's `color-scheme`: light by default, dark under `color-scheme: dark`, and the system's under `light dark`. A line's own color is its `stroke`, and a bar's its `fill`.
111
+ 📖 **[Read the docs](https://dhutaryan.github.io/ngx-mira-charts/)**: guides, live demos and the API reference.
115
112
 
116
113
  ## License
117
114
 
118
- MIT
115
+ [MIT](https://github.com/dhutaryan/ngx-mira-charts/blob/main/LICENSE)