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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  import * as i0 from '@angular/core';
2
- import { viewChild, TemplateRef, Directive, input, numberAttribute, inject, computed, forwardRef, ChangeDetectionStrategy, Component, LOCALE_ID, contentChildren, contentChild, signal, ElementRef, DestroyRef, afterNextRender, booleanAttribute, afterRenderEffect } from '@angular/core';
2
+ import { viewChild, TemplateRef, Directive, input, model, computed, booleanAttribute, contentChild, inject, ElementRef, linkedSignal, DestroyRef, afterRenderEffect, afterNextRender, ChangeDetectionStrategy, Component, numberAttribute, forwardRef, LOCALE_ID, contentChildren, signal } from '@angular/core';
3
3
  import { NgTemplateOutlet } from '@angular/common';
4
4
 
5
5
  /**
@@ -51,7 +51,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.35", ngImpo
51
51
  /**
52
52
  * A layer that plots the values under a key of the chart's data: a line or
53
53
  * bars now, areas later. The chart fits its y axis to the values of all its
54
- * series, whatever kind they are.
54
+ * series that aren't hidden, whatever kind they are.
55
55
  *
56
56
  * A series extends this class, and provides itself under it as well as under
57
57
  * {@link MiraChartLayer}. It also implements `color`, the color it's drawn
@@ -61,16 +61,36 @@ class MiraSeries extends MiraChartLayer {
61
61
  /** The key of the values to plot. */
62
62
  dataKey = input.required(...(ngDevMode ? [{ debugName: "dataKey" }] : []));
63
63
  /**
64
- * What the tooltip calls the series. Unset, the tooltip calls it by its
65
- * `dataKey`.
64
+ * What the tooltip and the legend call the series. Unset, they call it by
65
+ * its `dataKey`.
66
66
  */
67
67
  name = input(...(ngDevMode ? [undefined, { debugName: "name" }] : []));
68
+ /**
69
+ * Whether the series is hidden: the chart doesn't draw it, fits its y axis
70
+ * to the series that aren't, and leaves it out of the tooltip; the bars of
71
+ * the visible series share its room in the band. Shown by default. A click
72
+ * on its item in a toggleable legend toggles it. Write `[hidden]="true"`,
73
+ * not a bare `hidden`, to start hidden, or `[(hidden)]` to keep the state in
74
+ * your app. An app that sets the state after a click binds it both ways: a
75
+ * one-way binding takes effect only when its own value changes, so setting
76
+ * the value it last set does nothing.
77
+ */
78
+ hidden = model(false, ...(ngDevMode ? [{ debugName: "hidden" }] : []));
79
+ /** What the series is called: its `name`, or its `dataKey` without one. */
80
+ displayName = computed(() => this.name() ?? this.dataKey(), ...(ngDevMode ? [{ debugName: "displayName" }] : []));
81
+ /**
82
+ * The shape that marks the series in the legend: `'line'` for a line,
83
+ * `'square'` for bars, and `'circle'` by default. A series of your own picks
84
+ * the shape that looks like what it draws by overriding the field:
85
+ * `override readonly legendIcon: LegendIcon = 'square'`.
86
+ */
87
+ legendIcon = 'circle';
68
88
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.35", ngImport: i0, type: MiraSeries, deps: null, target: i0.ɵɵFactoryTarget.Directive });
69
- static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "20.3.35", type: MiraSeries, isStandalone: true, inputs: { dataKey: { classPropertyName: "dataKey", publicName: "dataKey", isSignal: true, isRequired: true, transformFunction: null }, name: { classPropertyName: "name", publicName: "name", isSignal: true, isRequired: false, transformFunction: null } }, usesInheritance: true, ngImport: i0 });
89
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "20.3.35", type: MiraSeries, isStandalone: true, inputs: { dataKey: { classPropertyName: "dataKey", publicName: "dataKey", isSignal: true, isRequired: true, transformFunction: null }, name: { classPropertyName: "name", publicName: "name", isSignal: true, isRequired: false, transformFunction: null }, hidden: { classPropertyName: "hidden", publicName: "hidden", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { hidden: "hiddenChange" }, usesInheritance: true, ngImport: i0 });
70
90
  }
71
91
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.35", ngImport: i0, type: MiraSeries, decorators: [{
72
92
  type: Directive
