ngx-mira-charts 0.2.0 → 0.2.1-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/fesm2022/ngx-mira-charts.mjs +457 -428
- package/fesm2022/ngx-mira-charts.mjs.map +1 -1
- package/index.d.ts +229 -212
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { viewChild, TemplateRef, Directive, input, model, computed,
|
|
2
|
+
import { viewChild, TemplateRef, Directive, input, model, computed, numberAttribute, inject, forwardRef, ChangeDetectionStrategy, Component, LOCALE_ID, contentChildren, contentChild, signal, ElementRef, DestroyRef, afterNextRender, booleanAttribute, afterRenderEffect, linkedSignal } from '@angular/core';
|
|
3
3
|
import { NgTemplateOutlet } from '@angular/common';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -303,446 +303,128 @@ const DEFAULT_TICK_COUNT = 5;
|
|
|
303
303
|
* scales, the labels along x, and the pointer and the datum under it. Every
|
|
304
304
|
* kind of chart provides itself under it, with `provideCartesianChart`, and
|
|
305
305
|
* the library's own parts inject it: they can't import the chart, which
|
|
306
|
-
* imports the axes
|
|
307
|
-
*
|
|
306
|
+
* imports the axes to leave room for them. The way Angular Material's tabs
|
|
307
|
+
* inject `MAT_TAB_GROUP`.
|
|
308
308
|
*
|
|
309
309
|
* @internal
|
|
310
310
|
*/
|
|
311
311
|
class CartesianContext {
|
|
312
312
|
}
|
|
313
|
-
|
|
314
313
|
/**
|
|
315
|
-
*
|
|
316
|
-
*
|
|
317
|
-
*
|
|
318
|
-
* that hides or shows the series. A hidden series' item takes a gray color,
|
|
319
|
-
* which your template can keep or set its own from `item.hidden`. Its context
|
|
320
|
-
* is a `LegendItemContext`, and typed: `let-item` holds the series' `name`,
|
|
321
|
-
* `color`, `icon` and `hidden`.
|
|
322
|
-
*
|
|
323
|
-
* Screen readers read the template's text out, as the button's name in a
|
|
324
|
-
* toggleable legend:
|
|
325
|
-
*
|
|
326
|
-
* - keep the series' name in it, the same whether the series is hidden or
|
|
327
|
-
* not, and show the state in the look: the button already tells it;
|
|
328
|
-
* - mark what only decorates, such as a swatch or an emoji,
|
|
329
|
-
* `aria-hidden="true"`;
|
|
330
|
-
* - in a toggleable legend, put no buttons or links in it, as it's inside a
|
|
331
|
-
* button.
|
|
314
|
+
* The legend as the chart sees it: the edge it sits along, and the room it
|
|
315
|
+
* takes there. The legend provides itself under it, so the chart finds it
|
|
316
|
+
* without importing it, and an app without a legend doesn't ship one.
|
|
332
317
|
*
|
|
333
|
-
*
|
|
334
|
-
|
|
335
|
-
|
|
318
|
+
* @internal
|
|
319
|
+
*/
|
|
320
|
+
class ChartLegend {
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* The category axis under the plot: a tick per datum, labelled with the
|
|
325
|
+
* datum's value under `dataKey`. Its line runs at zero, where values rise and
|
|
326
|
+
* fall from; the ticks and labels stay under the plot, clear of values below
|
|
327
|
+
* zero.
|
|
336
328
|
*
|
|
337
329
|
* @example
|
|
338
330
|
* ```html
|
|
339
|
-
* <mira-
|
|
340
|
-
* <ng-template miraLegendItemContent let-item>
|
|
341
|
-
* <span
|
|
342
|
-
* aria-hidden="true"
|
|
343
|
-
* [style.color]="item.hidden ? null : item.color"
|
|
344
|
-
* >●</span>
|
|
345
|
-
* <b>{{ item.name }}</b>
|
|
346
|
-
* </ng-template>
|
|
347
|
-
* </mira-legend>
|
|
331
|
+
* <mira-x-axis dataKey="month" />
|
|
348
332
|
* ```
|
|
349
333
|
*/
|
|
350
|
-
class
|
|
351
|
-
/**
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
334
|
+
class MiraXAxis extends MiraChartLayer {
|
|
335
|
+
/** The key of each datum's category. Without one, the ticks show indexes. */
|
|
336
|
+
dataKey = input(...(ngDevMode ? [undefined, { debugName: "dataKey" }] : []));
|
|
337
|
+
/** The room the axis takes under the plot, in px: 30 by default. */
|
|
338
|
+
height = input(30, ...(ngDevMode ? [{ debugName: "height", transform: numberAttribute }] : [{ transform: numberAttribute }]));
|
|
339
|
+
chart = inject(CartesianContext);
|
|
340
|
+
// Where the ticks and labels hang from: the bottom of the plot.
|
|
341
|
+
bottom = computed(() => this.chart.plot().top + this.chart.plot().height, ...(ngDevMode ? [{ debugName: "bottom" }] : []));
|
|
342
|
+
// Where the axis line runs: at zero, kept on the plot.
|
|
343
|
+
baseline = computed(() => {
|
|
344
|
+
const zero = this.chart.yScale()(0);
|
|
345
|
+
return Math.min(this.bottom(), Math.max(this.chart.plot().top, zero));
|
|
346
|
+
}, ...(ngDevMode ? [{ debugName: "baseline" }] : []));
|
|
347
|
+
// A tick at each datum, with its label: the chart makes the labels from
|
|
348
|
+
// the `dataKey` of its x axis.
|
|
349
|
+
ticks = computed(() => {
|
|
350
|
+
const xs = this.chart.xPositions();
|
|
351
|
+
return this.chart
|
|
352
|
+
.xLabels()
|
|
353
|
+
.map((label, index) => ({ offset: xs[index], label }));
|
|
354
|
+
}, ...(ngDevMode ? [{ debugName: "ticks" }] : []));
|
|
355
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.35", ngImport: i0, type: MiraXAxis, deps: null, target: i0.ɵɵFactoryTarget.Component });
|
|
356
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.3.35", type: MiraXAxis, isStandalone: true, selector: "mira-x-axis", inputs: { dataKey: { classPropertyName: "dataKey", publicName: "dataKey", isSignal: true, isRequired: false, transformFunction: null }, height: { classPropertyName: "height", publicName: "height", isSignal: true, isRequired: false, transformFunction: null } }, providers: [
|
|
357
|
+
{ provide: MiraChartLayer, useExisting: forwardRef(() => MiraXAxis) },
|
|
358
|
+
], usesInheritance: true, ngImport: i0, template: `
|
|
359
|
+
<ng-template>
|
|
360
|
+
<svg:g class="mira-x-axis">
|
|
361
|
+
<svg:line
|
|
362
|
+
[attr.x1]="chart.plot().left"
|
|
363
|
+
[attr.x2]="chart.plot().left + chart.plot().width"
|
|
364
|
+
[attr.y1]="baseline()"
|
|
365
|
+
[attr.y2]="baseline()"
|
|
366
|
+
/>
|
|
367
|
+
@for (tick of ticks(); track $index) {
|
|
368
|
+
<svg:g
|
|
369
|
+
[attr.transform]="'translate(' + tick.offset + ',' + bottom() + ')'"
|
|
370
|
+
>
|
|
371
|
+
<svg:line y2="6" />
|
|
372
|
+
<svg:text y="9" dy="0.71em" text-anchor="middle">
|
|
373
|
+
{{ tick.label }}
|
|
374
|
+
</svg:text>
|
|
375
|
+
</svg:g>
|
|
376
|
+
}
|
|
377
|
+
</svg:g>
|
|
378
|
+
</ng-template>
|
|
379
|
+
`, isInline: true, styles: [".mira-x-axis{font-size:12px}line{stroke:var(--_mira-axis-color)}text{fill:var(--_mira-axis-color)}\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
361
380
|
}
|
|
362
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.35", ngImport: i0, type:
|
|
363
|
-
type:
|
|
364
|
-
args: [{ selector: '
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
381
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.35", ngImport: i0, type: MiraXAxis, decorators: [{
|
|
382
|
+
type: Component,
|
|
383
|
+
args: [{ selector: 'mira-x-axis', changeDetection: ChangeDetectionStrategy.OnPush, providers: [
|
|
384
|
+
{ provide: MiraChartLayer, useExisting: forwardRef(() => MiraXAxis) },
|
|
385
|
+
], template: `
|
|
386
|
+
<ng-template>
|
|
387
|
+
<svg:g class="mira-x-axis">
|
|
388
|
+
<svg:line
|
|
389
|
+
[attr.x1]="chart.plot().left"
|
|
390
|
+
[attr.x2]="chart.plot().left + chart.plot().width"
|
|
391
|
+
[attr.y1]="baseline()"
|
|
392
|
+
[attr.y2]="baseline()"
|
|
393
|
+
/>
|
|
394
|
+
@for (tick of ticks(); track $index) {
|
|
395
|
+
<svg:g
|
|
396
|
+
[attr.transform]="'translate(' + tick.offset + ',' + bottom() + ')'"
|
|
397
|
+
>
|
|
398
|
+
<svg:line y2="6" />
|
|
399
|
+
<svg:text y="9" dy="0.71em" text-anchor="middle">
|
|
400
|
+
{{ tick.label }}
|
|
401
|
+
</svg:text>
|
|
402
|
+
</svg:g>
|
|
403
|
+
}
|
|
404
|
+
</svg:g>
|
|
405
|
+
</ng-template>
|
|
406
|
+
`, styles: [".mira-x-axis{font-size:12px}line{stroke:var(--_mira-axis-color)}text{fill:var(--_mira-axis-color)}\n"] }]
|
|
407
|
+
}], propDecorators: { dataKey: [{ type: i0.Input, args: [{ isSignal: true, alias: "dataKey", required: false }] }], height: [{ type: i0.Input, args: [{ isSignal: true, alias: "height", required: false }] }] } });
|
|
408
|
+
|
|
371
409
|
/**
|
|
372
|
-
*
|
|
373
|
-
*
|
|
374
|
-
*
|
|
375
|
-
* series' `legendIcon`). A series is called by its `name`, or its `dataKey`
|
|
376
|
-
* without one. The plot leaves room for the legend, as it does for the axes,
|
|
377
|
-
* and the chart stays as big as it is.
|
|
378
|
-
*
|
|
379
|
-
* Along the bottom, by default, or the top, the items go in rows, centered,
|
|
380
|
-
* as many as they take. Up the right or the left side, they go in a column in
|
|
381
|
-
* the middle of the chart's height, at most 40% of its width wide, where a
|
|
382
|
-
* longer name wraps. Left and right are as the svg is drawn, in a page that
|
|
383
|
-
* runs right to left too, where the y axis stays on the left. A legend on a
|
|
384
|
-
* side leaves the plot no room on the server: its width is known only once
|
|
385
|
-
* the browser lays it out.
|
|
386
|
-
*
|
|
387
|
-
* It's a list to read, unless it's `toggleable`: then each item is a button
|
|
388
|
-
* that hides its series, or shows it again, and the chart fits its y axis to
|
|
389
|
-
* the series that are left. The state is the series' own `hidden`, to bind
|
|
390
|
-
* as `[(hidden)]`. A hidden series' item stays, grayed and struck through.
|
|
391
|
-
* In a toggleable legend it's marked `aria-pressed="false"` for screen
|
|
392
|
-
* readers; in a list to read, screen readers and the keyboard skip it, as the
|
|
393
|
-
* chart doesn't draw it.
|
|
394
|
-
*
|
|
395
|
-
* The legend's text takes the `color` around it, the chart's in a chart. The
|
|
396
|
-
* rest are CSS custom properties, to set anywhere above the legend:
|
|
397
|
-
*
|
|
398
|
-
* - `--mira-font-size`: the size of the text, `0.75rem` by default; the room
|
|
399
|
-
* around the text follows it;
|
|
400
|
-
* - `--mira-legend-inactive-color`: a hidden series' item,
|
|
401
|
-
* `--mira-axis-color` by default.
|
|
402
|
-
*
|
|
403
|
-
* For items that show something of your own, write their template inside, as
|
|
404
|
-
* an `<ng-template miraLegendItemContent>`, and import `MiraLegendItemContent`
|
|
405
|
-
* along with `MiraLegend`: without it, the template goes unnoticed, and the
|
|
406
|
-
* legend shows its own icon and name.
|
|
407
|
-
*
|
|
408
|
-
* Anywhere else on the page, name the chart with `for`. There the legend sits
|
|
409
|
-
* where the page puts it, as a block, and the chart leaves it no room; its
|
|
410
|
-
* `position` only picks its layout, rows for the top or the bottom, a column
|
|
411
|
-
* for a side. Its colors come from above it, as in a chart: set the custom
|
|
412
|
-
* properties above both to change them alike.
|
|
410
|
+
* The value axis left of the plot. It fits the values of every series in the
|
|
411
|
+
* chart that isn't hidden, and zero, rounded out to round ticks. The ticks
|
|
412
|
+
* read as numbers in the app's locale (`LOCALE_ID`).
|
|
413
413
|
*
|
|
414
414
|
* @example
|
|
415
415
|
* ```html
|
|
416
|
-
* <mira-
|
|
417
|
-
* <mira-x-axis dataKey="hour" />
|
|
418
|
-
* <mira-y-axis />
|
|
419
|
-
* <mira-line dataKey="solar" name="Solar" stroke="#d97706" />
|
|
420
|
-
* <mira-line dataKey="usage" name="Usage" stroke="#3b82f6" />
|
|
421
|
-
* <mira-legend position="right" toggleable />
|
|
422
|
-
* </mira-line-chart>
|
|
423
|
-
* ```
|
|
424
|
-
*
|
|
425
|
-
* ```html
|
|
426
|
-
* <header>
|
|
427
|
-
* <h2>A sunny day</h2>
|
|
428
|
-
* <mira-legend [for]="chart" />
|
|
429
|
-
* </header>
|
|
430
|
-
* <mira-line-chart #chart [data]="day">…</mira-line-chart>
|
|
416
|
+
* <mira-y-axis [tickCount]="4" />
|
|
431
417
|
* ```
|
|
432
418
|
*/
|
|
433
|
-
class
|
|
434
|
-
/** The
|
|
435
|
-
|
|
436
|
-
/**
|
|
437
|
-
* Whether a click on an item, or Enter or Space on it, hides its series or
|
|
438
|
-
* shows it again. Off by default: the legend is then a list to read.
|
|
439
|
-
*/
|
|
440
|
-
toggleable = input(false, ...(ngDevMode ? [{ debugName: "toggleable", transform: booleanAttribute }] : [{ transform: booleanAttribute }]));
|
|
441
|
-
/**
|
|
442
|
-
* The chart whose series the legend lists, for a legend out of it: give
|
|
443
|
-
* the chart a reference, `<mira-line-chart #chart>`, and name it,
|
|
444
|
-
* `<mira-legend [for]="chart" />`. Unset, the chart the legend is in. With
|
|
445
|
-
* no chart, as while a chart named through a query is in an `@if` that's
|
|
446
|
-
* off, the legend lists nothing.
|
|
447
|
-
*/
|
|
448
|
-
for = input(...(ngDevMode ? [undefined, { debugName: "for" }] : []));
|
|
419
|
+
class MiraYAxis extends MiraChartLayer {
|
|
420
|
+
/** The room the axis takes left of the plot, in px: 60 by default. */
|
|
421
|
+
width = input(60, ...(ngDevMode ? [{ debugName: "width", transform: numberAttribute }] : [{ transform: numberAttribute }]));
|
|
449
422
|
/**
|
|
450
|
-
*
|
|
451
|
-
*
|
|
452
|
-
* last laid it out there. Until then, a row's height along the top or the
|
|
453
|
-
* bottom, and none on a side.
|
|
454
|
-
*
|
|
455
|
-
* @internal
|
|
423
|
+
* About how many ticks to show, 5 by default. The axis keeps its ticks 1, 2
|
|
424
|
+
* or 5 times a power of ten apart, so it may show a few more or a few fewer.
|
|
456
425
|
*/
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
// where the page puts it.
|
|
460
|
-
placement = computed(() => this.#parent ? this.position() : null, ...(ngDevMode ? [{ debugName: "placement" }] : []));
|
|
461
|
-
// How it lays out its items: in rows, or in a column.
|
|
462
|
-
layout = computed(() => inRows(this.position()) ? 'rows' : 'column', ...(ngDevMode ? [{ debugName: "layout" }] : []));
|
|
463
|
-
// What the legend lists: each series of the chart it names, or of the one
|
|
464
|
-
// it's in, hidden ones too.
|
|
465
|
-
entries = computed(() => {
|
|
466
|
-
const all = (this.for() ?? this.#parent)?.series() ?? [];
|
|
467
|
-
return all.flatMap((series) => {
|
|
468
|
-
const name = nameOf(series);
|
|
469
|
-
if (name === null)
|
|
470
|
-
return [];
|
|
471
|
-
const item = {
|
|
472
|
-
name,
|
|
473
|
-
color: series.color(),
|
|
474
|
-
icon: series.legendIcon,
|
|
475
|
-
hidden: series.hidden(),
|
|
476
|
-
};
|
|
477
|
-
return { series, item };
|
|
478
|
-
});
|
|
479
|
-
}, ...(ngDevMode ? [{ debugName: "entries" }] : []));
|
|
480
|
-
// A template of your own for the items, if there's one.
|
|
481
|
-
template = contentChild(MiraLegendItemContent, ...(ngDevMode ? [{ debugName: "template", read: TemplateRef }] : [{
|
|
482
|
-
read: TemplateRef,
|
|
483
|
-
}]));
|
|
484
|
-
#host = inject(ElementRef).nativeElement;
|
|
485
|
-
// The chart the legend is in, if it's in one.
|
|
486
|
-
#parent = inject(CartesianContext, { optional: true });
|
|
487
|
-
// The room the legend took, as the browser last laid it out: none yet on a
|
|
488
|
-
// side it has just moved to, which the old room says nothing about.
|
|
489
|
-
#measured = linkedSignal(...(ngDevMode ? [{ debugName: "#measured", source: this.position,
|
|
490
|
-
computation: () => null }] : [{
|
|
491
|
-
source: this.position,
|
|
492
|
-
computation: () => null,
|
|
493
|
-
}]));
|
|
494
|
-
/** @internal */
|
|
495
|
-
constructor() {
|
|
496
|
-
const parent = this.#parent;
|
|
497
|
-
const destroyRef = inject(DestroyRef);
|
|
498
|
-
// Out of a chart, there's no room to leave the legend, and nothing to
|
|
499
|
-
// measure.
|
|
500
|
-
if (!parent)
|
|
501
|
-
return;
|
|
502
|
-
// The legend is measured after a render that changes what it lists, how
|
|
503
|
-
// it shows it, its side, or the chart's size, which can wrap it onto more
|
|
504
|
-
// rows or fewer; and the plot leaves it room before the page is painted.
|
|
505
|
-
afterRenderEffect({
|
|
506
|
-
earlyRead: () => {
|
|
507
|
-
this.entries();
|
|
508
|
-
this.template();
|
|
509
|
-
parent.size();
|
|
510
|
-
return this.#measure();
|
|
511
|
-
},
|
|
512
|
-
write: (room) => this.#measured.set(room()),
|
|
513
|
-
});
|
|
514
|
-
// And again whenever it changes size on its own, as when a font loads,
|
|
515
|
-
// or an item of your own that changes, padding and border included: then
|
|
516
|
-
// the plot follows a frame later.
|
|
517
|
-
afterNextRender(() => {
|
|
518
|
-
const observer = new ResizeObserver(() => this.#measured.set(this.#measure()));
|
|
519
|
-
observer.observe(this.#host, { box: 'border-box' });
|
|
520
|
-
destroyRef.onDestroy(() => observer.disconnect());
|
|
521
|
-
});
|
|
522
|
-
}
|
|
523
|
-
// Hides the series, or shows it again.
|
|
524
|
-
toggle(series) {
|
|
525
|
-
series.hidden.update((hidden) => !hidden);
|
|
526
|
-
}
|
|
527
|
-
// The room the legend takes along its edge as laid out, in the svg's px: a
|
|
528
|
-
// transform on the page around the chart scales both alike.
|
|
529
|
-
#measure() {
|
|
530
|
-
const { offsetWidth, offsetHeight } = this.#host;
|
|
531
|
-
return inRows(this.position()) ? offsetHeight : offsetWidth;
|
|
532
|
-
}
|
|
533
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.35", ngImport: i0, type: MiraLegend, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
534
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.3.35", type: MiraLegend, isStandalone: true, selector: "mira-legend", inputs: { position: { classPropertyName: "position", publicName: "position", isSignal: true, isRequired: false, transformFunction: null }, toggleable: { classPropertyName: "toggleable", publicName: "toggleable", isSignal: true, isRequired: false, transformFunction: null }, for: { classPropertyName: "for", publicName: "for", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "attr.data-position": "placement()", "attr.data-layout": "layout()" } }, queries: [{ propertyName: "template", first: true, predicate: MiraLegendItemContent, descendants: true, read: TemplateRef, isSignal: true }], ngImport: i0, template: `
|
|
535
|
-
<ul class="mira-legend" role="list">
|
|
536
|
-
@for (entry of entries(); track entry.series) {
|
|
537
|
-
<li
|
|
538
|
-
[attr.data-hidden]="entry.item.hidden || null"
|
|
539
|
-
[attr.inert]="entry.item.hidden && !toggleable() ? '' : null"
|
|
540
|
-
>
|
|
541
|
-
@if (toggleable()) {
|
|
542
|
-
<button
|
|
543
|
-
type="button"
|
|
544
|
-
class="mira-legend-item"
|
|
545
|
-
[attr.aria-pressed]="!entry.item.hidden"
|
|
546
|
-
(click)="toggle(entry.series)"
|
|
547
|
-
>
|
|
548
|
-
<ng-container
|
|
549
|
-
[ngTemplateOutlet]="template() ?? own"
|
|
550
|
-
[ngTemplateOutletContext]="{ $implicit: entry.item }"
|
|
551
|
-
/>
|
|
552
|
-
</button>
|
|
553
|
-
} @else {
|
|
554
|
-
<ng-container
|
|
555
|
-
[ngTemplateOutlet]="template() ?? own"
|
|
556
|
-
[ngTemplateOutletContext]="{ $implicit: entry.item }"
|
|
557
|
-
/>
|
|
558
|
-
}
|
|
559
|
-
</li>
|
|
560
|
-
}
|
|
561
|
-
</ul>
|
|
562
|
-
|
|
563
|
-
<ng-template #own let-item>
|
|
564
|
-
<span class="mira-legend-label">
|
|
565
|
-
<span
|
|
566
|
-
class="mira-legend-icon"
|
|
567
|
-
[attr.data-icon]="item.icon"
|
|
568
|
-
[style.color]="item.hidden ? null : item.color"
|
|
569
|
-
></span>
|
|
570
|
-
<span class="mira-legend-name">{{ item.name }}</span>
|
|
571
|
-
</span>
|
|
572
|
-
</ng-template>
|
|
573
|
-
`, 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", ":host{display:block}:host([data-position]){position:absolute}:host([data-position=\"top\"]){inset:0 0 auto}:host([data-position=\"bottom\"]){inset:auto 0 0}:host([data-position=\"left\"]){inset:0 auto 0 0}:host([data-position=\"right\"]){inset:0 0 0 auto}:host([data-position=\"left\"]),:host([data-position=\"right\"]){display:flex;align-items:center;align-items:safe center;max-width:40%}.mira-legend{display:flex;flex-wrap:wrap;justify-content:center;justify-content:safe center;gap:max(.5em,24px - 1.5em) 1.25em;margin:0;padding:0 .75em;list-style:none;font-size:var(--mira-font-size, .75rem);line-height:1.5;overflow-wrap:anywhere}:host([data-position=\"top\"]) .mira-legend{padding-top:4px}:host([data-position=\"bottom\"]) .mira-legend{padding-bottom:4px}:host([data-layout=\"column\"]) .mira-legend{flex-direction:column;align-items:flex-start}:host([data-position]) li{pointer-events:auto}.mira-legend-item{all:unset;display:block;cursor:pointer}.mira-legend-item:focus-visible{outline:revert;outline-offset:2px}li[data-hidden]{color:var(--mira-legend-inactive-color, var(--_mira-axis-color))}li[data-hidden] .mira-legend-name{text-decoration:line-through}@media(forced-colors:active){li[data-hidden]{color:GrayText}}.mira-legend-label{display:flex;gap:.5em}.mira-legend-icon{display:grid;flex:none;place-items:center;width:1em;height:1.5em;forced-color-adjust:none;-webkit-print-color-adjust:exact;print-color-adjust:exact}.mira-legend-icon:before{content:\"\";width:.75em;height:.75em;border-radius:50%;background:currentColor}.mira-legend-icon[data-icon=square]:before{border-radius:.125em}.mira-legend-icon[data-icon=line]:before{width:100%;height:2px;border-radius:0}\n"], dependencies: [{ kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
574
|
-
}
|
|
575
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.35", ngImport: i0, type: MiraLegend, decorators: [{
|
|
576
|
-
type: Component,
|
|
577
|
-
args: [{ selector: 'mira-legend', changeDetection: ChangeDetectionStrategy.OnPush, imports: [NgTemplateOutlet], host: {
|
|
578
|
-
'[attr.data-position]': 'placement()',
|
|
579
|
-
'[attr.data-layout]': 'layout()',
|
|
580
|
-
}, template: `
|
|
581
|
-
<ul class="mira-legend" role="list">
|
|
582
|
-
@for (entry of entries(); track entry.series) {
|
|
583
|
-
<li
|
|
584
|
-
[attr.data-hidden]="entry.item.hidden || null"
|
|
585
|
-
[attr.inert]="entry.item.hidden && !toggleable() ? '' : null"
|
|
586
|
-
>
|
|
587
|
-
@if (toggleable()) {
|
|
588
|
-
<button
|
|
589
|
-
type="button"
|
|
590
|
-
class="mira-legend-item"
|
|
591
|
-
[attr.aria-pressed]="!entry.item.hidden"
|
|
592
|
-
(click)="toggle(entry.series)"
|
|
593
|
-
>
|
|
594
|
-
<ng-container
|
|
595
|
-
[ngTemplateOutlet]="template() ?? own"
|
|
596
|
-
[ngTemplateOutletContext]="{ $implicit: entry.item }"
|
|
597
|
-
/>
|
|
598
|
-
</button>
|
|
599
|
-
} @else {
|
|
600
|
-
<ng-container
|
|
601
|
-
[ngTemplateOutlet]="template() ?? own"
|
|
602
|
-
[ngTemplateOutletContext]="{ $implicit: entry.item }"
|
|
603
|
-
/>
|
|
604
|
-
}
|
|
605
|
-
</li>
|
|
606
|
-
}
|
|
607
|
-
</ul>
|
|
608
|
-
|
|
609
|
-
<ng-template #own let-item>
|
|
610
|
-
<span class="mira-legend-label">
|
|
611
|
-
<span
|
|
612
|
-
class="mira-legend-icon"
|
|
613
|
-
[attr.data-icon]="item.icon"
|
|
614
|
-
[style.color]="item.hidden ? null : item.color"
|
|
615
|
-
></span>
|
|
616
|
-
<span class="mira-legend-name">{{ item.name }}</span>
|
|
617
|
-
</span>
|
|
618
|
-
</ng-template>
|
|
619
|
-
`, 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", ":host{display:block}:host([data-position]){position:absolute}:host([data-position=\"top\"]){inset:0 0 auto}:host([data-position=\"bottom\"]){inset:auto 0 0}:host([data-position=\"left\"]){inset:0 auto 0 0}:host([data-position=\"right\"]){inset:0 0 0 auto}:host([data-position=\"left\"]),:host([data-position=\"right\"]){display:flex;align-items:center;align-items:safe center;max-width:40%}.mira-legend{display:flex;flex-wrap:wrap;justify-content:center;justify-content:safe center;gap:max(.5em,24px - 1.5em) 1.25em;margin:0;padding:0 .75em;list-style:none;font-size:var(--mira-font-size, .75rem);line-height:1.5;overflow-wrap:anywhere}:host([data-position=\"top\"]) .mira-legend{padding-top:4px}:host([data-position=\"bottom\"]) .mira-legend{padding-bottom:4px}:host([data-layout=\"column\"]) .mira-legend{flex-direction:column;align-items:flex-start}:host([data-position]) li{pointer-events:auto}.mira-legend-item{all:unset;display:block;cursor:pointer}.mira-legend-item:focus-visible{outline:revert;outline-offset:2px}li[data-hidden]{color:var(--mira-legend-inactive-color, var(--_mira-axis-color))}li[data-hidden] .mira-legend-name{text-decoration:line-through}@media(forced-colors:active){li[data-hidden]{color:GrayText}}.mira-legend-label{display:flex;gap:.5em}.mira-legend-icon{display:grid;flex:none;place-items:center;width:1em;height:1.5em;forced-color-adjust:none;-webkit-print-color-adjust:exact;print-color-adjust:exact}.mira-legend-icon:before{content:\"\";width:.75em;height:.75em;border-radius:50%;background:currentColor}.mira-legend-icon[data-icon=square]:before{border-radius:.125em}.mira-legend-icon[data-icon=line]:before{width:100%;height:2px;border-radius:0}\n"] }]
|
|
620
|
-
}], ctorParameters: () => [], propDecorators: { position: [{ type: i0.Input, args: [{ isSignal: true, alias: "position", required: false }] }], toggleable: [{ type: i0.Input, args: [{ isSignal: true, alias: "toggleable", required: false }] }], for: [{ type: i0.Input, args: [{ isSignal: true, alias: "for", required: false }] }], template: [{ type: i0.ContentChild, args: [i0.forwardRef(() => MiraLegendItemContent), { ...{
|
|
621
|
-
read: TemplateRef,
|
|
622
|
-
}, isSignal: true }] }] } });
|
|
623
|
-
// What the series is called, or null while it has no `dataKey` yet. Angular
|
|
624
|
-
// binds a series' inputs as it checks the block the series is written in,
|
|
625
|
-
// and a legend in a block it checks before reads the series first: such a
|
|
626
|
-
// series joins the list as soon as its inputs are bound, in the same pass.
|
|
627
|
-
function nameOf(series) {
|
|
628
|
-
try {
|
|
629
|
-
return series.displayName();
|
|
630
|
-
}
|
|
631
|
-
catch {
|
|
632
|
-
return null;
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
// Whether a legend on this side lists its items in rows, rather than in a
|
|
636
|
-
// column.
|
|
637
|
-
function inRows(side) {
|
|
638
|
-
return side === 'top' || side === 'bottom';
|
|
639
|
-
}
|
|
640
|
-
|
|
641
|
-
/**
|
|
642
|
-
* The category axis under the plot: a tick per datum, labelled with the
|
|
643
|
-
* datum's value under `dataKey`. Its line runs at zero, where values rise and
|
|
644
|
-
* fall from; the ticks and labels stay under the plot, clear of values below
|
|
645
|
-
* zero.
|
|
646
|
-
*
|
|
647
|
-
* @example
|
|
648
|
-
* ```html
|
|
649
|
-
* <mira-x-axis dataKey="month" />
|
|
650
|
-
* ```
|
|
651
|
-
*/
|
|
652
|
-
class MiraXAxis extends MiraChartLayer {
|
|
653
|
-
/** The key of each datum's category. Without one, the ticks show indexes. */
|
|
654
|
-
dataKey = input(...(ngDevMode ? [undefined, { debugName: "dataKey" }] : []));
|
|
655
|
-
/** The room the axis takes under the plot, in px: 30 by default. */
|
|
656
|
-
height = input(30, ...(ngDevMode ? [{ debugName: "height", transform: numberAttribute }] : [{ transform: numberAttribute }]));
|
|
657
|
-
chart = inject(CartesianContext);
|
|
658
|
-
// Where the ticks and labels hang from: the bottom of the plot.
|
|
659
|
-
bottom = computed(() => this.chart.plot().top + this.chart.plot().height, ...(ngDevMode ? [{ debugName: "bottom" }] : []));
|
|
660
|
-
// Where the axis line runs: at zero, kept on the plot.
|
|
661
|
-
baseline = computed(() => {
|
|
662
|
-
const zero = this.chart.yScale()(0);
|
|
663
|
-
return Math.min(this.bottom(), Math.max(this.chart.plot().top, zero));
|
|
664
|
-
}, ...(ngDevMode ? [{ debugName: "baseline" }] : []));
|
|
665
|
-
// A tick at each datum, with its label: the chart makes the labels from
|
|
666
|
-
// the `dataKey` of its x axis.
|
|
667
|
-
ticks = computed(() => {
|
|
668
|
-
const xs = this.chart.xPositions();
|
|
669
|
-
return this.chart
|
|
670
|
-
.xLabels()
|
|
671
|
-
.map((label, index) => ({ offset: xs[index], label }));
|
|
672
|
-
}, ...(ngDevMode ? [{ debugName: "ticks" }] : []));
|
|
673
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.35", ngImport: i0, type: MiraXAxis, deps: null, target: i0.ɵɵFactoryTarget.Component });
|
|
674
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.3.35", type: MiraXAxis, isStandalone: true, selector: "mira-x-axis", inputs: { dataKey: { classPropertyName: "dataKey", publicName: "dataKey", isSignal: true, isRequired: false, transformFunction: null }, height: { classPropertyName: "height", publicName: "height", isSignal: true, isRequired: false, transformFunction: null } }, providers: [
|
|
675
|
-
{ provide: MiraChartLayer, useExisting: forwardRef(() => MiraXAxis) },
|
|
676
|
-
], usesInheritance: true, ngImport: i0, template: `
|
|
677
|
-
<ng-template>
|
|
678
|
-
<svg:g class="mira-x-axis">
|
|
679
|
-
<svg:line
|
|
680
|
-
[attr.x1]="chart.plot().left"
|
|
681
|
-
[attr.x2]="chart.plot().left + chart.plot().width"
|
|
682
|
-
[attr.y1]="baseline()"
|
|
683
|
-
[attr.y2]="baseline()"
|
|
684
|
-
/>
|
|
685
|
-
@for (tick of ticks(); track $index) {
|
|
686
|
-
<svg:g
|
|
687
|
-
[attr.transform]="'translate(' + tick.offset + ',' + bottom() + ')'"
|
|
688
|
-
>
|
|
689
|
-
<svg:line y2="6" />
|
|
690
|
-
<svg:text y="9" dy="0.71em" text-anchor="middle">
|
|
691
|
-
{{ tick.label }}
|
|
692
|
-
</svg:text>
|
|
693
|
-
</svg:g>
|
|
694
|
-
}
|
|
695
|
-
</svg:g>
|
|
696
|
-
</ng-template>
|
|
697
|
-
`, isInline: true, styles: [".mira-x-axis{font-size:12px}line{stroke:var(--_mira-axis-color)}text{fill:var(--_mira-axis-color)}\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
698
|
-
}
|
|
699
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.35", ngImport: i0, type: MiraXAxis, decorators: [{
|
|
700
|
-
type: Component,
|
|
701
|
-
args: [{ selector: 'mira-x-axis', changeDetection: ChangeDetectionStrategy.OnPush, providers: [
|
|
702
|
-
{ provide: MiraChartLayer, useExisting: forwardRef(() => MiraXAxis) },
|
|
703
|
-
], template: `
|
|
704
|
-
<ng-template>
|
|
705
|
-
<svg:g class="mira-x-axis">
|
|
706
|
-
<svg:line
|
|
707
|
-
[attr.x1]="chart.plot().left"
|
|
708
|
-
[attr.x2]="chart.plot().left + chart.plot().width"
|
|
709
|
-
[attr.y1]="baseline()"
|
|
710
|
-
[attr.y2]="baseline()"
|
|
711
|
-
/>
|
|
712
|
-
@for (tick of ticks(); track $index) {
|
|
713
|
-
<svg:g
|
|
714
|
-
[attr.transform]="'translate(' + tick.offset + ',' + bottom() + ')'"
|
|
715
|
-
>
|
|
716
|
-
<svg:line y2="6" />
|
|
717
|
-
<svg:text y="9" dy="0.71em" text-anchor="middle">
|
|
718
|
-
{{ tick.label }}
|
|
719
|
-
</svg:text>
|
|
720
|
-
</svg:g>
|
|
721
|
-
}
|
|
722
|
-
</svg:g>
|
|
723
|
-
</ng-template>
|
|
724
|
-
`, styles: [".mira-x-axis{font-size:12px}line{stroke:var(--_mira-axis-color)}text{fill:var(--_mira-axis-color)}\n"] }]
|
|
725
|
-
}], propDecorators: { dataKey: [{ type: i0.Input, args: [{ isSignal: true, alias: "dataKey", required: false }] }], height: [{ type: i0.Input, args: [{ isSignal: true, alias: "height", required: false }] }] } });
|
|
726
|
-
|
|
727
|
-
/**
|
|
728
|
-
* The value axis left of the plot. It fits the values of every series in the
|
|
729
|
-
* chart that isn't hidden, and zero, rounded out to round ticks. The ticks
|
|
730
|
-
* read as numbers in the app's locale (`LOCALE_ID`).
|
|
731
|
-
*
|
|
732
|
-
* @example
|
|
733
|
-
* ```html
|
|
734
|
-
* <mira-y-axis [tickCount]="4" />
|
|
735
|
-
* ```
|
|
736
|
-
*/
|
|
737
|
-
class MiraYAxis extends MiraChartLayer {
|
|
738
|
-
/** The room the axis takes left of the plot, in px: 60 by default. */
|
|
739
|
-
width = input(60, ...(ngDevMode ? [{ debugName: "width", transform: numberAttribute }] : [{ transform: numberAttribute }]));
|
|
740
|
-
/**
|
|
741
|
-
* About how many ticks to show, 5 by default. The axis keeps its ticks 1, 2
|
|
742
|
-
* or 5 times a power of ten apart, so it may show a few more or a few fewer.
|
|
743
|
-
*/
|
|
744
|
-
tickCount = input(DEFAULT_TICK_COUNT, ...(ngDevMode ? [{ debugName: "tickCount", transform: numberAttribute }] : [{
|
|
745
|
-
transform: numberAttribute,
|
|
426
|
+
tickCount = input(DEFAULT_TICK_COUNT, ...(ngDevMode ? [{ debugName: "tickCount", transform: numberAttribute }] : [{
|
|
427
|
+
transform: numberAttribute,
|
|
746
428
|
}]));
|
|
747
429
|
chart = inject(CartesianContext);
|
|
748
430
|
x = computed(() => this.chart.plot().left, ...(ngDevMode ? [{ debugName: "x" }] : []));
|
|
@@ -879,8 +561,9 @@ const CARTESIAN_CHART_STYLES = [
|
|
|
879
561
|
`,
|
|
880
562
|
];
|
|
881
563
|
const DEFAULT_MARGIN = { top: 10, right: 20, bottom: 10, left: 10 };
|
|
882
|
-
// The size a chart draws at
|
|
883
|
-
// server, in the browser's first frame,
|
|
564
|
+
// The size a chart draws at where it can't take one from its container: on
|
|
565
|
+
// the server, in the browser's first frame, while it's hidden, and in a
|
|
566
|
+
// container that gives it no height or no width.
|
|
884
567
|
const FALLBACK_SIZE = { width: 600, height: 300 };
|
|
885
568
|
/**
|
|
886
569
|
* What every chart with an x and a y axis has, whatever its series: data, a
|
|
@@ -914,7 +597,11 @@ const FALLBACK_SIZE = { width: 600, height: 300 };
|
|
|
914
597
|
class MiraCartesianChart {
|
|
915
598
|
/** The rows to plot, a `ChartDatum` each. */
|
|
916
599
|
data = input([], ...(ngDevMode ? [{ debugName: "data" }] : []));
|
|
917
|
-
/**
|
|
600
|
+
/**
|
|
601
|
+
* The width in px. Without it, the chart is as wide as its container, and
|
|
602
|
+
* doesn't widen it: a container as wide as its content, such as an
|
|
603
|
+
* inline-block or a dialog, needs a width of its own.
|
|
604
|
+
*/
|
|
918
605
|
width = input(undefined, ...(ngDevMode ? [{ debugName: "width", transform: optionalNumber }] : [{
|
|
919
606
|
transform: optionalNumber,
|
|
920
607
|
}]));
|
|
@@ -934,8 +621,10 @@ class MiraCartesianChart {
|
|
|
934
621
|
/** The size the chart draws at, in px: its inputs, or its container's. */
|
|
935
622
|
size = computed(() => {
|
|
936
623
|
const measured = this.#measured();
|
|
937
|
-
// A size of 0 means the chart is hidden, or its container
|
|
938
|
-
//
|
|
624
|
+
// A size of 0 means the chart is hidden, or its container gives it none:
|
|
625
|
+
// it has no height, or it takes its width from its content. Drawing at 0
|
|
626
|
+
// would keep the height at 0 once the chart shows, and hide a chart whose
|
|
627
|
+
// container needs a width, rather than show it past the container.
|
|
939
628
|
return {
|
|
940
629
|
width: this.width() ?? (measured?.width || FALLBACK_SIZE.width),
|
|
941
630
|
height: this.height() ?? (measured?.height || FALLBACK_SIZE.height),
|
|
@@ -1035,7 +724,7 @@ class MiraCartesianChart {
|
|
|
1035
724
|
xAxis = contentChild(MiraXAxis, ...(ngDevMode ? [{ debugName: "xAxis", descendants: false }] : [{ descendants: false }]));
|
|
1036
725
|
yAxis = contentChild(MiraYAxis, ...(ngDevMode ? [{ debugName: "yAxis", descendants: false }] : [{ descendants: false }]));
|
|
1037
726
|
/** The chart's legend, if it has one: the plot leaves room for it too. */
|
|
1038
|
-
legend = contentChild(
|
|
727
|
+
legend = contentChild(ChartLegend, ...(ngDevMode ? [{ debugName: "legend", descendants: false }] : [{ descendants: false }]));
|
|
1039
728
|
/** The chart's svg, where the pointer is tracked. */
|
|
1040
729
|
svg = viewChild.required('svg');
|
|
1041
730
|
viewBox = computed(() => {
|
|
@@ -1106,19 +795,28 @@ class MiraCartesianChart {
|
|
|
1106
795
|
return { x, y };
|
|
1107
796
|
}
|
|
1108
797
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.35", ngImport: i0, type: MiraCartesianChart, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
1109
|
-
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.2.0", version: "20.3.35", type: MiraCartesianChart, isStandalone: true, inputs: { data: { classPropertyName: "data", publicName: "data", isSignal: true, isRequired: false, transformFunction: null }, width: { classPropertyName: "width", publicName: "width", isSignal: true, isRequired: false, transformFunction: null }, height: { classPropertyName: "height", publicName: "height", isSignal: true, isRequired: false, transformFunction: null }, margin: { classPropertyName: "margin", publicName: "margin", isSignal: true, isRequired: false, transformFunction: null }, ariaLabel: { classPropertyName: "ariaLabel", publicName: "ariaLabel", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "style.display": "\"block\"", "style.height": "height() === undefined ? \"100%\" : null" } }, queries: [{ propertyName: "series", predicate: MiraSeries, isSignal: true }, { propertyName: "layers", predicate: MiraChartLayer, isSignal: true }, { propertyName: "xAxis", first: true, predicate: MiraXAxis, isSignal: true }, { propertyName: "yAxis", first: true, predicate: MiraYAxis, isSignal: true }, { propertyName: "legend", first: true, predicate:
|
|
798
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.2.0", version: "20.3.35", type: MiraCartesianChart, isStandalone: true, inputs: { data: { classPropertyName: "data", publicName: "data", isSignal: true, isRequired: false, transformFunction: null }, width: { classPropertyName: "width", publicName: "width", isSignal: true, isRequired: false, transformFunction: null }, height: { classPropertyName: "height", publicName: "height", isSignal: true, isRequired: false, transformFunction: null }, margin: { classPropertyName: "margin", publicName: "margin", isSignal: true, isRequired: false, transformFunction: null }, ariaLabel: { classPropertyName: "ariaLabel", publicName: "ariaLabel", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "style.display": "\"block\"", "style.width": "width() === undefined ? \"100%\" : null", "style.height": "height() === undefined ? \"100%\" : null", "style.contain": "width() === undefined ? \"inline-size\" : null" } }, queries: [{ propertyName: "series", predicate: MiraSeries, isSignal: true }, { propertyName: "layers", predicate: MiraChartLayer, isSignal: true }, { propertyName: "xAxis", first: true, predicate: MiraXAxis, isSignal: true }, { propertyName: "yAxis", first: true, predicate: MiraYAxis, isSignal: true }, { propertyName: "legend", first: true, predicate: ChartLegend, isSignal: true }], viewQueries: [{ propertyName: "svg", first: true, predicate: ["svg"], descendants: true, isSignal: true }], ngImport: i0 });
|
|
1110
799
|
}
|
|
1111
800
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.35", ngImport: i0, type: MiraCartesianChart, decorators: [{
|
|
1112
801
|
type: Directive,
|
|
1113
802
|
args: [{
|
|
1114
803
|
host: {
|
|
1115
804
|
'[style.display]': '"block"',
|
|
805
|
+
// Fills its container's width, even where the container would center it,
|
|
806
|
+
// as a flex column with `align-items: center` does.
|
|
807
|
+
'[style.width]': 'width() === undefined ? "100%" : null',
|
|
1116
808
|
// Fills a container that has a height. In one without, the chart is as
|
|
1117
809
|
// tall as it draws itself.
|
|
1118
810
|
'[style.height]': 'height() === undefined ? "100%" : null',
|
|
811
|
+
// Without a width, what it draws doesn't count toward its container's
|
|
812
|
+
// width. If it did, the svg would hold a grid column or a flex item at the
|
|
813
|
+
// svg's width, the chart would measure that width again, and never get
|
|
814
|
+
// narrower. With a width, it counts, so a flex row of charts with a width
|
|
815
|
+
// lays out by them.
|
|
816
|
+
'[style.contain]': 'width() === undefined ? "inline-size" : null',
|
|
1119
817
|
},
|
|
1120
818
|
}]
|
|
1121
|
-
}], ctorParameters: () => [], propDecorators: { data: [{ type: i0.Input, args: [{ isSignal: true, alias: "data", required: false }] }], width: [{ type: i0.Input, args: [{ isSignal: true, alias: "width", required: false }] }], height: [{ type: i0.Input, args: [{ isSignal: true, alias: "height", required: false }] }], margin: [{ type: i0.Input, args: [{ isSignal: true, alias: "margin", required: false }] }], ariaLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "ariaLabel", required: false }] }], series: [{ type: i0.ContentChildren, args: [i0.forwardRef(() => MiraSeries), { isSignal: true }] }], layers: [{ type: i0.ContentChildren, args: [i0.forwardRef(() => MiraChartLayer), { isSignal: true }] }], xAxis: [{ type: i0.ContentChild, args: [i0.forwardRef(() => MiraXAxis), { ...{ descendants: false }, isSignal: true }] }], yAxis: [{ type: i0.ContentChild, args: [i0.forwardRef(() => MiraYAxis), { ...{ descendants: false }, isSignal: true }] }], legend: [{ type: i0.ContentChild, args: [i0.forwardRef(() =>
|
|
819
|
+
}], ctorParameters: () => [], propDecorators: { data: [{ type: i0.Input, args: [{ isSignal: true, alias: "data", required: false }] }], width: [{ type: i0.Input, args: [{ isSignal: true, alias: "width", required: false }] }], height: [{ type: i0.Input, args: [{ isSignal: true, alias: "height", required: false }] }], margin: [{ type: i0.Input, args: [{ isSignal: true, alias: "margin", required: false }] }], ariaLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "ariaLabel", required: false }] }], series: [{ type: i0.ContentChildren, args: [i0.forwardRef(() => MiraSeries), { isSignal: true }] }], layers: [{ type: i0.ContentChildren, args: [i0.forwardRef(() => MiraChartLayer), { isSignal: true }] }], xAxis: [{ type: i0.ContentChild, args: [i0.forwardRef(() => MiraXAxis), { ...{ descendants: false }, isSignal: true }] }], yAxis: [{ type: i0.ContentChild, args: [i0.forwardRef(() => MiraYAxis), { ...{ descendants: false }, isSignal: true }] }], legend: [{ type: i0.ContentChild, args: [i0.forwardRef(() => ChartLegend), { ...{ descendants: false }, isSignal: true }] }], svg: [{ type: i0.ViewChild, args: ['svg', { isSignal: true }] }] } });
|
|
1122
820
|
function sameSize(a, b) {
|
|
1123
821
|
return a?.width === b?.width && a?.height === b?.height;
|
|
1124
822
|
}
|
|
@@ -1567,6 +1265,337 @@ function beside(before, after, size, start, length) {
|
|
|
1567
1265
|
return Math.max(start, Math.min(after, end - size));
|
|
1568
1266
|
}
|
|
1569
1267
|
|
|
1268
|
+
/**
|
|
1269
|
+
* Marks a template of your own for what each item of `<mira-legend>` shows,
|
|
1270
|
+
* in place of its icon and its name. It flows as text inside the item, which
|
|
1271
|
+
* stays the legend's: in a toggleable legend, a button, marked `aria-pressed`,
|
|
1272
|
+
* that hides or shows the series. A hidden series' item takes a gray color,
|
|
1273
|
+
* which your template can keep or set its own from `item.hidden`. Its context
|
|
1274
|
+
* is a `LegendItemContext`, and typed: `let-item` holds the series' `name`,
|
|
1275
|
+
* `color`, `icon` and `hidden`.
|
|
1276
|
+
*
|
|
1277
|
+
* Screen readers read the template's text out, as the button's name in a
|
|
1278
|
+
* toggleable legend:
|
|
1279
|
+
*
|
|
1280
|
+
* - keep the series' name in it, the same whether the series is hidden or
|
|
1281
|
+
* not, and show the state in the look: the button already tells it;
|
|
1282
|
+
* - mark what only decorates, such as a swatch or an emoji,
|
|
1283
|
+
* `aria-hidden="true"`;
|
|
1284
|
+
* - in a toggleable legend, put no buttons or links in it, as it's inside a
|
|
1285
|
+
* button.
|
|
1286
|
+
*
|
|
1287
|
+
* Forced colors replace the colors you set, and print drops backgrounds by
|
|
1288
|
+
* default: give what shows the series' color `forced-color-adjust: none` and
|
|
1289
|
+
* `print-color-adjust: exact`, as the legend's own icons have.
|
|
1290
|
+
*
|
|
1291
|
+
* @example
|
|
1292
|
+
* ```html
|
|
1293
|
+
* <mira-legend>
|
|
1294
|
+
* <ng-template miraLegendItemContent let-item>
|
|
1295
|
+
* <span
|
|
1296
|
+
* aria-hidden="true"
|
|
1297
|
+
* [style.color]="item.hidden ? null : item.color"
|
|
1298
|
+
* >●</span>
|
|
1299
|
+
* <b>{{ item.name }}</b>
|
|
1300
|
+
* </ng-template>
|
|
1301
|
+
* </mira-legend>
|
|
1302
|
+
* ```
|
|
1303
|
+
*/
|
|
1304
|
+
class MiraLegendItemContent {
|
|
1305
|
+
/**
|
|
1306
|
+
* Types the template's context, for Angular's template checks.
|
|
1307
|
+
*
|
|
1308
|
+
* @internal
|
|
1309
|
+
*/
|
|
1310
|
+
static ngTemplateContextGuard(directive, context) {
|
|
1311
|
+
return true;
|
|
1312
|
+
}
|
|
1313
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.35", ngImport: i0, type: MiraLegendItemContent, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
1314
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "20.3.35", type: MiraLegendItemContent, isStandalone: true, selector: "ng-template[miraLegendItemContent]", ngImport: i0 });
|
|
1315
|
+
}
|
|
1316
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.35", ngImport: i0, type: MiraLegendItemContent, decorators: [{
|
|
1317
|
+
type: Directive,
|
|
1318
|
+
args: [{ selector: 'ng-template[miraLegendItemContent]' }]
|
|
1319
|
+
}] });
|
|
1320
|
+
// The height of a legend of one row along the top or the bottom, as its
|
|
1321
|
+
// styles lay it out in the browser's default font size, in px: the row and
|
|
1322
|
+
// the room beside it for the focus ring. The plot leaves it until the legend
|
|
1323
|
+
// is measured, on the server.
|
|
1324
|
+
const ROW_HEIGHT = 22;
|
|
1325
|
+
/**
|
|
1326
|
+
* Lists the chart's series along one of its edges, in the order they're
|
|
1327
|
+
* written, each with its icon in its color and its name: a stretch of line
|
|
1328
|
+
* marks a line, a square marks bars, and a circle any other series (the
|
|
1329
|
+
* series' `legendIcon`). A series is called by its `name`, or its `dataKey`
|
|
1330
|
+
* without one. The plot leaves room for the legend, as it does for the axes,
|
|
1331
|
+
* and the chart stays as big as it is.
|
|
1332
|
+
*
|
|
1333
|
+
* Along the bottom, by default, or the top, the items go in rows, centered,
|
|
1334
|
+
* as many as they take. Up the right or the left side, they go in a column in
|
|
1335
|
+
* the middle of the chart's height, at most 40% of its width wide, where a
|
|
1336
|
+
* longer name wraps. Left and right are as the svg is drawn, in a page that
|
|
1337
|
+
* runs right to left too, where the y axis stays on the left. A legend on a
|
|
1338
|
+
* side leaves the plot no room on the server: its width is known only once
|
|
1339
|
+
* the browser lays it out.
|
|
1340
|
+
*
|
|
1341
|
+
* It's a list to read, unless it's `toggleable`: then each item is a button
|
|
1342
|
+
* that hides its series, or shows it again, and the chart fits its y axis to
|
|
1343
|
+
* the series that are left. The state is the series' own `hidden`, to bind
|
|
1344
|
+
* as `[(hidden)]`. A hidden series' item stays, grayed and struck through.
|
|
1345
|
+
* In a toggleable legend it's marked `aria-pressed="false"` for screen
|
|
1346
|
+
* readers; in a list to read, screen readers and the keyboard skip it, as the
|
|
1347
|
+
* chart doesn't draw it.
|
|
1348
|
+
*
|
|
1349
|
+
* The legend's text takes the `color` around it, the chart's in a chart. The
|
|
1350
|
+
* rest are CSS custom properties, to set anywhere above the legend:
|
|
1351
|
+
*
|
|
1352
|
+
* - `--mira-font-size`: the size of the text, `0.75rem` by default; the room
|
|
1353
|
+
* around the text follows it;
|
|
1354
|
+
* - `--mira-legend-inactive-color`: a hidden series' item,
|
|
1355
|
+
* `--mira-axis-color` by default.
|
|
1356
|
+
*
|
|
1357
|
+
* For items that show something of your own, write their template inside, as
|
|
1358
|
+
* an `<ng-template miraLegendItemContent>`, and import `MiraLegendItemContent`
|
|
1359
|
+
* along with `MiraLegend`: without it, the template goes unnoticed, and the
|
|
1360
|
+
* legend shows its own icon and name.
|
|
1361
|
+
*
|
|
1362
|
+
* Anywhere else on the page, name the chart with `for`. There the legend sits
|
|
1363
|
+
* where the page puts it, as a block, and the chart leaves it no room; its
|
|
1364
|
+
* `position` only picks its layout, rows for the top or the bottom, a column
|
|
1365
|
+
* for a side. Its colors come from above it, as in a chart: set the custom
|
|
1366
|
+
* properties above both to change them alike.
|
|
1367
|
+
*
|
|
1368
|
+
* @example
|
|
1369
|
+
* ```html
|
|
1370
|
+
* <mira-line-chart [data]="day">
|
|
1371
|
+
* <mira-x-axis dataKey="hour" />
|
|
1372
|
+
* <mira-y-axis />
|
|
1373
|
+
* <mira-line dataKey="solar" name="Solar" stroke="#d97706" />
|
|
1374
|
+
* <mira-line dataKey="usage" name="Usage" stroke="#3b82f6" />
|
|
1375
|
+
* <mira-legend position="right" toggleable />
|
|
1376
|
+
* </mira-line-chart>
|
|
1377
|
+
* ```
|
|
1378
|
+
*
|
|
1379
|
+
* ```html
|
|
1380
|
+
* <header>
|
|
1381
|
+
* <h2>A sunny day</h2>
|
|
1382
|
+
* <mira-legend [for]="chart" />
|
|
1383
|
+
* </header>
|
|
1384
|
+
* <mira-line-chart #chart [data]="day">…</mira-line-chart>
|
|
1385
|
+
* ```
|
|
1386
|
+
*/
|
|
1387
|
+
class MiraLegend {
|
|
1388
|
+
/** The edge of the chart the legend sits along: `'bottom'` by default. */
|
|
1389
|
+
position = input('bottom', ...(ngDevMode ? [{ debugName: "position" }] : []));
|
|
1390
|
+
/**
|
|
1391
|
+
* Whether a click on an item, or Enter or Space on it, hides its series or
|
|
1392
|
+
* shows it again. Off by default: the legend is then a list to read.
|
|
1393
|
+
*/
|
|
1394
|
+
toggleable = input(false, ...(ngDevMode ? [{ debugName: "toggleable", transform: booleanAttribute }] : [{ transform: booleanAttribute }]));
|
|
1395
|
+
/**
|
|
1396
|
+
* The chart whose series the legend lists, for a legend out of it: give
|
|
1397
|
+
* the chart a reference, `<mira-line-chart #chart>`, and name it,
|
|
1398
|
+
* `<mira-legend [for]="chart" />`. Unset, the chart the legend is in. With
|
|
1399
|
+
* no chart, as while a chart named through a query is in an `@if` that's
|
|
1400
|
+
* off, the legend lists nothing.
|
|
1401
|
+
*/
|
|
1402
|
+
for = input(...(ngDevMode ? [undefined, { debugName: "for" }] : []));
|
|
1403
|
+
/**
|
|
1404
|
+
* The room the legend takes from the chart along its edge, in px: its
|
|
1405
|
+
* height along the top or the bottom, its width up a side, as the browser
|
|
1406
|
+
* last laid it out there. Until then, a row's height along the top or the
|
|
1407
|
+
* bottom, and none on a side.
|
|
1408
|
+
*
|
|
1409
|
+
* @internal
|
|
1410
|
+
*/
|
|
1411
|
+
room = computed(() => this.#measured() ?? (inRows(this.position()) ? ROW_HEIGHT : 0), ...(ngDevMode ? [{ debugName: "room" }] : []));
|
|
1412
|
+
// Where the legend sits: at an edge of the chart it's in. Out of a chart,
|
|
1413
|
+
// where the page puts it.
|
|
1414
|
+
placement = computed(() => this.#parent ? this.position() : null, ...(ngDevMode ? [{ debugName: "placement" }] : []));
|
|
1415
|
+
// How it lays out its items: in rows, or in a column.
|
|
1416
|
+
layout = computed(() => inRows(this.position()) ? 'rows' : 'column', ...(ngDevMode ? [{ debugName: "layout" }] : []));
|
|
1417
|
+
// What the legend lists: each series of the chart it names, or of the one
|
|
1418
|
+
// it's in, hidden ones too.
|
|
1419
|
+
entries = computed(() => {
|
|
1420
|
+
const all = (this.for() ?? this.#parent)?.series() ?? [];
|
|
1421
|
+
return all.flatMap((series) => {
|
|
1422
|
+
const name = nameOf(series);
|
|
1423
|
+
if (name === null)
|
|
1424
|
+
return [];
|
|
1425
|
+
const item = {
|
|
1426
|
+
name,
|
|
1427
|
+
color: series.color(),
|
|
1428
|
+
icon: series.legendIcon,
|
|
1429
|
+
hidden: series.hidden(),
|
|
1430
|
+
};
|
|
1431
|
+
return { series, item };
|
|
1432
|
+
});
|
|
1433
|
+
}, ...(ngDevMode ? [{ debugName: "entries" }] : []));
|
|
1434
|
+
// A template of your own for the items, if there's one.
|
|
1435
|
+
template = contentChild(MiraLegendItemContent, ...(ngDevMode ? [{ debugName: "template", read: TemplateRef }] : [{
|
|
1436
|
+
read: TemplateRef,
|
|
1437
|
+
}]));
|
|
1438
|
+
#host = inject(ElementRef).nativeElement;
|
|
1439
|
+
// The chart the legend is in, if it's in one.
|
|
1440
|
+
#parent = inject(CartesianContext, { optional: true });
|
|
1441
|
+
// The room the legend took, as the browser last laid it out: none yet on a
|
|
1442
|
+
// side it has just moved to, which the old room says nothing about.
|
|
1443
|
+
#measured = linkedSignal(...(ngDevMode ? [{ debugName: "#measured", source: this.position,
|
|
1444
|
+
computation: () => null }] : [{
|
|
1445
|
+
source: this.position,
|
|
1446
|
+
computation: () => null,
|
|
1447
|
+
}]));
|
|
1448
|
+
/** @internal */
|
|
1449
|
+
constructor() {
|
|
1450
|
+
const parent = this.#parent;
|
|
1451
|
+
const destroyRef = inject(DestroyRef);
|
|
1452
|
+
// Out of a chart, there's no room to leave the legend, and nothing to
|
|
1453
|
+
// measure.
|
|
1454
|
+
if (!parent)
|
|
1455
|
+
return;
|
|
1456
|
+
// The legend is measured after a render that changes what it lists, how
|
|
1457
|
+
// it shows it, its side, or the chart's size, which can wrap it onto more
|
|
1458
|
+
// rows or fewer; and the plot leaves it room before the page is painted.
|
|
1459
|
+
afterRenderEffect({
|
|
1460
|
+
earlyRead: () => {
|
|
1461
|
+
this.entries();
|
|
1462
|
+
this.template();
|
|
1463
|
+
parent.size();
|
|
1464
|
+
return this.#measure();
|
|
1465
|
+
},
|
|
1466
|
+
write: (room) => this.#measured.set(room()),
|
|
1467
|
+
});
|
|
1468
|
+
// And again whenever it changes size on its own, as when a font loads,
|
|
1469
|
+
// or an item of your own that changes, padding and border included: then
|
|
1470
|
+
// the plot follows a frame later.
|
|
1471
|
+
afterNextRender(() => {
|
|
1472
|
+
const observer = new ResizeObserver(() => this.#measured.set(this.#measure()));
|
|
1473
|
+
observer.observe(this.#host, { box: 'border-box' });
|
|
1474
|
+
destroyRef.onDestroy(() => observer.disconnect());
|
|
1475
|
+
});
|
|
1476
|
+
}
|
|
1477
|
+
// Hides the series, or shows it again.
|
|
1478
|
+
toggle(series) {
|
|
1479
|
+
series.hidden.update((hidden) => !hidden);
|
|
1480
|
+
}
|
|
1481
|
+
// The room the legend takes along its edge as laid out, in the svg's px: a
|
|
1482
|
+
// transform on the page around the chart scales both alike.
|
|
1483
|
+
#measure() {
|
|
1484
|
+
const { offsetWidth, offsetHeight } = this.#host;
|
|
1485
|
+
return inRows(this.position()) ? offsetHeight : offsetWidth;
|
|
1486
|
+
}
|
|
1487
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.35", ngImport: i0, type: MiraLegend, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
1488
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.3.35", type: MiraLegend, isStandalone: true, selector: "mira-legend", inputs: { position: { classPropertyName: "position", publicName: "position", isSignal: true, isRequired: false, transformFunction: null }, toggleable: { classPropertyName: "toggleable", publicName: "toggleable", isSignal: true, isRequired: false, transformFunction: null }, for: { classPropertyName: "for", publicName: "for", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "attr.data-position": "placement()", "attr.data-layout": "layout()" } }, providers: [
|
|
1489
|
+
{ provide: ChartLegend, useExisting: forwardRef(() => MiraLegend) },
|
|
1490
|
+
], queries: [{ propertyName: "template", first: true, predicate: MiraLegendItemContent, descendants: true, read: TemplateRef, isSignal: true }], ngImport: i0, template: `
|
|
1491
|
+
<ul class="mira-legend" role="list">
|
|
1492
|
+
@for (entry of entries(); track entry.series) {
|
|
1493
|
+
<li
|
|
1494
|
+
[attr.data-hidden]="entry.item.hidden || null"
|
|
1495
|
+
[attr.inert]="entry.item.hidden && !toggleable() ? '' : null"
|
|
1496
|
+
>
|
|
1497
|
+
@if (toggleable()) {
|
|
1498
|
+
<button
|
|
1499
|
+
type="button"
|
|
1500
|
+
class="mira-legend-item"
|
|
1501
|
+
[attr.aria-pressed]="!entry.item.hidden"
|
|
1502
|
+
(click)="toggle(entry.series)"
|
|
1503
|
+
>
|
|
1504
|
+
<ng-container
|
|
1505
|
+
[ngTemplateOutlet]="template() ?? own"
|
|
1506
|
+
[ngTemplateOutletContext]="{ $implicit: entry.item }"
|
|
1507
|
+
/>
|
|
1508
|
+
</button>
|
|
1509
|
+
} @else {
|
|
1510
|
+
<ng-container
|
|
1511
|
+
[ngTemplateOutlet]="template() ?? own"
|
|
1512
|
+
[ngTemplateOutletContext]="{ $implicit: entry.item }"
|
|
1513
|
+
/>
|
|
1514
|
+
}
|
|
1515
|
+
</li>
|
|
1516
|
+
}
|
|
1517
|
+
</ul>
|
|
1518
|
+
|
|
1519
|
+
<ng-template #own let-item>
|
|
1520
|
+
<span class="mira-legend-label">
|
|
1521
|
+
<span
|
|
1522
|
+
class="mira-legend-icon"
|
|
1523
|
+
[attr.data-icon]="item.icon"
|
|
1524
|
+
[style.color]="item.hidden ? null : item.color"
|
|
1525
|
+
></span>
|
|
1526
|
+
<span class="mira-legend-name">{{ item.name }}</span>
|
|
1527
|
+
</span>
|
|
1528
|
+
</ng-template>
|
|
1529
|
+
`, 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", ":host{display:block}:host([data-position]){position:absolute}:host([data-position=\"top\"]){inset:0 0 auto}:host([data-position=\"bottom\"]){inset:auto 0 0}:host([data-position=\"left\"]){inset:0 auto 0 0}:host([data-position=\"right\"]){inset:0 0 0 auto}:host([data-position=\"left\"]),:host([data-position=\"right\"]){display:flex;align-items:center;align-items:safe center;max-width:40%}.mira-legend{display:flex;flex-wrap:wrap;justify-content:center;justify-content:safe center;gap:max(.5em,24px - 1.5em) 1.25em;margin:0;padding:0 .75em;list-style:none;font-size:var(--mira-font-size, .75rem);line-height:1.5;overflow-wrap:anywhere}:host([data-position=\"top\"]) .mira-legend{padding-top:4px}:host([data-position=\"bottom\"]) .mira-legend{padding-bottom:4px}:host([data-layout=\"column\"]) .mira-legend{flex-direction:column;align-items:flex-start}:host([data-position]) li{pointer-events:auto}.mira-legend-item{all:unset;display:block;cursor:pointer}.mira-legend-item:focus-visible{outline:revert;outline-offset:2px}li[data-hidden]{color:var(--mira-legend-inactive-color, var(--_mira-axis-color))}li[data-hidden] .mira-legend-name{text-decoration:line-through}@media(forced-colors:active){li[data-hidden]{color:GrayText}}.mira-legend-label{display:flex;gap:.5em}.mira-legend-icon{display:grid;flex:none;place-items:center;width:1em;height:1.5em;forced-color-adjust:none;-webkit-print-color-adjust:exact;print-color-adjust:exact}.mira-legend-icon:before{content:\"\";width:.75em;height:.75em;border-radius:50%;background:currentColor}.mira-legend-icon[data-icon=square]:before{border-radius:.125em}.mira-legend-icon[data-icon=line]:before{width:100%;height:2px;border-radius:0}\n"], dependencies: [{ kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
1530
|
+
}
|
|
1531
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.35", ngImport: i0, type: MiraLegend, decorators: [{
|
|
1532
|
+
type: Component,
|
|
1533
|
+
args: [{ selector: 'mira-legend', changeDetection: ChangeDetectionStrategy.OnPush, imports: [NgTemplateOutlet], providers: [
|
|
1534
|
+
{ provide: ChartLegend, useExisting: forwardRef(() => MiraLegend) },
|
|
1535
|
+
], host: {
|
|
1536
|
+
'[attr.data-position]': 'placement()',
|
|
1537
|
+
'[attr.data-layout]': 'layout()',
|
|
1538
|
+
}, template: `
|
|
1539
|
+
<ul class="mira-legend" role="list">
|
|
1540
|
+
@for (entry of entries(); track entry.series) {
|
|
1541
|
+
<li
|
|
1542
|
+
[attr.data-hidden]="entry.item.hidden || null"
|
|
1543
|
+
[attr.inert]="entry.item.hidden && !toggleable() ? '' : null"
|
|
1544
|
+
>
|
|
1545
|
+
@if (toggleable()) {
|
|
1546
|
+
<button
|
|
1547
|
+
type="button"
|
|
1548
|
+
class="mira-legend-item"
|
|
1549
|
+
[attr.aria-pressed]="!entry.item.hidden"
|
|
1550
|
+
(click)="toggle(entry.series)"
|
|
1551
|
+
>
|
|
1552
|
+
<ng-container
|
|
1553
|
+
[ngTemplateOutlet]="template() ?? own"
|
|
1554
|
+
[ngTemplateOutletContext]="{ $implicit: entry.item }"
|
|
1555
|
+
/>
|
|
1556
|
+
</button>
|
|
1557
|
+
} @else {
|
|
1558
|
+
<ng-container
|
|
1559
|
+
[ngTemplateOutlet]="template() ?? own"
|
|
1560
|
+
[ngTemplateOutletContext]="{ $implicit: entry.item }"
|
|
1561
|
+
/>
|
|
1562
|
+
}
|
|
1563
|
+
</li>
|
|
1564
|
+
}
|
|
1565
|
+
</ul>
|
|
1566
|
+
|
|
1567
|
+
<ng-template #own let-item>
|
|
1568
|
+
<span class="mira-legend-label">
|
|
1569
|
+
<span
|
|
1570
|
+
class="mira-legend-icon"
|
|
1571
|
+
[attr.data-icon]="item.icon"
|
|
1572
|
+
[style.color]="item.hidden ? null : item.color"
|
|
1573
|
+
></span>
|
|
1574
|
+
<span class="mira-legend-name">{{ item.name }}</span>
|
|
1575
|
+
</span>
|
|
1576
|
+
</ng-template>
|
|
1577
|
+
`, 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", ":host{display:block}:host([data-position]){position:absolute}:host([data-position=\"top\"]){inset:0 0 auto}:host([data-position=\"bottom\"]){inset:auto 0 0}:host([data-position=\"left\"]){inset:0 auto 0 0}:host([data-position=\"right\"]){inset:0 0 0 auto}:host([data-position=\"left\"]),:host([data-position=\"right\"]){display:flex;align-items:center;align-items:safe center;max-width:40%}.mira-legend{display:flex;flex-wrap:wrap;justify-content:center;justify-content:safe center;gap:max(.5em,24px - 1.5em) 1.25em;margin:0;padding:0 .75em;list-style:none;font-size:var(--mira-font-size, .75rem);line-height:1.5;overflow-wrap:anywhere}:host([data-position=\"top\"]) .mira-legend{padding-top:4px}:host([data-position=\"bottom\"]) .mira-legend{padding-bottom:4px}:host([data-layout=\"column\"]) .mira-legend{flex-direction:column;align-items:flex-start}:host([data-position]) li{pointer-events:auto}.mira-legend-item{all:unset;display:block;cursor:pointer}.mira-legend-item:focus-visible{outline:revert;outline-offset:2px}li[data-hidden]{color:var(--mira-legend-inactive-color, var(--_mira-axis-color))}li[data-hidden] .mira-legend-name{text-decoration:line-through}@media(forced-colors:active){li[data-hidden]{color:GrayText}}.mira-legend-label{display:flex;gap:.5em}.mira-legend-icon{display:grid;flex:none;place-items:center;width:1em;height:1.5em;forced-color-adjust:none;-webkit-print-color-adjust:exact;print-color-adjust:exact}.mira-legend-icon:before{content:\"\";width:.75em;height:.75em;border-radius:50%;background:currentColor}.mira-legend-icon[data-icon=square]:before{border-radius:.125em}.mira-legend-icon[data-icon=line]:before{width:100%;height:2px;border-radius:0}\n"] }]
|
|
1578
|
+
}], ctorParameters: () => [], propDecorators: { position: [{ type: i0.Input, args: [{ isSignal: true, alias: "position", required: false }] }], toggleable: [{ type: i0.Input, args: [{ isSignal: true, alias: "toggleable", required: false }] }], for: [{ type: i0.Input, args: [{ isSignal: true, alias: "for", required: false }] }], template: [{ type: i0.ContentChild, args: [i0.forwardRef(() => MiraLegendItemContent), { ...{
|
|
1579
|
+
read: TemplateRef,
|
|
1580
|
+
}, isSignal: true }] }] } });
|
|
1581
|
+
// What the series is called, or null while it has no `dataKey` yet. Angular
|
|
1582
|
+
// binds a series' inputs as it checks the block the series is written in,
|
|
1583
|
+
// and a legend in a block it checks before reads the series first: such a
|
|
1584
|
+
// series joins the list as soon as its inputs are bound, in the same pass.
|
|
1585
|
+
function nameOf(series) {
|
|
1586
|
+
try {
|
|
1587
|
+
return series.displayName();
|
|
1588
|
+
}
|
|
1589
|
+
catch {
|
|
1590
|
+
return null;
|
|
1591
|
+
}
|
|
1592
|
+
}
|
|
1593
|
+
// Whether a legend on this side lists its items in rows, rather than in a
|
|
1594
|
+
// column.
|
|
1595
|
+
function inRows(side) {
|
|
1596
|
+
return side === 'top' || side === 'bottom';
|
|
1597
|
+
}
|
|
1598
|
+
|
|
1570
1599
|
/**
|
|
1571
1600
|
* The providers of a kind of cartesian chart: under `MiraCartesianChart`, for
|
|
1572
1601
|
* layers of your own, and under the context the library's layers inject.
|