derive-dashboards 0.8.0 → 0.9.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 +513 -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 +10 -8
- package/dist/core/document/display.mjs +25 -4
- 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 +18 -4
- 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/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 +9 -1
- 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.mjs +1 -1
- 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 +256 -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,7 +1,19 @@
|
|
|
1
|
-
import { lastIncludedMillisecond } from "derive-dashboards/core";
|
|
1
|
+
import { isDateOnly, lastIncludedMillisecond, parseTextTime, textMillis } from "derive-dashboards/core";
|
|
2
2
|
// src/format-time.ts
|
|
3
|
-
/**
|
|
3
|
+
/** The kit's one cache of date formats: a table would make one for every cell of a time column. */
|
|
4
4
|
const FORMATS = /* @__PURE__ */ new Map();
|
|
5
|
+
/** A date format for a locale and a zone (the viewer's when none), made once. */
|
|
6
|
+
function dateFormat(locale, options, timeZone) {
|
|
7
|
+
const key = `${locale ?? ""}|${timeZone ?? ""}|${JSON.stringify(options)}`;
|
|
8
|
+
const cached = FORMATS.get(key);
|
|
9
|
+
if (cached !== void 0) return cached;
|
|
10
|
+
const made = new Intl.DateTimeFormat(locale, {
|
|
11
|
+
timeZone,
|
|
12
|
+
...options
|
|
13
|
+
});
|
|
14
|
+
FORMATS.set(key, made);
|
|
15
|
+
return made;
|
|
16
|
+
}
|
|
5
17
|
const DATE_LABEL = /^\d{4}-\d{2}-\d{2}$/u;
|
|
6
18
|
const STYLES = {
|
|
7
19
|
day: {
|
|
@@ -21,59 +33,166 @@ const STYLES = {
|
|
|
21
33
|
hour: {
|
|
22
34
|
dateStyle: "medium",
|
|
23
35
|
timeStyle: "short"
|
|
36
|
+
},
|
|
37
|
+
zone: { timeZoneName: "short" },
|
|
38
|
+
wall: {
|
|
39
|
+
year: "numeric",
|
|
40
|
+
month: "numeric",
|
|
41
|
+
day: "numeric",
|
|
42
|
+
hour: "numeric",
|
|
43
|
+
minute: "numeric",
|
|
44
|
+
second: "numeric",
|
|
45
|
+
hourCycle: "h23"
|
|
24
46
|
}
|
|
25
47
|
};
|
|
26
48
|
function styleFor(grain, withYear = false) {
|
|
27
|
-
if (grain === "week" || grain === "day") return withYear ?
|
|
28
|
-
return grain === "quarter" ? "month" : grain;
|
|
49
|
+
if (grain === "week" || grain === "day") return withYear ? STYLES.dated : STYLES.day;
|
|
50
|
+
return STYLES[grain === "quarter" ? "month" : grain];
|
|
29
51
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
|
|
52
|
+
/**
|
|
53
|
+
* An hour's label as an instant, read by the one grammar text time has (`parseTextTime`). A
|
|
54
|
+
* label that names no zone of its own ("2026-03-11 12:00:00", as a host's own rows may carry)
|
|
55
|
+
* is read as UTC: read on the wall of the machine that draws it, a server and a browser would
|
|
56
|
+
* write different hours. A label that is not a time is no instant, and stays as sent.
|
|
57
|
+
*/
|
|
58
|
+
function hourInstant(label) {
|
|
59
|
+
const micros = parseTextTime(label) ?? parseTextTime(`${label}Z`);
|
|
60
|
+
return micros === void 0 ? void 0 : new Date(Number(micros / 1000n));
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* A text as an instant, for every namer here: a time by the one grammar text time has, one
|
|
64
|
+
* that names no zone read as UTC (`hourInstant`); else a calendar date alone, which is its
|
|
65
|
+
* first instant in UTC, read as core reads a date (`textMillis`). Anything else is no instant:
|
|
66
|
+
* what core refuses ("2026-02-30") comes back as it was sent.
|
|
67
|
+
*/
|
|
68
|
+
function instantOf(text) {
|
|
69
|
+
const timed = hourInstant(text);
|
|
70
|
+
if (timed !== void 0 || !DATE_LABEL.test(text)) return timed;
|
|
71
|
+
const day = textMillis(text);
|
|
72
|
+
return day === void 0 ? void 0 : new Date(day.ms);
|
|
73
|
+
}
|
|
74
|
+
const DAY_MS = 864e5;
|
|
75
|
+
/** A zone's offset from UTC at an instant, in milliseconds, read off the wall clock Intl gives there. */
|
|
76
|
+
function offsetAt(date, timeZone) {
|
|
77
|
+
const parts = dateFormat("en-US", STYLES.wall, timeZone).formatToParts(date);
|
|
78
|
+
const read = (type) => Number(parts.find((part) => part.type === type)?.value ?? 0);
|
|
79
|
+
return Date.UTC(read("year"), read("month") - 1, read("day"), read("hour"), read("minute"), read("second")) - Math.floor(date.getTime() / 1e3) * 1e3;
|
|
80
|
+
}
|
|
81
|
+
/** Whether each UTC day asked of a zone is steady (`steady`), kept: every hour of a day asks the same. */
|
|
82
|
+
const STEADY = /* @__PURE__ */ new Map();
|
|
83
|
+
const DAYS_KEPT = 4096;
|
|
84
|
+
/**
|
|
85
|
+
* Whether no clock changes within a day either side of an instant: its zone's offset is the
|
|
86
|
+
* same at the midnights around it. Nearly every hour of a year is so, and is named by one
|
|
87
|
+
* format of its own with no look at its neighbours.
|
|
88
|
+
*/
|
|
89
|
+
function steady(date, timeZone) {
|
|
90
|
+
const day = Math.floor(date.getTime() / DAY_MS);
|
|
91
|
+
const zone = timeZone ?? "";
|
|
92
|
+
const days = STEADY.get(zone) ?? /* @__PURE__ */ new Map();
|
|
93
|
+
const kept = days.get(day);
|
|
94
|
+
if (kept !== void 0) return kept;
|
|
95
|
+
const [first = 0, ...rest] = [
|
|
96
|
+
day - 1,
|
|
97
|
+
day,
|
|
98
|
+
day + 1,
|
|
99
|
+
day + 2
|
|
100
|
+
].map((other) => offsetAt(/* @__PURE__ */ new Date(other * DAY_MS), timeZone));
|
|
101
|
+
const calm = rest.every((offset) => offset === first);
|
|
102
|
+
if (days.size >= DAYS_KEPT) days.clear();
|
|
103
|
+
days.set(day, calm);
|
|
104
|
+
STEADY.set(zone, days);
|
|
105
|
+
return calm;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Where an instant's twin would be, if a clock change repeats its wall time: as far before it
|
|
109
|
+
* as the clock was set back in the day before, and as far after it as the clock is set back in
|
|
110
|
+
* the day after. Whatever the zone sets its clock back by: an hour nearly everywhere, half an
|
|
111
|
+
* hour on Lord Howe Island, two hours at Troll station. No clock change near, no twin.
|
|
112
|
+
*/
|
|
113
|
+
function twinsOf(date, timeZone) {
|
|
114
|
+
const at = offsetAt(date, timeZone);
|
|
115
|
+
const before = offsetAt(/* @__PURE__ */ new Date(date.getTime() - DAY_MS), timeZone) - at;
|
|
116
|
+
const after = at - offsetAt(new Date(date.getTime() + DAY_MS), timeZone);
|
|
117
|
+
return [-Math.max(0, before), Math.max(0, after)].filter((by) => by !== 0).map((by) => new Date(date.getTime() + by));
|
|
40
118
|
}
|
|
119
|
+
/** The zone's short name at an instant ("EDT"), in the locale; none when Intl gives none. */
|
|
120
|
+
const zoneName = (date, locale, timeZone) => dateFormat(locale, STYLES.zone, timeZone).formatToParts(date).find((part) => part.type === "timeZoneName")?.value;
|
|
41
121
|
/**
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
122
|
+
* An hour as its date and clock time on the wall. The hour a clock change repeats reads twice
|
|
123
|
+
* alike there ("Nov 1, 2026, 1:00 AM"), so each of the two also says its zone's short name at
|
|
124
|
+
* its instant ("1:00 AM EDT", "1:00 AM EST"), however far the clock is set back; every other
|
|
125
|
+
* hour says the wall time alone.
|
|
45
126
|
*/
|
|
46
|
-
function
|
|
47
|
-
|
|
127
|
+
function hourText(date, locale, timeZone) {
|
|
128
|
+
const wall = dateFormat(locale, STYLES.hour, timeZone);
|
|
129
|
+
const text = wall.format(date);
|
|
130
|
+
if (steady(date, timeZone)) return text;
|
|
131
|
+
const zone = twinsOf(date, timeZone).some((twin) => wall.format(twin) === text) ? zoneName(date, locale, timeZone) : void 0;
|
|
132
|
+
return zone === void 0 ? text : `${text} ${zone}`;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* An hour bucket's name in a zone, the one name every table, list, drill and chart gives it:
|
|
136
|
+
* its date and clock time there, with the zone's short name where a clock change repeats the
|
|
137
|
+
* hour (`hourText`). With no zone to read it in it stays as sent: read in whatever zone the
|
|
138
|
+
* code runs in, a server and a browser would write it differently. So does an hour in a zone
|
|
139
|
+
* that is none, and a label that is not a time.
|
|
140
|
+
*/
|
|
141
|
+
function nameHour(label, locale, timeZone) {
|
|
142
|
+
const instant = timeZone === void 0 ? void 0 : hourInstant(label);
|
|
143
|
+
if (instant === void 0) return label;
|
|
144
|
+
try {
|
|
145
|
+
return hourText(instant, locale, timeZone);
|
|
146
|
+
} catch (failure) {
|
|
147
|
+
if (failure instanceof RangeError) return label;
|
|
148
|
+
throw failure;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* A time bucket's label for a person, the one name every table and chart gives it: "Nov 2" for
|
|
153
|
+
* a day or week, "Jun 2026" for a month or the month a (possibly fiscal) quarter starts. A date
|
|
154
|
+
* label names a calendar date, so it is formatted as that date, not as an instant in any zone.
|
|
155
|
+
* An hour's label is an instant, named in the zone given by `nameHour`, and left as sent with
|
|
156
|
+
* none.
|
|
157
|
+
*/
|
|
158
|
+
function formatBucket(label, grain, locale, at = {}) {
|
|
159
|
+
if (grain === "hour") return nameHour(label, locale, at.timeZone);
|
|
160
|
+
if (!isDateOnly(label)) return label;
|
|
48
161
|
const [year = 0, month = 1, day = 1] = label.split("-").map(Number);
|
|
49
162
|
const date = /* @__PURE__ */ new Date(0);
|
|
50
163
|
date.setUTCFullYear(year, month - 1, day);
|
|
51
|
-
return dateFormat(locale, styleFor(grain, withYear), "UTC").format(date);
|
|
164
|
+
return dateFormat(locale, styleFor(grain, at.withYear), "UTC").format(date);
|
|
52
165
|
}
|
|
53
166
|
/** An instant (text time to the microsecond) as a date and time, in a zone (the dashboard's) or the viewer's own. */
|
|
54
167
|
function formatInstant(text, locale, timeZone) {
|
|
55
|
-
const date =
|
|
56
|
-
|
|
57
|
-
return dateFormat(locale, "hour", timeZone).format(date);
|
|
168
|
+
const date = instantOf(text);
|
|
169
|
+
return date === void 0 ? text : dateFormat(locale, STYLES.hour, timeZone).format(date);
|
|
58
170
|
}
|
|
59
171
|
/**
|
|
60
172
|
* The bucket an instant starts, named at its grain in a zone, as a chart names it: "Nov 9" for
|
|
61
|
-
* a day or week, "Jul 2026" for a month, and a date with its clock time for an hour
|
|
62
|
-
*
|
|
173
|
+
* a day or week, "Jul 2026" for a month, and a date with its clock time for an hour, with its
|
|
174
|
+
* zone's short name where a clock change repeats that hour. A time that names no zone of its
|
|
175
|
+
* own is read as UTC, never in the zone the code runs in. A text that is not a time is given
|
|
176
|
+
* back as it is, as `formatInstant` gives it.
|
|
63
177
|
*/
|
|
64
178
|
function formatInstantAt(text, grain, locale, timeZone) {
|
|
65
|
-
const date =
|
|
66
|
-
if (
|
|
179
|
+
const date = instantOf(text);
|
|
180
|
+
if (date === void 0) return text;
|
|
181
|
+
if (grain === "hour") return hourText(date, locale, timeZone);
|
|
67
182
|
return dateFormat(locale, styleFor(grain), timeZone).format(date);
|
|
68
183
|
}
|
|
69
|
-
/**
|
|
184
|
+
/**
|
|
185
|
+
* The included calendar days in a receipt, shared by tiles and every drill view: its first day
|
|
186
|
+
* to its last, or the one day when it is one ("Nov 1", not "Nov 1 to Nov 1").
|
|
187
|
+
*/
|
|
70
188
|
function formatPeriod(range, format, timeZone) {
|
|
71
189
|
const last = lastIncludedMillisecond(range);
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const year = dateFormat(format.locale,
|
|
190
|
+
const first = instantOf(range.from);
|
|
191
|
+
if (last === void 0 || first === void 0) return format.messages.noData;
|
|
192
|
+
const year = dateFormat(format.locale, STYLES.year, timeZone);
|
|
75
193
|
const crossesYear = year.format(first) !== year.format(last);
|
|
76
194
|
const day = dateFormat(format.locale, styleFor("day", crossesYear), timeZone);
|
|
77
|
-
|
|
195
|
+
const [from, to] = [day.format(first), day.format(last)];
|
|
196
|
+
return from === to ? from : format.messages.drillRange(from, to);
|
|
78
197
|
}
|
|
79
|
-
export { formatBucket, formatInstant, formatInstantAt, formatPeriod };
|
|
198
|
+
export { dateFormat, formatBucket, formatInstant, formatInstantAt, formatPeriod, instantOf };
|
package/dist/react/format.d.mts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { CellFormat } from "./messages.mjs";
|
|
2
2
|
import { formatBucket, formatInstant, formatInstantAt } from "./format-time.mjs";
|
|
3
|
-
import { ResultCell, ResultColumn } from "derive-dashboards/core";
|
|
3
|
+
import { NumberShape, ResultCell, ResultColumn } from "derive-dashboards/core";
|
|
4
4
|
/**
|
|
5
5
|
* A number for drawing. Exact values stay strings everywhere else; a chart needs a number
|
|
6
6
|
* for the pixel position only, never for a label.
|
|
7
7
|
*/
|
|
8
8
|
export declare function plotValue(cell: ResultCell): number | null;
|
|
9
9
|
/** What formatting reads of a column: its type, and a time bucket's grain or a money unit. */
|
|
10
|
-
export type Shape = Pick<ResultColumn, "id" | "role" | "type" | "grain" | "unit" | "format" | "signed" | "fraction">;
|
|
10
|
+
export type Shape = Pick<ResultColumn, "id" | "role" | "type" | "grain" | "unit" | "format" | "signed" | "fraction"> & Pick<NumberShape, "beside">;
|
|
11
11
|
/**
|
|
12
12
|
* A cell as text for a person, in their locale and words. A renderer can pass its own props as
|
|
13
13
|
* `format`: they carry both.
|
|
@@ -17,5 +17,5 @@ export declare function formatCell(cell: ResultCell, column?: Partial<Shape>, fo
|
|
|
17
17
|
* A short axis label: 12K, $1.25M, 0.025. A tick is written in three figures, which hold
|
|
18
18
|
* every round step an axis takes, so no two ticks read alike and none reads off its line.
|
|
19
19
|
*/
|
|
20
|
-
export declare function formatTick(value: number, column?:
|
|
20
|
+
export declare function formatTick(value: number, column?: Partial<Shape>, locale?: string): string;
|
|
21
21
|
export { formatBucket, formatInstant, formatInstantAt };
|
package/dist/react/format.mjs
CHANGED
|
@@ -1,13 +1,23 @@
|
|
|
1
1
|
import { isNumberValue } from "./columns.mjs";
|
|
2
|
-
import { digitsFor, fine, lost, percentDigits, tickDigits } from "./digits.mjs";
|
|
3
2
|
import { formatBucket, formatInstant, formatInstantAt } from "./format-time.mjs";
|
|
4
|
-
import {
|
|
5
|
-
import { digitsOf, plainOf, plainText } from "./renderers/exact.mjs";
|
|
6
|
-
import { isMark } from "derive-dashboards/core";
|
|
3
|
+
import { cellDigits, isMark, numberWriters } from "derive-dashboards/core";
|
|
7
4
|
// src/format.ts
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
/** The kit's number writer for each locale, made once: a table writes every cell by one. */
|
|
6
|
+
const writerIn = numberWriters();
|
|
7
|
+
/**
|
|
8
|
+
* The words a cell is written with: a gap, Other, a total, a group with none, true and false.
|
|
9
|
+
* `formatCell`'s default and part of `ENGLISH`, held apart so a chart tile brings these words,
|
|
10
|
+
* not the whole catalog.
|
|
11
|
+
*/
|
|
12
|
+
const ENGLISH_CELL = {
|
|
13
|
+
other: "Other",
|
|
14
|
+
total: "Total",
|
|
15
|
+
empty: "None",
|
|
16
|
+
noValue: "–",
|
|
17
|
+
drillNone: (field) => `No ${field.toLowerCase()}`,
|
|
18
|
+
drillYes: "Yes",
|
|
19
|
+
drillNo: "No"
|
|
20
|
+
};
|
|
11
21
|
/**
|
|
12
22
|
* A number for drawing. Exact values stay strings everywhere else; a chart needs a number
|
|
13
23
|
* for the pixel position only, never for a label.
|
|
@@ -18,6 +28,8 @@ function plotValue(cell) {
|
|
|
18
28
|
const value = Number(typeof cell === "string" ? cell : cell.v);
|
|
19
29
|
return Number.isFinite(value) ? value : null;
|
|
20
30
|
}
|
|
31
|
+
/** Whether a cell is a total's mark: it stands for every group of its column. */
|
|
32
|
+
const isTotal = (cell) => cell !== void 0 && isMark(cell) && cell.mark === "all";
|
|
21
33
|
/** The unformatted key used for group matching, lexical sorting and template links. */
|
|
22
34
|
function rawCellText(cell) {
|
|
23
35
|
if (cell === void 0 || cell === null || isMark(cell)) return void 0;
|
|
@@ -32,150 +44,32 @@ function groupText(cell, column, format) {
|
|
|
32
44
|
* `format`: they carry both.
|
|
33
45
|
*/
|
|
34
46
|
function formatCell(cell, column, format = {}) {
|
|
35
|
-
const { locale, messages =
|
|
47
|
+
const { locale, messages = ENGLISH_CELL } = format;
|
|
36
48
|
if (cell === null) return messages.noValue;
|
|
37
|
-
if (isMark(cell)) return cell
|
|
49
|
+
if (isMark(cell)) return isTotal(cell) ? messages.total : messages.other;
|
|
38
50
|
if (typeof cell === "boolean") return cell ? messages.drillYes : messages.drillNo;
|
|
39
|
-
if (typeof cell !== "string") return
|
|
51
|
+
if (typeof cell !== "string") return writerIn(locale).text(cell, column);
|
|
40
52
|
const sent = numberSent(cell, column);
|
|
41
53
|
if (sent === void 0) return formatText(cell, column, locale, format.timeZone);
|
|
42
|
-
return
|
|
54
|
+
return writerIn(locale).text(sent, column);
|
|
43
55
|
}
|
|
44
56
|
/** Decimal text as a driver may write it: a plus before it, a point with no digit before or after it. */
|
|
45
57
|
const plain = (text) => text.trim().replace(/^\+/u, "").replace(/^(-?)\./u, "$10.").replace(/\.$/u, "");
|
|
46
58
|
/** A value a driver sent as its text, in a measure or a calc of numbers: its digits, to be written as any number is. */
|
|
47
59
|
function numberSent(text, column) {
|
|
48
|
-
const digits = isNumberValue(column) && /\d/u.test(text) ?
|
|
60
|
+
const digits = isNumberValue(column) && /\d/u.test(text) ? cellDigits(plain(text)) : void 0;
|
|
49
61
|
return digits === void 0 ? void 0 : { v: digits };
|
|
50
62
|
}
|
|
51
|
-
/** Number formats by locale and style: making one costs fifty times a format, and a table or a chart would make one for every cell. */
|
|
52
|
-
const FORMATS = /* @__PURE__ */ new Map();
|
|
53
|
-
/** The number format for a locale and a style, made once. */
|
|
54
|
-
function numberFormat(locale, style) {
|
|
55
|
-
const key = `${locale ?? ""}|${JSON.stringify(style)}`;
|
|
56
|
-
const made = FORMATS.get(key) ?? new Intl.NumberFormat(locale, {
|
|
57
|
-
signDisplay: "negative",
|
|
58
|
-
...style
|
|
59
|
-
});
|
|
60
|
-
FORMATS.set(key, made);
|
|
61
|
-
return made;
|
|
62
|
-
}
|
|
63
|
-
/** A number by its column's format: a percent, a duration, money or a plain number. */
|
|
64
|
-
function numberText(cell, column, locale) {
|
|
65
|
-
if (column?.format === "percent") return percentText(cell, {
|
|
66
|
-
signed: column.signed === true,
|
|
67
|
-
fraction: column.fraction === true
|
|
68
|
-
}, locale);
|
|
69
|
-
if (column?.format === "duration") return durationText(typeof cell === "number" ? cell : Number(cell.v), locale);
|
|
70
|
-
const currency = currencyOf(column?.unit);
|
|
71
|
-
const style = currency === void 0 ? {} : {
|
|
72
|
-
style: "currency",
|
|
73
|
-
currency
|
|
74
|
-
};
|
|
75
|
-
if (typeof cell === "number") return numberFormat(locale, {
|
|
76
|
-
...digitsFor(cell, placesOf(currency, locale)),
|
|
77
|
-
...style
|
|
78
|
-
}).format(cell);
|
|
79
|
-
return exactText(cell.v, currency, locale);
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* A value in percent points (42.5) as a percent (42.5%). Exact digits move two places as text,
|
|
83
|
-
* so Intl formats them without a float.
|
|
84
|
-
*/
|
|
85
|
-
function percentText(cell, how, locale) {
|
|
86
|
-
const { signed } = how;
|
|
87
|
-
const shift = how.fraction ? "" : "E-2";
|
|
88
|
-
const style = {
|
|
89
|
-
style: "percent",
|
|
90
|
-
...percentDigits(weigh(cell), how.fraction ? 1 : 100),
|
|
91
|
-
signDisplay: signed ? "exceptZero" : "negative"
|
|
92
|
-
};
|
|
93
|
-
const digits = typeof cell === "number" ? floatText(cell) : plainText(cell.v) ?? cell.v;
|
|
94
|
-
return numberFormat(locale, style).format(`${digits}${shift}`);
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* A cell's value as a float, for choosing its digits only. An exact text too small for a
|
|
98
|
-
* float, yet not zero, weighs as the smallest float there is, so it is never taken for zero;
|
|
99
|
-
* the digits written are still the text's own.
|
|
100
|
-
*/
|
|
101
|
-
function weigh(cell) {
|
|
102
|
-
if (typeof cell === "number") return cell;
|
|
103
|
-
const value = Number(cell.v);
|
|
104
|
-
const digits = cell.v.split(/e/iu)[0] ?? "";
|
|
105
|
-
return value === 0 && /[1-9]/u.test(digits) ? Number.MIN_VALUE : value;
|
|
106
|
-
}
|
|
107
|
-
/** A float as text Intl reads: its plain decimal digits, or what it is called when it is not a finite number. */
|
|
108
|
-
const floatText = (value) => Number.isFinite(value) ? plainOf(value) : String(value);
|
|
109
|
-
const DURATION_UNITS = [
|
|
110
|
-
["day", 86400],
|
|
111
|
-
["hour", 3600],
|
|
112
|
-
["minute", 60],
|
|
113
|
-
["second", 1]
|
|
114
|
-
];
|
|
115
|
-
/** Seconds in the largest unit that keeps the value at one or more: 90 is "1.5 min". A tick keeps three figures (75 is "1.25 min"). */
|
|
116
|
-
function durationText(seconds, locale, tick = false) {
|
|
117
|
-
const size = Math.abs(seconds);
|
|
118
|
-
const [unit, per] = DURATION_UNITS.find(([, n]) => size >= n) ?? ["second", 1];
|
|
119
|
-
return numberFormat(locale, {
|
|
120
|
-
style: "unit",
|
|
121
|
-
unit,
|
|
122
|
-
unitDisplay: "short",
|
|
123
|
-
...tick ? tickDigits(seconds / per, 1) : digitsFor(seconds / per, 1)
|
|
124
|
-
}).format(seconds / per);
|
|
125
|
-
}
|
|
126
63
|
/** A text cell: a time bucket's label, an instant (in the dashboard's zone when given), or the text itself. */
|
|
127
64
|
function formatText(text, column, locale, timeZone) {
|
|
128
|
-
if (column?.grain !== void 0) return formatBucket(text, column.grain, locale);
|
|
65
|
+
if (column?.grain !== void 0) return formatBucket(text, column.grain, locale, { timeZone });
|
|
129
66
|
return column?.type === "time" ? formatInstant(text, locale, timeZone) : text;
|
|
130
67
|
}
|
|
131
68
|
/**
|
|
132
|
-
* The places a number with a fraction is written to: two, or its currency's own where that
|
|
133
|
-
* has more, as a dinar has three. A thousandth of a dinar is not rounded away as a cent's part.
|
|
134
|
-
*/
|
|
135
|
-
const placesOf = (currency, locale) => currency === void 0 ? 2 : Math.max(2, numberFormat(locale, {
|
|
136
|
-
style: "currency",
|
|
137
|
-
currency
|
|
138
|
-
}).resolvedOptions().maximumFractionDigits ?? 2);
|
|
139
|
-
/** Decimal text in the viewer's locale, exactly: Intl formats the digits, never a float. */
|
|
140
|
-
function exactText(text, currency, locale) {
|
|
141
|
-
const cents = text.split(".")[1] ?? "";
|
|
142
|
-
const style = currency === void 0 ? {} : {
|
|
143
|
-
style: "currency",
|
|
144
|
-
currency
|
|
145
|
-
};
|
|
146
|
-
const most = placesOf(currency, locale);
|
|
147
|
-
const places = /^0*$/u.test(cents) ? 0 : currency === void 0 ? Math.min(cents.length, most) : most;
|
|
148
|
-
const size = Math.abs(weigh({ v: text }));
|
|
149
|
-
const written = numberFormat(locale, {
|
|
150
|
-
...lost(size, places) ? fine(size) : {
|
|
151
|
-
minimumFractionDigits: places,
|
|
152
|
-
maximumFractionDigits: places
|
|
153
|
-
},
|
|
154
|
-
...style
|
|
155
|
-
}).format(text);
|
|
156
|
-
return written.includes("∞") ? text : written;
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
69
|
* A short axis label: 12K, $1.25M, 0.025. A tick is written in three figures, which hold
|
|
160
70
|
* every round step an axis takes, so no two ticks read alike and none reads off its line.
|
|
161
71
|
*/
|
|
162
72
|
function formatTick(value, column, locale) {
|
|
163
|
-
|
|
164
|
-
const [whole, shift] = column.fraction === true ? [1, ""] : [100, "E-2"];
|
|
165
|
-
return numberFormat(locale, {
|
|
166
|
-
style: "percent",
|
|
167
|
-
...tickDigits(value, whole)
|
|
168
|
-
}).format(`${floatText(value)}${shift}`);
|
|
169
|
-
}
|
|
170
|
-
if (column?.format === "duration") return durationText(value, locale, true);
|
|
171
|
-
const currency = currencyOf(column?.unit);
|
|
172
|
-
const style = currency === void 0 ? {} : {
|
|
173
|
-
style: "currency",
|
|
174
|
-
currency
|
|
175
|
-
};
|
|
176
|
-
return numberFormat(locale, {
|
|
177
|
-
...tickDigits(value, 1),
|
|
178
|
-
...style
|
|
179
|
-
}).format(value);
|
|
73
|
+
return writerIn(locale).tick(value, column);
|
|
180
74
|
}
|
|
181
|
-
export {
|
|
75
|
+
export { ENGLISH_CELL, formatBucket, formatCell, formatInstant, formatInstantAt, formatTick, groupText, isTotal, numberSent, plotValue, rawCellText, writerIn };
|
|
@@ -3,7 +3,10 @@ import { CellFormat } from "./messages.mjs";
|
|
|
3
3
|
import { ResultCell } from "derive-dashboards/core";
|
|
4
4
|
/**
|
|
5
5
|
* A cell as a tile's headline, the one number it is read by. An amount or a plain number of a
|
|
6
|
-
* thousand or more is written in whole units, rounded: $1,487,340 for 1487340.03.
|
|
7
|
-
*
|
|
6
|
+
* thousand or more is written in whole units, rounded: $1,487,340 for 1487340.03. A rate of
|
|
7
|
+
* ten percent or more keeps a tenth of a point: 25.2%. Anything else is written as
|
|
8
|
+
* `formatCell` writes it, which is also how a headline is written in full.
|
|
9
|
+
* A figure that stands beside the headline (its change, the period before) passes the
|
|
10
|
+
* headline as `headline` and is written in its places: "1,981" then "+249 from 1,732".
|
|
8
11
|
*/
|
|
9
|
-
export declare function formatHeadline(cell: ResultCell, column?: Partial<Shape>, format?: CellFormat): string;
|
|
12
|
+
export declare function formatHeadline(cell: ResultCell, column?: Partial<Shape>, format?: CellFormat, headline?: ResultCell): string;
|
package/dist/react/headline.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { compareExact
|
|
1
|
+
import { formatCell, numberSent, writerIn } from "./format.mjs";
|
|
2
|
+
import { compareExact } from "./renderers/exact.mjs";
|
|
3
|
+
import { cellDigits, currencyOf, displayOf, signOf } from "derive-dashboards/core";
|
|
3
4
|
// src/headline.ts
|
|
4
5
|
/**
|
|
5
6
|
* From this size a headline is written in whole units: $205.35 reads as an amount, the cents
|
|
@@ -7,45 +8,100 @@ import { compareExact, digitsOf } from "./renderers/exact.mjs";
|
|
|
7
8
|
* headline reads "$1,000.00" beside one that reads "$1,000".
|
|
8
9
|
*/
|
|
9
10
|
const WHOLE_FROM = "999.995";
|
|
10
|
-
/** A
|
|
11
|
+
/** A number's digits when it is of the size written whole: a thousand or more, either side of nothing. */
|
|
11
12
|
function wholeDigits(cell, column) {
|
|
12
|
-
|
|
13
|
-
const digits = typeof cell === "string" ? numberSent(cell, column)?.v : digitsOf(cell);
|
|
13
|
+
const digits = digitsOf(cell, column);
|
|
14
14
|
return digits !== void 0 && compareExact(digits.replace("-", ""), WHOLE_FROM) >= 0 ? digits : void 0;
|
|
15
15
|
}
|
|
16
|
+
/** A cell's digits as decimal text, a number a driver sent as text among them; none for what is no number. */
|
|
17
|
+
const digitsOf = (cell, column) => typeof cell === "string" ? numberSent(cell, column)?.v : cellDigits(cell);
|
|
16
18
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
19
|
+
* The percents whose headline keeps a tenth of a point: from ten to under a thousand. Below
|
|
20
|
+
* ten every percent is written to a tenth, or to its first figures, already, and so is one
|
|
21
|
+
* that rounds up to ten (9.96 is "10.0%" in a cell, which a headline must not say less than);
|
|
22
|
+
* from a thousand a tenth of a point is noise, as cents are from a thousand dollars.
|
|
23
|
+
*/
|
|
24
|
+
const TENTHS = {
|
|
25
|
+
from: 10,
|
|
26
|
+
under: 999.95
|
|
27
|
+
};
|
|
28
|
+
/** Whether a percent's headline keeps a tenth of a point (`TENTHS`), by its digits. */
|
|
29
|
+
function keepsTenth(digits, fraction) {
|
|
30
|
+
const points = Math.abs(Number(digits)) * (fraction ? 100 : 1);
|
|
31
|
+
return points >= TENTHS.from && points < TENTHS.under;
|
|
32
|
+
}
|
|
33
|
+
/** The style of a rate's headline: at most a tenth of a point, a whole rate whole, signed as its column says (core's `signOf`). */
|
|
34
|
+
const rateStyle = (column) => ({
|
|
35
|
+
style: "percent",
|
|
36
|
+
minimumFractionDigits: 0,
|
|
37
|
+
maximumFractionDigits: 1,
|
|
38
|
+
...signOf(column)
|
|
39
|
+
});
|
|
40
|
+
/**
|
|
41
|
+
* A rate as a headline, from ten percent to under a thousand: to a tenth of a point (25.2%),
|
|
42
|
+
* where a cell keeps whole percents. A tile's rate is read against what it was, and half a
|
|
43
|
+
* point is a change to see in both; a whole rate is written whole (25%). Null for a smaller
|
|
44
|
+
* or a larger rate, written as everywhere, or for what is no number.
|
|
45
|
+
*/
|
|
46
|
+
function rateText(cell, column, writer) {
|
|
47
|
+
const digits = digitsOf(cell, column);
|
|
48
|
+
const fraction = column.fraction === true;
|
|
49
|
+
if (digits === void 0 || !keepsTenth(digits, fraction)) return null;
|
|
50
|
+
const shifted = `${digits}${fraction ? "" : "E-2"}`;
|
|
51
|
+
const written = writer.styled(rateStyle(column), shifted);
|
|
52
|
+
return written.includes("∞") ? null : written;
|
|
53
|
+
}
|
|
54
|
+
/** Whether a column's numbers can be written in whole units at all: not a percent or a duration, nor a currency of three places. */
|
|
55
|
+
const takesWhole = (column, locale) => column?.format !== "percent" && column?.format !== "duration" && writerIn(locale).places(currencyOf(column?.unit)) <= 2;
|
|
56
|
+
/**
|
|
57
|
+
* A cell in whole units, rounded, when it is an amount or a plain number of a thousand or
|
|
58
|
+
* more: $1,487,340 for 1487340.03. Null for anything else, and for an amount past what Intl
|
|
59
|
+
* holds, whose own digits are the truth.
|
|
20
60
|
*/
|
|
21
|
-
function
|
|
61
|
+
function wholeText(cell, column, format, headline = cell) {
|
|
62
|
+
const digits = takesWhole(column, format.locale) && wholeDigits(headline, column) !== void 0 ? digitsOf(cell, column) : void 0;
|
|
63
|
+
if (digits === void 0) return null;
|
|
22
64
|
const currency = currencyOf(column?.unit);
|
|
23
|
-
const digits = placesOf(currency, format.locale) <= 2 ? wholeDigits(cell, column) : void 0;
|
|
24
|
-
if (digits === void 0) return formatFigure(cell, column, format);
|
|
25
65
|
const style = currency === void 0 ? {} : {
|
|
26
66
|
style: "currency",
|
|
27
67
|
currency
|
|
28
68
|
};
|
|
29
|
-
const
|
|
69
|
+
const whole = {
|
|
30
70
|
minimumFractionDigits: 0,
|
|
31
71
|
maximumFractionDigits: 0,
|
|
72
|
+
...signOf(column ?? {})
|
|
73
|
+
};
|
|
74
|
+
const written = writerIn(format.locale).styled({
|
|
75
|
+
...whole,
|
|
32
76
|
...style
|
|
33
|
-
}
|
|
34
|
-
return
|
|
77
|
+
}, digits);
|
|
78
|
+
return written.includes("∞") ? null : written;
|
|
35
79
|
}
|
|
36
80
|
/**
|
|
37
|
-
* A
|
|
38
|
-
*
|
|
81
|
+
* A cell as a tile's headline, the one number it is read by. An amount or a plain number of a
|
|
82
|
+
* thousand or more is written in whole units, rounded: $1,487,340 for 1487340.03. A rate of
|
|
83
|
+
* ten percent or more keeps a tenth of a point: 25.2%. Anything else is written as
|
|
84
|
+
* `formatCell` writes it, which is also how a headline is written in full.
|
|
85
|
+
* A figure that stands beside the headline (its change, the period before) passes the
|
|
86
|
+
* headline as `headline` and is written in its places: "1,981" then "+249 from 1,732".
|
|
39
87
|
*/
|
|
40
|
-
|
|
88
|
+
function formatHeadline(cell, column, format = {}, headline = cell) {
|
|
89
|
+
const rate = column?.format === "percent" ? rateText(cell, column, writerIn(format.locale)) : null;
|
|
90
|
+
return wholeText(cell, column, format, headline) ?? rate ?? formatCell(cell, column, format);
|
|
91
|
+
}
|
|
41
92
|
/**
|
|
42
|
-
* A headline's
|
|
43
|
-
*
|
|
44
|
-
*
|
|
93
|
+
* A headline's value in full, a pointer away from it: as a cell writes it (an amount with its
|
|
94
|
+
* cents), except a rate, whose headline says more than a cell does (25.2% for 25%) and is its
|
|
95
|
+
* own value in full.
|
|
45
96
|
*/
|
|
46
|
-
function
|
|
47
|
-
|
|
48
|
-
const sign = numberFormat(locale, {}).formatToParts(-1).find((part) => part.type === "minusSign")?.value;
|
|
49
|
-
return sign === void 0 ? written : written.replace(sign, sign.replace("-", "−"));
|
|
97
|
+
function formatFull(cell, column, format = {}) {
|
|
98
|
+
return (column?.format === "percent" ? rateText(cell, column, writerIn(format.locale)) : null) ?? formatCell(cell, column, format);
|
|
50
99
|
}
|
|
51
|
-
|
|
100
|
+
/**
|
|
101
|
+
* How a number tile writes its large value, and what that value is read against (the period
|
|
102
|
+
* before): in full where its widget asks (`display.full`), else as a headline. In full is
|
|
103
|
+
* `formatFull`: an amount with its cents, and a rate with the tenth its headline has, never the
|
|
104
|
+
* whole percent of a cell, which says less than the headline does.
|
|
105
|
+
*/
|
|
106
|
+
const headlineWriterOf = (widget) => displayOf("number", widget.display).full === true ? formatFull : formatHeadline;
|
|
107
|
+
export { digitsOf, formatFull, formatHeadline, headlineWriterOf, takesWhole, wholeDigits, wholeText };
|