derive-dashboards 0.8.0 → 0.10.0
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/CHANGELOG.md +534 -0
- package/README.md +8 -2
- package/dist/adapter/statement.mjs +9 -7
- package/dist/authorize.mjs +27 -6
- package/dist/body.mjs +28 -25
- package/dist/cache.d.mts +2 -2
- package/dist/charts/data/buckets.d.mts +25 -7
- package/dist/charts/data/buckets.mjs +92 -15
- package/dist/charts/data/clean.mjs +254 -12
- package/dist/charts/data/format.d.mts +7 -2
- package/dist/charts/data/format.mjs +68 -70
- package/dist/charts/data/input-error.d.mts +2 -0
- package/dist/charts/data/input-error.mjs +2 -0
- package/dist/charts/data/rows.d.mts +3 -1
- package/dist/charts/data/rows.mjs +4 -2
- package/dist/charts/data/types.d.mts +50 -7
- package/dist/charts/data/words.d.mts +13 -0
- package/dist/charts/data/words.mjs +8 -1
- package/dist/charts/describe.mjs +6 -6
- package/dist/charts/index.d.mts +14 -14
- package/dist/charts/index.mjs +4 -1
- package/dist/charts/kinds/area-marks.mjs +67 -26
- package/dist/charts/kinds/area.d.mts +3 -3
- package/dist/charts/kinds/area.mjs +32 -11
- package/dist/charts/kinds/bars-data.d.mts +3 -3
- package/dist/charts/kinds/bars-data.mjs +12 -6
- package/dist/charts/kinds/bars-layout.mjs +60 -6
- package/dist/charts/kinds/bars-marks.mjs +6 -6
- package/dist/charts/kinds/bars.d.mts +5 -3
- package/dist/charts/kinds/bars.mjs +39 -6
- package/dist/charts/kinds/columns-data.mjs +14 -5
- package/dist/charts/kinds/columns-marks.mjs +52 -23
- package/dist/charts/kinds/columns.d.mts +2 -2
- package/dist/charts/kinds/columns.mjs +36 -10
- package/dist/charts/kinds/course-data.mjs +44 -0
- package/dist/charts/kinds/course-layout.mjs +77 -0
- package/dist/charts/kinds/course-marks.mjs +52 -0
- package/dist/charts/kinds/course-words.mjs +64 -0
- package/dist/charts/kinds/course.d.mts +10 -0
- package/dist/charts/kinds/course.mjs +55 -0
- package/dist/charts/kinds/dumbbell-data.d.mts +4 -4
- package/dist/charts/kinds/dumbbell-data.mjs +3 -3
- package/dist/charts/kinds/dumbbell-layout.mjs +17 -8
- package/dist/charts/kinds/dumbbell.d.mts +5 -3
- package/dist/charts/kinds/dumbbell.mjs +35 -4
- package/dist/charts/kinds/funnel-data.d.mts +3 -3
- package/dist/charts/kinds/funnel-data.mjs +11 -16
- package/dist/charts/kinds/funnel-layout.mjs +7 -6
- package/dist/charts/kinds/funnel.d.mts +5 -4
- package/dist/charts/kinds/funnel.mjs +33 -6
- package/dist/charts/kinds/grid-data.d.mts +3 -3
- package/dist/charts/kinds/grid-data.mjs +55 -13
- package/dist/charts/kinds/grid-layout.mjs +88 -13
- package/dist/charts/kinds/grid-legend.mjs +60 -0
- package/dist/charts/kinds/grid-marks.mjs +81 -30
- package/dist/charts/kinds/grid-time.mjs +19 -5
- package/dist/charts/kinds/grid-words.mjs +57 -35
- package/dist/charts/kinds/grid.d.mts +7 -4
- package/dist/charts/kinds/grid.mjs +49 -8
- package/dist/charts/kinds/histogram-data.mjs +68 -26
- package/dist/charts/kinds/histogram-layout.mjs +4 -3
- package/dist/charts/kinds/histogram-words.mjs +2 -3
- package/dist/charts/kinds/histogram.d.mts +2 -2
- package/dist/charts/kinds/histogram.mjs +17 -1
- package/dist/charts/kinds/line-marks.mjs +19 -11
- package/dist/charts/kinds/line.d.mts +2 -2
- package/dist/charts/kinds/line.mjs +21 -3
- package/dist/charts/kinds/multiples-grid.mjs +57 -27
- package/dist/charts/kinds/multiples-head.mjs +52 -22
- package/dist/charts/kinds/multiples-layout.mjs +106 -52
- package/dist/charts/kinds/multiples-marks.mjs +6 -5
- package/dist/charts/kinds/multiples-words.mjs +53 -38
- package/dist/charts/kinds/multiples.d.mts +2 -2
- package/dist/charts/kinds/multiples.mjs +35 -7
- package/dist/charts/kinds/row-chart.d.mts +7 -0
- package/dist/charts/kinds/row-chart.mjs +47 -10
- package/dist/charts/kinds/row-marks.mjs +5 -5
- package/dist/charts/kinds/scatter-data.d.mts +5 -5
- package/dist/charts/kinds/scatter-data.mjs +6 -6
- package/dist/charts/kinds/scatter-marks.mjs +46 -19
- package/dist/charts/kinds/scatter-words.mjs +8 -8
- package/dist/charts/kinds/scatter.d.mts +5 -3
- package/dist/charts/kinds/scatter.mjs +18 -0
- package/dist/charts/kinds/stat-data.mjs +7 -7
- package/dist/charts/kinds/stat-marks.mjs +2 -2
- package/dist/charts/kinds/stat.d.mts +4 -4
- package/dist/charts/kinds/stat.mjs +19 -0
- package/dist/charts/kinds/time-chart.mjs +13 -4
- package/dist/charts/kinds/time-frame.mjs +50 -19
- package/dist/charts/kinds/time-plan.mjs +29 -2
- package/dist/charts/kinds/time-plot.mjs +1 -1
- package/dist/charts/kinds/time-stops.mjs +58 -29
- package/dist/charts/kinds/waterfall-data.d.mts +3 -3
- package/dist/charts/kinds/waterfall-data.mjs +2 -2
- package/dist/charts/kinds/waterfall.d.mts +5 -4
- package/dist/charts/kinds/waterfall.mjs +29 -2
- package/dist/charts/layout/frame.mjs +5 -3
- package/dist/charts/layout/stack.mjs +43 -22
- package/dist/charts/marks/axes.mjs +10 -5
- package/dist/charts/marks/budget.mjs +14 -0
- package/dist/charts/marks/end-labels.mjs +24 -10
- package/dist/charts/marks/legend.mjs +19 -8
- package/dist/charts/marks/lines.mjs +3 -3
- package/dist/charts/marks/more.mjs +79 -13
- package/dist/charts/marks/notes.mjs +12 -6
- package/dist/charts/marks/series-line.mjs +14 -10
- package/dist/charts/marks/thin.mjs +16 -33
- package/dist/charts/scale/calendar.mjs +41 -26
- package/dist/charts/scale/linear.mjs +58 -0
- package/dist/charts/scale/value.d.mts +21 -0
- package/dist/charts/scale/value.mjs +67 -9
- package/dist/charts/scene/lazy.mjs +27 -0
- package/dist/charts/scene/markup.mjs +2 -1
- package/dist/charts/scene/svg.mjs +20 -8
- package/dist/charts/scene/types.d.mts +34 -0
- package/dist/charts/text/measure.mjs +33 -3
- package/dist/charts/theme.mjs +13 -4
- package/dist/charts-react/Chart.d.mts +20 -0
- package/dist/charts-react/Chart.mjs +9 -67
- package/dist/charts-react/Reader.mjs +50 -96
- package/dist/charts-react/box.mjs +106 -0
- package/dist/charts-react/bucket-names.mjs +9 -24
- package/dist/charts-react/columns-picture.mjs +12 -0
- package/dist/charts-react/exact-sum.mjs +4 -7
- package/dist/charts-react/from-answer.mjs +9 -4
- package/dist/charts-react/index.d.mts +9 -2
- package/dist/charts-react/index.mjs +9 -2
- package/dist/charts-react/kinds/area.d.mts +4 -0
- package/dist/charts-react/kinds/area.mjs +38 -0
- package/dist/charts-react/kinds/bar.d.mts +4 -0
- package/dist/charts-react/kinds/bar.mjs +15 -0
- package/dist/charts-react/kinds/funnel.d.mts +4 -0
- package/dist/charts-react/kinds/funnel.mjs +13 -0
- package/dist/charts-react/kinds/heatmap.d.mts +4 -0
- package/dist/charts-react/kinds/heatmap.mjs +13 -0
- package/dist/charts-react/kinds/line.d.mts +4 -0
- package/dist/charts-react/kinds/line.mjs +20 -0
- package/dist/charts-react/kinds/multiples.d.mts +4 -0
- package/dist/charts-react/kinds/multiples.mjs +33 -0
- package/dist/charts-react/kinds/number.d.mts +5 -0
- package/dist/charts-react/kinds/number.mjs +86 -0
- package/dist/charts-react/plan-bars.mjs +15 -8
- package/dist/charts-react/plan-funnel.mjs +3 -1
- package/dist/charts-react/plan-grid.mjs +14 -5
- package/dist/charts-react/plan-of.mjs +17 -0
- package/dist/charts-react/plan-parts.mjs +16 -5
- package/dist/charts-react/plan-time.mjs +4 -53
- package/dist/charts-react/reader-page.d.mts +1 -1
- package/dist/charts-react/reader-page.mjs +19 -9
- package/dist/charts-react/renderers.d.mts +14 -0
- package/dist/charts-react/renderers.mjs +22 -0
- package/dist/charts-react/table.d.mts +1 -0
- package/dist/charts-react/table.mjs +108 -0
- package/dist/charts-react/tiles.mjs +21 -49
- package/dist/charts-react/useScene.mjs +45 -17
- package/dist/charts-react/words.mjs +19 -0
- package/dist/checks.mjs +97 -19
- package/dist/cli/add.mjs +4 -3
- package/dist/cli/doctor.mjs +2 -2
- package/dist/core/conformance/index.d.mts +5 -2
- package/dist/core/conformance/index.mjs +5 -2
- package/dist/core/conformance/memory/aggregate.mjs +11 -6
- package/dist/core/conformance/memory/rows.d.mts +7 -3
- package/dist/core/conformance/memory/rows.mjs +19 -13
- package/dist/core/conformance/memory/source.mjs +4 -4
- package/dist/core/document/control-fields.d.mts +20 -0
- package/dist/core/document/control-fields.mjs +117 -0
- package/dist/core/document/display-comparisons.d.mts +17 -0
- package/dist/core/document/display-comparisons.mjs +15 -4
- package/dist/core/document/display-entries.d.mts +14 -0
- package/dist/core/document/display-entries.mjs +25 -9
- package/dist/core/document/display-validation.d.mts +5 -1
- package/dist/core/document/display-validation.mjs +14 -7
- package/dist/core/document/display.d.mts +12 -10
- package/dist/core/document/display.mjs +32 -6
- package/dist/core/document/layout.d.mts +8 -9
- package/dist/core/document/layout.mjs +23 -6
- package/dist/core/document/stacked.d.mts +0 -7
- package/dist/core/document/types.mjs +8 -6
- package/dist/core/document/upgrade.d.mts +1 -0
- package/dist/core/document/upgrade.mjs +4 -2
- package/dist/core/engine/access.mjs +3 -3
- package/dist/core/engine/assert.mjs +4 -2
- package/dist/core/engine/bucket.mjs +2 -2
- package/dist/core/engine/checks.mjs +6 -7
- package/dist/core/engine/custom/ask.mjs +22 -2
- package/dist/core/engine/custom/cells.mjs +22 -22
- package/dist/core/engine/custom/level.mjs +12 -13
- package/dist/core/engine/custom/measures.mjs +12 -9
- package/dist/core/engine/custom/reader.mjs +3 -1
- package/dist/core/engine/custom/records.mjs +8 -7
- package/dist/core/engine/custom/unread.mjs +78 -0
- package/dist/core/engine/custom/where.mjs +15 -10
- package/dist/core/engine/index.d.mts +2 -13
- package/dist/core/engine/index.mjs +2 -12
- package/dist/core/engine/measure.mjs +1 -0
- package/dist/core/engine/members.mjs +7 -3
- package/dist/core/engine/nan.mjs +10 -1
- package/dist/core/engine/native.mjs +2 -20
- package/dist/core/engine/numbers.mjs +26 -14
- package/dist/core/engine/postgres.mjs +9 -5
- package/dist/core/engine/prepare.mjs +4 -4
- package/dist/core/engine/rank-sets.mjs +1 -1
- package/dist/core/engine/read.mjs +5 -4
- package/dist/core/engine/reader.d.mts +6 -0
- package/dist/core/engine/record-layout.mjs +3 -3
- package/dist/core/engine/run.mjs +77 -20
- package/dist/core/engine/segmented.d.mts +2 -1
- package/dist/core/engine/segmented.mjs +19 -12
- package/dist/core/engine/series.mjs +1 -1
- package/dist/core/engine/shape.mjs +8 -8
- package/dist/core/engine/sql-partition.mjs +2 -2
- package/dist/core/engine/sql-pass.mjs +3 -2
- package/dist/core/engine/sql-reader.mjs +13 -5
- package/dist/core/engine/sql-reads.mjs +2 -1
- package/dist/core/engine/sql-records.mjs +2 -2
- package/dist/core/engine/sql-split.mjs +1 -1
- package/dist/core/engine/sql-unread.mjs +70 -0
- package/dist/core/engine/time.mjs +2 -1
- package/dist/core/engine/types.d.mts +17 -0
- package/dist/core/engine/version.d.mts +1 -1
- package/dist/core/engine/version.mjs +1 -1
- package/dist/core/error/codes.d.mts +24 -1
- package/dist/core/error/codes.mjs +23 -3
- package/dist/core/error/refusal.d.mts +8 -3
- package/dist/core/error/refusal.mjs +6 -1
- package/dist/core/exact/decimal.d.mts +1 -14
- package/dist/core/exact/decimal.mjs +9 -19
- package/dist/core/exact/stored.d.mts +9 -0
- package/dist/core/exact/stored.mjs +38 -0
- package/dist/core/exact/text.d.mts +16 -1
- package/dist/core/exact/text.mjs +50 -1
- package/dist/core/format/digits.mjs +55 -0
- package/dist/core/format/index.d.mts +16 -0
- package/dist/core/format/index.mjs +27 -0
- package/dist/core/format/number.d.mts +27 -0
- package/dist/core/format/number.mjs +158 -0
- package/dist/core/format/write.d.mts +6 -0
- package/dist/core/format/write.mjs +57 -0
- package/dist/core/index.d.mts +43 -33
- package/dist/core/index.mjs +31 -28
- package/dist/core/model/defaults.d.mts +18 -1
- package/dist/core/model/defaults.mjs +19 -1
- package/dist/core/model/define.d.mts +17 -8
- package/dist/core/model/define.mjs +2 -0
- package/dist/core/model/member.d.mts +5 -3
- package/dist/core/model/member.mjs +33 -6
- package/dist/core/model/storage.mjs +40 -12
- package/dist/core/model/types.d.mts +17 -1
- package/dist/core/model/types.mjs +5 -0
- package/dist/core/model/validate/expr.d.mts +1 -7
- package/dist/core/model/validate/fields.d.mts +2 -0
- package/dist/core/model/validate/fields.mjs +14 -7
- package/dist/core/model/validate/issues.mjs +5 -1
- package/dist/core/model/validate/known-members.mjs +6 -5
- package/dist/core/model/validate/shape.mjs +36 -3
- package/dist/core/model/validate/source.mjs +2 -2
- package/dist/core/oracle/data.d.mts +4 -2
- package/dist/core/oracle/evaluate.d.mts +19 -1
- package/dist/core/oracle/evaluate.mjs +56 -10
- package/dist/core/oracle/expr.mjs +1 -1
- package/dist/core/oracle/facts.mjs +12 -5
- package/dist/core/oracle/measure.mjs +1 -1
- package/dist/core/oracle/request.mjs +39 -4
- package/dist/core/oracle/segmented.d.mts +3 -1
- package/dist/core/oracle/segmented.mjs +19 -13
- package/dist/core/oracle/unread.mjs +32 -0
- package/dist/core/oracle/visibility.mjs +4 -3
- package/dist/core/policy/bind.d.mts +2 -11
- package/dist/core/policy/bind.mjs +1 -1
- package/dist/core/policy/match.mjs +1 -1
- package/dist/core/query/closure.d.mts +7 -2
- package/dist/core/query/closure.mjs +29 -12
- package/dist/core/query/compose-tile.d.mts +3 -2
- package/dist/core/query/compose-tile.mjs +32 -13
- package/dist/core/query/compose.d.mts +0 -5
- package/dist/core/query/drill/internal.d.mts +5 -5
- package/dist/core/query/drill/internal.mjs +11 -0
- package/dist/core/query/drill/links.d.mts +2 -3
- package/dist/core/query/drill/links.mjs +31 -5
- package/dist/core/query/drill/selection.d.mts +8 -2
- package/dist/core/query/drill/selection.mjs +14 -3
- package/dist/core/query/drill/synthetic.mjs +1 -1
- package/dist/core/query/drill/time.mjs +11 -10
- package/dist/core/query/filter.d.mts +1 -6
- package/dist/core/query/filter.mjs +1 -4
- package/dist/core/query/fold.mjs +23 -0
- package/dist/core/query/segments.mjs +42 -3
- package/dist/core/query/to-wire.d.mts +7 -0
- package/dist/core/query/to-wire.mjs +14 -2
- package/dist/core/query/types.d.mts +30 -13
- package/dist/core/result/columns.mjs +23 -13
- package/dist/core/result/number.mjs +3 -3
- package/dist/core/result/status.d.mts +13 -0
- package/dist/core/result/status.mjs +18 -0
- package/dist/core/result/time-axis.d.mts +14 -13
- package/dist/core/result/time-axis.mjs +20 -2
- package/dist/core/result/types.d.mts +33 -3
- package/dist/core/result/whole.d.mts +23 -0
- package/dist/core/result/whole.mjs +27 -0
- package/dist/core/schema/agent-query.d.mts +89 -0
- package/dist/core/schema/agent-query.mjs +115 -0
- package/dist/core/schema/aliases.mjs +1 -52
- package/dist/core/schema/answer-parts.mjs +17 -13
- package/dist/core/schema/answers.d.mts +787 -319
- package/dist/core/schema/commands.d.mts +33 -23
- package/dist/core/schema/commands.mjs +26 -18
- package/dist/core/schema/custom.mjs +46 -45
- package/dist/core/schema/document.d.mts +32 -27
- package/dist/core/schema/document.mjs +61 -81
- package/dist/core/schema/drill-answers.mjs +4 -1
- package/dist/core/schema/drill.d.mts +14 -9
- package/dist/core/schema/drill.mjs +23 -22
- package/dist/core/schema/index.d.mts +5 -3
- package/dist/core/schema/index.mjs +5 -3
- package/dist/core/schema/options.d.mts +92 -0
- package/dist/core/schema/options.mjs +104 -0
- package/dist/core/schema/picks.d.mts +2 -2
- package/dist/core/schema/picks.mjs +7 -6
- package/dist/core/schema/query.d.mts +9 -83
- package/dist/core/schema/query.mjs +49 -73
- package/dist/core/schema/strict.d.mts +3 -0
- package/dist/core/schema/strict.mjs +91 -0
- package/dist/core/schema/tools.mjs +4 -0
- package/dist/core/schema/union-error.mjs +30 -7
- package/dist/core/schema/view.d.mts +4 -3
- package/dist/core/schema/view.mjs +16 -11
- package/dist/core/store/ddl.d.mts +0 -2
- package/dist/core/store/ddl.mjs +1 -5
- package/dist/core/time/bucket.d.mts +1 -19
- package/dist/core/time/bucket.mjs +6 -6
- package/dist/core/time/compare.mjs +3 -2
- package/dist/core/time/index.d.mts +7 -8
- package/dist/core/time/instant.d.mts +15 -9
- package/dist/core/time/instant.mjs +23 -9
- package/dist/core/time/range.d.mts +3 -15
- package/dist/core/time/range.mjs +17 -7
- package/dist/core/time/stored.d.mts +8 -5
- package/dist/core/time/stored.mjs +51 -15
- package/dist/core/time/temporal.d.mts +1 -5
- package/dist/core/time/temporal.mjs +9 -4
- package/dist/core/time/text-time.d.mts +31 -2
- package/dist/core/time/text-time.mjs +139 -22
- package/dist/core/time/zone.mjs +2 -2
- package/dist/core/types/api.d.mts +1 -1
- package/dist/core/types/api.mjs +1 -1
- package/dist/core/types/dashboard.d.mts +185 -0
- package/dist/core/types/dashboard.mjs +26 -0
- package/dist/core/types/drill-api.d.mts +14 -2
- package/dist/core/types/infer.d.mts +0 -4
- package/dist/core/types/options-check.d.mts +42 -0
- package/dist/core/types/options-check.mjs +90 -0
- package/dist/core/types/options.d.mts +14 -8
- package/dist/core/value/casefold.d.mts +1 -3
- package/dist/core/value/stored.d.mts +26 -0
- package/dist/core/value/stored.mjs +28 -0
- package/dist/cursor-seal.mjs +37 -9
- package/dist/dashboard-documents.d.mts +14 -6
- package/dist/dashboard-documents.mjs +32 -12
- package/dist/dashboards.mjs +10 -9
- package/dist/drill-access.mjs +6 -6
- package/dist/drill-change.mjs +18 -20
- package/dist/drill-comparison.mjs +2 -1
- package/dist/drill-crumbs.mjs +63 -28
- package/dist/drill-distinct.mjs +2 -1
- package/dist/drill-explain.mjs +1 -1
- package/dist/drill-items.mjs +1 -1
- package/dist/drill-open.mjs +39 -23
- package/dist/drill-seal.mjs +41 -13
- package/dist/drill-share.mjs +1 -1
- package/dist/drill-summary.mjs +2 -1
- package/dist/drill-targets.mjs +4 -4
- package/dist/drill-views.mjs +4 -3
- package/dist/drill.mjs +1 -1
- package/dist/editing.mjs +5 -3
- package/dist/endpoints/index.d.mts +29 -8
- package/dist/endpoints/index.mjs +4 -1
- package/dist/endpoints/meta.mjs +4 -3
- package/dist/endpoints/query.mjs +5 -2
- package/dist/endpoints/read.mjs +7 -6
- package/dist/endpoints/versions.mjs +2 -1
- package/dist/execute.d.mts +3 -0
- package/dist/execute.mjs +23 -12
- package/dist/grant.d.mts +9 -0
- package/dist/grant.mjs +43 -0
- package/dist/handler.mjs +8 -13
- package/dist/http.d.mts +6 -2
- package/dist/http.mjs +6 -2
- package/dist/index.d.mts +25 -4
- package/dist/index.mjs +91 -40
- package/dist/llms.txt +3 -3
- package/dist/mcp/api.mjs +2 -1
- package/dist/mcp/query.mjs +3 -8
- package/dist/mcp/resolve.mjs +9 -2
- package/dist/node/index.d.mts +36 -0
- package/dist/node/index.mjs +89 -0
- package/dist/node/request.d.mts +12 -0
- package/dist/node/request.mjs +119 -0
- package/dist/node/response.mjs +58 -0
- package/dist/principal.mjs +15 -7
- package/dist/react/Canvas.mjs +88 -67
- package/dist/react/Cell.mjs +2 -1
- package/dist/react/Dashboard.d.mts +11 -4
- package/dist/react/Dashboard.mjs +42 -42
- package/dist/react/DashboardList.mjs +9 -4
- package/dist/react/Editing.d.mts +9 -0
- package/dist/react/Editing.mjs +8 -3
- package/dist/react/Grid.mjs +1 -1
- package/dist/react/Header.mjs +4 -35
- package/dist/react/History.mjs +3 -2
- package/dist/react/LoadFailed.mjs +59 -0
- package/dist/react/Panel.d.mts +1 -1
- package/dist/react/Panel.mjs +1 -1
- package/dist/react/Parts.d.mts +34 -0
- package/dist/react/Parts.mjs +9 -6
- package/dist/react/ReviewPanel.mjs +1 -1
- package/dist/react/RowBody.d.mts +2 -0
- package/dist/react/RowBody.mjs +5 -1
- package/dist/react/Share.mjs +153 -0
- package/dist/react/TabStrip.mjs +37 -0
- package/dist/react/Tile.d.mts +3 -1
- package/dist/react/Tile.mjs +89 -92
- package/dist/react/TileState.mjs +117 -0
- package/dist/react/ago.mjs +45 -0
- package/dist/react/arrange-steps.mjs +99 -11
- package/dist/react/arrange.mjs +11 -4
- package/dist/react/board.mjs +2 -2
- package/dist/react/bucket-name.d.mts +8 -0
- package/dist/react/bucket-name.mjs +13 -0
- package/dist/react/builder/DisplayOptions.mjs +219 -0
- package/dist/react/builder/Preview.mjs +13 -13
- package/dist/react/builder/RangeEditor.mjs +4 -3
- package/dist/react/builder/WidgetBuilder.d.mts +1 -7
- package/dist/react/builder/WidgetBuilder.mjs +12 -3
- package/dist/react/builder/base.d.mts +13 -2
- package/dist/react/builder/base.mjs +70 -12
- package/dist/react/builder/display.d.mts +3 -0
- package/dist/react/builder/display.mjs +257 -0
- package/dist/react/builder/labels.mjs +19 -5
- package/dist/react/builder/options.mjs +11 -6
- package/dist/react/builder/state.mjs +25 -3
- package/dist/react/builder/useBuilder.d.mts +7 -1
- package/dist/react/builder/useBuilder.mjs +6 -9
- package/dist/react/builder/usePreview.mjs +3 -2
- package/dist/react/builder/words.d.mts +16 -1
- package/dist/react/builder/words.mjs +41 -1
- package/dist/react/change-text.mjs +149 -0
- package/dist/react/client.d.mts +9 -0
- package/dist/react/client.mjs +105 -14
- package/dist/react/context.d.mts +24 -3
- package/dist/react/context.mjs +23 -7
- package/dist/react/dates-shown.mjs +76 -0
- package/dist/react/draft.mjs +3 -2
- package/dist/react/drill/Bars.mjs +12 -16
- package/dist/react/drill/Comparison.mjs +1 -1
- package/dist/react/drill/DrillPanel.d.mts +1 -1
- package/dist/react/drill/DrillPanel.mjs +2 -1
- package/dist/react/drill/Header.mjs +65 -12
- package/dist/react/drill/Items.d.mts +1 -1
- package/dist/react/drill/Notes.mjs +10 -7
- package/dist/react/drill/PanelStates.mjs +8 -1
- package/dist/react/drill/Trend.mjs +10 -5
- package/dist/react/drill/board.d.mts +1 -1
- package/dist/react/drill/host.mjs +4 -1
- package/dist/react/drill/lazy.mjs +2 -27
- package/dist/react/drill/props.d.mts +17 -7
- package/dist/react/drill/props.mjs +55 -14
- package/dist/react/drill/state.d.mts +15 -5
- package/dist/react/drill/state.mjs +12 -3
- package/dist/react/drill/words.d.mts +46 -3
- package/dist/react/drill/words.mjs +30 -5
- package/dist/react/english.mjs +33 -8
- package/dist/react/export/ExportButton.mjs +4 -1
- package/dist/react/export/csv.d.mts +7 -2
- package/dist/react/export/csv.mjs +24 -7
- package/dist/react/failure-words.mjs +60 -0
- package/dist/react/filters/bar.d.mts +1 -1
- package/dist/react/filters/bar.mjs +4 -1
- package/dist/react/filters/calendar.mjs +23 -8
- package/dist/react/filters/chip.mjs +7 -3
- package/dist/react/filters/context.d.mts +13 -1
- package/dist/react/filters/context.mjs +1 -1
- package/dist/react/filters/dates-said.mjs +57 -0
- package/dist/react/filters/days.d.mts +3 -4
- package/dist/react/filters/days.mjs +10 -17
- package/dist/react/filters/hooks.d.mts +11 -0
- package/dist/react/filters/hooks.mjs +10 -6
- package/dist/react/filters/menu-search.mjs +17 -9
- package/dist/react/filters/menu.mjs +10 -8
- package/dist/react/filters/phone.mjs +41 -16
- package/dist/react/filters/place.mjs +40 -0
- package/dist/react/filters/popover.mjs +18 -13
- package/dist/react/filters/rules.d.mts +4 -3
- package/dist/react/filters/rules.mjs +3 -3
- package/dist/react/filters/sheet.mjs +7 -3
- package/dist/react/filters/state.mjs +6 -1
- package/dist/react/filters/values.mjs +24 -7
- package/dist/react/filters/words.d.mts +13 -0
- package/dist/react/filters/words.mjs +5 -0
- package/dist/react/format-time.d.mts +17 -6
- package/dist/react/format-time.mjs +152 -33
- package/dist/react/format.d.mts +3 -3
- package/dist/react/format.mjs +27 -133
- package/dist/react/headline.d.mts +6 -3
- package/dist/react/headline.mjs +81 -25
- package/dist/react/index.d.mts +19 -17
- package/dist/react/index.mjs +12 -10
- package/dist/react/lazy.mjs +38 -0
- package/dist/react/messages.d.mts +78 -2
- package/dist/react/now.mjs +38 -0
- package/dist/react/read.d.mts +1 -0
- package/dist/react/read.mjs +140 -9
- package/dist/react/renderers/exact.mjs +31 -59
- package/dist/react/renderers/index.d.mts +27 -6
- package/dist/react/renderers/index.mjs +141 -102
- package/dist/react/renderers/list-parts.mjs +24 -0
- package/dist/react/renderers/list.d.mts +1 -0
- package/dist/react/renderers/list.mjs +99 -43
- package/dist/react/renderers/more-rows.mjs +75 -0
- package/dist/react/renderers/number-before.mjs +320 -0
- package/dist/react/renderers/number-period.mjs +54 -0
- package/dist/react/renderers/number-whole.mjs +29 -0
- package/dist/react/renderers/props.d.mts +24 -1
- package/dist/react/renderers/props.mjs +8 -0
- package/dist/react/renderers/table-cells.mjs +137 -31
- package/dist/react/renderers/table-fit.mjs +55 -10
- package/dist/react/renderers/table-measure.mjs +29 -9
- package/dist/react/renderers/table-row.mjs +14 -9
- package/dist/react/renderers/table-scale.mjs +2 -3
- package/dist/react/renderers/table-sort.mjs +3 -2
- package/dist/react/renderers/table-whole.mjs +37 -0
- package/dist/react/renderers/table.mjs +73 -53
- package/dist/react/review.d.mts +7 -0
- package/dist/react/review.mjs +35 -8
- package/dist/react/roving.d.mts +6 -0
- package/dist/react/roving.mjs +123 -0
- package/dist/react/says-dates.d.mts +7 -0
- package/dist/react/says-dates.mjs +51 -0
- package/dist/react/series.mjs +5 -6
- package/dist/react/stable.mjs +1 -1
- package/dist/react/tabs/EditTabs.mjs +125 -0
- package/dist/react/tabs/NameField.mjs +72 -0
- package/dist/react/tabs/TabMenu.mjs +175 -0
- package/dist/react/tabs/actions.mjs +37 -0
- package/dist/react/tabs/commands.mjs +76 -0
- package/dist/react/tabs/focus.mjs +22 -0
- package/dist/react/tabs/keys.mjs +28 -0
- package/dist/react/theme-unlayered.css +1 -1
- package/dist/react/theme.css +1 -1
- package/dist/react/tile-store.d.mts +4 -0
- package/dist/react/tile-store.mjs +93 -13
- package/dist/react/touch.d.mts +16 -0
- package/dist/react/touch.mjs +39 -0
- package/dist/react/useBoard.d.mts +6 -0
- package/dist/react/useBoard.mjs +1 -0
- package/dist/react/useDashboard.d.mts +2 -0
- package/dist/react/useDashboard.mjs +5 -2
- package/dist/react/useTiles.d.mts +3 -0
- package/dist/react/useTiles.mjs +73 -17
- package/dist/react/view-grid.mjs +2 -2
- package/dist/react/view.mjs +1 -1
- package/dist/recharts/axes.mjs +1 -1
- package/dist/recharts/axis.mjs +23 -73
- package/dist/recharts/bar.d.mts +2 -1
- package/dist/recharts/bar.mjs +140 -64
- package/dist/recharts/fit.mjs +33 -0
- package/dist/recharts/line.mjs +21 -15
- package/dist/recharts/marks.mjs +2 -1
- package/dist/recharts/parts.mjs +16 -13
- package/dist/recharts/table.mjs +8 -3
- package/dist/refusal.mjs +46 -0
- package/dist/registry/filter-bar.json +1 -1
- package/dist/skills/derive-dashboards/SKILL.md +23 -8
- package/dist/tile-doc.mjs +1 -1
- package/package.json +21 -6
- package/dist/charts-react/plan.d.mts +0 -3
- package/dist/charts-react/plan.mjs +0 -37
- package/dist/charts-react/tiles.d.mts +0 -24
- package/dist/core/policy/match.d.mts +0 -16
- package/dist/core/schema/aliases.d.mts +0 -7
- package/dist/core/time/compare.d.mts +0 -30
- package/dist/react/EditBar.d.mts +0 -16
- package/dist/react/History.d.mts +0 -30
- package/dist/react/ReviewPanel.d.mts +0 -15
- package/dist/react/digits.mjs +0 -46
- package/dist/react/drill/trend-touch.mjs +0 -33
- package/dist/react/renderers/exact.d.mts +0 -6
|
@@ -1,32 +1,274 @@
|
|
|
1
1
|
import { ChartInputError } from "./input-error.mjs";
|
|
2
2
|
import { otherLast } from "./rows.mjs";
|
|
3
|
+
import { cellDigits, didYouMean } from "derive-dashboards/core";
|
|
3
4
|
// src/data/clean.ts
|
|
4
|
-
/**
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
/**
|
|
6
|
+
* A path from where a value was given: the field as the caller wrote it, with a `#` for each
|
|
7
|
+
* index, each replaced by the next index (`rows[#].value` and 3 is `rows[3].value`).
|
|
8
|
+
*/
|
|
9
|
+
const pathOf = (field, indices) => {
|
|
10
|
+
let next = 0;
|
|
11
|
+
return field.replaceAll("#", () => String(indices[next++] ?? "#"));
|
|
12
|
+
};
|
|
13
|
+
const at = (field, key) => typeof key === "number" ? `${field}[${String(key)}]` : field === "" ? key : `${field}.${key}`;
|
|
14
|
+
const is = (test, what) => (value, field) => {
|
|
15
|
+
if (!test(value)) throw new ChartInputError(field, `Expected ${what}.`);
|
|
16
|
+
};
|
|
17
|
+
const ANY = () => {};
|
|
18
|
+
const FUNCTION = is((v) => typeof v === "function", "a function");
|
|
19
|
+
const TEXT = is((v) => typeof v === "string", "text");
|
|
20
|
+
const NUMBER = is((v) => typeof v === "number", "a number");
|
|
21
|
+
const FLAG = is((v) => typeof v === "boolean", "true or false");
|
|
22
|
+
/** A picture is drawn a pixel column at a time: one past this is no screen's, and no page's. */
|
|
23
|
+
const LARGEST = 1e5;
|
|
24
|
+
const SIZE = is((v) => typeof v === "number" && v > 0 && v <= LARGEST, `a size in pixels above zero and at most ${String(LARGEST)}`);
|
|
25
|
+
const oneOf = (...values) => is((v) => typeof v === "string" && values.includes(v), values.join(", "));
|
|
26
|
+
const listOf = (item) => (value, field) => {
|
|
27
|
+
if (!Array.isArray(value)) throw new ChartInputError(field, "Expected a list.");
|
|
28
|
+
if (item !== ANY) for (const [i, one] of value.entries()) item(one, at(field, i));
|
|
29
|
+
};
|
|
30
|
+
const shape = (needs, may = {}) => (value, field) => {
|
|
31
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) throw new ChartInputError(field, "Expected an object.");
|
|
32
|
+
for (const [key, check] of Object.entries(needs)) check(Reflect.get(value, key), at(field, key));
|
|
33
|
+
for (const [key, check] of Object.entries(may)) {
|
|
34
|
+
const one = Reflect.get(value, key);
|
|
35
|
+
if (one !== void 0) check(one, at(field, key));
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
/** A check at the root of an input, an object there named by what it is (a list names itself). */
|
|
39
|
+
const rooted = (check, name) => (value, field) => {
|
|
40
|
+
if (field === "" && (typeof value !== "object" || value === null || Array.isArray(value))) throw new ChartInputError(name, "Expected an object.");
|
|
41
|
+
check(value, field);
|
|
42
|
+
};
|
|
43
|
+
const TINT = {
|
|
44
|
+
slot: NUMBER,
|
|
45
|
+
color: TEXT,
|
|
46
|
+
other: FLAG
|
|
47
|
+
};
|
|
48
|
+
const NAMED = shape({ label: TEXT }, {
|
|
49
|
+
key: TEXT,
|
|
50
|
+
...TINT
|
|
51
|
+
});
|
|
52
|
+
const MEASURE = shape({
|
|
53
|
+
label: TEXT,
|
|
54
|
+
tick: FUNCTION,
|
|
55
|
+
text: FUNCTION
|
|
56
|
+
}, {
|
|
57
|
+
whole: FLAG,
|
|
58
|
+
additive: FLAG,
|
|
59
|
+
share: FLAG,
|
|
60
|
+
better: oneOf("up", "down"),
|
|
61
|
+
unit: TEXT
|
|
62
|
+
});
|
|
63
|
+
const LEVELS = listOf(shape({
|
|
64
|
+
value: NUMBER,
|
|
65
|
+
label: TEXT
|
|
66
|
+
}));
|
|
67
|
+
const TABLE = shape({
|
|
68
|
+
x: shape({
|
|
69
|
+
grain: oneOf("hour", "day", "week", "month", "quarter", "year"),
|
|
70
|
+
buckets: listOf(shape({
|
|
71
|
+
label: TEXT,
|
|
72
|
+
from: NUMBER,
|
|
73
|
+
to: NUMBER
|
|
74
|
+
}))
|
|
75
|
+
}),
|
|
76
|
+
series: listOf(shape({
|
|
77
|
+
key: TEXT,
|
|
78
|
+
label: TEXT,
|
|
79
|
+
values: listOf(ANY),
|
|
80
|
+
measure: MEASURE
|
|
81
|
+
}, {
|
|
82
|
+
previous: listOf(ANY),
|
|
83
|
+
...TINT
|
|
84
|
+
}))
|
|
85
|
+
});
|
|
86
|
+
/** What every public entry takes, by what it is given: rows, steps, points, values, a table or a grid. */
|
|
87
|
+
const SHAPES = {
|
|
88
|
+
rows: listOf(NAMED),
|
|
89
|
+
steps: listOf(NAMED),
|
|
90
|
+
points: listOf(NAMED),
|
|
91
|
+
values: listOf(ANY),
|
|
92
|
+
table: rooted(TABLE, "table"),
|
|
93
|
+
course: (value, field) => {
|
|
94
|
+
if (value !== void 0) rooted(TABLE, "course")(value, field);
|
|
95
|
+
},
|
|
96
|
+
grid: rooted(shape({
|
|
97
|
+
rows: listOf(NAMED),
|
|
98
|
+
columns: listOf(NAMED),
|
|
99
|
+
values: listOf(listOf(ANY))
|
|
100
|
+
}), "grid")
|
|
101
|
+
};
|
|
102
|
+
/** The options every kind may take, checked when given. */
|
|
103
|
+
const OPTIONS = {
|
|
104
|
+
title: TEXT,
|
|
105
|
+
subtitle: TEXT,
|
|
106
|
+
source: TEXT,
|
|
107
|
+
fromLabel: TEXT,
|
|
108
|
+
toLabel: TEXT,
|
|
109
|
+
againstLabel: TEXT,
|
|
110
|
+
rowTitle: TEXT,
|
|
111
|
+
columnTitle: TEXT,
|
|
112
|
+
sizeTitle: TEXT,
|
|
113
|
+
measure: MEASURE,
|
|
114
|
+
x: MEASURE,
|
|
115
|
+
y: MEASURE,
|
|
116
|
+
size: MEASURE,
|
|
117
|
+
focus: listOf(TEXT),
|
|
118
|
+
sort: oneOf("value", "given", "change"),
|
|
119
|
+
arrange: oneOf("stacked", "grouped", "share"),
|
|
120
|
+
curve: oneOf("straight", "smooth", "step"),
|
|
121
|
+
naming: oneOf("end", "legend", "none"),
|
|
122
|
+
references: (v, f) => {
|
|
123
|
+
(Array.isArray(v) ? LEVELS : shape({}, {
|
|
124
|
+
x: LEVELS,
|
|
125
|
+
y: LEVELS
|
|
126
|
+
}))(v, f);
|
|
127
|
+
},
|
|
128
|
+
events: listOf(shape({
|
|
129
|
+
at: NUMBER,
|
|
130
|
+
label: TEXT
|
|
131
|
+
}))
|
|
132
|
+
};
|
|
133
|
+
/** Every key of an options type, each once: a key the type gains that this lacks does not compile. */
|
|
134
|
+
const keysOf = (all) => Object.keys(all);
|
|
135
|
+
/** The keys of what a chart says of itself (`Header`) and of the marks on a time axis (`TimeNotes`). */
|
|
136
|
+
const HEADER = {
|
|
137
|
+
title: true,
|
|
138
|
+
subtitle: true,
|
|
139
|
+
source: true
|
|
140
|
+
};
|
|
141
|
+
const NOTES = {
|
|
142
|
+
references: true,
|
|
143
|
+
events: true
|
|
144
|
+
};
|
|
145
|
+
/**
|
|
146
|
+
* Refuses a key an options object has that its entry does not take, by name, with the key it
|
|
147
|
+
* most likely meant (core's `didYouMean`, as the server says it): from JavaScript a misspelt
|
|
148
|
+
* `fokus` would otherwise be read as no option at all.
|
|
149
|
+
*/
|
|
150
|
+
function knownKeys(given, known) {
|
|
151
|
+
if (typeof given !== "object" || given === null) return;
|
|
152
|
+
const unknown = Object.keys(given).find((key) => !known.includes(key));
|
|
153
|
+
if (unknown !== void 0) throw new ChartInputError(`options.${unknown}`, `Unknown key "${unknown}".${didYouMean(unknown, known)} The keys here are ${known.join(", ")}.`);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* The input of a public entry checked: what it is given (by the name it is given under, which is
|
|
157
|
+
* the root of its paths: `rows[2].label`, or for a table `x.grain`), the options (measures named
|
|
158
|
+
* by their own field: `measure.tick`; only the keys the entry takes, `known`, and those it
|
|
159
|
+
* `needs`), and where it is drawn (`width`).
|
|
160
|
+
*/
|
|
161
|
+
function checkInput(given, options, env, keys) {
|
|
162
|
+
const root = [
|
|
163
|
+
"table",
|
|
164
|
+
"course",
|
|
165
|
+
"grid"
|
|
166
|
+
].includes(given.what) ? "" : given.what;
|
|
167
|
+
SHAPES[given.what](given.data, root);
|
|
168
|
+
const needed = (keys.needs ?? []).map((field) => [field, OPTIONS[field] ?? MEASURE]);
|
|
169
|
+
rooted(shape(Object.fromEntries(needed), OPTIONS), "options")(options, "");
|
|
170
|
+
knownKeys(options, keys.known);
|
|
171
|
+
rooted(shape({
|
|
172
|
+
width: SIZE,
|
|
173
|
+
height: SIZE,
|
|
174
|
+
measure: FUNCTION
|
|
175
|
+
}), "env")(env, "");
|
|
176
|
+
}
|
|
177
|
+
/** A picture's size checked before it is written: SVG of no size, or of NaN, is not a picture. */
|
|
178
|
+
function checkSize(scene) {
|
|
179
|
+
rooted(shape({
|
|
180
|
+
width: SIZE,
|
|
181
|
+
height: SIZE
|
|
182
|
+
}), "scene")(scene, "");
|
|
183
|
+
}
|
|
184
|
+
/** A number worked out from drawn values when it can be drawn, else none: a quotient may be infinite. */
|
|
185
|
+
const finiteOrNone = (value) => Number.isFinite(value) ? value : null;
|
|
186
|
+
/**
|
|
187
|
+
* Decimal text as a driver sends a numeric ("412", "31900.50"): its plain digits, by core's one
|
|
188
|
+
* reader of them, as the dashboards read a driver's text; none for a number or other text.
|
|
189
|
+
*/
|
|
190
|
+
const digitsOf = (value) => typeof value === "string" ? cellDigits(value) : void 0;
|
|
191
|
+
/** Why a value that is not a finite number is refused, by what it is. */
|
|
192
|
+
const refusal = (value) => typeof value === "number" ? "Expected a finite number or null." : typeof value === "bigint" ? "Expected a number or null. Convert a bigint with Number() before drawing." : "Expected a number, decimal text such as 12.50, or null.";
|
|
193
|
+
/**
|
|
194
|
+
* A value as given: none for null, undefined or NaN (a failed parse upstream); decimal text (a
|
|
195
|
+
* driver's numeric) as its number. Anything else that is not a finite number (other text, an
|
|
196
|
+
* infinity) is refused with a `ChartInputError` whose `field` is the value's own path, so the
|
|
197
|
+
* caller can find it (`series[1].values[0]`): `field` names where it was given, a `#` for each
|
|
198
|
+
* index, and the path is written only when a value is refused, never for the millions that are
|
|
199
|
+
* fine.
|
|
200
|
+
*/
|
|
201
|
+
function drawable(value, field, i = -1, j = -1) {
|
|
202
|
+
if (value === null || value === void 0 || Number.isNaN(value)) return null;
|
|
203
|
+
const digits = digitsOf(value);
|
|
204
|
+
const number = digits === void 0 ? value : Number(digits);
|
|
205
|
+
if (typeof number !== "number" || !Number.isFinite(number)) throw new ChartInputError(pathOf(field, [i, j]), refusal(value));
|
|
206
|
+
return number;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* A value's own text when it was given as decimal text: every digit, by its measure's `exact`
|
|
210
|
+
* (core's writer, as a dashboard tile writes an exact cell); none for a number, which its
|
|
211
|
+
* measure writes.
|
|
212
|
+
*/
|
|
213
|
+
function writtenOf(value, reads) {
|
|
214
|
+
const digits = digitsOf(value);
|
|
215
|
+
return digits === void 0 ? void 0 : reads.exact?.(digits);
|
|
9
216
|
}
|
|
10
|
-
/**
|
|
217
|
+
/**
|
|
218
|
+
* Values as given, each drawn by `read` (which knows its path); when some were given as decimal
|
|
219
|
+
* text, their texts too, each written with every digit, a host's own text for a place first.
|
|
220
|
+
*/
|
|
221
|
+
function readValues(given, read, how) {
|
|
222
|
+
const values = given.map((value, i) => read(value, i));
|
|
223
|
+
if (!given.some((value) => typeof value === "string")) return { values };
|
|
224
|
+
return {
|
|
225
|
+
values,
|
|
226
|
+
texts: given.map((value, i) => how.texts?.[i] ?? writtenOf(value, how.measure))
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
/** A series has one value per bucket, `null` where there is none, so every value has its place. */
|
|
11
230
|
function cleanSeries(series, index, buckets) {
|
|
12
231
|
const { previous, ...rest } = series;
|
|
13
232
|
for (const field of ["values", "previous"]) {
|
|
14
|
-
const length = series[field]?.length ??
|
|
15
|
-
if (length
|
|
233
|
+
const length = series[field]?.length ?? buckets;
|
|
234
|
+
if (length !== buckets) throw new ChartInputError(`series[${String(index)}].${field}`, `Series "${series.key}" has ${String(length)} values for ${String(buckets)} time buckets.`);
|
|
16
235
|
}
|
|
17
236
|
return {
|
|
18
237
|
...rest,
|
|
19
|
-
|
|
20
|
-
|
|
238
|
+
...readValues(series.values, (value, i) => drawable(value, "series[#].values[#]", index, i), {
|
|
239
|
+
measure: series.measure,
|
|
240
|
+
texts: series.texts
|
|
241
|
+
}),
|
|
242
|
+
...previous === void 0 ? {} : { previous: previous.map((value, i) => drawable(value, "series[#].previous[#]", index, i)) }
|
|
21
243
|
};
|
|
22
244
|
}
|
|
23
|
-
/** Each
|
|
245
|
+
/** Each table cleaned once: a chart drawn again for a new size (a resize) reads it again as it was. */
|
|
246
|
+
const CLEANED = /* @__PURE__ */ new WeakMap();
|
|
247
|
+
/**
|
|
248
|
+
* Each bucket must cover a finite interval and follow the previous one. Calendar gaps are valid.
|
|
249
|
+
* A table is read as it was given, once: new data is a new table.
|
|
250
|
+
*/
|
|
24
251
|
function cleanTable(table) {
|
|
252
|
+
const known = CLEANED.get(table);
|
|
253
|
+
if (known !== void 0) return known;
|
|
254
|
+
const cleaned = cleanedOf(table);
|
|
255
|
+
CLEANED.set(table, cleaned);
|
|
256
|
+
CLEANED.set(cleaned, cleaned);
|
|
257
|
+
return cleaned;
|
|
258
|
+
}
|
|
259
|
+
/** The table cleaned. */
|
|
260
|
+
function cleanedOf(table) {
|
|
25
261
|
let end = -Infinity;
|
|
26
262
|
for (const [i, bucket] of table.x.buckets.entries()) {
|
|
27
263
|
if (!Number.isFinite(bucket.from) || !Number.isFinite(bucket.to) || bucket.from < end || bucket.to <= bucket.from) throw new ChartInputError(`x.buckets[${String(i)}]`, "Expected a non-overlapping time interval in chronological order.");
|
|
28
264
|
end = bucket.to;
|
|
29
265
|
}
|
|
266
|
+
const first = /* @__PURE__ */ new Map();
|
|
267
|
+
for (const [i, { key }] of table.series.entries()) {
|
|
268
|
+
const before = first.get(key);
|
|
269
|
+
if (before !== void 0) throw new ChartInputError(`series[${String(i)}].key`, `Expected a key no other series has; series[${String(before)}] has "${key}".`);
|
|
270
|
+
first.set(key, i);
|
|
271
|
+
}
|
|
30
272
|
return {
|
|
31
273
|
x: table.x,
|
|
32
274
|
series: table.series.map((s, index) => cleanSeries(s, index, table.x.buckets.length))
|
|
@@ -52,4 +294,4 @@ function panelTable(table) {
|
|
|
52
294
|
series: otherLast(cleaned.series)
|
|
53
295
|
};
|
|
54
296
|
}
|
|
55
|
-
export { cleanTable, drawable, finiteRange, panelTable };
|
|
297
|
+
export { HEADER, NOTES, checkInput, checkSize, cleanTable, drawable, finiteOrNone, finiteRange, keysOf, knownKeys, panelTable, readValues, writtenOf };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Measure } from "./types.mjs";
|
|
2
2
|
export type MeasureStyle = {
|
|
3
|
-
/** An ISO 4217 code: the values are money. */
|
|
3
|
+
/** An ISO 4217 code, in any case: the values are money. */
|
|
4
4
|
currency?: string;
|
|
5
5
|
/** The values are fractions of one, read as percents. */
|
|
6
6
|
percent?: boolean;
|
|
@@ -9,7 +9,12 @@ export type MeasureStyle = {
|
|
|
9
9
|
better?: "up" | "down";
|
|
10
10
|
locale?: string;
|
|
11
11
|
};
|
|
12
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* A measure whose values are plain numbers, money or percents, written by core's one writer of
|
|
14
|
+
* numbers, as the React kit writes a cell and a tick: to its places (two, or its currency's own)
|
|
15
|
+
* while they hold the value within a tenth of itself, else by its first figures, so nothing that
|
|
16
|
+
* is not zero reads as zero; every negative with a true minus; a tick in three figures, short.
|
|
17
|
+
*/
|
|
13
18
|
export declare function measure(label: string, style?: MeasureStyle): Measure;
|
|
14
19
|
/**
|
|
15
20
|
* How a host writes a number of points: "4 pts" for 4. It is given a size, never below zero:
|
|
@@ -1,86 +1,71 @@
|
|
|
1
|
+
import { keysOf, knownKeys } from "./clean.mjs";
|
|
2
|
+
import { ChartInputError } from "./input-error.mjs";
|
|
3
|
+
import { MINUS, numberWriters } from "derive-dashboards/core";
|
|
1
4
|
// src/data/format.ts
|
|
2
|
-
/** The
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
/** The keys a measure's style takes: any other is refused, with the one it most likely meant. */
|
|
6
|
+
const STYLE = keysOf({
|
|
7
|
+
currency: true,
|
|
8
|
+
percent: true,
|
|
9
|
+
whole: true,
|
|
10
|
+
additive: true,
|
|
11
|
+
better: true,
|
|
12
|
+
locale: true
|
|
13
|
+
});
|
|
14
|
+
/** The ISO 4217 codes Intl writes. */
|
|
15
|
+
const CURRENCIES = new Set(Intl.supportedValuesOf("currency"));
|
|
16
|
+
/** A currency code as Intl writes it, given in any case ("usd"); refused when it names no currency. */
|
|
17
|
+
function currencyOf(code) {
|
|
18
|
+
const upper = code.toUpperCase();
|
|
19
|
+
if (!CURRENCIES.has(upper)) throw new ChartInputError("currency", `Expected an ISO 4217 code such as USD, not "${code}".`);
|
|
20
|
+
return upper;
|
|
21
|
+
}
|
|
22
|
+
/** A locale as given, refused with its field when it is not one, never the platform's RangeError. */
|
|
23
|
+
function localeOf(locale) {
|
|
24
|
+
if (locale === void 0) return void 0;
|
|
25
|
+
try {
|
|
26
|
+
Intl.getCanonicalLocales(locale);
|
|
27
|
+
} catch {
|
|
28
|
+
throw new ChartInputError("locale", `Expected a locale such as en-US, not "${locale}".`);
|
|
29
|
+
}
|
|
30
|
+
return locale;
|
|
14
31
|
}
|
|
15
|
-
/**
|
|
16
|
-
function
|
|
17
|
-
if (style.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
trailingZeroDisplay: "stripIfInteger"
|
|
32
|
+
/** What a measure's style says of how its numbers are written, as core's writer reads a column. */
|
|
33
|
+
function shapeOf(style) {
|
|
34
|
+
if (style.percent === true) return {
|
|
35
|
+
format: "percent",
|
|
36
|
+
fraction: true
|
|
21
37
|
};
|
|
22
|
-
return
|
|
38
|
+
return style.currency === void 0 ? {} : { unit: currencyOf(style.currency) };
|
|
23
39
|
}
|
|
24
|
-
/**
|
|
25
|
-
const
|
|
26
|
-
/** Below this a number's leading zeros run long, and it is written by its power of ten. */
|
|
27
|
-
const MINUTE = 1e-6;
|
|
40
|
+
/** The charts' number writer for each locale, made once: every chart of a page writes by one. */
|
|
41
|
+
const writerIn = numberWriters();
|
|
28
42
|
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* and whole things have no fractions: for those, and for any number a tenth or more, nothing.
|
|
43
|
+
* A measure whose values are plain numbers, money or percents, written by core's one writer of
|
|
44
|
+
* numbers, as the React kit writes a cell and a tick: to its places (two, or its currency's own)
|
|
45
|
+
* while they hold the value within a tenth of itself, else by its first figures, so nothing that
|
|
46
|
+
* is not zero reads as zero; every negative with a true minus; a tick in three figures, short.
|
|
34
47
|
*/
|
|
35
|
-
function fineOf(style, unit) {
|
|
36
|
-
const plain = style.currency === void 0 && style.percent !== true && style.whole !== true;
|
|
37
|
-
const figures = {
|
|
38
|
-
...unit,
|
|
39
|
-
maximumSignificantDigits: 2
|
|
40
|
-
};
|
|
41
|
-
const small = new Intl.NumberFormat(style.locale, figures);
|
|
42
|
-
const minute = new Intl.NumberFormat(style.locale, {
|
|
43
|
-
...figures,
|
|
44
|
-
notation: "scientific"
|
|
45
|
-
});
|
|
46
|
-
return (value) => {
|
|
47
|
-
const size = Math.abs(value);
|
|
48
|
-
if (!plain || !(size > 0) || size >= FINE) return void 0;
|
|
49
|
-
return (size < MINUTE ? minute : small).format(value);
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
/** A measure whose values are plain numbers, money or percents, formatted by the locale's rules. */
|
|
53
48
|
function measure(label, style = {}) {
|
|
54
|
-
|
|
49
|
+
knownKeys(style, STYLE);
|
|
55
50
|
const percent = style.percent === true;
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
...percent ? {} : { notation: "compact" },
|
|
59
|
-
maximumFractionDigits: 1
|
|
60
|
-
});
|
|
61
|
-
const whole = new Intl.NumberFormat(style.locale, {
|
|
62
|
-
...unit,
|
|
63
|
-
maximumFractionDigits: 0
|
|
64
|
-
});
|
|
65
|
-
const short = (value) => percent && Math.abs(value) >= .1 ? whole.format(value) : compact.format(value);
|
|
66
|
-
const full = new Intl.NumberFormat(style.locale, {
|
|
67
|
-
...unit,
|
|
68
|
-
...fullOf(style)
|
|
69
|
-
});
|
|
70
|
-
const fine = fineOf(style, unit);
|
|
51
|
+
const shape = shapeOf(style);
|
|
52
|
+
const writer = writerIn(localeOf(style.locale));
|
|
71
53
|
return {
|
|
72
54
|
label,
|
|
73
55
|
...percent ? { share: true } : {},
|
|
74
|
-
tick: (value) =>
|
|
75
|
-
text: (value) =>
|
|
56
|
+
tick: (value) => writer.tick(value, shape),
|
|
57
|
+
text: (value) => writer.text(value, shape),
|
|
58
|
+
exact: (digits) => writer.text({ v: digits }, shape),
|
|
76
59
|
...style.whole === void 0 ? {} : { whole: style.whole },
|
|
77
60
|
additive: style.additive ?? !percent,
|
|
78
|
-
...style.better === void 0 ? {} : { better: style.better }
|
|
61
|
+
...style.better === void 0 ? {} : { better: style.better },
|
|
62
|
+
...percent ? { unit: "%" } : shape.unit === void 0 ? {} : { unit: shape.unit }
|
|
79
63
|
};
|
|
80
64
|
}
|
|
81
65
|
/**
|
|
82
66
|
* How a share of a whole is written wherever a chart says one (a step's share of the first, a
|
|
83
|
-
* bin's share of all values, a change):
|
|
67
|
+
* bin's share of all values, a change): a percent in full, as every percent is written (67%,
|
|
68
|
+
* 4.5%, 0.06%).
|
|
84
69
|
*/
|
|
85
70
|
function percentText(locale) {
|
|
86
71
|
return measure("", {
|
|
@@ -98,7 +83,7 @@ function textAt(series, index) {
|
|
|
98
83
|
return said(series.texts?.[index]) ?? series.measure.text(value);
|
|
99
84
|
}
|
|
100
85
|
/** A size with the sign of the way it went: "+4 pts", "−4 pts", and as it is for no change. */
|
|
101
|
-
const signed = (sign, size) => sign > 0 ? `+${size}` : sign < 0 ?
|
|
86
|
+
const signed = (sign, size) => sign > 0 ? `+${size}` : sign < 0 ? `${MINUS}${size}` : size;
|
|
102
87
|
/**
|
|
103
88
|
* How far something changed between two values, as it may be written, and which way it reads
|
|
104
89
|
* as having gone: the one rule every kind that writes a change goes by. A change in a share is
|
|
@@ -158,9 +143,22 @@ function movedAsWritten(from, to, text) {
|
|
|
158
143
|
*/
|
|
159
144
|
function topAsWritten(things, value, text, counts = () => true) {
|
|
160
145
|
if (things.length < 2) return void 0;
|
|
161
|
-
const [first, second] = things.filter((thing) => counts(thing)).
|
|
146
|
+
const [first, second] = topTwo(things.filter((thing) => counts(thing)).map((t) => [t, value(t)]));
|
|
162
147
|
if (first === void 0) return void 0;
|
|
163
|
-
return second !== void 0 && orderAsWritten(
|
|
148
|
+
return second !== void 0 && orderAsWritten(first[1], second[1], text) === 0 ? void 0 : first[0];
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* The two largest of some valued things in one pass, each value read once: the first of equals
|
|
152
|
+
* first, as a stable sort from the largest down would put them.
|
|
153
|
+
*/
|
|
154
|
+
function topTwo(valued) {
|
|
155
|
+
let first;
|
|
156
|
+
let second;
|
|
157
|
+
for (const one of valued) if (first === void 0 || one[1] > first[1]) {
|
|
158
|
+
second = first;
|
|
159
|
+
first = one;
|
|
160
|
+
} else if (second === void 0 || one[1] > second[1]) second = one;
|
|
161
|
+
return [first, second];
|
|
164
162
|
}
|
|
165
163
|
/**
|
|
166
164
|
* Whether a change went its measure's better way: 1 the better way, -1 the worse, 0 for a change
|
|
@@ -171,4 +169,4 @@ function betterWay(sign, reads) {
|
|
|
171
169
|
if (reads.better === void 0 || sign === 0) return 0;
|
|
172
170
|
return sign > 0 === (reads.better === "up") ? 1 : -1;
|
|
173
171
|
}
|
|
174
|
-
export { arrowOf, arrowed, betterWay, changeWritten, measure, movedAsWritten, orderAsWritten, percentText, said, signAsWritten, signed, textAt, topAsWritten };
|
|
172
|
+
export { arrowOf, arrowed, betterWay, changeWritten, measure, movedAsWritten, orderAsWritten, percentText, said, signAsWritten, signed, textAt, topAsWritten, writerIn };
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/** A standalone chart received an input it cannot represent, with the field the caller can fix. */
|
|
2
2
|
export declare class ChartInputError extends TypeError {
|
|
3
|
+
/** One code for every chart refusal, as each typed error of the library carries one. */
|
|
4
|
+
readonly code = "CHART_INPUT";
|
|
3
5
|
readonly field: string;
|
|
4
6
|
constructor(field: string, message: string);
|
|
5
7
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// src/data/input-error.ts
|
|
2
2
|
/** A standalone chart received an input it cannot represent, with the field the caller can fix. */
|
|
3
3
|
var ChartInputError = class extends TypeError {
|
|
4
|
+
/** One code for every chart refusal, as each typed error of the library carries one. */
|
|
5
|
+
code = "CHART_INPUT";
|
|
4
6
|
field;
|
|
5
7
|
constructor(field, message) {
|
|
6
8
|
super(`${field}: ${message}`);
|
|
@@ -8,6 +8,8 @@ export type Named = {
|
|
|
8
8
|
export declare const keyOf: (thing: Named) => string;
|
|
9
9
|
/**
|
|
10
10
|
* The identity of a thing in two parts: a series and a bucket, a row and a column. Written so
|
|
11
|
-
* no two pairs can read alike, whatever is in their parts: a label may hold any character.
|
|
11
|
+
* no two pairs can read alike, whatever is in their parts: a label may hold any character. The
|
|
12
|
+
* first part's length leads ("2:r0c19"), so where it ends is known, and nothing is escaped: a
|
|
13
|
+
* picture writes the key on every cell.
|
|
12
14
|
*/
|
|
13
15
|
export declare const pairKey: (first: string, second: string) => string;
|
|
@@ -5,9 +5,11 @@ const keyOf = (thing) => thing.key ?? thing.label;
|
|
|
5
5
|
const lastAt = (values) => values.findLastIndex((v) => v !== null);
|
|
6
6
|
/**
|
|
7
7
|
* The identity of a thing in two parts: a series and a bucket, a row and a column. Written so
|
|
8
|
-
* no two pairs can read alike, whatever is in their parts: a label may hold any character.
|
|
8
|
+
* no two pairs can read alike, whatever is in their parts: a label may hold any character. The
|
|
9
|
+
* first part's length leads ("2:r0c19"), so where it ends is known, and nothing is escaped: a
|
|
10
|
+
* picture writes the key on every cell.
|
|
9
11
|
*/
|
|
10
|
-
const pairKey = (first, second) =>
|
|
12
|
+
const pairKey = (first, second) => `${String(first.length)}:${first}${second}`;
|
|
11
13
|
/**
|
|
12
14
|
* Rows in ranked order: those with a value to rank by first, largest first, then those with
|
|
13
15
|
* none, then those `last` names (Other); ties, and every row when the order is given, keep the
|
|
@@ -2,13 +2,33 @@ import { TextMeasurer } from "../text/measure.mjs";
|
|
|
2
2
|
import { Words } from "./words.mjs";
|
|
3
3
|
/** A value to draw; null where there is none, which leaves a gap and is never drawn as zero. */
|
|
4
4
|
export type Value = number | null;
|
|
5
|
+
/**
|
|
6
|
+
* A value as a host gives it: a number, decimal text as a driver sends a numeric ("31900.50"),
|
|
7
|
+
* drawn as its number and written with every digit, or null. Every row and table a chart takes
|
|
8
|
+
* reads its values as this; what it draws is `Value`.
|
|
9
|
+
*/
|
|
10
|
+
export type ValueIn = number | string | null;
|
|
5
11
|
/** How a measure's values read and what they mean. */
|
|
6
12
|
export type Measure = {
|
|
7
13
|
label: string;
|
|
8
|
-
/**
|
|
9
|
-
|
|
14
|
+
/**
|
|
15
|
+
* A short form for an axis: 12K, $1.2M. `beside`, for values counted in `units`: a value
|
|
16
|
+
* counted alike whose unit it is written in, so an axis's ticks all read in the unit it steps in.
|
|
17
|
+
*/
|
|
18
|
+
tick: (value: number, beside?: number) => string;
|
|
19
|
+
/**
|
|
20
|
+
* For values counted in several units (a duration: a day, an hour, a minute, a second), the
|
|
21
|
+
* size of each, largest first, counted as the values are. An axis steps in whole numbers of
|
|
22
|
+
* one of them and writes every tick in it: 2, 4, 6 days, never 2.31 days.
|
|
23
|
+
*/
|
|
24
|
+
units?: readonly number[];
|
|
10
25
|
/** The full form, for a label or a tooltip. */
|
|
11
26
|
text: (value: number) => string;
|
|
27
|
+
/**
|
|
28
|
+
* The full form of a value given as decimal text (a driver's numeric), every digit kept.
|
|
29
|
+
* Left out, such a value is written as its number.
|
|
30
|
+
*/
|
|
31
|
+
exact?: (digits: string) => string;
|
|
12
32
|
/** Counts: the axis steps in whole numbers. */
|
|
13
33
|
whole?: boolean;
|
|
14
34
|
/** False for a rate or an average: its values are never stacked or summed. */
|
|
@@ -20,7 +40,18 @@ export type Measure = {
|
|
|
20
40
|
share?: boolean;
|
|
21
41
|
/** Which way is good, so a change can be read as better or worse. */
|
|
22
42
|
better?: "up" | "down";
|
|
43
|
+
/**
|
|
44
|
+
* What its values are counted in, when it is not a plain number: a currency's code, or "%".
|
|
45
|
+
* A chart over time reads every series on its first series' axis, so a series in another
|
|
46
|
+
* unit is not drawn there and is named under the chart (`Scene.left`).
|
|
47
|
+
*/
|
|
48
|
+
unit?: string;
|
|
23
49
|
};
|
|
50
|
+
/**
|
|
51
|
+
* How a measure's numbers read, for whatever writes them along an axis: the short form, the
|
|
52
|
+
* full form, and whether they step in whole numbers.
|
|
53
|
+
*/
|
|
54
|
+
export type Reads = Pick<Measure, "tick" | "text" | "whole" | "units">;
|
|
24
55
|
/**
|
|
25
56
|
* The colour a thing asks for, in every kind that colours things one by one (a series, a
|
|
26
57
|
* ranked bar, a scatter's point): its place in the palette, which follows the thing so a
|
|
@@ -34,11 +65,12 @@ export type Tint = {
|
|
|
34
65
|
export type Toned = Tint & {
|
|
35
66
|
other?: boolean;
|
|
36
67
|
};
|
|
37
|
-
|
|
68
|
+
/** A series of a time chart: its values as given (`ValueIn`, decimal text too) or as drawn (`Value`). */
|
|
69
|
+
export type Series<V extends ValueIn = Value> = Toned & {
|
|
38
70
|
key: string;
|
|
39
71
|
label: string;
|
|
40
72
|
/** One value per place on the x axis. */
|
|
41
|
-
values: readonly
|
|
73
|
+
values: readonly V[];
|
|
42
74
|
/**
|
|
43
75
|
* Each value as the host writes it, place for place, when it has a more exact way than the
|
|
44
76
|
* measure's (a decimal a float cannot hold). The picture is still placed by `values`.
|
|
@@ -46,7 +78,7 @@ export type Series = Toned & {
|
|
|
46
78
|
texts?: readonly (string | undefined)[];
|
|
47
79
|
measure: Measure;
|
|
48
80
|
/** The same series over the comparison period, place for place. */
|
|
49
|
-
previous?: readonly
|
|
81
|
+
previous?: readonly V[];
|
|
50
82
|
};
|
|
51
83
|
export type Grain = "hour" | "day" | "week" | "month" | "quarter" | "year";
|
|
52
84
|
/**
|
|
@@ -76,9 +108,9 @@ export type TimeX = {
|
|
|
76
108
|
* but they are read in one unit. Measures in different units belong in different charts, or in
|
|
77
109
|
* small multiples with a scale each.
|
|
78
110
|
*/
|
|
79
|
-
export type TimeTable = {
|
|
111
|
+
export type TimeTable<V extends ValueIn = Value> = {
|
|
80
112
|
x: TimeX;
|
|
81
|
-
series: readonly Series[];
|
|
113
|
+
series: readonly Series<V>[];
|
|
82
114
|
};
|
|
83
115
|
/** Where a chart is drawn: its size, how wide a text is, the reader's locale and words. */
|
|
84
116
|
export type Env = {
|
|
@@ -87,6 +119,17 @@ export type Env = {
|
|
|
87
119
|
measure: TextMeasurer;
|
|
88
120
|
locale?: string;
|
|
89
121
|
words?: Words;
|
|
122
|
+
/**
|
|
123
|
+
* Only the height the picture asks for is wanted (`Scene.natural`), to size a box that cannot
|
|
124
|
+
* be measured yet. A chart of rows lying down then lays no row out: it answers with its
|
|
125
|
+
* header alone and that height, and says nothing of its rows. It is the height the chart asks
|
|
126
|
+
* for laid out wherever it has room across for its rows; whether a width has that room is
|
|
127
|
+
* known only by laying it out, so a chart too narrow to draw a row is still asked for its
|
|
128
|
+
* rows' height here. A grid's answer turns on the width asked at, since its width sets how
|
|
129
|
+
* many rows its cells allow, and so does small multiples', since their width sets how many
|
|
130
|
+
* panels stand across. A chart that fills any height asks for none, and is laid out as ever.
|
|
131
|
+
*/
|
|
132
|
+
sizing?: boolean;
|
|
90
133
|
};
|
|
91
134
|
/** What a chart says of itself, drawn inside it so a saved picture stands alone. */
|
|
92
135
|
export type Header = {
|