73
- }], propDecorators: { dataKey: [{ type: i0.Input, args: [{ isSignal: true, alias: "dataKey", required: true }] }], name: [{ type: i0.Input, args: [{ isSignal: true, alias: "name", required: false }] }] } });
93
+ }], propDecorators: { dataKey: [{ type: i0.Input, args: [{ isSignal: true, alias: "dataKey", required: true }] }], name: [{ type: i0.Input, args: [{ isSignal: true, alias: "name", required: false }] }], hidden: [{ type: i0.Input, args: [{ isSignal: true, alias: "hidden", required: false }] }, { type: i0.Output, args: ["hiddenChange"] }] } });
74
94
 
75
95
  /**
76
96
  * Styles every chart takes: the colors its layers draw with, for a light page
@@ -278,19 +298,346 @@ function ticksBetween([min, max], increment) {
278
298
  */
279
299
  const DEFAULT_TICK_COUNT = 5;
280
300
  /**
281
- * What the parts of a chart with an x and a y axis, its layers and its
282
- * tooltip, draw by: the data, the series, the plot area, the scales, the
283
- * labels along x, and the pointer and the datum under it. Every kind of chart
284
- * provides itself under it, with `provideCartesianChart`, and the library's
285
- * own parts inject it: they can't import the chart, which imports the axes to
286
- * leave room for them. The way Angular Material's tabs inject
287
- * `MAT_TAB_GROUP`.
301
+ * What the parts of a chart with an x and a y axis, its layers, its tooltip
302
+ * and its legend, draw by: the data, the series, the size, the plot area, the
303
+ * scales, the labels along x, and the pointer and the datum under it. Every
304
+ * kind of chart provides itself under it, with `provideCartesianChart`, and
305
+ * the library's own parts inject it: they can't import the chart, which
306
+ * imports the axes and the legend to leave room for them. The way Angular
307
+ * Material's tabs inject `MAT_TAB_GROUP`.
288
308
  *
289
309
  * @internal
290
310
  */
291
311
  class CartesianContext {
292
312
  }
293
313
 
