@mantha911/ng-echarts 0.1.0-rc.18 → 0.1.0-rc.21

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 { ApplicationRef, ChangeDetectionStrategy, Component, DestroyRef, Directive, ElementRef, PLATFORM_ID, afterNextRender, afterRenderEffect, computed, effect, inject, input, output, signal, untracked, viewChild } from "@angular/core";
2
+ import { ApplicationRef, ChangeDetectionStrategy, Component, DestroyRef, Directive, ElementRef, PLATFORM_ID, afterNextRender, afterRenderEffect, computed, effect, inject, input, linkedSignal, output, signal, untracked, viewChild } from "@angular/core";
3
3
  import { isPlatformBrowser } from "@angular/common";
4
4
  var ChartFrame = class ChartFrame {
5
5
  title = input.required(...ngDevMode ? [{ debugName: "title" }] : /* istanbul ignore next */ []);
@@ -468,6 +468,40 @@ var ChartFocusKeeper = class {
468
468
  this.remembered = null;
469
469
  }
470
470
  };
471
+ var TablePagination = class {
472
+ data;
473
+ pageSize;
474
+ error = computed(() => {
475
+ const size = this.pageSize();
476
+ return size === null || Number.isSafeInteger(size) && size > 0 ? null : "Table page size must be a positive safe integer or null.";
477
+ }, ...ngDevMode ? [{ debugName: "error" }] : /* istanbul ignore next */ []);
478
+ total = computed(() => {
479
+ const rows = this.data();
480
+ return Array.isArray(rows) ? rows.length : 0;
481
+ }, ...ngDevMode ? [{ debugName: "total" }] : /* istanbul ignore next */ []);
482
+ requestedPage = linkedSignal(() => {
483
+ this.data();
484
+ this.pageSize();
485
+ return 0;
486
+ }, ...ngDevMode ? [{ debugName: "requestedPage" }] : /* istanbul ignore next */ []);
487
+ count = computed(() => {
488
+ const size = this.pageSize();
489
+ return !this.error() && size !== null ? Math.max(1, Math.ceil(this.total() / size)) : 1;
490
+ }, ...ngDevMode ? [{ debugName: "count" }] : /* istanbul ignore next */ []);
491
+ page = computed(() => Math.min(this.requestedPage(), this.count() - 1), ...ngDevMode ? [{ debugName: "page" }] : /* istanbul ignore next */ []);
492
+ start = computed(() => this.page() * (this.pageSize() ?? this.total()), ...ngDevMode ? [{ debugName: "start" }] : /* istanbul ignore next */ []);
493
+ end = computed(() => Math.min(this.total(), this.start() + (this.pageSize() ?? this.total())), ...ngDevMode ? [{ debugName: "end" }] : /* istanbul ignore next */ []);
494
+ constructor(data, pageSize) {
495
+ this.data = data;
496
+ this.pageSize = pageSize;
497
+ }
498
+ rows(rows) {
499
+ return this.pageSize() === null ? rows : rows.slice(this.start(), this.end());
500
+ }
501
+ move(delta) {
502
+ this.requestedPage.set(Math.max(0, Math.min(this.page() + delta, this.count() - 1)));
503
+ }
504
+ };
471
505
  var PlotController = class {
472
506
  host;
473
507
  environment;
@@ -596,10 +630,16 @@ var CartesianChart = class CartesianChart {
596
630
  this.formatting(),
597
631
  this.categoryTicks(),
598
632
  this.tokens(),
599
- this.tableExpanded()
633
+ this.tableExpanded(),
634
+ this.tablePagination.page()
600
635
  ], ...ngDevMode ? [{ debugName: "plotContext" }] : /* istanbul ignore next */ []);
