ngx-mira-charts 0.3.0-dev.1 → 0.4.0-dev.1
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 +2 -1
- package/fesm2022/ngx-mira-charts.mjs +360 -23
- package/fesm2022/ngx-mira-charts.mjs.map +1 -1
- package/index.d.ts +144 -23
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,6 +17,7 @@ Composable SVG charts for Angular, built on signals. A chart is put together in
|
|
|
17
17
|
|
|
18
18
|
- 📈 Line charts: straight or smooth lines, with a dot on each value
|
|
19
19
|
- 📊 Bar charts: one series, or several side by side
|
|
20
|
+
- ⛰️ Area charts: filled to zero, with a gradient if you like, and lines among them
|
|
20
21
|
- ↕️ Values below zero, and gaps where a value is missing
|
|
21
22
|
- 🧭 Axes, a grid and a cursor at the datum under the pointer
|
|
22
23
|
- 💬 A tooltip with each series' value there, or a box of your own
|
|
@@ -28,7 +29,7 @@ Composable SVG charts for Angular, built on signals. A chart is put together in
|
|
|
28
29
|
|
|
29
30
|
## Not here (yet)
|
|
30
31
|
|
|
31
|
-
|
|
32
|
+
Pie charts, stacked bars and stacked areas, 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).
|
|
32
33
|
|
|
33
34
|
## Installation
|
|
34
35
|
|
|
@@ -113,9 +113,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.35", ngImpo
|
|
|
113
113
|
}], propDecorators: { template: [{ type: i0.ViewChild, args: [i0.forwardRef(() => MiraLayerContent), { ...{ read: TemplateRef }, isSignal: true }] }] } });
|
|
114
114
|
|
|
115
115
|
/**
|
|
116
|
-
* A layer that plots the values under a key of the chart's data: a line
|
|
117
|
-
* bars
|
|
118
|
-
*
|
|
116
|
+
* A layer that plots the values under a key of the chart's data: a line,
|
|
117
|
+
* bars or an area. The chart fits its y axis to the values of all its series
|
|
118
|
+
* that aren't hidden, whatever kind they are.
|
|
119
119
|
*
|
|
120
120
|
* A series extends this class, and provides itself under it as well as under
|
|
121
121
|
* `MiraChartLayer`. It also implements `color`, the color it's drawn in.
|
|
@@ -143,9 +143,9 @@ class MiraSeries extends MiraChartLayer {
|
|
|
143
143
|
displayName = computed(() => this.name() ?? this.dataKey(), ...(ngDevMode ? [{ debugName: "displayName" }] : []));
|
|
144
144
|
/**
|
|
145
145
|
* The shape that marks the series in the legend: `'line'` for a line,
|
|
146
|
-
* `'square'` for bars, and `'circle'` by default. A series of your
|
|
147
|
-
* the shape that looks like what it draws by overriding the
|
|
148
|
-
* `override readonly legendIcon: LegendIcon = 'square'`.
|
|
146
|
+
* `'square'` for bars and areas, and `'circle'` by default. A series of your
|
|
147
|
+
* own picks the shape that looks like what it draws by overriding the
|
|
148
|
+
* field: `override readonly legendIcon: LegendIcon = 'square'`.
|
|
149
149
|
*/
|
|
150
150
|
legendIcon = 'circle';
|
|
151
151
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.35", ngImport: i0, type: MiraSeries, deps: null, target: i0.ɵɵFactoryTarget.Directive });
|
|
@@ -603,14 +603,16 @@ const FALLBACK_SIZE = { width: 600, height: 300 };
|
|
|
603
603
|
* What every chart with an x and a y axis has, whatever its series: data, a
|
|
604
604
|
* size, a margin, the plot area they leave, a y scale that fits the values of
|
|
605
605
|
* its visible series, a label for each datum, and the pointer and the datum
|
|
606
|
-
* under it. Nothing about a kind of chart: a line chart
|
|
607
|
-
* point per datum along x, and a bar chart with a band per
|
|
606
|
+
* under it. Nothing about a kind of chart: a line chart and an area chart
|
|
607
|
+
* extend it with a point per datum along x, and a bar chart with a band per
|
|
608
|
+
* datum.
|
|
608
609
|
*
|
|
609
610
|
* Parts of your own, a layer (`MiraChartLayer`) that draws in the svg or a
|
|
610
611
|
* component that shows something in HTML over it, inject
|
|
611
612
|
* `MiraCartesianContext`. A chart isn't provided as `MiraCartesianChart`:
|
|
612
613
|
* neither `inject()` nor a query such as `viewChild()` finds one by it, so
|
|
613
|
-
* query a chart by its own class, `MiraLineChart` or
|
|
614
|
+
* query a chart by its own class, `MiraLineChart`, `MiraAreaChart` or
|
|
615
|
+
* `MiraBarChart`.
|
|
614
616
|
*
|
|
615
617
|
* Its colors are CSS custom properties, to set anywhere above the chart:
|
|
616
618
|
*
|
|
@@ -627,7 +629,8 @@ const FALLBACK_SIZE = { width: 600, height: 300 };
|
|
|
627
629
|
*
|
|
628
630
|
* Unset, they suit the `color-scheme` the chart is in: light by default, dark
|
|
629
631
|
* under `color-scheme: dark`, and the system's under `light dark`. A line's
|
|
630
|
-
* own color is its `stroke`,
|
|
632
|
+
* own color is its `stroke`, a bar's its `fill`, and an area's its `stroke`
|
|
633
|
+
* and `fill`.
|
|
631
634
|
*/
|
|
632
635
|
class MiraCartesianChart {
|
|
633
636
|
/** The rows to plot, a `ChartDatum` each. */
|
|
@@ -637,15 +640,15 @@ class MiraCartesianChart {
|
|
|
637
640
|
* doesn't widen it: a container as wide as its content, such as an
|
|
638
641
|
* inline-block or a dialog, needs a width of its own.
|
|
639
642
|
*/
|
|
640
|
-
width = input(undefined, ...(ngDevMode ? [{ debugName: "width", transform: optionalNumber }] : [{
|
|
641
|
-
transform: optionalNumber,
|
|
643
|
+
width = input(undefined, ...(ngDevMode ? [{ debugName: "width", transform: optionalNumber$1 }] : [{
|
|
644
|
+
transform: optionalNumber$1,
|
|
642
645
|
}]));
|
|
643
646
|
/**
|
|
644
647
|
* The height in px. Without it, the chart is as tall as its container, or
|
|
645
648
|
* 300px in a container without a height.
|
|
646
649
|
*/
|
|
647
|
-
height = input(undefined, ...(ngDevMode ? [{ debugName: "height", transform: optionalNumber }] : [{
|
|
648
|
-
transform: optionalNumber,
|
|
650
|
+
height = input(undefined, ...(ngDevMode ? [{ debugName: "height", transform: optionalNumber$1 }] : [{
|
|
651
|
+
transform: optionalNumber$1,
|
|
649
652
|
}]));
|
|
650
653
|
/**
|
|
651
654
|
* Overrides some sides of the default margin: 10px, and 20px on the right.
|
|
@@ -831,7 +834,7 @@ function sameSize(a, b) {
|
|
|
831
834
|
}
|
|
832
835
|
// Takes `width="640"` as well as `[width]="640"`, and no value at all. A value
|
|
833
836
|
// that isn't a number, like `width="auto"`, counts as none.
|
|
834
|
-
function optionalNumber(value) {
|
|
837
|
+
function optionalNumber$1(value) {
|
|
835
838
|
if (value == null || value === '')
|
|
836
839
|
return undefined;
|
|
837
840
|
const number = numberAttribute(value);
|
|
@@ -1334,8 +1337,8 @@ const ROW_HEIGHT = 22;
|
|
|
1334
1337
|
/**
|
|
1335
1338
|
* Lists the chart's series along one of its edges, in the order they're
|
|
1336
1339
|
* written, each with its icon in its color and its name: a stretch of line
|
|
1337
|
-
* marks a line, a square marks bars, and a circle any other series
|
|
1338
|
-
* series' `legendIcon`). A series is called by its `name`, or its `dataKey`
|
|
1340
|
+
* marks a line, a square marks bars and areas, and a circle any other series
|
|
1341
|
+
* (the series' `legendIcon`). A series is called by its `name`, or its `dataKey`
|
|
1339
1342
|
* without one. The plot leaves room for the legend, as it does for the axes,
|
|
1340
1343
|
* and the chart stays as big as it is.
|
|
1341
1344
|
*
|
|
@@ -1639,10 +1642,11 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.35", ngImpo
|
|
|
1639
1642
|
}], propDecorators: { template: [{ type: i0.Input, args: [{ isSignal: true, alias: "miraLayerOutlet", required: false }] }] } });
|
|
1640
1643
|
|
|
1641
1644
|
/**
|
|
1642
|
-
* A chart of lines over categories, a point per datum
|
|
1643
|
-
*
|
|
1644
|
-
*
|
|
1645
|
-
*
|
|
1645
|
+
* A chart of lines over categories, a point per datum: areas go in it too, as
|
|
1646
|
+
* lines go in an area chart. What's in it comes as content, drawn in the
|
|
1647
|
+
* order it's written, so the first one ends up at the bottom. What it tells
|
|
1648
|
+
* the parts in it, `plot`, `yScale` and the rest, is described on
|
|
1649
|
+
* `MiraCartesianContext`, which parts of your own inject.
|
|
1646
1650
|
*
|
|
1647
1651
|
* @example
|
|
1648
1652
|
* ```html
|
|
@@ -1690,9 +1694,33 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.35", ngImpo
|
|
|
1690
1694
|
*/
|
|
1691
1695
|
function linePath(points, curve) {
|
|
1692
1696
|
return runsOf(points)
|
|
1693
|
-
.map((run) => (
|
|
1697
|
+
.map((run) => lineThrough(run, curve))
|
|
1698
|
+
.join('');
|
|
1699
|
+
}
|
|
1700
|
+
/**
|
|
1701
|
+
* The svg path of the area between a line through the points and a level,
|
|
1702
|
+
* `base`, a y in px within the svg as the points' are: for each stretch of
|
|
1703
|
+
* points between the nulls, the line, as `linePath` draws it, then straight
|
|
1704
|
+
* to the base under its last point, back along the base to under its first,
|
|
1705
|
+
* and closed. Where a point is null, the area breaks, as the line does.
|
|
1706
|
+
*
|
|
1707
|
+
* @internal
|
|
1708
|
+
*/
|
|
1709
|
+
function areaPath(points, base, curve) {
|
|
1710
|
+
return runsOf(points)
|
|
1711
|
+
.map((run) => {
|
|
1712
|
+
const first = run[0];
|
|
1713
|
+
const last = run[run.length - 1];
|
|
1714
|
+
return (lineThrough(run, curve) +
|
|
1715
|
+
`L${xy({ x: last.x, y: base })}` +
|
|
1716
|
+
`L${xy({ x: first.x, y: base })}Z`);
|
|
1717
|
+
})
|
|
1694
1718
|
.join('');
|
|
1695
1719
|
}
|
|
1720
|
+
// The line through one stretch of points.
|
|
1721
|
+
function lineThrough(points, curve) {
|
|
1722
|
+
return curve === 'monotone' ? monotone(points) : straight(points);
|
|
1723
|
+
}
|
|
1696
1724
|
// The stretches of points between the nulls.
|
|
1697
1725
|
function runsOf(points) {
|
|
1698
1726
|
const runs = [[]];
|
|
@@ -2074,6 +2102,315 @@ function slotOf(rank, count, bandwidth) {
|
|
|
2074
2102
|
return { offset: bandwidth * CATEGORY_GAP + rank * (width + gap), width };
|
|
2075
2103
|
}
|
|
2076
2104
|
|
|
2105
|
+
/**
|
|
2106
|
+
* A chart of areas over categories, a point per datum: a line chart by
|
|
2107
|
+
* another name, so lines go in it too, and areas go in a line chart. What's
|
|
2108
|
+
* in it comes as content, drawn in the order it's written, so the first one
|
|
2109
|
+
* ends up at the bottom: write an area before a line it shouldn't cover.
|
|
2110
|
+
* What it tells the parts in it, `plot`, `yScale` and the rest, is described
|
|
2111
|
+
* on `MiraCartesianContext`, which parts of your own inject.
|
|
2112
|
+
*
|
|
2113
|
+
* @example
|
|
2114
|
+
* ```html
|
|
2115
|
+
* <mira-area-chart [data]="day">
|
|
2116
|
+
* <mira-cartesian-grid />
|
|
2117
|
+
* <mira-x-axis dataKey="hour" />
|
|
2118
|
+
* <mira-y-axis />
|
|
2119
|
+
* <mira-area dataKey="solar" stroke="#d97706" />
|
|
2120
|
+
* <mira-line dataKey="usage" stroke="#3b82f6" />
|
|
2121
|
+
* </mira-area-chart>
|
|
2122
|
+
* ```
|
|
2123
|
+
*/
|
|
2124
|
+
class MiraAreaChart extends MiraCartesianChart {
|
|
2125
|
+
/**
|
|
2126
|
+
* A point per datum, from edge to edge of the plot, or in its middle for a
|
|
2127
|
+
* single datum.
|
|
2128
|
+
*/
|
|
2129
|
+
xPositions = computed(() => {
|
|
2130
|
+
const { left, width } = this.plot();
|
|
2131
|
+
return pointPositions(this.data().length, [left, left + width]);
|
|
2132
|
+
}, ...(ngDevMode ? [{ debugName: "xPositions" }] : []));
|
|
2133
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.35", ngImport: i0, type: MiraAreaChart, deps: null, target: i0.ɵɵFactoryTarget.Component });
|
|
2134
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.3.35", type: MiraAreaChart, isStandalone: true, selector: "mira-area-chart", providers: [
|
|
2135
|
+
{
|
|
2136
|
+
provide: MiraCartesianContext,
|
|
2137
|
+
useExisting: forwardRef(() => MiraAreaChart),
|
|
2138
|
+
},
|
|
2139
|
+
], usesInheritance: true, ngImport: i0, template: "\n <div class=\"mira-chart\">\n <svg\n #svg\n role=\"img\"\n [attr.width]=\"size().width\"\n [attr.height]=\"size().height\"\n [attr.viewBox]=\"viewBox()\"\n [attr.aria-label]=\"ariaLabel() ?? null\"\n >\n @for (layer of drawnLayers(); track layer) {\n <svg:g [miraLayerOutlet]=\"layer.template()\" />\n }\n </svg>\n <div class=\"mira-chart-overlay\">\n <ng-content />\n </div>\n </div>\n", isInline: true, styles: [":host{--_mira-axis-color: var(--mira-axis-color, #666);--_mira-grid-color: var(--mira-grid-color, #ccc);--_mira-background: var(--mira-background, #fff);--_mira-cursor-color: var(--mira-cursor-color, #999)}@supports (color: light-dark(#000,#fff)){:host{--_mira-axis-color: var(--mira-axis-color, light-dark(#666, #999));--_mira-grid-color: var(--mira-grid-color, light-dark(#ccc, #333));--_mira-background: var(--mira-background, Canvas);--_mira-cursor-color: var(--mira-cursor-color, light-dark(#999, #666))}}\n", ".mira-chart{display:grid;width:fit-content}.mira-chart>*{grid-area:1 / 1}svg{display:block}.mira-chart-overlay{position:relative;pointer-events:none;isolation:isolate}\n"], dependencies: [{ kind: "component", type: LayerOutlet, selector: "g[miraLayerOutlet]", inputs: ["miraLayerOutlet"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
2140
|
+
}
|
|
2141
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.35", ngImport: i0, type: MiraAreaChart, decorators: [{
|
|
2142
|
+
type: Component,
|
|
2143
|
+
args: [{ selector: 'mira-area-chart', changeDetection: ChangeDetectionStrategy.OnPush, imports: [LayerOutlet], providers: [
|
|
2144
|
+
{
|
|
2145
|
+
provide: MiraCartesianContext,
|
|
2146
|
+
useExisting: forwardRef(() => MiraAreaChart),
|
|
2147
|
+
},
|
|
2148
|
+
], template: CARTESIAN_CHART_TEMPLATE, styles: [":host{--_mira-axis-color: var(--mira-axis-color, #666);--_mira-grid-color: var(--mira-grid-color, #ccc);--_mira-background: var(--mira-background, #fff);--_mira-cursor-color: var(--mira-cursor-color, #999)}@supports (color: light-dark(#000,#fff)){:host{--_mira-axis-color: var(--mira-axis-color, light-dark(#666, #999));--_mira-grid-color: var(--mira-grid-color, light-dark(#ccc, #333));--_mira-background: var(--mira-background, Canvas);--_mira-cursor-color: var(--mira-cursor-color, light-dark(#999, #666))}}\n", ".mira-chart{display:grid;width:fit-content}.mira-chart>*{grid-area:1 / 1}svg{display:block}.mira-chart-overlay{position:relative;pointer-events:none;isolation:isolate}\n"] }]
|
|
2149
|
+
}] });
|
|
2150
|
+
|
|
2151
|
+
// A wash: the grid, and the series behind, stay in sight.
|
|
2152
|
+
const DEFAULT_FILL_OPACITY = 0.1;
|
|
2153
|
+
// A gradient fades to nothing, so it starts stronger than a wash.
|
|
2154
|
+
const DEFAULT_GRADIENT_OPACITY = 0.4;
|
|
2155
|
+
// Numbers the areas' gradients: an svg id is the page's, not its svg's, so
|
|
2156
|
+
// each gradient needs one no other has.
|
|
2157
|
+
let gradients = 0;
|
|
2158
|
+
/**
|
|
2159
|
+
* An area through the values under `dataKey`, a point per datum: a line
|
|
2160
|
+
* through them, on the same curves as `<mira-line>`, and the area between the
|
|
2161
|
+
* line and zero filled, down to zero from values above it and up from values
|
|
2162
|
+
* below it. A bigger dot, in a halo, marks the value under the pointer, and
|
|
2163
|
+
* with `dot`, a dot marks each value, as on a line. Where a datum has no
|
|
2164
|
+
* number under the key, the area breaks; a value alone between two gaps
|
|
2165
|
+
* shows only as its dot, with `dot`, and otherwise only under the pointer. It
|
|
2166
|
+
* goes in an area chart, or in a line chart, along with lines: write it
|
|
2167
|
+
* before a line it shouldn't cover.
|
|
2168
|
+
*
|
|
2169
|
+
* @example
|
|
2170
|
+
* ```html
|
|
2171
|
+
* <mira-area dataKey="solar" stroke="#d97706" />
|
|
2172
|
+
* ```
|
|
2173
|
+
*/
|
|
2174
|
+
class MiraArea extends MiraSeries {
|
|
2175
|
+
/**
|
|
2176
|
+
* The color of the area's line, through its values, of its dots, and of the
|
|
2177
|
+
* area itself unless `fill` sets another: `#3182bd` by default.
|
|
2178
|
+
*/
|
|
2179
|
+
stroke = input('#3182bd', ...(ngDevMode ? [{ debugName: "stroke" }] : []));
|
|
2180
|
+
/**
|
|
2181
|
+
* The area's color, the `stroke`'s unless set. Any svg paint goes, such as
|
|
2182
|
+
* `url(#sunset)` for a gradient or a pattern of your own, in an svg on the
|
|
2183
|
+
* page; `fillOpacity` still applies over it, so set that to 1 to keep a
|
|
2184
|
+
* gradient's own opacities.
|
|
2185
|
+
*/
|
|
2186
|
+
fill = input(...(ngDevMode ? [undefined, { debugName: "fill" }] : []));
|
|
2187
|
+
/**
|
|
2188
|
+
* How opaque the area is, from 0 to 1, where it's strongest: 0.1 by default,
|
|
2189
|
+
* a wash that keeps the grid and the series behind it in sight; with
|
|
2190
|
+
* `gradient`, 0.4 at the value farthest from zero. A value that isn't a
|
|
2191
|
+
* finite number counts as unset.
|
|
2192
|
+
*/
|
|
2193
|
+
fillOpacity = input(undefined, ...(ngDevMode ? [{ debugName: "fillOpacity", transform: optionalNumber }] : [{
|
|
2194
|
+
transform: optionalNumber,
|
|
2195
|
+
}]));
|
|
2196
|
+
/**
|
|
2197
|
+
* How the line goes from one value to the next, `'linear'` by default; the
|
|
2198
|
+
* area follows it.
|
|
2199
|
+
*/
|
|
2200
|
+
curve = input('linear', ...(ngDevMode ? [{ debugName: "curve" }] : []));
|
|
2201
|
+
/**
|
|
2202
|
+
* Whether to mark each value with a dot. Off by default: the area shows the
|
|
2203
|
+
* values' shape, and the bigger dot the value under the pointer.
|
|
2204
|
+
*/
|
|
2205
|
+
dot = input(false, ...(ngDevMode ? [{ debugName: "dot", transform: booleanAttribute }] : [{ transform: booleanAttribute }]));
|
|
2206
|
+
/**
|
|
2207
|
+
* Whether to mark the value under the pointer with a bigger dot, in a halo.
|
|
2208
|
+
* On by default.
|
|
2209
|
+
*/
|
|
2210
|
+
activeDot = input(true, ...(ngDevMode ? [{ debugName: "activeDot", transform: booleanAttribute }] : [{ transform: booleanAttribute }]));
|
|
2211
|
+
/**
|
|
2212
|
+
* Whether the area fades out toward zero: from its value farthest from
|
|
2213
|
+
* zero, at `fillOpacity`, to nothing at zero, as fast on either side of it.
|
|
2214
|
+
* Off by default. It fades the area's color, its `fill` or its `stroke`,
|
|
2215
|
+
* which has to be a color then: for a gradient of your own, set `fill` to
|
|
2216
|
+
* it and leave this off.
|
|
2217
|
+
*/
|
|
2218
|
+
gradient = input(false, ...(ngDevMode ? [{ debugName: "gradient", transform: booleanAttribute }] : [{ transform: booleanAttribute }]));
|
|
2219
|
+
/**
|
|
2220
|
+
* The color of the area's line, for the tooltip and the legend. Set it with
|
|
2221
|
+
* `stroke`.
|
|
2222
|
+
*/
|
|
2223
|
+
color = this.stroke;
|
|
2224
|
+
/** A square marks the area in the legend. */
|
|
2225
|
+
legendIcon = 'square';
|
|
2226
|
+
gradientId = `mira-area-gradient-${gradients++}`;
|
|
2227
|
+
line = computed(() => linePath(this.#points(), this.curve()), ...(ngDevMode ? [{ debugName: "line" }] : []));
|
|
2228
|
+
area = computed(() => areaPath(this.#points(), this.#zero(), this.curve()), ...(ngDevMode ? [{ debugName: "area" }] : []));
|
|
2229
|
+
fillColor = computed(() => this.fill() || this.stroke(), ...(ngDevMode ? [{ debugName: "fillColor" }] : []));
|
|
2230
|
+
// What the area is painted with: its color, or its gradient.
|
|
2231
|
+
paint = computed(() => this.gradient() ? `url(#${this.gradientId})` : this.fillColor(), ...(ngDevMode ? [{ debugName: "paint" }] : []));
|
|
2232
|
+
opacity = computed(() => this.fillOpacity() ??
|
|
2233
|
+
(this.gradient() ? DEFAULT_GRADIENT_OPACITY : DEFAULT_FILL_OPACITY), ...(ngDevMode ? [{ debugName: "opacity" }] : []));
|
|
2234
|
+
// Where the gradient runs along y: from as far above zero as the area
|
|
2235
|
+
// reaches on either side of it, to as far below. Zero is in its middle, so
|
|
2236
|
+
// the area fades as fast both ways.
|
|
2237
|
+
fade = computed(() => {
|
|
2238
|
+
const zero = this.#zero();
|
|
2239
|
+
const reach = this.#points().reduce((far, point) => point === null ? far : Math.max(far, Math.abs(point.y - zero)), 0);
|
|
2240
|
+
return { y1: zero - reach, y2: zero + reach };
|
|
2241
|
+
}, ...(ngDevMode ? [{ debugName: "fade" }] : []));
|
|
2242
|
+
// A dot per value, each with its datum's index, so its element stays with
|
|
2243
|
+
// its datum as the values around it come and go.
|
|
2244
|
+
dots = computed(() => this.#points().flatMap((point, index) => point === null ? [] : [{ ...point, index }]), ...(ngDevMode ? [{ debugName: "dots" }] : []));
|
|
2245
|
+
// The point under the pointer, if the area has a value there.
|
|
2246
|
+
activePoint = computed(() => {
|
|
2247
|
+
if (!this.activeDot())
|
|
2248
|
+
return null;
|
|
2249
|
+
const index = this.#chart.activeIndex();
|
|
2250
|
+
if (index === null)
|
|
2251
|
+
return null;
|
|
2252
|
+
return this.#points()[index] ?? null;
|
|
2253
|
+
}, ...(ngDevMode ? [{ debugName: "activePoint" }] : []));
|
|
2254
|
+
#chart = inject(MiraCartesianContext);
|
|
2255
|
+
// A point per datum, or null where the datum has no value to plot.
|
|
2256
|
+
#points = computed(() => {
|
|
2257
|
+
const key = this.dataKey();
|
|
2258
|
+
const xs = this.#chart.xPositions();
|
|
2259
|
+
const y = this.#chart.yScale();
|
|
2260
|
+
return this.#chart.data().map((datum, index) => {
|
|
2261
|
+
const value = numberAt(datum, key);
|
|
2262
|
+
return value === null ? null : { x: xs[index], y: y(value) };
|
|
2263
|
+
});
|
|
2264
|
+
}, ...(ngDevMode ? [{ debugName: "#points" }] : []));
|
|
2265
|
+
// The y of zero, which the area is filled to: the y axis always takes it in.
|
|
2266
|
+
#zero = computed(() => this.#chart.yScale()(0), ...(ngDevMode ? [{ debugName: "#zero" }] : []));
|
|
2267
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.35", ngImport: i0, type: MiraArea, deps: null, target: i0.ɵɵFactoryTarget.Component });
|
|
2268
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.3.35", type: MiraArea, isStandalone: true, selector: "mira-area", inputs: { stroke: { classPropertyName: "stroke", publicName: "stroke", isSignal: true, isRequired: false, transformFunction: null }, fill: { classPropertyName: "fill", publicName: "fill", isSignal: true, isRequired: false, transformFunction: null }, fillOpacity: { classPropertyName: "fillOpacity", publicName: "fillOpacity", isSignal: true, isRequired: false, transformFunction: null }, curve: { classPropertyName: "curve", publicName: "curve", isSignal: true, isRequired: false, transformFunction: null }, dot: { classPropertyName: "dot", publicName: "dot", isSignal: true, isRequired: false, transformFunction: null }, activeDot: { classPropertyName: "activeDot", publicName: "activeDot", isSignal: true, isRequired: false, transformFunction: null }, gradient: { classPropertyName: "gradient", publicName: "gradient", isSignal: true, isRequired: false, transformFunction: null } }, providers: [
|
|
2269
|
+
{ provide: MiraChartLayer, useExisting: forwardRef(() => MiraArea) },
|
|
2270
|
+
{ provide: MiraSeries, useExisting: forwardRef(() => MiraArea) },
|
|
2271
|
+
], usesInheritance: true, ngImport: i0, template: `
|
|
2272
|
+
<ng-template miraLayerContent>
|
|
2273
|
+
<svg:g class="mira-area">
|
|
2274
|
+
@if (gradient()) {
|
|
2275
|
+
<svg:defs>
|
|
2276
|
+
<svg:linearGradient
|
|
2277
|
+
gradientUnits="userSpaceOnUse"
|
|
2278
|
+
x1="0"
|
|
2279
|
+
x2="0"
|
|
2280
|
+
[attr.id]="gradientId"
|
|
2281
|
+
[attr.y1]="fade().y1"
|
|
2282
|
+
[attr.y2]="fade().y2"
|
|
2283
|
+
>
|
|
2284
|
+
<svg:stop offset="0" [attr.stop-color]="fillColor()" />
|
|
2285
|
+
<svg:stop
|
|
2286
|
+
offset="0.5"
|
|
2287
|
+
stop-opacity="0"
|
|
2288
|
+
[attr.stop-color]="fillColor()"
|
|
2289
|
+
/>
|
|
2290
|
+
<svg:stop offset="1" [attr.stop-color]="fillColor()" />
|
|
2291
|
+
</svg:linearGradient>
|
|
2292
|
+
</svg:defs>
|
|
2293
|
+
}
|
|
2294
|
+
<svg:path
|
|
2295
|
+
class="mira-area-fill"
|
|
2296
|
+
[attr.d]="area()"
|
|
2297
|
+
[attr.fill]="paint()"
|
|
2298
|
+
[attr.fill-opacity]="opacity()"
|
|
2299
|
+
/>
|
|
2300
|
+
<svg:path
|
|
2301
|
+
class="mira-area-curve"
|
|
2302
|
+
[attr.d]="line()"
|
|
2303
|
+
[attr.stroke]="stroke()"
|
|
2304
|
+
/>
|
|
2305
|
+
@if (dot()) {
|
|
2306
|
+
@for (point of dots(); track point.index) {
|
|
2307
|
+
<svg:circle
|
|
2308
|
+
class="mira-area-dot"
|
|
2309
|
+
r="4"
|
|
2310
|
+
[attr.cx]="point.x"
|
|
2311
|
+
[attr.cy]="point.y"
|
|
2312
|
+
[attr.fill]="stroke()"
|
|
2313
|
+
/>
|
|
2314
|
+
}
|
|
2315
|
+
}
|
|
2316
|
+
@if (activePoint(); as point) {
|
|
2317
|
+
<svg:circle
|
|
2318
|
+
class="mira-area-halo"
|
|
2319
|
+
r="10"
|
|
2320
|
+
[attr.cx]="point.x"
|
|
2321
|
+
[attr.cy]="point.y"
|
|
2322
|
+
[attr.fill]="stroke()"
|
|
2323
|
+
/>
|
|
2324
|
+
<svg:circle
|
|
2325
|
+
class="mira-area-active-dot"
|
|
2326
|
+
r="6"
|
|
2327
|
+
[attr.cx]="point.x"
|
|
2328
|
+
[attr.cy]="point.y"
|
|
2329
|
+
[attr.fill]="stroke()"
|
|
2330
|
+
/>
|
|
2331
|
+
}
|
|
2332
|
+
</svg:g>
|
|
2333
|
+
</ng-template>
|
|
2334
|
+
`, isInline: true, styles: [".mira-area-curve{fill:none;stroke-width:2}.mira-area-halo{fill-opacity:.25}.mira-area-active-dot{stroke:var(--_mira-background);stroke-width:2}\n"], dependencies: [{ kind: "directive", type: MiraLayerContent, selector: "ng-template[miraLayerContent]" }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
2335
|
+
}
|
|
2336
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.35", ngImport: i0, type: MiraArea, decorators: [{
|
|
2337
|
+
type: Component,
|
|
2338
|
+
args: [{ selector: 'mira-area', changeDetection: ChangeDetectionStrategy.OnPush, imports: [MiraLayerContent], providers: [
|
|
2339
|
+
{ provide: MiraChartLayer, useExisting: forwardRef(() => MiraArea) },
|
|
2340
|
+
{ provide: MiraSeries, useExisting: forwardRef(() => MiraArea) },
|
|
2341
|
+
], template: `
|
|
2342
|
+
<ng-template miraLayerContent>
|
|
2343
|
+
<svg:g class="mira-area">
|
|
2344
|
+
@if (gradient()) {
|
|
2345
|
+
<svg:defs>
|
|
2346
|
+
<svg:linearGradient
|
|
2347
|
+
gradientUnits="userSpaceOnUse"
|
|
2348
|
+
x1="0"
|
|
2349
|
+
x2="0"
|
|
2350
|
+
[attr.id]="gradientId"
|
|
2351
|
+
[attr.y1]="fade().y1"
|
|
2352
|
+
[attr.y2]="fade().y2"
|
|
2353
|
+
>
|
|
2354
|
+
<svg:stop offset="0" [attr.stop-color]="fillColor()" />
|
|
2355
|
+
<svg:stop
|
|
2356
|
+
offset="0.5"
|
|
2357
|
+
stop-opacity="0"
|
|
2358
|
+
[attr.stop-color]="fillColor()"
|
|
2359
|
+
/>
|
|
2360
|
+
<svg:stop offset="1" [attr.stop-color]="fillColor()" />
|
|
2361
|
+
</svg:linearGradient>
|
|
2362
|
+
</svg:defs>
|
|
2363
|
+
}
|
|
2364
|
+
<svg:path
|
|
2365
|
+
class="mira-area-fill"
|
|
2366
|
+
[attr.d]="area()"
|
|
2367
|
+
[attr.fill]="paint()"
|
|
2368
|
+
[attr.fill-opacity]="opacity()"
|
|
2369
|
+
/>
|
|
2370
|
+
<svg:path
|
|
2371
|
+
class="mira-area-curve"
|
|
2372
|
+
[attr.d]="line()"
|
|
2373
|
+
[attr.stroke]="stroke()"
|
|
2374
|
+
/>
|
|
2375
|
+
@if (dot()) {
|
|
2376
|
+
@for (point of dots(); track point.index) {
|
|
2377
|
+
<svg:circle
|
|
2378
|
+
class="mira-area-dot"
|
|
2379
|
+
r="4"
|
|
2380
|
+
[attr.cx]="point.x"
|
|
2381
|
+
[attr.cy]="point.y"
|
|
2382
|
+
[attr.fill]="stroke()"
|
|
2383
|
+
/>
|
|
2384
|
+
}
|
|
2385
|
+
}
|
|
2386
|
+
@if (activePoint(); as point) {
|
|
2387
|
+
<svg:circle
|
|
2388
|
+
class="mira-area-halo"
|
|
2389
|
+
r="10"
|
|
2390
|
+
[attr.cx]="point.x"
|
|
2391
|
+
[attr.cy]="point.y"
|
|
2392
|
+
[attr.fill]="stroke()"
|
|
2393
|
+
/>
|
|
2394
|
+
<svg:circle
|
|
2395
|
+
class="mira-area-active-dot"
|
|
2396
|
+
r="6"
|
|
2397
|
+
[attr.cx]="point.x"
|
|
2398
|
+
[attr.cy]="point.y"
|
|
2399
|
+
[attr.fill]="stroke()"
|
|
2400
|
+
/>
|
|
2401
|
+
}
|
|
2402
|
+
</svg:g>
|
|
2403
|
+
</ng-template>
|
|
2404
|
+
`, styles: [".mira-area-curve{fill:none;stroke-width:2}.mira-area-halo{fill-opacity:.25}.mira-area-active-dot{stroke:var(--_mira-background);stroke-width:2}\n"] }]
|
|
2405
|
+
}], propDecorators: { stroke: [{ type: i0.Input, args: [{ isSignal: true, alias: "stroke", required: false }] }], fill: [{ type: i0.Input, args: [{ isSignal: true, alias: "fill", required: false }] }], fillOpacity: [{ type: i0.Input, args: [{ isSignal: true, alias: "fillOpacity", required: false }] }], curve: [{ type: i0.Input, args: [{ isSignal: true, alias: "curve", required: false }] }], dot: [{ type: i0.Input, args: [{ isSignal: true, alias: "dot", required: false }] }], activeDot: [{ type: i0.Input, args: [{ isSignal: true, alias: "activeDot", required: false }] }], gradient: [{ type: i0.Input, args: [{ isSignal: true, alias: "gradient", required: false }] }] } });
|
|
2406
|
+
// Takes `fillOpacity="0.4"` as well as `[fillOpacity]="0.4"`, and no value at
|
|
2407
|
+
// all. A value that isn't a finite number, like `fillOpacity="half"`, counts
|
|
2408
|
+
// as none.
|
|
2409
|
+
function optionalNumber(value) {
|
|
2410
|
+
const number = numberAttribute(value);
|
|
2411
|
+
return Number.isFinite(number) ? number : undefined;
|
|
2412
|
+
}
|
|
2413
|
+
|
|
2077
2414
|
/*
|
|
2078
2415
|
* Public API Surface of ngx-mira-charts
|
|
2079
2416
|
*/
|
|
@@ -2082,5 +2419,5 @@ function slotOf(rank, count, bandwidth) {
|
|
|
2082
2419
|
* Generated bundle index. Do not edit.
|
|
2083
2420
|
*/
|
|
2084
2421
|
|
|
2085
|
-
export { MiraBar, MiraBarChart, MiraCartesianChart, MiraCartesianContext, MiraCartesianGrid, MiraChartLayer, MiraCursor, MiraLayerContent, MiraLegend, MiraLegendItemContent, MiraLine, MiraLineChart, MiraSeries, MiraTooltip, MiraTooltipContent, MiraXAxis, MiraYAxis };
|
|
2422
|
+
export { MiraArea, MiraAreaChart, MiraBar, MiraBarChart, MiraCartesianChart, MiraCartesianContext, MiraCartesianGrid, MiraChartLayer, MiraCursor, MiraLayerContent, MiraLegend, MiraLegendItemContent, MiraLine, MiraLineChart, MiraSeries, MiraTooltip, MiraTooltipContent, MiraXAxis, MiraYAxis };
|
|
2086
2423
|
//# sourceMappingURL=ngx-mira-charts.mjs.map
|