314
+ /**
315
+ * Marks a template of your own for what each item of `<mira-legend>` shows,
316
+ * in place of its icon and its name. It flows as text inside the item, which
317
+ * stays the legend's: in a toggleable legend, a button, marked `aria-pressed`,
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.
332
+ *
333
+ * Forced colors replace the colors you set, and print drops backgrounds by
334
+ * default: give what shows the series' color `forced-color-adjust: none` and
335
+ * `print-color-adjust: exact`, as the legend's own icons have.
336
+ *
337
+ * @example
338
+ * ```html
339
+ * <mira-legend>
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>
348
+ * ```
349
+ */
350
+ class MiraLegendItemContent {
351
+ /**
352
+ * Types the template's context, for Angular's template checks.
353
+ *
354
+ * @internal
355
+ */
356
+ static ngTemplateContextGuard(directive, context) {
357
+ return true;
358
+ }
359
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.35", ngImport: i0, type: MiraLegendItemContent, deps: [], target: i0.ɵɵFactoryTarget.Directive });
360
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "20.3.35", type: MiraLegendItemContent, isStandalone: true, selector: "ng-template[miraLegendItemContent]", ngImport: i0 });
361
+ }
362
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.35", ngImport: i0, type: MiraLegendItemContent, decorators: [{
363
+ type: Directive,
364
+ args: [{ selector: 'ng-template[miraLegendItemContent]' }]
365
+ }] });
366
+ // The height of a legend of one row along the top or the bottom, as its
367
+ // styles lay it out in the browser's default font size, in px: the row and
368
+ // the room beside it for the focus ring. The plot leaves it until the legend
369
+ // is measured, on the server.
370
+ const ROW_HEIGHT = 22;
371
+ /**
372
+ * Lists the chart's series along one of its edges, in the order they're
373
+ * written, each with its icon in its color and its name: a stretch of line
374
+ * marks a line, a square marks bars, and a circle any other series (the
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.
413
+ *
414
+ * @example
415
+ * ```html
416
+ * <mira-line-chart [data]="day">
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>
431
+ * ```
432
+ */
433
+ class MiraLegend {
434
+ /** The edge of the chart the legend sits along: `'bottom'` by default. */
435
+ position = input('bottom', ...(ngDevMode ? [{ debugName: "position" }] : []));
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" }] : []));
449
+ /**
450
+ * The room the legend takes from the chart along its edge, in px: its
451
+ * height along the top or the bottom, its width up a side, as the browser
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
456
+ */
457
+ room = computed(() => this.#measured() ?? (inRows(this.position()) ? ROW_HEIGHT : 0), ...(ngDevMode ? [{ debugName: "room" }] : []));
458
+ // Where the legend sits: at an edge of the chart it's in. Out of a chart,
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
+
294
641
  /**
295
642
  * The category axis under the plot: a tick per datum, labelled with the
296
643
  * datum's value under `dataKey`. Its line runs at zero, where values rise and
@@ -379,8 +726,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.35", ngImpo
379
726
 
380
727
  /**
381
728
  * The value axis left of the plot. It fits the values of every series in the
382
- * chart, and zero, rounded out to round ticks. The ticks read as numbers in
383
- * the app's locale (`LOCALE_ID`).
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`).
384
731
  *
385
732
  * @example
386
733
  * ```html
@@ -470,9 +817,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.35", ngImpo
470
817
 
471
818
  /**
472
819
  * The template of every chart with an x and a y axis: an svg with the
473
- * chart's layers in it, in the order they're written, each in an outlet of
474
- * its own; and over the svg, the chart's content itself, for what it shows in
475
- * HTML, such as the tooltip. A chart that takes it imports `LayerOutlet`.
820
+ * chart's layers in it, less the hidden series, in the order they're
821
+ * written, each in an outlet of its own; and over the svg, the chart's
822
+ * content itself, for what it shows in HTML, such as the tooltip and the
823
+ * legend. A chart that takes it imports `LayerOutlet`.
476
824
  *
477
825
  * @internal
478
826
  */
@@ -486,7 +834,7 @@ const CARTESIAN_CHART_TEMPLATE = `
486
834
  [attr.viewBox]="viewBox()"
487
835
  [attr.aria-label]="ariaLabel() ?? null"
488
836
  >
489
- @for (layer of layers(); track layer) {
837
+ @for (layer of drawnLayers(); track layer) {
490
838
  <svg:g [miraLayerOutlet]="layer.template()" />
491
839
  }
492
840
  </svg>
@@ -521,10 +869,12 @@ const CARTESIAN_CHART_STYLES = [
521
869
  }
522
870
 
523
871
  /* Positioned, so its HTML can be placed in the svg's px, and clear for
524
- the pointer, which the svg tracks. */
872
+ the pointer, which the svg tracks. Isolated, so what's stacked in it,
873
+ the tooltip over the legend, stays stacked within the chart. */
525
874
  .mira-chart-overlay {
526
875
  position: relative;
527
876
  pointer-events: none;
877
+ isolation: isolate;
528
878
  }
529
879
  `,
530
880
  ];
@@ -535,9 +885,9 @@ const FALLBACK_SIZE = { width: 600, height: 300 };
535
885
  /**
536
886
  * What every chart with an x and a y axis has, whatever its series: data, a
537
887
  * size, a margin, the plot area they leave, a y scale that fits the values of
538
- * its series, a label for each datum, and the pointer and the datum under it.
539
- * Nothing about a kind of chart: a line chart extends it with a point per
540
- * datum along x, and a bar chart with a band per datum.
888
+ * its visible series, a label for each datum, and the pointer and the datum
889
+ * under it. Nothing about a kind of chart: a line chart extends it with a
890
+ * point per datum along x, and a bar chart with a band per datum.
541
891
  *
542
892
  * Inject it in a layer of your own ({@link MiraChartLayer}) to draw where the
543
893
  * series are, or in a component of your own that shows something in HTML:
@@ -591,10 +941,17 @@ class MiraCartesianChart {
591
941
  height: this.height() ?? (measured?.height || FALLBACK_SIZE.height),
592
942
  };
593
943
  }, ...(ngDevMode ? [{ debugName: "size", equal: sameSize }] : [{ equal: sameSize }]));
594
- /** Where the series are drawn: the chart less its margin and its axes. */
944
+ /**
945
+ * Where the series are drawn: the chart less its margin, its axes and its
946
+ * legend.
947
+ */
595
948
  plot = computed(() => {
596
949
  const { width, height } = this.size();
597
950
  const margin = { ...DEFAULT_MARGIN, ...this.margin() };
951
+ const legend = this.legend();
952
+ // The legend takes its room at the edge it sits along, outside the margin.
953
+ if (legend)
954
+ margin[legend.position()] += legend.room();
598
955
  const left = margin.left + (this.yAxis()?.width() ?? 0);
599
956
  const bottom = margin.bottom + (this.xAxis()?.height() ?? 0);
600
957
  return {
@@ -663,16 +1020,22 @@ class MiraCartesianChart {
663
1020
  label: this.xLabels()[index],
664
1021
  };
665
1022
  }, ...(ngDevMode ? [{ debugName: "active" }] : []));
1023
+ /** The series, of whatever kind, in the order they're written, hidden too. */
1024
+ series = contentChildren(MiraSeries, ...(ngDevMode ? [{ debugName: "series" }] : []));
666
1025
  /**
667
- * The series, of whatever kind, in the order they're written: the y axis
668
- * fits all their values.
1026
+ * The series that aren't hidden, in the order they're written: the y axis
1027
+ * fits their values, and the tooltip shows them.
669
1028
  */
670
- series = contentChildren(MiraSeries, ...(ngDevMode ? [{ debugName: "series" }] : []));
671
- /** What the chart draws, in the order it's written. */
1029
+ visibleSeries = computed(() => this.series().filter((series) => !series.hidden()), ...(ngDevMode ? [{ debugName: "visibleSeries" }] : []));
1030
+ /** The chart's layers, in the order they're written. */
672
1031
  layers = contentChildren(MiraChartLayer, ...(ngDevMode ? [{ debugName: "layers" }] : []));
1032
+ /** What the chart draws: its layers, less the hidden series. */
1033
+ drawnLayers = computed(() => this.layers().filter((layer) => !(layer instanceof MiraSeries && layer.hidden())), ...(ngDevMode ? [{ debugName: "drawnLayers" }] : []));
673
1034
  /** The chart's axes, if it has them: the plot leaves room for them. */
674
1035
  xAxis = contentChild(MiraXAxis, ...(ngDevMode ? [{ debugName: "xAxis", descendants: false }] : [{ descendants: false }]));
675
1036
  yAxis = contentChild(MiraYAxis, ...(ngDevMode ? [{ debugName: "yAxis", descendants: false }] : [{ descendants: false }]));
1037
+ /** The chart's legend, if it has one: the plot leaves room for it too. */
1038
+ legend = contentChild(MiraLegend, ...(ngDevMode ? [{ debugName: "legend", descendants: false }] : [{ descendants: false }]));
676
1039
  /** The chart's svg, where the pointer is tracked. */
677
1040
  svg = viewChild.required('svg');
678
1041
  viewBox = computed(() => {
@@ -683,9 +1046,9 @@ class MiraCartesianChart {
683
1046
  #measured = signal(null, ...(ngDevMode ? [{ debugName: "#measured", equal: sameSize }] : [{ equal: sameSize }]));
684
1047
  // The pointer in the svg's own px, while it's over the svg.
685
1048
  #pointer = signal(null, ...(ngDevMode ? [{ debugName: "#pointer" }] : []));
686
- // The values of every series, and zero, rounded out to round ticks.
1049
+ // The values of every visible series, and zero, rounded out to round ticks.
687
1050
  #yNice = computed(() => {
688
- const keys = this.series().map((series) => series.dataKey());
1051
+ const keys = this.visibleSeries().map((series) => series.dataKey());
689
1052
  const [min, max] = extentOf(this.data(), keys) ?? [0, 0];
690
1053
  const count = this.yAxis()?.tickCount() ?? DEFAULT_TICK_COUNT;
691
1054
  return linearTicks([Math.min(0, min), Math.max(0, max)], count);
@@ -743,7 +1106,7 @@ class MiraCartesianChart {
743
1106
  return { x, y };
744
1107
  }
745
1108
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.35", ngImport: i0, type: MiraCartesianChart, deps: [], target: i0.ɵɵFactoryTarget.Directive });
746
- 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 }], viewQueries: [{ propertyName: "svg", first: true, predicate: ["svg"], descendants: true, isSignal: true }], ngImport: i0 });
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: MiraLegend, isSignal: true }], viewQueries: [{ propertyName: "svg", first: true, predicate: ["svg"], descendants: true, isSignal: true }], ngImport: i0 });
747
1110
  }