601
- plotPreview = signal(null, {
636
+ plotPreview = linkedSignal({
602
637
  ...ngDevMode ? { debugName: "plotPreview" } : /* istanbul ignore next */ {},
638
+ source: () => ({
639
+ context: this.plotContext(),
640
+ ready: this.state().kind === "ready"
641
+ }),
642
+ computation: ({ context, ready }, previous) => ready && previous?.value?.context === context ? previous.value : null,
603
643
  equal: (a, b) => a?.context === b?.context && a?.point.rowId === b?.point.rowId && a?.point.seriesId === b?.point.seriesId
604
644
  });
605
645
  previewSnapshot = null;
@@ -608,6 +648,7 @@ var CartesianChart = class CartesianChart {
608
648
  this.settings(),
609
649
  this.hiddenIds(),
610
650
  this.tableExpanded(),
651
+ this.tablePagination.page(),
611
652
  this.state()
612
653
  ], ...ngDevMode ? [{ debugName: "previewContext" }] : /* istanbul ignore next */ []);
613
654
  title = input.required(...ngDevMode ? [{ debugName: "title" }] : /* istanbul ignore next */ []);
@@ -624,6 +665,7 @@ var CartesianChart = class CartesianChart {
624
665
  valueFormatter = input(...ngDevMode ? [void 0, { debugName: "valueFormatter" }] : /* istanbul ignore next */ []);
625
666
  categoryTickFormatter = input(...ngDevMode ? [void 0, { debugName: "categoryTickFormatter" }] : /* istanbul ignore next */ []);
626
667
  showDataTable = input(true, ...ngDevMode ? [{ debugName: "showDataTable" }] : /* istanbul ignore next */ []);
668
+ tablePageSize = input(null, ...ngDevMode ? [{ debugName: "tablePageSize" }] : /* istanbul ignore next */ []);
627
669
  loading = input(false, ...ngDevMode ? [{ debugName: "loading" }] : /* istanbul ignore next */ []);
628
670
  error = input(null, ...ngDevMode ? [{ debugName: "error" }] : /* istanbul ignore next */ []);
629
671
  animation = input(true, ...ngDevMode ? [{ debugName: "animation" }] : /* istanbul ignore next */ []);
@@ -636,14 +678,32 @@ var CartesianChart = class CartesianChart {
636
678
  plot = viewChild.required("plot", ...ngDevMode ? [{ debugName: "plot" }] : /* istanbul ignore next */ []);
637
679
  browserReady = signal(false, ...ngDevMode ? [{ debugName: "browserReady" }] : /* istanbul ignore next */ []);
638
680
  reducedMotion = signal(false, ...ngDevMode ? [{ debugName: "reducedMotion" }] : /* istanbul ignore next */ []);
639
- hiddenIds = signal(/* @__PURE__ */ new Set(), ...ngDevMode ? [{ debugName: "hiddenIds" }] : /* istanbul ignore next */ []);
681
+ hiddenIds = linkedSignal({
682
+ ...ngDevMode ? { debugName: "hiddenIds" } : /* istanbul ignore next */ {},
683
+ source: this.series,
684
+ computation: (series, previous) => {
685
+ const hidden = previous?.value ?? /* @__PURE__ */ new Set();
686
+ if (!Array.isArray(series) || !series.every((item) => item && typeof item.id === "string" && item.id && typeof item.key === "string" && typeof item.label === "string")) return hidden;
687
+ const validIds = new Set(series.map((item) => item.id));
688
+ if (validIds.size !== series.length) return hidden;
689
+ const retained = new Set([...hidden].filter((id) => validIds.has(id)));
690
+ return retained.size === hidden.size ? hidden : retained;
691
+ }
692
+ });
640
693
  measuredTheme = signal(null, ...ngDevMode ? [{ debugName: "measuredTheme" }] : /* istanbul ignore next */ []);
641
694
  controller = null;
642
695
  removeMotionListener = null;
643
696
  focusKeeper = null;
644
697
  removePreviewListeners = null;
645
- rendererError = signal(false, ...ngDevMode ? [{ debugName: "rendererError" }] : /* istanbul ignore next */ []);
698
+ rendererError = linkedSignal(() => {
699
+ this.model();
700
+ this.settings();
701
+ this.formatting();
702
+ this.categoryTicks();
703
+ return false;
704
+ }, ...ngDevMode ? [{ debugName: "rendererError" }] : /* istanbul ignore next */ []);
646
705
  tableExpanded = signal(false, ...ngDevMode ? [{ debugName: "tableExpanded" }] : /* istanbul ignore next */ []);
706
+ tablePagination = new TablePagination(this.data, this.tablePageSize);
647
707
  model = computed(() => normalizeCartesianData(this.data(), this.rowIdKey(), this.categoryKey(), this.series()), ...ngDevMode ? [{ debugName: "model" }] : /* istanbul ignore next */ []);
648
708
  formatting = computed(() => {
649
709
  const model = this.model();
@@ -660,22 +720,24 @@ var CartesianChart = class CartesianChart {
660
720
  themeRevision: this.themeRevision(),
661
721
  animation: this.animation(),
662
722
  loading: this.loading(),
663
- error: this.error()
723
+ error: this.error(),
724
+ tablePageSize: this.tablePageSize()
664
725
  }), ...ngDevMode ? [{ debugName: "settings" }] : /* istanbul ignore next */ []);
665
726
  tokens = computed(() => this.measuredTheme() ?? defaultCartesianTheme(this.theme()), ...ngDevMode ? [{ debugName: "tokens" }] : /* istanbul ignore next */ []);
666
727
  plotHeight = computed(() => Number.isFinite(this.height()) && this.height() > 0 ? this.height() : 320, ...ngDevMode ? [{ debugName: "plotHeight" }] : /* istanbul ignore next */ []);
667
728
  state = computed(() => {
668
729
  const settings = this.settings();
669
- const configurationError = !Number.isFinite(settings.height) || settings.height <= 0 ? "Chart height must be a positive, finite number." : !["light", "dark"].includes(settings.theme) || !Number.isFinite(settings.themeRevision) ? "Chart theme configuration is invalid." : this.familyError() ?? this.formatting().error ?? this.categoryTicks().error;
730
+ const configurationError = !Number.isFinite(settings.height) || settings.height <= 0 ? "Chart height must be a positive, finite number." : !["light", "dark"].includes(settings.theme) || !Number.isFinite(settings.themeRevision) ? "Chart theme configuration is invalid." : this.familyError() ?? this.tablePagination.error() ?? this.formatting().error ?? this.categoryTicks().error;
670
731
  return resolveCartesianState(settings.error, settings.loading, this.model(), this.rendererError(), configurationError);
671
732
  }, ...ngDevMode ? [{ debugName: "state" }] : /* istanbul ignore next */ []);
672
733
  legendItems = computed(() => {
734
+ const hiddenIds = this.hiddenIds();
673
735
  const model = this.model();
674
736
  if (model.kind === "error") return [];
675
737
  return model.series.map((item, index) => ({
676
738
  id: item.id,
677
739
  label: item.label,
678
- visible: !this.hiddenIds().has(item.id),
740
+ visible: !hiddenIds.has(item.id),
679
741
  color: this.tokens().series[index % this.tokens().series.length]
680
742
  }));
681
743
  }, ...ngDevMode ? [{ debugName: "legendItems" }] : /* istanbul ignore next */ []);
@@ -698,7 +760,7 @@ var CartesianChart = class CartesianChart {
698
760
  tableRows = computed(() => {
699
761
  const model = this.model();
700
762
  if (!this.showDataTable() || !this.tableExpanded() || this.state().kind !== "ready" || model.kind === "error") return [];
701
- return model.rows.map((row) => ({
763
+ return this.tablePagination.rows(model.rows).map((row) => ({
702
764
  id: row.id,
703
765
  category: row.category,
704
766
  selected: this.rowIsSelected(row.id),
@@ -714,13 +776,6 @@ var CartesianChart = class CartesianChart {
714
776
  }));
715
777
  }, ...ngDevMode ? [{ debugName: "tableRows" }] : /* istanbul ignore next */ []);
716
778
  constructor() {
717
- effect(() => {
718
- this.model();
719
- this.settings();
720
- this.formatting();
721
- this.categoryTicks();
722
- this.rendererError.set(false);
723
- });
724
779
  effect(() => {
725
780
  const context = this.previewContext();
726
781
  untracked(() => {
@@ -729,24 +784,7 @@ var CartesianChart = class CartesianChart {
729
784
  });
730
785
  effect(() => {
731
786
  const current = this.plotPreview();
732
- const context = this.plotContext();
733
- const ready = this.state().kind === "ready";
734
- const hidden = this.hiddenIds();
735
- const enabled = this.canPreview();
736
- if (current && (current.context !== context || !ready || hidden.has(current.point.seriesId))) {
737
- this.plotPreview.set(null);
738
- return;
739
- }
740
- if (enabled) untracked(() => this.previewPoint(current?.point ?? null, "plot", "pointer"));
741
- });
742
- effect(() => {
743
- const series = this.series();
744
- if (!Array.isArray(series) || !series.every((item) => item && typeof item.id === "string" && item.id && typeof item.key === "string" && typeof item.label === "string")) return;
745
- const validIds = new Set(series.map((item) => item.id));
746
- if (validIds.size !== series.length) return;
747
- const previous = untracked(this.hiddenIds);
748
- const retained = new Set([...previous].filter((id) => validIds.has(id)));
749
- if (retained.size !== previous.size) this.hiddenIds.set(retained);
787
+ if (this.canPreview()) untracked(() => this.previewPoint(current?.point ?? null, "plot", "pointer"));
750
788
  });
751
789
  afterNextRender(() => {
752
790
  if (!isPlatformBrowser(this.platform)) return;
@@ -769,7 +807,7 @@ var CartesianChart = class CartesianChart {
769
807
  }
770
808
  });
771
809
  });
772
- afterRenderEffect(() => {
810
+ afterRenderEffect({ mixedReadWrite: () => {
773
811
  if (!this.browserReady()) return;
774
812
  const series = this.series();
775
813
  const theme = this.theme();
@@ -780,24 +818,24 @@ var CartesianChart = class CartesianChart {
780
818
  } catch {
781
819
  this.rendererError.set(true);
782
820
  }
783
- });
784
- afterRenderEffect(() => {
821
+ } });
822
+ afterRenderEffect({ write: () => {
785
823
  this.browserReady();
786
824
  this.controller?.update(this.options());
787
- });
788
- afterRenderEffect(() => {
825
+ } });
826
+ afterRenderEffect({ mixedReadWrite: () => {
789
827
  if (this.browserReady() && this.observePreviews()) this.removePreviewListeners ??= observeTablePreviews(this.host.nativeElement, (point, trigger) => this.previewPoint(point, "table", trigger));
790
828
  else {
791
829
  this.removePreviewListeners?.();
792
830
  this.removePreviewListeners = null;
793
831
  }
794
- });
795
- afterRenderEffect(() => {
832
+ } });
833
+ afterRenderEffect({ mixedReadWrite: () => {
796
834
  this.state();
797
835
  this.tableRows();
798
836
  this.legendItems();
799
837
  this.focusKeeper?.restore();
800
- });
838
+ } });
801
839
  this.destroyRef.onDestroy(() => {
802
840
  this.removeMotionListener?.();
803
841
  this.removePreviewListeners?.();
@@ -983,6 +1021,13 @@ var CartesianChart = class CartesianChart {
983
1021
  isRequired: false,
984
1022
  transformFunction: null
985
1023
  },
1024
+ tablePageSize: {
1025
+ classPropertyName: "tablePageSize",
1026
+ publicName: "tablePageSize",
1027
+ isSignal: true,
1028
+ isRequired: false,
1029
+ transformFunction: null
1030
+ },
986
1031
  loading: {
987
1032
  classPropertyName: "loading",
988
1033
  publicName: "loading",
@@ -1139,6 +1184,14 @@ i0.ɵɵngDeclareClassMetadata({
1139
1184
  required: false
1140
1185
  }]
1141
1186
  }],
1187
+ tablePageSize: [{
1188
+ type: i0.Input,
1189
+ args: [{
1190
+ isSignal: true,
1191
+ alias: "tablePageSize",
1192
+ required: false
1193
+ }]
1194
+ }],
1142
1195
  loading: [{
1143
1196
  type: i0.Input,
1144
1197
  args: [{
@@ -1385,6 +1438,129 @@ i0.ɵɵngDeclareClassMetadata({
1385
1438
  }]
1386
1439
  }
1387
1440
  });
1388
- export { ChartFrame, CartesianChart as ɵCartesianChart, ChartFocusKeeper as ɵChartFocusKeeper, ChartStage as ɵChartStage, PlotController as ɵPlotController, browserPlotEnvironment as ɵbrowserPlotEnvironment, buildCartesianOptions as ɵbuildCartesianOptions, buildCurveOptions as ɵbuildCurveOptions, createValueFormatting as ɵcreateValueFormatting, curvePoint as ɵcurvePoint, defaultCartesianTheme as ɵdefaultCartesianTheme, escapeTooltipText as ɵescapeTooltipText, formatCategoryTicks as ɵformatCategoryTicks, normalizeCartesianData as ɵnormalizeCartesianData, readCartesianTheme as ɵreadCartesianTheme, resolveCartesianState as ɵresolveCartesianState, tooltipMarkup as ɵtooltipMarkup, tooltipStyle as ɵtooltipStyle };
1441
+ var TablePager = class TablePager {
1442
+ pagination = input.required(...ngDevMode ? [{ debugName: "pagination" }] : /* istanbul ignore next */ []);
1443
+ label = input.required(...ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []);
1444
+ static ɵfac = i0.ɵɵngDeclareFactory({
1445
+ minVersion: "12.0.0",
1446
+ version: "22.2.6",
1447
+ ngImport: i0,
1448
+ type: TablePager,
1449
+ deps: [],
1450
+ target: i0.ɵɵFactoryTarget.Component
1451
+ });
1452
+ static ɵcmp = i0.ɵɵngDeclareComponent({
1453
+ minVersion: "17.0.0",
1454
+ version: "22.2.6",
1455
+ type: TablePager,
1456
+ isStandalone: true,
1457
+ selector: "nec-table-pager",
1458
+ inputs: {
1459
+ pagination: {
1460
+ classPropertyName: "pagination",
1461
+ publicName: "pagination",
1462
+ isSignal: true,
1463
+ isRequired: true,
1464
+ transformFunction: null
1465
+ },
1466
+ label: {
1467
+ classPropertyName: "label",
1468
+ publicName: "label",
1469
+ isSignal: true,
1470
+ isRequired: true,
1471
+ transformFunction: null
1472
+ }
1473
+ },
1474
+ ngImport: i0,
1475
+ template: `
1476
+ @let pages = pagination();
1477
+ @if (pages.count() > 1) {
1478
+ <nav [attr.aria-label]="label() + ' data table pages'">
1479
+ <button
1480
+ type="button"
1481
+ aria-label="Previous table page"
1482
+ [attr.aria-disabled]="pages.page() === 0 ? 'true' : null"
1483
+ (click)="pages.move(-1)"
1484
+ >
1485
+ Previous
1486
+ </button>
1487
+ <span role="status" aria-atomic="true">
1488
+ Rows {{ pages.start() + 1 }}–{{ pages.end() }} of {{ pages.total() }}
1489
+ </span>
1490
+ <button
1491
+ type="button"
1492
+ aria-label="Next table page"
1493
+ [attr.aria-disabled]="pages.page() === pages.count() - 1 ? 'true' : null"
1494
+ (click)="pages.move(1)"
1495
+ >
1496
+ Next
1497
+ </button>
1498
+ </nav>
1499
+ }
1500
+ `,
1501
+ isInline: true,
1502
+ styles: ["nav{display:flex;flex-wrap:wrap;align-items:center;gap:.5rem;margin-top:1rem}span{font-size:.875rem;font-variant-numeric:tabular-nums}button{padding:.5rem .75rem;border:1px solid var(--nec-border, #d6dce5);border-radius:.375rem;color:inherit;background:transparent;font:inherit;cursor:pointer}button:focus-visible{outline:3px solid var(--nec-focus, #648dff);outline-offset:3px}button[aria-disabled=true]{color:var(--nec-muted, #536176);cursor:default;border-style:dashed}\n"],
1503
+ changeDetection: i0.ChangeDetectionStrategy.OnPush
1504
+ });
1505
+ };
1506
+ i0.ɵɵngDeclareClassMetadata({
1507
+ minVersion: "12.0.0",
1508
+ version: "22.2.6",
1509
+ ngImport: i0,
1510
+ type: TablePager,
1511
+ decorators: [{
1512
+ type: Component,
1513
+ args: [{
1514
+ selector: "nec-table-pager",
1515
+ template: `
1516
+ @let pages = pagination();
1517
+ @if (pages.count() > 1) {
1518
+ <nav [attr.aria-label]="label() + ' data table pages'">
1519
+ <button
1520
+ type="button"
1521
+ aria-label="Previous table page"
1522
+ [attr.aria-disabled]="pages.page() === 0 ? 'true' : null"
1523
+ (click)="pages.move(-1)"
1524
+ >
1525
+ Previous
1526
+ </button>
1527
+ <span role="status" aria-atomic="true">
1528
+ Rows {{ pages.start() + 1 }}–{{ pages.end() }} of {{ pages.total() }}
1529
+ </span>
1530
+ <button
1531
+ type="button"
1532
+ aria-label="Next table page"
1533
+ [attr.aria-disabled]="pages.page() === pages.count() - 1 ? 'true' : null"
1534
+ (click)="pages.move(1)"
1535
+ >
1536
+ Next
1537
+ </button>
1538
+ </nav>
1539
+ }
1540
+ `,
1541
+ changeDetection: ChangeDetectionStrategy.OnPush,
1542
+ styles: ["nav{display:flex;flex-wrap:wrap;align-items:center;gap:.5rem;margin-top:1rem}span{font-size:.875rem;font-variant-numeric:tabular-nums}button{padding:.5rem .75rem;border:1px solid var(--nec-border, #d6dce5);border-radius:.375rem;color:inherit;background:transparent;font:inherit;cursor:pointer}button:focus-visible{outline:3px solid var(--nec-focus, #648dff);outline-offset:3px}button[aria-disabled=true]{color:var(--nec-muted, #536176);cursor:default;border-style:dashed}\n"]
1543
+ }]
1544
+ }],
1545
+ propDecorators: {
1546
+ pagination: [{
1547
+ type: i0.Input,
1548
+ args: [{
1549
+ isSignal: true,
1550
+ alias: "pagination",
1551
+ required: true
1552
+ }]
1553
+ }],
1554
+ label: [{
1555
+ type: i0.Input,
1556
+ args: [{
1557
+ isSignal: true,
1558
+ alias: "label",
1559
+ required: true
1560
+ }]
1561
+ }]
1562
+ }
1563
+ });
1564
+ export { ChartFrame, CartesianChart as ɵCartesianChart, ChartFocusKeeper as ɵChartFocusKeeper, ChartStage as ɵChartStage, PlotController as ɵPlotController, TablePager as ɵTablePager, TablePagination as ɵTablePagination, browserPlotEnvironment as ɵbrowserPlotEnvironment, buildCartesianOptions as ɵbuildCartesianOptions, buildCurveOptions as ɵbuildCurveOptions, createValueFormatting as ɵcreateValueFormatting, curvePoint as ɵcurvePoint, defaultCartesianTheme as ɵdefaultCartesianTheme, escapeTooltipText as ɵescapeTooltipText, formatCategoryTicks as ɵformatCategoryTicks, normalizeCartesianData as ɵnormalizeCartesianData, readCartesianTheme as ɵreadCartesianTheme, resolveCartesianState as ɵresolveCartesianState, tooltipMarkup as ɵtooltipMarkup, tooltipStyle as ɵtooltipStyle };
1389
1565
 
1390
1566
  //# sourceMappingURL=mantha911-ng-echarts-core.mjs.map