derive-dashboards 0.1.0 → 0.2.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/README.md +8 -5
- package/dist/adapter/sql-adapter.mjs +4 -4
- package/dist/body.mjs +11 -1
- package/dist/cache.d.mts +1 -1
- package/dist/cli/add.mjs +130 -0
- package/dist/cli/check.mjs +14 -1
- package/dist/cli/cli.mjs +14 -12
- package/dist/cli/config.mjs +12 -1
- package/dist/cli/doctor.mjs +147 -0
- package/dist/cli/import/dbt-schema.mjs +2 -2
- package/dist/cli/import/index.mjs +2 -2
- package/dist/cli/init.mjs +3 -2
- package/dist/cli/json.mjs +21 -0
- package/dist/cli/layers.mjs +33 -0
- package/dist/core/conformance/cases.d.mts +3 -0
- package/dist/core/conformance/cases.mjs +20 -4
- package/dist/core/conformance/check.mjs +6 -3
- package/dist/core/conformance/drill-cases.mjs +120 -0
- package/dist/core/document/layout.mjs +1 -1
- package/dist/core/document/view-layout.d.mts +14 -0
- package/dist/core/document/view-layout.mjs +157 -0
- package/dist/core/document/view.d.mts +26 -7
- package/dist/core/document/view.mjs +42 -11
- package/dist/core/engine/filter.mjs +2 -2
- package/dist/core/engine/index.d.mts +14 -2
- package/dist/core/engine/index.mjs +12 -1
- package/dist/core/engine/leaf.mjs +9 -4
- package/dist/core/engine/members.mjs +2 -2
- package/dist/core/engine/postgres.mjs +1 -1
- package/dist/core/engine/record-layout.d.mts +11 -0
- package/dist/core/engine/record-layout.mjs +7 -7
- package/dist/core/engine/records.d.mts +3 -2
- package/dist/core/engine/records.mjs +2 -1
- package/dist/core/engine/segmented.mjs +5 -2
- package/dist/core/engine/sql-records.mjs +2 -1
- package/dist/core/engine/statement.mjs +37 -3
- package/dist/core/engine/types.d.mts +3 -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 +33 -1
- package/dist/core/error/codes.mjs +30 -2
- package/dist/core/index.d.mts +13 -7
- package/dist/core/index.mjs +9 -5
- package/dist/core/model/catalog/check.mjs +1 -1
- package/dist/core/model/hints.d.mts +36 -0
- package/dist/core/model/member.d.mts +4 -2
- package/dist/core/model/member.mjs +19 -3
- package/dist/core/model/types.d.mts +21 -19
- package/dist/core/model/validate/drill.mjs +70 -0
- package/dist/core/model/validate/index.mjs +3 -0
- package/dist/core/model/validate/members.mjs +7 -4
- package/dist/core/model/validate/shape.mjs +150 -0
- package/dist/core/model/validate/source.mjs +5 -3
- package/dist/core/policy/bind-query.d.mts +12 -0
- package/dist/core/policy/bind-query.mjs +53 -0
- package/dist/core/query/alias.mjs +7 -1
- package/dist/core/query/drill/compose.d.mts +22 -0
- package/dist/core/query/drill/compose.mjs +85 -0
- package/dist/core/query/drill/fields.d.mts +21 -0
- package/dist/core/query/drill/fields.mjs +91 -0
- package/dist/core/query/drill/internal.d.mts +11 -0
- package/dist/core/query/drill/items.d.mts +29 -0
- package/dist/core/query/drill/items.mjs +98 -0
- package/dist/core/query/drill/line.d.mts +31 -0
- package/dist/core/query/drill/line.mjs +183 -0
- package/dist/core/query/drill/links.d.mts +33 -0
- package/dist/core/query/drill/links.mjs +31 -0
- package/dist/core/query/drill/operand.mjs +7 -0
- package/dist/core/query/drill/scopes.d.mts +22 -0
- package/dist/core/query/drill/scopes.mjs +58 -0
- package/dist/core/query/drill/selection.d.mts +37 -0
- package/dist/core/query/drill/selection.mjs +144 -0
- package/dist/core/query/drill/steps.d.mts +14 -0
- package/dist/core/query/drill/steps.mjs +35 -0
- package/dist/core/query/drill/synthetic-expr.mjs +85 -0
- package/dist/core/query/drill/synthetic.d.mts +22 -0
- package/dist/core/query/drill/synthetic.mjs +165 -0
- package/dist/core/query/drill/time.d.mts +11 -0
- package/dist/core/query/drill/time.mjs +71 -0
- package/dist/core/query/drill/types.d.mts +155 -0
- package/dist/core/query/drill/types.mjs +4 -0
- package/dist/core/query/drill/views.d.mts +62 -0
- package/dist/core/query/drill/views.mjs +257 -0
- package/dist/core/query/filter.d.mts +6 -0
- package/dist/core/query/picks.d.mts +8 -2
- package/dist/core/query/picks.mjs +11 -4
- package/dist/core/query/segments.d.mts +12 -2
- package/dist/core/query/segments.mjs +5 -2
- package/dist/core/result/columns.mjs +20 -4
- package/dist/core/result/types.d.mts +5 -1
- package/dist/core/schema/aliases.d.mts +7 -0
- package/dist/core/schema/aliases.mjs +77 -0
- package/dist/core/schema/answer-parts.mjs +117 -0
- package/dist/core/schema/answers.d.mts +2109 -128
- package/dist/core/schema/answers.mjs +11 -113
- package/dist/core/schema/commands.d.mts +2 -2
- package/dist/core/schema/document.d.mts +1 -1
- package/dist/core/schema/drill-answers.mjs +179 -0
- package/dist/core/schema/drill.d.mts +260 -0
- package/dist/core/schema/drill.mjs +107 -0
- package/dist/core/schema/index.d.mts +6 -3
- package/dist/core/schema/index.mjs +6 -3
- package/dist/core/schema/picks.d.mts +35 -0
- package/dist/core/schema/picks.mjs +23 -0
- package/dist/core/schema/query.d.mts +82 -1
- package/dist/core/schema/query.mjs +9 -5
- package/dist/core/schema/tools.mjs +1 -1
- package/dist/core/schema/view.d.mts +0 -35
- package/dist/core/schema/view.mjs +19 -24
- package/dist/core/store/schema.d.mts +5 -0
- package/dist/core/store/schema.mjs +10 -0
- package/dist/core/types/api.d.mts +21 -1
- package/dist/core/types/api.mjs +1 -1
- package/dist/core/types/drill-api.d.mts +210 -0
- package/dist/core/types/options.d.mts +21 -0
- package/dist/core/types/viewer.d.mts +5 -0
- package/dist/cursor-seal.d.mts +8 -0
- package/dist/cursor-seal.mjs +98 -0
- package/dist/dashboard-id.mjs +1 -1
- package/dist/dashboards.mjs +4 -0
- package/dist/drill-access.mjs +93 -0
- package/dist/drill-change.mjs +76 -0
- package/dist/drill-crumbs.mjs +113 -0
- package/dist/drill-distinct.mjs +130 -0
- package/dist/drill-explain.mjs +64 -0
- package/dist/drill-identity.mjs +35 -0
- package/dist/drill-item-id.mjs +35 -0
- package/dist/drill-items.mjs +132 -0
- package/dist/drill-open.mjs +169 -0
- package/dist/drill-seal.mjs +170 -0
- package/dist/drill-secret.mjs +14 -0
- package/dist/drill-share.mjs +53 -0
- package/dist/drill-summary.mjs +158 -0
- package/dist/drill-targets.mjs +53 -0
- package/dist/drill-totals.mjs +8 -0
- package/dist/drill-views.mjs +175 -0
- package/dist/drill.mjs +157 -0
- package/dist/editing.mjs +3 -3
- package/dist/endpoints/dashboards.mjs +28 -5
- package/dist/endpoints/drill.mjs +55 -0
- package/dist/endpoints/index.d.mts +245 -4
- package/dist/endpoints/index.mjs +5 -1
- package/dist/endpoints/meta.mjs +10 -1
- package/dist/endpoints/query.mjs +26 -4
- package/dist/execute.d.mts +19 -1
- package/dist/execute.mjs +34 -27
- package/dist/handler.mjs +5 -1
- package/dist/index.d.mts +3 -1
- package/dist/index.mjs +29 -2
- package/dist/llms.txt +22 -0
- package/dist/mcp/drill.mjs +61 -0
- package/dist/mcp/format.mjs +69 -11
- package/dist/mcp/index.d.mts +15 -4
- package/dist/mcp/index.mjs +13 -7
- package/dist/mcp/query.d.mts +7 -2
- package/dist/mcp/query.mjs +40 -6
- package/dist/node-postgres.d.mts +8 -4
- package/dist/node-postgres.mjs +29 -6
- package/dist/owner.mjs +3 -3
- package/dist/postgres-connection.d.mts +8 -2
- package/dist/postgres-connection.mjs +2 -1
- package/dist/postgres-store.mjs +1 -0
- package/dist/react/Canvas.mjs +28 -5
- package/dist/react/Cell.mjs +2 -1
- package/dist/react/Dashboard.d.mts +10 -5
- package/dist/react/Dashboard.mjs +62 -22
- package/dist/react/DashboardList.mjs +52 -24
- package/dist/react/DashboardListRow.mjs +49 -0
- package/dist/react/Discard.mjs +12 -4
- package/dist/react/Editing.mjs +19 -5
- package/dist/react/FilterBar.d.mts +7 -9
- package/dist/react/Grid.mjs +19 -24
- package/dist/react/Header.mjs +10 -1
- package/dist/react/History.mjs +5 -0
- package/dist/react/Parts.mjs +6 -2
- package/dist/react/ReadFailed.mjs +23 -0
- package/dist/react/ReviewPanel.mjs +13 -2
- package/dist/react/RowBody.d.mts +19 -0
- package/dist/react/RowBody.mjs +55 -0
- package/dist/react/Spaces.mjs +15 -1
- package/dist/react/Tile.d.mts +3 -1
- package/dist/react/Tile.mjs +84 -32
- package/dist/react/_virtual/_rolldown/runtime.mjs +12 -0
- package/dist/react/arrange-steps.mjs +16 -13
- package/dist/react/arrange.mjs +10 -3
- package/dist/react/builder/Calcs.mjs +35 -11
- package/dist/react/builder/FilterEditor.mjs +196 -0
- package/dist/react/builder/Filters.mjs +172 -116
- package/dist/react/builder/Formula.mjs +82 -0
- package/dist/react/builder/Groups.mjs +1 -0
- package/dist/react/builder/Preview.mjs +1 -1
- package/dist/react/builder/RangeEditor.mjs +184 -0
- package/dist/react/builder/Sections.mjs +41 -6
- package/dist/react/builder/Time.mjs +138 -60
- package/dist/react/builder/Values.mjs +85 -0
- package/dist/react/builder/WidgetBuilder.mjs +50 -49
- package/dist/react/builder/base.d.mts +5 -0
- package/dist/react/builder/base.mjs +33 -8
- package/dist/react/builder/calc.mjs +15 -1
- package/dist/react/builder/escape.d.mts +1 -0
- package/dist/react/builder/escape.mjs +62 -0
- package/dist/react/builder/filter-tree.d.mts +9 -0
- package/dist/react/builder/filter-tree.mjs +186 -0
- package/dist/react/builder/formula-parse.d.mts +18 -0
- package/dist/react/builder/formula-parse.mjs +136 -0
- package/dist/react/builder/labels.d.mts +1 -1
- package/dist/react/builder/state.d.mts +2 -1
- package/dist/react/builder/state.mjs +23 -37
- package/dist/react/builder/useBuilder.d.mts +12 -1
- package/dist/react/builder/useBuilder.mjs +6 -3
- package/dist/react/builder/words.d.mts +59 -0
- package/dist/react/builder/words.mjs +73 -0
- package/dist/react/client.d.mts +2 -0
- package/dist/react/client.mjs +1 -0
- package/dist/react/context.d.mts +28 -1
- package/dist/react/context.mjs +25 -4
- package/dist/react/drill/Bars.mjs +179 -0
- package/dist/react/drill/Controls.mjs +173 -0
- package/dist/react/drill/DashboardTile.d.mts +18 -0
- package/dist/react/drill/DashboardTile.mjs +107 -0
- package/dist/react/drill/DrillPanel.d.mts +31 -0
- package/dist/react/drill/DrillPanel.mjs +104 -0
- package/dist/react/drill/DrillTabs.mjs +52 -0
- package/dist/react/drill/Header.mjs +131 -0
- package/dist/react/drill/Items.d.mts +22 -0
- package/dist/react/drill/Items.mjs +164 -0
- package/dist/react/drill/ItemsFoot.mjs +60 -0
- package/dist/react/drill/Notes.mjs +58 -0
- package/dist/react/drill/PanelBody.mjs +74 -0
- package/dist/react/drill/PanelStates.mjs +37 -0
- package/dist/react/drill/board.d.mts +18 -0
- package/dist/react/drill/board.mjs +91 -0
- package/dist/react/drill/counts.mjs +14 -0
- package/dist/react/drill/host.mjs +26 -0
- package/dist/react/drill/item-parts.d.mts +5 -0
- package/dist/react/drill/item-parts.mjs +76 -0
- package/dist/react/drill/item-type.d.mts +26 -0
- package/dist/react/drill/item-type.mjs +7 -0
- package/dist/react/drill/lazy.d.mts +6 -0
- package/dist/react/drill/lazy.mjs +17 -0
- package/dist/react/drill/pages.mjs +48 -0
- package/dist/react/drill/panel-focus.mjs +51 -0
- package/dist/react/drill/props.d.mts +25 -0
- package/dist/react/drill/props.mjs +72 -0
- package/dist/react/drill/state.d.mts +18 -0
- package/dist/react/drill/state.mjs +68 -0
- package/dist/react/drill/useDrill.d.mts +46 -0
- package/dist/react/drill/useDrill.mjs +194 -0
- package/dist/react/drill/words.d.mts +101 -0
- package/dist/react/drill/words.mjs +79 -0
- package/dist/react/english.mjs +29 -6
- package/dist/react/filters/bar.d.mts +12 -0
- package/dist/react/filters/bar.mjs +135 -0
- package/dist/react/filters/calendar.mjs +193 -0
- package/dist/react/filters/chip.mjs +174 -0
- package/dist/react/filters/context.d.mts +22 -0
- package/dist/react/filters/context.mjs +78 -0
- package/dist/react/filters/dates.mjs +89 -0
- package/dist/react/filters/days.d.mts +36 -0
- package/dist/react/filters/days.mjs +87 -0
- package/dist/react/filters/field-step.mjs +81 -0
- package/dist/react/filters/hooks.d.mts +34 -0
- package/dist/react/filters/hooks.mjs +94 -0
- package/dist/react/filters/listbox.mjs +131 -0
- package/dist/react/filters/logic.d.mts +59 -0
- package/dist/react/filters/logic.mjs +109 -0
- package/dist/react/filters/menu-search.mjs +211 -0
- package/dist/react/filters/menu.mjs +85 -0
- package/dist/react/filters/number.mjs +127 -0
- package/dist/react/filters/numbers.d.mts +47 -0
- package/dist/react/filters/numbers.mjs +151 -0
- package/dist/react/filters/operator.mjs +104 -0
- package/dist/react/filters/phone.mjs +104 -0
- package/dist/react/filters/popover.d.mts +19 -0
- package/dist/react/filters/popover.mjs +153 -0
- package/dist/react/filters/rules.d.mts +8 -0
- package/dist/react/filters/rules.mjs +55 -0
- package/dist/react/filters/sheet.mjs +196 -0
- package/dist/react/filters/state.mjs +132 -0
- package/dist/react/filters/suggest.d.mts +47 -0
- package/dist/react/filters/suggest.mjs +97 -0
- package/dist/react/filters/values.mjs +166 -0
- package/dist/react/filters/words.d.mts +81 -0
- package/dist/react/filters/words.mjs +73 -0
- package/dist/react/format.d.mts +3 -3
- package/dist/react/format.mjs +45 -16
- package/dist/react/index.d.mts +34 -5
- package/dist/react/index.mjs +15 -4
- package/dist/react/messages.d.mts +47 -2
- package/dist/react/place.mjs +7 -3
- package/dist/react/renderers/index.d.mts +10 -2
- package/dist/react/renderers/index.mjs +116 -14
- package/dist/react/renderers/list.d.mts +22 -0
- package/dist/react/renderers/list.mjs +118 -0
- package/dist/react/review-words.mjs +1 -1
- package/dist/react/review.mjs +2 -2
- package/dist/react/scope.mjs +2 -7
- package/dist/react/series.d.mts +54 -0
- package/dist/react/series.mjs +191 -0
- package/dist/react/theme.css +2734 -1296
- package/dist/react/theme.css.d.ts +1 -0
- package/dist/react/tile-store.mjs +15 -3
- package/dist/react/useBoard.d.mts +7 -0
- package/dist/react/useBoard.mjs +4 -1
- package/dist/react/useDashboard.d.mts +4 -0
- package/dist/react/useDashboard.mjs +8 -1
- package/dist/react/useTiles.mjs +50 -15
- package/dist/react/view-grid.mjs +16 -0
- package/dist/react/view.d.mts +9 -0
- package/dist/react/view.mjs +22 -10
- package/dist/reading.d.mts +2 -0
- package/dist/reading.mjs +9 -1
- package/dist/recharts/axes.mjs +28 -0
- package/dist/recharts/axis.mjs +84 -0
- package/dist/recharts/bar.d.mts +7 -0
- package/dist/recharts/bar.mjs +140 -0
- package/dist/recharts/charts.d.mts +4 -6
- package/dist/recharts/charts.mjs +2 -114
- package/dist/recharts/index.d.mts +5 -3
- package/dist/recharts/index.mjs +6 -3
- package/dist/recharts/line.d.mts +2 -0
- package/dist/recharts/line.mjs +111 -0
- package/dist/recharts/marks.mjs +112 -0
- package/dist/recharts/parts.mjs +88 -0
- package/dist/recharts/series.d.mts +2 -22
- package/dist/recharts/series.mjs +1 -64
- package/dist/recharts/table.mjs +71 -0
- package/dist/records-read.mjs +44 -0
- package/dist/registry/filter-bar.json +26 -0
- package/dist/skills/derive-dashboards/SKILL.md +69 -0
- package/dist/store/apply.mjs +5 -5
- package/dist/store/commands.mjs +4 -4
- package/dist/store/discard.mjs +7 -7
- package/dist/store/drafts.mjs +5 -5
- package/dist/store/editor.mjs +1 -1
- package/dist/store/publish.mjs +12 -12
- package/dist/store/reader.mjs +41 -22
- package/dist/store/review.mjs +16 -16
- package/dist/store/rows.mjs +20 -20
- package/dist/store/undo.mjs +3 -3
- package/dist/store/unpublished.mjs +4 -4
- package/dist/store/versions.mjs +14 -14
- package/dist/testing/adapter-suite.mjs +4 -4
- package/dist/tiles.mjs +37 -3
- package/package.json +12 -10
- package/dist/react/FilterBar.mjs +0 -119
- package/dist/react/Records.d.mts +0 -12
- package/dist/react/Records.mjs +0 -97
- package/src/adapter/sql-adapter.ts +0 -95
- package/src/adapter/statement.ts +0 -185
- package/src/authorize.ts +0 -73
- package/src/body.ts +0 -169
- package/src/bounded.ts +0 -43
- package/src/cache.ts +0 -192
- package/src/checks.ts +0 -170
- package/src/custom-source.ts +0 -59
- package/src/dashboard-id.ts +0 -36
- package/src/dashboards.ts +0 -132
- package/src/editing.ts +0 -148
- package/src/endpoints/access.ts +0 -41
- package/src/endpoints/dashboards.ts +0 -92
- package/src/endpoints/drafts.ts +0 -138
- package/src/endpoints/index.ts +0 -21
- package/src/endpoints/meta.ts +0 -137
- package/src/endpoints/query.ts +0 -86
- package/src/endpoints/read.ts +0 -92
- package/src/endpoints/review.ts +0 -89
- package/src/endpoints/values.ts +0 -62
- package/src/endpoints/versions.ts +0 -104
- package/src/execute.ts +0 -207
- package/src/handler.ts +0 -232
- package/src/http.ts +0 -66
- package/src/index.ts +0 -163
- package/src/introspect.ts +0 -205
- package/src/mcp/api.ts +0 -59
- package/src/mcp/format.ts +0 -67
- package/src/mcp/index.ts +0 -151
- package/src/mcp/query.ts +0 -153
- package/src/mcp/resolve.ts +0 -114
- package/src/node-postgres.ts +0 -81
- package/src/owner.ts +0 -36
- package/src/postgres-connection.ts +0 -143
- package/src/postgres-store.ts +0 -82
- package/src/principal.ts +0 -39
- package/src/reading.ts +0 -56
- package/src/request-rows.ts +0 -23
- package/src/request.ts +0 -22
- package/src/storage.ts +0 -63
- package/src/store/apply.ts +0 -129
- package/src/store/commands.ts +0 -75
- package/src/store/conflicts.ts +0 -98
- package/src/store/create-tables.ts +0 -104
- package/src/store/discard.ts +0 -42
- package/src/store/drafts.ts +0 -133
- package/src/store/editor.ts +0 -28
- package/src/store/log.ts +0 -28
- package/src/store/publish.ts +0 -199
- package/src/store/publisher.ts +0 -21
- package/src/store/reader.ts +0 -139
- package/src/store/review.ts +0 -239
- package/src/store/rows.ts +0 -250
- package/src/store/tenant.ts +0 -28
- package/src/store/undo.ts +0 -56
- package/src/store/unpublished.ts +0 -33
- package/src/store/versions.ts +0 -106
- package/src/store/writer.ts +0 -19
- package/src/testing/adapter-suite.ts +0 -239
- package/src/testing/index.ts +0 -2
- package/src/tile-doc.ts +0 -46
- package/src/tiles.ts +0 -120
|
@@ -1,29 +1,125 @@
|
|
|
1
1
|
import { formatCell } from "../format.mjs";
|
|
2
|
+
import { ListTile } from "./list.mjs";
|
|
2
3
|
import { isMark } from "derive-dashboards/core";
|
|
3
4
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
5
|
// src/renderers/index.tsx
|
|
5
6
|
const isMeasure = (column) => column.id.startsWith("m") || column.id.startsWith("c");
|
|
6
7
|
const isAll = (cell) => isMark(cell) && cell.mark === "all";
|
|
8
|
+
/** A calc is what the query was built to show (a share, a rate); else its first value. */
|
|
9
|
+
const shownIndex = (columns) => {
|
|
10
|
+
const calc = columns.findIndex((c) => c.id.startsWith("c") && c.signed !== true);
|
|
11
|
+
return calc === -1 ? columns.findIndex((c) => isMeasure(c)) : calc;
|
|
12
|
+
};
|
|
7
13
|
/**
|
|
8
|
-
* The first value column, large, from the total row when there is one, else the first row;
|
|
14
|
+
* The first calc or value column, large, from the total row when there is one, else the first row;
|
|
9
15
|
* a change calc (a signed column) sits under it.
|
|
10
16
|
*/
|
|
11
17
|
function NumberTile(props) {
|
|
12
18
|
const { answer } = props;
|
|
13
|
-
const index = answer.columns
|
|
19
|
+
const index = shownIndex(answer.columns);
|
|
14
20
|
const change = answer.columns.findIndex((c) => c.signed === true);
|
|
15
21
|
const row = answer.rows.find((cells) => cells.some((cell) => isAll(cell))) ?? answer.rows[0];
|
|
16
22
|
const cell = row?.[index] ?? null;
|
|
23
|
+
const entry = answer.columns[index]?.id;
|
|
24
|
+
const marks = row === void 0 ? void 0 : props.drill?.props(row, entry);
|
|
17
25
|
return /* @__PURE__ */ jsxs("div", {
|
|
18
26
|
className: "dd-number",
|
|
19
|
-
children: [
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
children: [
|
|
28
|
+
/* @__PURE__ */ jsx("span", {
|
|
29
|
+
className: "dd-number-value",
|
|
30
|
+
title: formatCell(cell, answer.columns[index], props),
|
|
31
|
+
...marks,
|
|
32
|
+
children: formatCell(cell, answer.columns[index], props)
|
|
33
|
+
}),
|
|
34
|
+
change === -1 ? null : /* @__PURE__ */ jsx("span", {
|
|
35
|
+
className: "dd-number-change",
|
|
36
|
+
children: formatCell(row?.[change] ?? null, answer.columns[change], props)
|
|
37
|
+
}),
|
|
38
|
+
/* @__PURE__ */ jsx(Before, {
|
|
39
|
+
...props,
|
|
40
|
+
index
|
|
41
|
+
})
|
|
42
|
+
]
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/** A cell as a number, for the change against the period before. */
|
|
46
|
+
const numberOf = (cell) => {
|
|
47
|
+
if (typeof cell === "number") return cell;
|
|
48
|
+
if (cell !== null && typeof cell === "object" && "v" in cell) return Number(cell.v);
|
|
49
|
+
};
|
|
50
|
+
const PLAIN_DECIMAL = /^-?\d+(\.\d+)?$/u;
|
|
51
|
+
/** A cell's exact digits ("12.50"), when it has them: exact cells, and whole JS numbers. */
|
|
52
|
+
const digitsOf = (cell) => {
|
|
53
|
+
if (typeof cell === "number") return Number.isSafeInteger(cell) ? String(cell) : void 0;
|
|
54
|
+
if (cell !== null && typeof cell === "object" && "v" in cell && typeof cell.v === "string") return PLAIN_DECIMAL.test(cell.v) ? cell.v : void 0;
|
|
55
|
+
};
|
|
56
|
+
/** A decimal as an integer of `scale` fraction digits: "12.5" at scale 2 is 1250n. */
|
|
57
|
+
const scaled = (digits, scale) => {
|
|
58
|
+
const negative = digits.startsWith("-");
|
|
59
|
+
const [whole = "0", fraction = ""] = digits.replace("-", "").split(".");
|
|
60
|
+
return BigInt(`${negative ? "-" : ""}${whole}${fraction.padEnd(scale, "0")}`);
|
|
61
|
+
};
|
|
62
|
+
/** now − was in floats, for values that are not exact digits. */
|
|
63
|
+
function floatDifference(now, was) {
|
|
64
|
+
const [x, y] = [numberOf(now), numberOf(was)];
|
|
65
|
+
if (x === void 0 || y === void 0) return void 0;
|
|
66
|
+
return {
|
|
67
|
+
sign: Math.sign(x - y),
|
|
68
|
+
size: Math.abs(x - y)
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/** a − b of two decimal strings, exactly, as a cell of `type`. */
|
|
72
|
+
function exactDifference(a, b, type) {
|
|
73
|
+
const scale = Math.max(a.split(".")[1]?.length ?? 0, b.split(".")[1]?.length ?? 0);
|
|
74
|
+
const d = scaled(a, scale) - scaled(b, scale);
|
|
75
|
+
const abs = (d < 0n ? -d : d).toString().padStart(scale + 1, "0");
|
|
76
|
+
const v = scale === 0 ? abs : `${abs.slice(0, -scale)}.${abs.slice(-scale)}`;
|
|
77
|
+
return {
|
|
78
|
+
sign: d === 0n ? 0 : d > 0n ? 1 : -1,
|
|
79
|
+
size: {
|
|
80
|
+
t: type,
|
|
81
|
+
v
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* now − was, exactly when both are exact (a 2^53 amount that moved by 1 moved by 1), else in
|
|
87
|
+
* floats; its sign and its size as a cell to format. Undefined when either is not a number.
|
|
88
|
+
*/
|
|
89
|
+
function difference(now, was) {
|
|
90
|
+
const [a, b] = [digitsOf(now), digitsOf(was)];
|
|
91
|
+
if (a === void 0 || b === void 0) return floatDifference(now, was);
|
|
92
|
+
return exactDifference(a, b, typeof now === "object" && now !== null && "t" in now ? now.t : "decimal");
|
|
93
|
+
}
|
|
94
|
+
/** What the period before says: "+17 from 0", "No change from 12", or the bare value when it is not a number. */
|
|
95
|
+
function beforeText(props, column, now, was) {
|
|
96
|
+
const wasText = formatCell(was, column, props);
|
|
97
|
+
const delta = difference(now, was);
|
|
98
|
+
if (delta === void 0) return props.messages.drillBefore(wasText);
|
|
99
|
+
if (delta.sign === 0) return props.messages.beforeSame(wasText);
|
|
100
|
+
const change = `${delta.sign > 0 ? "+" : "−"}${formatCell(delta.size, column, props)}`;
|
|
101
|
+
return props.messages.beforeChange(change, wasText);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* The change against the period before, when the answer compares ("+17 from 0"): it opens that
|
|
105
|
+
* period's rows. No value before (a rate over no rows) says nothing, so it is left out.
|
|
106
|
+
*/
|
|
107
|
+
function Before(props) {
|
|
108
|
+
const { answer, index } = props;
|
|
109
|
+
const before = answer.compare?.rows[0];
|
|
110
|
+
const column = answer.columns[index];
|
|
111
|
+
const was = before?.[index] ?? null;
|
|
112
|
+
if (before === void 0 || column === void 0 || was === null) return null;
|
|
113
|
+
const marks = props.drill?.props(before, column.id);
|
|
114
|
+
const text = beforeText(props, column, answer.rows[0]?.[index], was);
|
|
115
|
+
const named = marks === void 0 ? marks : {
|
|
116
|
+
...marks,
|
|
117
|
+
"aria-label": props.messages.drillMark(text)
|
|
118
|
+
};
|
|
119
|
+
return /* @__PURE__ */ jsx("span", {
|
|
120
|
+
className: "dd-number-before",
|
|
121
|
+
...named,
|
|
122
|
+
children: text
|
|
27
123
|
});
|
|
28
124
|
}
|
|
29
125
|
/** Cells as table cells: a run of equal marks is one cell spanning its columns. */
|
|
@@ -41,10 +137,13 @@ function spans(cells) {
|
|
|
41
137
|
return out;
|
|
42
138
|
}
|
|
43
139
|
/** One table row. A row that folds dimensions is a summary, labelled where it folds them. */
|
|
44
|
-
function Row({ cells, columns, format }) {
|
|
140
|
+
function Row({ cells, columns, format, drill }) {
|
|
45
141
|
const summary = cells.some((cell) => isMark(cell));
|
|
142
|
+
const whole = drill?.props(cells);
|
|
143
|
+
const cellMarks = (column) => whole === void 0 && column !== void 0 && isMeasure(column) ? drill?.props(cells, column.id) : void 0;
|
|
46
144
|
return /* @__PURE__ */ jsx("tr", {
|
|
47
145
|
className: summary ? "dd-table-summary" : void 0,
|
|
146
|
+
...whole,
|
|
48
147
|
children: spans(cells).map(({ cell, at, span }) => {
|
|
49
148
|
const column = columns[at];
|
|
50
149
|
const numeric = column !== void 0 && isMeasure(column);
|
|
@@ -55,7 +154,8 @@ function Row({ cells, columns, format }) {
|
|
|
55
154
|
}, column?.id ?? at);
|
|
56
155
|
return /* @__PURE__ */ jsx("td", {
|
|
57
156
|
"data-numeric": numeric,
|
|
58
|
-
|
|
157
|
+
...cellMarks(column),
|
|
158
|
+
children: cell === null && column !== void 0 && !numeric ? format.messages.drillNone(column.label) : formatCell(cell, column, format)
|
|
59
159
|
}, column?.id ?? at);
|
|
60
160
|
})
|
|
61
161
|
});
|
|
@@ -74,12 +174,14 @@ function TableTile(props) {
|
|
|
74
174
|
}, c.id)) }) }), /* @__PURE__ */ jsx("tbody", { children: answer.rows.map((cells) => /* @__PURE__ */ jsx(Row, {
|
|
75
175
|
cells,
|
|
76
176
|
columns,
|
|
77
|
-
format: props
|
|
177
|
+
format: props,
|
|
178
|
+
drill: props.drill
|
|
78
179
|
}, JSON.stringify(cells.slice(0, keys)))) })]
|
|
79
180
|
});
|
|
80
181
|
}
|
|
81
182
|
const BUILTIN_RENDERERS = {
|
|
82
183
|
number: NumberTile,
|
|
83
|
-
table: TableTile
|
|
184
|
+
table: TableTile,
|
|
185
|
+
list: ListTile
|
|
84
186
|
};
|
|
85
187
|
export { BUILTIN_RENDERERS, NumberTile, TableTile };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { TileRendererProps } from "./index.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* How a list draws its rows, by the query's entry ids. Every key is optional: with none, the
|
|
4
|
+
* first group is the title, the other groups the subtitle, and the last value the number.
|
|
5
|
+
*/
|
|
6
|
+
export type ListDisplay = {
|
|
7
|
+
/** The entry shown as the row's title. */
|
|
8
|
+
title?: string;
|
|
9
|
+
/** Entries shown under the title, joined with a dot. */
|
|
10
|
+
subtitle?: readonly string[];
|
|
11
|
+
/** The entry whose initials make the row's avatar. */
|
|
12
|
+
avatar?: string;
|
|
13
|
+
/** The number at the end of the row. */
|
|
14
|
+
meta?: string;
|
|
15
|
+
/** A link per row, with `{entry}` replaced by that entry's value: "/a/{t}". */
|
|
16
|
+
href?: string;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Rows as a list: an avatar, a title, a subtitle and one number, each row a link into the
|
|
20
|
+
* app (`display.href`) or, without one, a drill like a table row. Summary rows are left out.
|
|
21
|
+
*/
|
|
22
|
+
export declare function ListTile(props: TileRendererProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { formatCell } from "../format.mjs";
|
|
2
|
+
import { RowBody } from "../RowBody.mjs";
|
|
3
|
+
import { isMark } from "derive-dashboards/core";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
// src/renderers/list.tsx
|
|
6
|
+
const initials = (text) => text.split(/[\s._@-]+/u).filter(Boolean).slice(0, 2).map((word) => word[0]?.toUpperCase()).join("");
|
|
7
|
+
const asText = (value) => typeof value === "string" ? value : void 0;
|
|
8
|
+
const asList = (value) => Array.isArray(value) && value.every((v) => typeof v === "string") ? value : void 0;
|
|
9
|
+
const isValue = (c) => c.id.startsWith("m") || c.id.startsWith("c");
|
|
10
|
+
/** With no display, the first group is the title, the others the subtitle, the last value the number. */
|
|
11
|
+
function defaults(columns) {
|
|
12
|
+
const groups = columns.filter((c) => !isValue(c)).map((c) => c.id);
|
|
13
|
+
const meta = columns.findLast((c) => isValue(c))?.id;
|
|
14
|
+
return {
|
|
15
|
+
title: groups[0],
|
|
16
|
+
subtitle: groups.slice(1),
|
|
17
|
+
meta
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The answer names a query's entries by place (m1.. measures, d1.. groups, c1.. calcs), as the
|
|
22
|
+
* server runs it; `display` names them as the widget's query does. This maps one to the other.
|
|
23
|
+
*/
|
|
24
|
+
function answerIds(widget) {
|
|
25
|
+
const query = widget.queries.main;
|
|
26
|
+
if (query === void 0) return /* @__PURE__ */ new Map();
|
|
27
|
+
return new Map([
|
|
28
|
+
...query.measures.map((entry, i) => [entry.id, `m${String(i + 1)}`]),
|
|
29
|
+
...(query.dimensions ?? []).map((entry, i) => [entry.id, `d${String(i + 1)}`]),
|
|
30
|
+
...(query.calc ?? []).map((entry, i) => [entry.id, `c${String(i + 1)}`])
|
|
31
|
+
]);
|
|
32
|
+
}
|
|
33
|
+
function readDisplay(widget, columns) {
|
|
34
|
+
const display = widget.display ?? {};
|
|
35
|
+
const ids = answerIds(widget);
|
|
36
|
+
const id = (entry) => entry === void 0 ? void 0 : ids.get(entry) ?? entry;
|
|
37
|
+
const fallback = defaults(columns);
|
|
38
|
+
const href = asText(display.href);
|
|
39
|
+
return {
|
|
40
|
+
title: id(asText(display.title)) ?? fallback.title,
|
|
41
|
+
subtitle: asList(display.subtitle)?.map((entry) => id(entry) ?? entry) ?? fallback.subtitle,
|
|
42
|
+
avatar: id(asText(display.avatar)),
|
|
43
|
+
meta: id(asText(display.meta)) ?? fallback.meta,
|
|
44
|
+
href: href?.replaceAll(/\{([^}]+)\}/gu, (_, entry) => `{${id(entry) ?? entry}}`)
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
const text = ({ cells, at, props }, id) => {
|
|
48
|
+
const index = at(id);
|
|
49
|
+
if (index === -1) return "";
|
|
50
|
+
const cell = cells[index] ?? null;
|
|
51
|
+
return cell === null ? "" : formatCell(cell, props.answer.columns[index], props);
|
|
52
|
+
};
|
|
53
|
+
/** A row's link: each `{entry}` in the template becomes that entry's raw value, encoded. */
|
|
54
|
+
const linkOf = (template, line) => {
|
|
55
|
+
let missing = false;
|
|
56
|
+
const href = template.replaceAll(/\{([^}]+)\}/gu, (_, id) => {
|
|
57
|
+
const cell = line.cells[line.at(id)];
|
|
58
|
+
if (cell === void 0 || cell === null || isMark(cell)) {
|
|
59
|
+
missing = true;
|
|
60
|
+
return "";
|
|
61
|
+
}
|
|
62
|
+
return encodeURIComponent(typeof cell === "object" ? cell.v : String(cell));
|
|
63
|
+
});
|
|
64
|
+
return missing ? void 0 : href;
|
|
65
|
+
};
|
|
66
|
+
function Anchor(props) {
|
|
67
|
+
const Link = props.link;
|
|
68
|
+
return Link === void 0 ? /* @__PURE__ */ jsx("a", {
|
|
69
|
+
className: "dd-lines-row",
|
|
70
|
+
href: props.href,
|
|
71
|
+
children: props.children
|
|
72
|
+
}) : /* @__PURE__ */ jsx(Link, {
|
|
73
|
+
className: "dd-lines-row",
|
|
74
|
+
href: props.href,
|
|
75
|
+
children: props.children
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Rows as a list: an avatar, a title, a subtitle and one number, each row a link into the
|
|
80
|
+
* app (`display.href`) or, without one, a drill like a table row. Summary rows are left out.
|
|
81
|
+
*/
|
|
82
|
+
function ListTile(props) {
|
|
83
|
+
const { answer } = props;
|
|
84
|
+
const shown = readDisplay(props.widget, answer.columns);
|
|
85
|
+
const at = (id) => answer.columns.findIndex((c) => c.id === id);
|
|
86
|
+
const rows = answer.rows.filter((cells) => !cells.some((cell) => isMark(cell)));
|
|
87
|
+
return /* @__PURE__ */ jsx("ul", {
|
|
88
|
+
className: "dd-lines",
|
|
89
|
+
children: rows.map((cells) => {
|
|
90
|
+
const line = {
|
|
91
|
+
cells,
|
|
92
|
+
at,
|
|
93
|
+
props
|
|
94
|
+
};
|
|
95
|
+
const row = {
|
|
96
|
+
title: text(line, shown.title) || props.messages.empty,
|
|
97
|
+
meta: shown.subtitle.map((id) => text(line, id)).filter(Boolean),
|
|
98
|
+
lead: shown.avatar === void 0 ? void 0 : initials(text(line, shown.avatar)),
|
|
99
|
+
value: text(line, shown.meta)
|
|
100
|
+
};
|
|
101
|
+
const body = /* @__PURE__ */ jsx(RowBody, {
|
|
102
|
+
row,
|
|
103
|
+
family: "lines"
|
|
104
|
+
});
|
|
105
|
+
const href = shown.href === void 0 ? void 0 : linkOf(shown.href, line);
|
|
106
|
+
return /* @__PURE__ */ jsx("li", { children: href === void 0 ? /* @__PURE__ */ jsx("div", {
|
|
107
|
+
className: "dd-lines-row",
|
|
108
|
+
...props.drill?.props(cells),
|
|
109
|
+
children: body
|
|
110
|
+
}) : /* @__PURE__ */ jsx(Anchor, {
|
|
111
|
+
href,
|
|
112
|
+
link: props.link,
|
|
113
|
+
children: body
|
|
114
|
+
}) }, JSON.stringify(cells));
|
|
115
|
+
})
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
export { ListTile };
|
|
@@ -95,7 +95,7 @@ const ENGLISH_REVIEW = {
|
|
|
95
95
|
decideFirst: "Decide each change that no longer applies, then publish.",
|
|
96
96
|
addWidgetFirst: "Add a widget to publish this dashboard.",
|
|
97
97
|
headMoved: (n, who) => `${who ?? "Someone"} published version ${String(n)} just now. Showing your changes on top of it.`,
|
|
98
|
-
widgetGone: "was removed in the version you are publishing over.",
|
|
98
|
+
widgetGone: "its tile was removed in the version you are publishing over.",
|
|
99
99
|
layoutGaps: "The layout has gaps.",
|
|
100
100
|
closeGaps: "Pull tiles left",
|
|
101
101
|
pullLeft: "Pull tiles left",
|
package/dist/react/review.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import { useState } from "react";
|
|
|
4
4
|
// src/review.ts
|
|
5
5
|
/** The preview of what publishing would do, loaded on request, with its failure kept to show. */
|
|
6
6
|
function usePreview(dashboardId) {
|
|
7
|
-
const { client } = useDashboards();
|
|
7
|
+
const { client, messages } = useDashboards();
|
|
8
8
|
const [preview, setPreview] = useState();
|
|
9
9
|
const [loading, setLoading] = useState(false);
|
|
10
10
|
const [failed, setFailed] = useState();
|
|
@@ -16,7 +16,7 @@ function usePreview(dashboardId) {
|
|
|
16
16
|
setPreview(next);
|
|
17
17
|
return next;
|
|
18
18
|
} catch (failure) {
|
|
19
|
-
setFailed(failure instanceof Error ? failure.message : String(failure));
|
|
19
|
+
setFailed(failure instanceof TypeError ? messages.unreachable : failure instanceof Error ? failure.message : String(failure));
|
|
20
20
|
return null;
|
|
21
21
|
} finally {
|
|
22
22
|
setLoading(false);
|
package/dist/react/scope.mjs
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import { createContext
|
|
1
|
+
import { createContext } from "react";
|
|
2
2
|
// src/scope.tsx
|
|
3
3
|
const ScopeContext = createContext(null);
|
|
4
|
-
|
|
5
|
-
const scope = useContext(ScopeContext);
|
|
6
|
-
if (scope === null) throw new Error("This part is drawn only inside a <Dashboard>.");
|
|
7
|
-
return scope;
|
|
8
|
-
}
|
|
9
|
-
export { ScopeContext, useDashboardScope };
|
|
4
|
+
export { ScopeContext };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { CellFormat } from "./messages.mjs";
|
|
2
|
+
import { Receipt, ResultColumn, TileAnswer } from "derive-dashboards/core";
|
|
3
|
+
/** One point of a chart: its x label, its place (`#`, never an entry id) and a number per series key. */
|
|
4
|
+
export type Point = {
|
|
5
|
+
x: string;
|
|
6
|
+
} & Record<string, number | string | null>;
|
|
7
|
+
/**
|
|
8
|
+
* A drawn series: its key in each point, its label and the column it reads. `axis` is the side
|
|
9
|
+
* of the chart its scale is read on: values in another unit than the first get the right axis.
|
|
10
|
+
*/
|
|
11
|
+
export type Series = {
|
|
12
|
+
key: string;
|
|
13
|
+
label: string;
|
|
14
|
+
column: ResultColumn;
|
|
15
|
+
axis: "left" | "right";
|
|
16
|
+
};
|
|
17
|
+
/** The series key a dimension's Other draws as. */
|
|
18
|
+
export declare const OTHER_KEY = "other";
|
|
19
|
+
/**
|
|
20
|
+
* Chart data from an answer. Key columns (in any order) are the x axis (the first, a time bucket
|
|
21
|
+
* when there is one) and, after it, what splits the series; value columns are what is drawn.
|
|
22
|
+
* With split keys, the first value (the first calc, when there are calcs) becomes one series per
|
|
23
|
+
* combination of the keys ("Design · High"), Other one more. Without, every value is a series.
|
|
24
|
+
* Values in a second unit are read on a right axis; a third unit, or more values than a split can
|
|
25
|
+
* draw, are not drawn and are named in `notDrawn`, never silently dropped. Points and series are
|
|
26
|
+
* keyed by raw values, so two that read alike stay apart. Totals are not drawn.
|
|
27
|
+
*/
|
|
28
|
+
export declare function toSeries(answer: Pick<TileAnswer, "columns" | "rows">, format?: CellFormat): Drawn;
|
|
29
|
+
/**
|
|
30
|
+
* What a chart draws, and the way back from any chart kit's point to the answer's row:
|
|
31
|
+
* `rowAt(point, seriesKey)` gives the row's index in `answer.rows` (for a drill), or undefined
|
|
32
|
+
* for a point no row stands behind. `notDrawn` lists the values the chart leaves to the table.
|
|
33
|
+
*/
|
|
34
|
+
export type Drawn = {
|
|
35
|
+
points: Point[];
|
|
36
|
+
series: Series[];
|
|
37
|
+
split: boolean;
|
|
38
|
+
notDrawn: ResultColumn[];
|
|
39
|
+
rowAt: (point: number | Point, seriesKey: string) => number | undefined;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* The row of the answer behind a point of any chart kit's series, by the point's place (or the
|
|
43
|
+
* point) and the series key; undefined for a point no row stands behind. Pass it to
|
|
44
|
+
* `drill.open(row, series.column.id)` to open what is behind the point.
|
|
45
|
+
*/
|
|
46
|
+
export declare const rowAt: (drawn: Drawn, point: number | Point, seriesKey: string) => number | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* Whether the answer's last time bucket is still running: the range ends before the bucket
|
|
49
|
+
* does, as this week does on its Monday. Its value is not final, so a chart marks it rather
|
|
50
|
+
* than draw it as a fall.
|
|
51
|
+
*/
|
|
52
|
+
export declare function lastBucketOpen(answer: Pick<TileAnswer, "columns" | "rows"> & {
|
|
53
|
+
receipt: Pick<Receipt, "range" | "calendar">;
|
|
54
|
+
}): boolean;
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { formatCell, plotValue } from "./format.mjs";
|
|
2
|
+
import { ENGLISH } from "./english.mjs";
|
|
3
|
+
import { isMark } from "derive-dashboards/core";
|
|
4
|
+
// src/series.ts
|
|
5
|
+
const isValue = (c) => c.id.startsWith("m") || c.id.startsWith("c");
|
|
6
|
+
/** The series key a dimension's Other draws as. */
|
|
7
|
+
const OTHER_KEY = "other";
|
|
8
|
+
const isAll = (cell) => isMark(cell) && cell.mark === "all";
|
|
9
|
+
/** What a value is read against: two columns share an axis only when this is equal. */
|
|
10
|
+
const scaleOf = (c) => JSON.stringify([
|
|
11
|
+
c.unit ?? null,
|
|
12
|
+
c.format ?? null,
|
|
13
|
+
c.fraction ?? null
|
|
14
|
+
]);
|
|
15
|
+
/**
|
|
16
|
+
* Chart data from an answer. Key columns (in any order) are the x axis (the first, a time bucket
|
|
17
|
+
* when there is one) and, after it, what splits the series; value columns are what is drawn.
|
|
18
|
+
* With split keys, the first value (the first calc, when there are calcs) becomes one series per
|
|
19
|
+
* combination of the keys ("Design · High"), Other one more. Without, every value is a series.
|
|
20
|
+
* Values in a second unit are read on a right axis; a third unit, or more values than a split can
|
|
21
|
+
* draw, are not drawn and are named in `notDrawn`, never silently dropped. Points and series are
|
|
22
|
+
* keyed by raw values, so two that read alike stay apart. Totals are not drawn.
|
|
23
|
+
*/
|
|
24
|
+
function toSeries(answer, format = {}) {
|
|
25
|
+
const at = /* @__PURE__ */ new Map();
|
|
26
|
+
const drawn = drawSeries(answer, format, (point, key, row) => {
|
|
27
|
+
at.set(`${String(point)}|${key}`, row);
|
|
28
|
+
});
|
|
29
|
+
return {
|
|
30
|
+
...drawn,
|
|
31
|
+
rowAt: (point, key) => {
|
|
32
|
+
const index = typeof point === "number" ? point : drawn.points.indexOf(point);
|
|
33
|
+
return at.get(`${String(index)}|${key}`) ?? at.get(`${String(index)}|*`);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/** The values to draw: calcs when there are any (what the widget was built to see), else measures. */
|
|
38
|
+
function valuesOf(columns) {
|
|
39
|
+
const all = columns.filter((c) => isValue(c));
|
|
40
|
+
const calcs = all.filter((c) => c.id.startsWith("c"));
|
|
41
|
+
return calcs.length > 0 ? calcs : all;
|
|
42
|
+
}
|
|
43
|
+
function drawSeries(answer, format, seen) {
|
|
44
|
+
const keys = answer.columns.flatMap((c, i) => isValue(c) ? [] : [i]);
|
|
45
|
+
const values = valuesOf(answer.columns);
|
|
46
|
+
const rows = answer.rows.map((row, index) => ({
|
|
47
|
+
row,
|
|
48
|
+
index
|
|
49
|
+
})).filter(({ row }) => !row.some((cell) => isAll(cell)));
|
|
50
|
+
const keyText = (cell, column) => {
|
|
51
|
+
if (cell !== null && cell !== "") return formatCell(cell, column, format);
|
|
52
|
+
const words = format.messages ?? ENGLISH;
|
|
53
|
+
return column === void 0 ? words.empty : words.drillNone(column.label);
|
|
54
|
+
};
|
|
55
|
+
const shape = {
|
|
56
|
+
answer,
|
|
57
|
+
keys,
|
|
58
|
+
keyText,
|
|
59
|
+
seen
|
|
60
|
+
};
|
|
61
|
+
return keys.length < 2 ? plainSeries(rows, values, shape) : splitSeries(rows, values, shape);
|
|
62
|
+
}
|
|
63
|
+
/** The x label of a row, from its first key. */
|
|
64
|
+
const xOf = (shape, row) => {
|
|
65
|
+
const at = shape.keys[0];
|
|
66
|
+
return at === void 0 ? "" : shape.keyText(row[at] ?? null, shape.answer.columns[at]);
|
|
67
|
+
};
|
|
68
|
+
/** One series per value: the first unit on the left axis, a second on the right, a third not drawn. */
|
|
69
|
+
function plainSeries(rows, values, shape) {
|
|
70
|
+
const scales = [...new Set(values.map((c) => scaleOf(c)))];
|
|
71
|
+
const side = (c) => scales.indexOf(scaleOf(c));
|
|
72
|
+
const drawn = values.filter((c) => side(c) < 2);
|
|
73
|
+
const series = drawn.map((column) => ({
|
|
74
|
+
key: column.id,
|
|
75
|
+
label: column.label,
|
|
76
|
+
column,
|
|
77
|
+
axis: side(column) === 0 ? "left" : "right"
|
|
78
|
+
}));
|
|
79
|
+
return {
|
|
80
|
+
points: rows.map(({ row, index }, i) => {
|
|
81
|
+
shape.seen(i, "*", index);
|
|
82
|
+
const cells = drawn.map((c) => [c.id, plotValue(row[shape.answer.columns.indexOf(c)] ?? null)]);
|
|
83
|
+
return {
|
|
84
|
+
x: xOf(shape, row),
|
|
85
|
+
"#": i,
|
|
86
|
+
...Object.fromEntries(cells)
|
|
87
|
+
};
|
|
88
|
+
}),
|
|
89
|
+
series,
|
|
90
|
+
split: false,
|
|
91
|
+
notDrawn: values.filter((c) => side(c) >= 2)
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/** One value split into a series per combination of the keys after the first; other values are not drawn. */
|
|
95
|
+
function splitSeries(rows, values, shape) {
|
|
96
|
+
const [first, ...rest] = values;
|
|
97
|
+
if (first === void 0) return {
|
|
98
|
+
points: [],
|
|
99
|
+
series: [],
|
|
100
|
+
split: true,
|
|
101
|
+
notDrawn: []
|
|
102
|
+
};
|
|
103
|
+
const { answer, keys, keyText } = shape;
|
|
104
|
+
const valueAt = answer.columns.indexOf(first);
|
|
105
|
+
const byX = /* @__PURE__ */ new Map();
|
|
106
|
+
const names = /* @__PURE__ */ new Map();
|
|
107
|
+
for (const { row, index } of rows) {
|
|
108
|
+
const splitCells = keys.slice(1).map((i) => row[i] ?? null);
|
|
109
|
+
const key = splitKey(splitCells);
|
|
110
|
+
const label = splitCells.map((cell, i) => keyText(cell, answer.columns[keys[i + 1] ?? -1]));
|
|
111
|
+
names.set(key, label.join(" · "));
|
|
112
|
+
const xKey = JSON.stringify(row[keys[0] ?? 0] ?? null);
|
|
113
|
+
const point = byX.get(xKey) ?? {
|
|
114
|
+
x: xOf(shape, row),
|
|
115
|
+
"#": byX.size
|
|
116
|
+
};
|
|
117
|
+
point[key] = plotValue(row[valueAt] ?? null);
|
|
118
|
+
byX.set(xKey, point);
|
|
119
|
+
shape.seen(Number(point["#"]), key, index);
|
|
120
|
+
}
|
|
121
|
+
const series = [...names].map(([key, label]) => ({
|
|
122
|
+
key,
|
|
123
|
+
label,
|
|
124
|
+
column: first,
|
|
125
|
+
axis: "left"
|
|
126
|
+
})).toSorted((a, b) => Number(a.key === OTHER_KEY) - Number(b.key === OTHER_KEY));
|
|
127
|
+
return {
|
|
128
|
+
points: [...byX.values()],
|
|
129
|
+
series,
|
|
130
|
+
split: true,
|
|
131
|
+
notDrawn: rest
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
/** A series' key from its split cells: Other stays "other", any value is its raw JSON. */
|
|
135
|
+
function splitKey(cells) {
|
|
136
|
+
const [only] = cells;
|
|
137
|
+
if (cells.length === 1 && only !== void 0 && isMark(only)) return only.mark;
|
|
138
|
+
return `s${JSON.stringify(cells.length === 1 ? only ?? null : cells)}`;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* The row of the answer behind a point of any chart kit's series, by the point's place (or the
|
|
142
|
+
* point) and the series key; undefined for a point no row stands behind. Pass it to
|
|
143
|
+
* `drill.open(row, series.column.id)` to open what is behind the point.
|
|
144
|
+
*/
|
|
145
|
+
const rowAt = (drawn, point, seriesKey) => drawn.rowAt(point, seriesKey);
|
|
146
|
+
const DAY = 864e5;
|
|
147
|
+
const DAYS = {
|
|
148
|
+
day: 1,
|
|
149
|
+
week: 7
|
|
150
|
+
};
|
|
151
|
+
const MONTHS = {
|
|
152
|
+
month: 1,
|
|
153
|
+
quarter: 3,
|
|
154
|
+
year: 12
|
|
155
|
+
};
|
|
156
|
+
/** A calendar date ("2026-11-16") as the UTC midnight that names it. */
|
|
157
|
+
const dateOf = (text) => {
|
|
158
|
+
const [year = 0, month = 1, day = 1] = text.slice(0, 10).split("-").map(Number);
|
|
159
|
+
return Date.UTC(year, month - 1, day);
|
|
160
|
+
};
|
|
161
|
+
/** Where a bucket that starts on a calendar date ends, at its grain; none for a grain it cannot step. */
|
|
162
|
+
function bucketEnd(start, grain) {
|
|
163
|
+
const days = DAYS[grain];
|
|
164
|
+
if (days !== void 0) return start + days * DAY;
|
|
165
|
+
const months = MONTHS[grain];
|
|
166
|
+
if (months === void 0) return void 0;
|
|
167
|
+
const at = new Date(start);
|
|
168
|
+
return Date.UTC(at.getUTCFullYear(), at.getUTCMonth() + months, at.getUTCDate());
|
|
169
|
+
}
|
|
170
|
+
/** An instant as the calendar day it falls on in a zone, named as a bucket names its day. */
|
|
171
|
+
const dayIn = (instant, timeZone) => new Intl.DateTimeFormat("en-CA", {
|
|
172
|
+
timeZone,
|
|
173
|
+
year: "numeric",
|
|
174
|
+
month: "2-digit",
|
|
175
|
+
day: "2-digit"
|
|
176
|
+
}).format(new Date(instant));
|
|
177
|
+
/**
|
|
178
|
+
* Whether the answer's last time bucket is still running: the range ends before the bucket
|
|
179
|
+
* does, as this week does on its Monday. Its value is not final, so a chart marks it rather
|
|
180
|
+
* than draw it as a fall.
|
|
181
|
+
*/
|
|
182
|
+
function lastBucketOpen(answer) {
|
|
183
|
+
const grain = answer.columns[0]?.grain;
|
|
184
|
+
const to = answer.receipt.range?.to;
|
|
185
|
+
const last = answer.rows.findLast((row) => typeof row[0] === "string")?.[0];
|
|
186
|
+
if (grain === void 0 || to === void 0 || typeof last !== "string") return false;
|
|
187
|
+
if (!/^\d{4}-\d{2}-\d{2}/u.test(last)) return false;
|
|
188
|
+
const end = bucketEnd(dateOf(last), grain);
|
|
189
|
+
return end !== void 0 && dateOf(dayIn(to, answer.receipt.calendar.timezone)) + DAY < end;
|
|
190
|
+
}
|
|
191
|
+
export { OTHER_KEY, lastBucketOpen, rowAt, toSeries };
|