748
1111
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.35", ngImport: i0, type: MiraCartesianChart, decorators: [{
749
1112
  type: Directive,
@@ -755,7 +1118,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.35", ngImpo
755
1118
  '[style.height]': 'height() === undefined ? "100%" : null',
756
1119
  },
757
1120
  }]
758
- }], 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 }] }], svg: [{ type: i0.ViewChild, args: ['svg', { isSignal: true }] }] } });
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(() => MiraLegend), { ...{ descendants: false }, isSignal: true }] }], svg: [{ type: i0.ViewChild, args: ['svg', { isSignal: true }] }] } });
759
1122
  function sameSize(a, b) {
760
1123
  return a?.width === b?.width && a?.height === b?.height;
761
1124
  }
@@ -949,10 +1312,11 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.35", ngImpo
949
1312
  const GAP = 12;
950
1313
  /**
951
1314
  * Marks a template of your own for `<mira-tooltip>`. It replaces the whole
952
- * box, border and background too; the tooltip still places it and shows it
953
- * while a datum is under the pointer. Its context is a `TooltipContext`, and
954
- * typed: `let-items` holds a `TooltipItem` for each series with a value at
955
- * the datum, and `label`, `datum` and `index` describe the datum.
1315
+ * box, border and background too; the tooltip still places it, and shows it
1316
+ * while the datum under the pointer has a value in a visible series. Its
1317
+ * context is a `TooltipContext`, and typed: `let-items` holds a `TooltipItem`
1318
+ * for each visible series with a value at the datum, and `label`, `datum` and
1319
+ * `index` describe the datum.
956
1320
  *
957
1321
  * @example
958
1322
  * ```html
@@ -986,10 +1350,11 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.35", ngImpo
986
1350
  }] });
987
1351
  /**
988
1352
  * Shows the values at the datum under the pointer, in a box beside it: the
989
- * datum's label along x, then a row for each series with a value there, in
990
- * the order the series are written. A row has the series' color, its name and
991
- * the value, as a number in the app's locale (`LOCALE_ID`), with three
992
- * decimals at most, or three digits of its own below 1: 0.0004 rather than 0.
1353
+ * datum's label along x, then a row for each visible series with a value
1354
+ * there, in the order the series are written. A row has the series' color, its
1355
+ * name and the value, as a number in the app's locale (`LOCALE_ID`), with
1356
+ * three decimals at most, or three digits of its own below 1: 0.0004 rather
1357
+ * than 0. Where no visible series has a value, the tooltip doesn't show.
993
1358
  *
994
1359
  * The box goes past the datum, or past the edge of its band in a chart with
995
1360
  * bands: on its right where it fits, else on its left. It follows the pointer
@@ -997,9 +1362,11 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.35", ngImpo
997
1362
  * side, it's pressed onto the plot, over the datum; a box bigger than the
998
1363
  * plot starts at its edge and runs past it.
999
1364
  *
1000
- * The box's text takes the chart's `color`. Its other colors are CSS custom
1365
+ * The box's text takes the chart's `color`. The rest are CSS custom
1001
1366
  * properties, to set anywhere above the tooltip:
1002
1367
  *
1368
+ * - `--mira-font-size`: the size of the text, `0.75rem` by default; the room
1369
+ * around the text follows it;
1003
1370
  * - `--mira-tooltip-background`: the box, the chart's `--mira-background` by
1004
1371
  * default;
1005
1372
  * - `--mira-tooltip-border-color`: its border, the chart's
@@ -1022,22 +1389,24 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.35", ngImpo
1022
1389
  */
1023
1390
  class MiraTooltip {
1024
1391
  // What the tooltip shows while a datum is under the pointer, as a template
1025
- // of your own gets it.
1392
+ // of your own gets it; null where it has no value to show.
1026
1393
  context = computed(() => {
1027
1394
  const active = this.#chart.active();
1028
1395
  if (active === null)
1029
1396
  return null;
1030
- const items = this.#chart.series().flatMap((series) => {
1397
+ const items = this.#chart.visibleSeries().flatMap((series) => {
1031
1398
  const value = numberAt(active.datum, series.dataKey());
1032
1399
  if (value === null)
1033
1400
  return [];
1034
1401
  return {
1035
- name: series.name() ?? series.dataKey(),
1402
+ name: series.displayName(),
1036
1403
  dataKey: series.dataKey(),
1037
1404
  value,
1038
1405
  color: series.color(),
1039
1406
  };
1040
1407
  });
1408
+ if (items.length === 0)
1409
+ return null;
1041
1410
  const { label, datum, index } = active;
1042
1411
  return { $implicit: items, label, datum, index };
1043
1412
  }, ...(ngDevMode ? [{ debugName: "context" }] : []));
@@ -1144,7 +1513,7 @@ class MiraTooltip {
1144
1513
  }
1145
1514
  </div>
1146
1515
  }
1147
- `, isInline: true, styles: [".mira-tooltip-frame{position:absolute;width:max-content}.mira-tooltip{display:grid;grid-template-columns:auto 1fr auto;column-gap:6px;align-items:center;padding:6px 10px;border:1px solid var(--mira-tooltip-border-color, var(--_mira-grid-color));border-radius:4px;background:var( --mira-tooltip-background, var(--mira-background, Canvas) );box-shadow:0 2px 6px #00000026;font-size:12px;line-height:1.6}.mira-tooltip-label{grid-column:1 / -1}.mira-tooltip-swatch{width:8px;height:8px;border-radius:50%}.mira-tooltip-value{padding-inline-start:10px;font-weight:600;font-variant-numeric:tabular-nums;text-align:end}\n"], dependencies: [{ kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
1516
+ `, isInline: true, styles: [".mira-tooltip-frame{position:absolute;z-index:1;width:max-content}.mira-tooltip{display:grid;grid-template-columns:auto 1fr auto;column-gap:.5em;align-items:center;padding:.5em .75em;border:1px solid var(--mira-tooltip-border-color, var(--_mira-grid-color));border-radius:4px;background:var( --mira-tooltip-background, var(--mira-background, Canvas) );box-shadow:0 2px 6px #00000026;font-size:var(--mira-font-size, .75rem);line-height:1.6}.mira-tooltip-label{grid-column:1 / -1}.mira-tooltip-swatch{width:.75em;height:.75em;border-radius:50%;forced-color-adjust:none;-webkit-print-color-adjust:exact;print-color-adjust:exact}.mira-tooltip-value{padding-inline-start:.75em;font-weight:600;font-variant-numeric:tabular-nums;text-align:end}\n"], dependencies: [{ kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
1148
1517
  }
1149
1518
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.35", ngImport: i0, type: MiraTooltip, decorators: [{
1150
1519
  type: Component,
@@ -1176,7 +1545,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.35", ngImpo
1176
1545
  }
1177
1546
  </div>
1178
1547
  }
1179
- `, styles: [".mira-tooltip-frame{position:absolute;width:max-content}.mira-tooltip{display:grid;grid-template-columns:auto 1fr auto;column-gap:6px;align-items:center;padding:6px 10px;border:1px solid var(--mira-tooltip-border-color, var(--_mira-grid-color));border-radius:4px;background:var( --mira-tooltip-background, var(--mira-background, Canvas) );box-shadow:0 2px 6px #00000026;font-size:12px;line-height:1.6}.mira-tooltip-label{grid-column:1 / -1}.mira-tooltip-swatch{width:8px;height:8px;border-radius:50%}.mira-tooltip-value{padding-inline-start:10px;font-weight:600;font-variant-numeric:tabular-nums;text-align:end}\n"] }]
1548
+ `, styles: [".mira-tooltip-frame{position:absolute;z-index:1;width:max-content}.mira-tooltip{display:grid;grid-template-columns:auto 1fr auto;column-gap:.5em;align-items:center;padding:.5em .75em;border:1px solid var(--mira-tooltip-border-color, var(--_mira-grid-color));border-radius:4px;background:var( --mira-tooltip-background, var(--mira-background, Canvas) );box-shadow:0 2px 6px #00000026;font-size:var(--mira-font-size, .75rem);line-height:1.6}.mira-tooltip-label{grid-column:1 / -1}.mira-tooltip-swatch{width:.75em;height:.75em;border-radius:50%;forced-color-adjust:none;-webkit-print-color-adjust:exact;print-color-adjust:exact}.mira-tooltip-value{padding-inline-start:.75em;font-weight:600;font-variant-numeric:tabular-nums;text-align:end}\n"] }]
1180
1549
  }], ctorParameters: () => [], propDecorators: { template: [{ type: i0.ContentChild, args: [i0.forwardRef(() => MiraTooltipContent), { ...{
1181
1550
  read: TemplateRef,
1182
1551
  }, isSignal: true }] }], frame: [{ type: i0.ViewChild, args: ['frame', { isSignal: true }] }] } });
@@ -1268,11 +1637,11 @@ class MiraLineChart extends MiraCartesianChart {
1268
1637
  return pointPositions(this.data().length, [left, left + width]);
1269
1638
  }, ...(ngDevMode ? [{ debugName: "xPositions" }] : []));
1270
1639
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.35", ngImport: i0, type: MiraLineChart, deps: null, target: i0.ɵɵFactoryTarget.Component });
1271
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.3.35", type: MiraLineChart, isStandalone: true, selector: "mira-line-chart", providers: [provideCartesianChart(forwardRef(() => MiraLineChart))], 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 layers(); 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}\n"], dependencies: [{ kind: "component", type: LayerOutlet, selector: "g[miraLayerOutlet]", inputs: ["miraLayerOutlet"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
1640
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.3.35", type: MiraLineChart, isStandalone: true, selector: "mira-line-chart", providers: [provideCartesianChart(forwardRef(() => MiraLineChart))], 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 });
1272
1641
  }
1273
1642
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.35", ngImport: i0, type: MiraLineChart, decorators: [{
1274
1643
  type: Component,
1275
- args: [{ selector: 'mira-line-chart', changeDetection: ChangeDetectionStrategy.OnPush, imports: [LayerOutlet], providers: [provideCartesianChart(forwardRef(() => MiraLineChart))], 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}\n"] }]
1644
+ args: [{ selector: 'mira-line-chart', changeDetection: ChangeDetectionStrategy.OnPush, imports: [LayerOutlet], providers: [provideCartesianChart(forwardRef(() => MiraLineChart))], 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"] }]
1276
1645
  }] });
1277
1646
 
1278
1647
  /**
@@ -1378,8 +1747,10 @@ class MiraLine extends MiraSeries {
1378
1747
  * On by default.
1379
1748
  */
1380
1749
  activeDot = input(true, ...(ngDevMode ? [{ debugName: "activeDot", transform: booleanAttribute }] : [{ transform: booleanAttribute }]));
1381
- /** The line's color, for the tooltip. Set it with `stroke`. */
1750
+ /** The line's color, for the tooltip and the legend. Set it with `stroke`. */
1382
1751
  color = this.stroke;
1752
+ /** A stretch of line marks the line in the legend. */
1753
+ legendIcon = 'line';
1383
1754
  path = computed(() => linePath(this.#points(), this.curve()), ...(ngDevMode ? [{ debugName: "path" }] : []));
1384
1755
  dots = computed(() => this.#points().filter((point) => point !== null), ...(ngDevMode ? [{ debugName: "dots" }] : []));
1385
1756
  // The point under the pointer, if the line has a value there.
@@ -1518,11 +1889,11 @@ class MiraBarChart extends MiraCartesianChart {
1518
1889
  return bandPositions(this.data().length, [left, left + width]);
1519
1890
  }, ...(ngDevMode ? [{ debugName: "#bands" }] : []));
1520
1891
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.35", ngImport: i0, type: MiraBarChart, deps: null, target: i0.ɵɵFactoryTarget.Component });
1521
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.3.35", type: MiraBarChart, isStandalone: true, selector: "mira-bar-chart", providers: [provideCartesianChart(forwardRef(() => MiraBarChart))], 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 layers(); 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}\n"], dependencies: [{ kind: "component", type: LayerOutlet, selector: "g[miraLayerOutlet]", inputs: ["miraLayerOutlet"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
1892
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.3.35", type: MiraBarChart, isStandalone: true, selector: "mira-bar-chart", providers: [provideCartesianChart(forwardRef(() => MiraBarChart))], 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 });
1522
1893
  }
1523
1894
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.35", ngImport: i0, type: MiraBarChart, decorators: [{
1524
1895
  type: Component,
1525
- args: [{ selector: 'mira-bar-chart', changeDetection: ChangeDetectionStrategy.OnPush, imports: [LayerOutlet], providers: [provideCartesianChart(forwardRef(() => MiraBarChart))], 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}\n"] }]
1896
+ args: [{ selector: 'mira-bar-chart', changeDetection: ChangeDetectionStrategy.OnPush, imports: [LayerOutlet], providers: [provideCartesianChart(forwardRef(() => MiraBarChart))], 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"] }]
1526
1897
  }] });
1527
1898
 
1528
1899
  // The room the bars leave on each side of their band, as a share of the band.
@@ -1533,9 +1904,10 @@ const BAR_GAP = 4;
1533
1904
  * A series of bars: a bar for each datum of the chart's data, from zero to
1534
1905
  * the datum's value under `dataKey`, up for a value above zero and down for
1535
1906
  * one below. Write one per key: the bars of several share each band, side by
1536
- * side in the order they're written. A datum with no number under the key
1537
- * has no bar, and leaves its place in the band empty. It goes in a chart with
1538
- * a band per datum, such as `<mira-bar-chart>`.
1907
+ * side in the order they're written, and a hidden one leaves its room to the
1908
+ * others. A datum with no number under the key has no bar, and leaves its
1909
+ * place in the band empty. It goes in a chart with a band per datum, such as
1910
+ * `<mira-bar-chart>`.
1539
1911
  *
1540
1912
  * @example
1541
1913
  * ```html
@@ -1546,8 +1918,10 @@ const BAR_GAP = 4;
1546
1918
  class MiraBar extends MiraSeries {
1547
1919
  /** The color of the bars, `#3182bd` by default. */
1548
1920
  fill = input('#3182bd', ...(ngDevMode ? [{ debugName: "fill" }] : []));
1549
- /** The bars' color, for the tooltip. Set it with `fill`. */
1921
+ /** The bars' color, for the tooltip and the legend. Set it with `fill`. */
1550
1922
  color = this.fill;
1923
+ /** A square marks the bars in the legend. */
1924
+ legendIcon = 'square';
1551
1925
  // A rect per datum with a value: at the bar's place in the datum's band,
1552
1926
  // and from zero to the value, whichever way that goes.
1553
1927
  bars = computed(() => {
@@ -1576,10 +1950,10 @@ class MiraBar extends MiraSeries {
1576
1950
  // further out.
1577
1951
  #chart = inject(CartesianContext);
1578
1952
  #bandwidth = bandwidthOf(this.#chart);
1579
- // The bar's place in each band: the chart's bars share it, side by side in
1580
- // the order they're written.
1953
+ // The bar's place in each band: the chart's visible bars share it, side by
1954
+ // side in the order they're written.
1581
1955
  #slot = computed(() => {
1582
- const bars = this.#chart.series().filter(isBar);
1956
+ const bars = this.#chart.visibleSeries().filter(isBar);
1583
1957
  return slotOf(bars.indexOf(this), bars.length, this.#bandwidth());
1584
1958
  }, ...(ngDevMode ? [{ debugName: "#slot" }] : []));
1585
1959
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.35", ngImport: i0, type: MiraBar, deps: null, target: i0.ɵɵFactoryTarget.Component });
@@ -1658,5 +2032,5 @@ function slotOf(rank, count, bandwidth) {
1658
2032
  * Generated bundle index. Do not edit.
1659
2033
  */
1660
2034
 
1661
- export { MiraBar, MiraBarChart, MiraCartesianChart, MiraCartesianGrid, MiraChartLayer, MiraCursor, MiraLine, MiraLineChart, MiraSeries, MiraTooltip, MiraTooltipContent, MiraXAxis, MiraYAxis };
2035
+ export { MiraBar, MiraBarChart, MiraCartesianChart, MiraCartesianGrid, MiraChartLayer, MiraCursor, MiraLegend, MiraLegendItemContent, MiraLine, MiraLineChart, MiraSeries, MiraTooltip, MiraTooltipContent, MiraXAxis, MiraYAxis };
1662
2036
  //# sourceMappingURL=ngx-mira-charts.mjs.map