derive-dashboards 0.1.0 → 0.1.1
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 +4 -3
- package/dist/adapter/sql-adapter.mjs +4 -4
- package/dist/body.mjs +11 -1
- package/dist/cache.d.mts +1 -1
- package/dist/cli/check.mjs +14 -1
- package/dist/cli/import/dbt-schema.mjs +2 -2
- package/dist/cli/import/index.mjs +2 -2
- 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/view.d.mts +26 -7
- package/dist/core/document/view.mjs +42 -11
- package/dist/core/engine/index.d.mts +14 -2
- package/dist/core/engine/index.mjs +12 -1
- package/dist/core/engine/members.mjs +1 -1
- 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 +31 -0
- package/dist/core/error/codes.mjs +28 -1
- package/dist/core/index.d.mts +9 -5
- package/dist/core/index.mjs +5 -3
- 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 +16 -3
- package/dist/core/model/types.d.mts +8 -6
- package/dist/core/model/validate/drill.mjs +70 -0
- package/dist/core/model/validate/index.mjs +3 -0
- package/dist/core/model/validate/shape.mjs +150 -0
- package/dist/core/model/validate/source.mjs +5 -3
- 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/segments.d.mts +12 -2
- package/dist/core/query/segments.mjs +3 -1
- package/dist/core/result/columns.mjs +17 -4
- package/dist/core/result/types.d.mts +5 -1
- package/dist/core/schema/answer-parts.mjs +117 -0
- package/dist/core/schema/answers.d.mts +2108 -128
- package/dist/core/schema/answers.mjs +10 -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 +4 -2
- package/dist/core/schema/index.mjs +4 -2
- package/dist/core/schema/picks.d.mts +35 -0
- package/dist/core/schema/picks.mjs +23 -0
- package/dist/core/schema/query.d.mts +1 -1
- 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 +15 -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/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 +2 -2
- package/dist/endpoints/dashboards.mjs +11 -3
- package/dist/endpoints/drill.mjs +55 -0
- package/dist/endpoints/index.d.mts +233 -2
- package/dist/endpoints/index.mjs +5 -1
- package/dist/endpoints/query.mjs +26 -4
- package/dist/execute.d.mts +19 -1
- package/dist/execute.mjs +15 -17
- package/dist/index.d.mts +3 -1
- package/dist/index.mjs +29 -2
- package/dist/mcp/drill.mjs +61 -0
- package/dist/mcp/format.mjs +27 -3
- 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 +7 -3
- 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/react/Dashboard.d.mts +10 -5
- package/dist/react/Dashboard.mjs +51 -23
- package/dist/react/DashboardList.mjs +30 -2
- package/dist/react/Discard.mjs +7 -2
- package/dist/react/Grid.mjs +12 -5
- package/dist/react/Header.mjs +9 -0
- package/dist/react/Parts.mjs +6 -2
- 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/Tile.d.mts +1 -1
- package/dist/react/Tile.mjs +54 -30
- package/dist/react/builder/state.d.mts +1 -1
- package/dist/react/client.d.mts +2 -0
- package/dist/react/client.mjs +1 -0
- package/dist/react/context.d.mts +15 -1
- package/dist/react/context.mjs +19 -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 +98 -0
- package/dist/react/drill/words.mjs +77 -0
- package/dist/react/english.mjs +9 -1
- package/dist/react/format.d.mts +3 -3
- package/dist/react/format.mjs +34 -12
- package/dist/react/index.d.mts +27 -4
- package/dist/react/index.mjs +10 -3
- package/dist/react/messages.d.mts +14 -1
- package/dist/react/renderers/index.d.mts +10 -2
- package/dist/react/renderers/index.mjs +54 -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 +37 -0
- package/dist/react/series.mjs +95 -0
- package/dist/react/theme.css +1823 -1296
- package/dist/react/theme.css.d.ts +1 -0
- package/dist/react/tile-store.mjs +15 -3
- package/dist/react/useBoard.d.mts +5 -0
- package/dist/react/useBoard.mjs +4 -1
- package/dist/react/useDashboard.d.mts +1 -0
- package/dist/react/useDashboard.mjs +2 -1
- package/dist/react/useTiles.mjs +50 -15
- 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/charts.d.mts +0 -1
- package/dist/recharts/charts.mjs +128 -34
- package/dist/recharts/index.d.mts +2 -2
- package/dist/recharts/index.mjs +2 -2
- package/dist/recharts/marks.mjs +83 -0
- package/dist/recharts/series.d.mts +2 -22
- package/dist/recharts/series.mjs +1 -64
- package/dist/records-read.mjs +44 -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 +8 -10
- 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
package/dist/react/index.d.mts
CHANGED
|
@@ -1,27 +1,50 @@
|
|
|
1
|
+
import { ItemFor } from "./drill/item-type.mjs";
|
|
1
2
|
import { WidgetPreview } from "./builder/Preview.mjs";
|
|
2
3
|
import { Builder, useBuilder } from "./builder/useBuilder.mjs";
|
|
3
4
|
import { WidgetBuilder, WidgetBuilderProps } from "./builder/WidgetBuilder.mjs";
|
|
4
5
|
import { DashboardsError, DashboardsErrorCode } from "./errors.mjs";
|
|
5
6
|
import { ClientOptions, DashboardsClient, DashboardsServer, TypedCall, createDashboardsClient } from "./client.mjs";
|
|
6
|
-
import { DashboardsProvider, DashboardsProviderProps, useDashboards } from "./context.mjs";
|
|
7
|
+
import { DashboardsProvider, DashboardsProviderProps, LinkComponent, LinkProps, useDashboards } from "./context.mjs";
|
|
7
8
|
import { Dashboard, DashboardProps } from "./Dashboard.mjs";
|
|
8
|
-
import { ENGLISH } from "./english.mjs";
|
|
9
9
|
import { DashboardList } from "./DashboardList.mjs";
|
|
10
|
+
import { ENGLISH } from "./english.mjs";
|
|
10
11
|
import { Attempt, DraftClosed, DraftEditor, DraftStatus, useDraft } from "./draft.mjs";
|
|
12
|
+
import { DashboardDrillProps, DrillEvent } from "./drill/board.mjs";
|
|
13
|
+
import { DashboardTile, DashboardTileProps } from "./drill/DashboardTile.mjs";
|
|
14
|
+
import { DrillPanelProps } from "./drill/DrillPanel.mjs";
|
|
15
|
+
import { ItemHelpers, ItemOptions } from "./drill/Items.mjs";
|
|
16
|
+
import { DrillPanel } from "./drill/lazy.mjs";
|
|
17
|
+
import { DrillMarkProps, TileDrill } from "./drill/props.mjs";
|
|
18
|
+
import { DrillChange, DrillHistory, drillFrom } from "./drill/state.mjs";
|
|
19
|
+
import { DrillController, DrillOptions, useDrill } from "./drill/useDrill.mjs";
|
|
20
|
+
import { DrillMessages, ENGLISH_DRILL } from "./drill/words.mjs";
|
|
11
21
|
import { EditBar } from "./EditBar.mjs";
|
|
12
22
|
import { FilterBar } from "./FilterBar.mjs";
|
|
13
23
|
import { formatBucket, formatCell, formatInstant, formatTick, plotValue } from "./format.mjs";
|
|
14
24
|
import { HistoryPanel, VersionBar } from "./History.mjs";
|
|
15
25
|
import { CellFormat, Messages } from "./messages.mjs";
|
|
16
26
|
import { ChangeList, Panel } from "./Panel.mjs";
|
|
17
|
-
import { RecordsPanel } from "./Records.mjs";
|
|
18
27
|
import { ReviewPanel } from "./ReviewPanel.mjs";
|
|
19
28
|
import { ClientSchemas } from "./read.mjs";
|
|
20
29
|
import { NumberTile, TableTile, TileRenderer, TileRendererProps } from "./renderers/index.mjs";
|
|
30
|
+
import { ListDisplay, ListTile } from "./renderers/list.mjs";
|
|
21
31
|
import { Moved, Review, useReview } from "./review.mjs";
|
|
22
32
|
import { ENGLISH_REVIEW, ReviewMessages } from "./review-words.mjs";
|
|
33
|
+
import { Drawn, OTHER_KEY, Point, Series, rowAt, toSeries } from "./series.mjs";
|
|
23
34
|
import { Tile } from "./Tile.mjs";
|
|
24
35
|
import { useBoard } from "./useBoard.mjs";
|
|
25
36
|
import { useDashboard } from "./useDashboard.mjs";
|
|
26
37
|
import { useTiles } from "./useTiles.mjs";
|
|
27
|
-
|
|
38
|
+
import { ViewChange } from "./view.mjs";
|
|
39
|
+
import { DrillItem } from "derive-dashboards/core";
|
|
40
|
+
/**
|
|
41
|
+
* Register your server to type drill items by source:
|
|
42
|
+
* `declare module "derive-dashboards/react" { interface Register { server: typeof dashboards } }`.
|
|
43
|
+
* Then `item.source === "order"` narrows `item.key` to the order key's columns.
|
|
44
|
+
*/
|
|
45
|
+
export interface Register {}
|
|
46
|
+
/** A drill item, typed from the registered server's model, or a plain `DrillItem` without one. */
|
|
47
|
+
export type Item = Register extends {
|
|
48
|
+
server: infer S;
|
|
49
|
+
} ? ItemFor<S> : DrillItem;
|
|
50
|
+
export { type Attempt, type Builder, type CellFormat, ChangeList, type ClientOptions, type ClientSchemas, Dashboard, type DashboardDrillProps, DashboardList, type DashboardProps, DashboardTile, type DashboardTileProps, type DashboardsClient, DashboardsError, type DashboardsErrorCode, DashboardsProvider, type DashboardsProviderProps, type DashboardsServer, type DraftClosed, type DraftEditor, type DraftStatus, type Drawn, type DrillChange, type DrillController, type DrillEvent, type DrillHistory, type DrillMarkProps, type DrillMessages, type DrillOptions, DrillPanel, type DrillPanelProps, ENGLISH, ENGLISH_DRILL, ENGLISH_REVIEW, EditBar, FilterBar, HistoryPanel, type ItemFor, type ItemHelpers, type ItemOptions, type LinkComponent, type LinkProps, type ListDisplay, ListTile, type Messages, type Moved, NumberTile, OTHER_KEY, Panel, type Point, type Review, type ReviewMessages, ReviewPanel, type Series, TableTile, Tile, type TileDrill, type TileRenderer, type TileRendererProps, type TypedCall, VersionBar, type ViewChange, WidgetBuilder, type WidgetBuilderProps, WidgetPreview, createDashboardsClient, drillFrom, formatBucket, formatCell, formatInstant, formatTick, plotValue, rowAt, toSeries, useBoard, useBuilder, useDashboard, useDashboards, useDraft, useDrill, useReview, useTiles };
|
package/dist/react/index.mjs
CHANGED
|
@@ -1,25 +1,32 @@
|
|
|
1
|
+
"use client";
|
|
1
2
|
import { WidgetPreview } from "./builder/Preview.mjs";
|
|
2
3
|
import { useBuilder } from "./builder/useBuilder.mjs";
|
|
3
4
|
import { WidgetBuilder } from "./builder/WidgetBuilder.mjs";
|
|
4
5
|
import { createDashboardsClient } from "./client.mjs";
|
|
5
6
|
import { DashboardsProvider, useDashboards } from "./context.mjs";
|
|
6
|
-
import { DashboardsError } from "./errors.mjs";
|
|
7
7
|
import { Dashboard } from "./Dashboard.mjs";
|
|
8
8
|
import { DashboardList } from "./DashboardList.mjs";
|
|
9
|
+
import { DashboardsError } from "./errors.mjs";
|
|
9
10
|
import { useDraft } from "./draft.mjs";
|
|
11
|
+
import { DashboardTile } from "./drill/DashboardTile.mjs";
|
|
12
|
+
import { DrillPanel } from "./drill/lazy.mjs";
|
|
13
|
+
import { drillFrom } from "./drill/state.mjs";
|
|
14
|
+
import { useDrill } from "./drill/useDrill.mjs";
|
|
15
|
+
import { ENGLISH_DRILL } from "./drill/words.mjs";
|
|
10
16
|
import { EditBar } from "./EditBar.mjs";
|
|
11
17
|
import { FilterBar } from "./FilterBar.mjs";
|
|
12
18
|
import { formatBucket, formatCell, formatInstant, formatTick, plotValue } from "./format.mjs";
|
|
13
19
|
import { HistoryPanel, VersionBar } from "./History.mjs";
|
|
14
20
|
import { ENGLISH } from "./english.mjs";
|
|
15
21
|
import { ChangeList, Panel } from "./Panel.mjs";
|
|
16
|
-
import { RecordsPanel } from "./Records.mjs";
|
|
17
22
|
import { ReviewPanel } from "./ReviewPanel.mjs";
|
|
18
23
|
import { NumberTile, TableTile } from "./renderers/index.mjs";
|
|
24
|
+
import { ListTile } from "./renderers/list.mjs";
|
|
19
25
|
import { useReview } from "./review.mjs";
|
|
20
26
|
import { ENGLISH_REVIEW } from "./review-words.mjs";
|
|
27
|
+
import { OTHER_KEY, rowAt, toSeries } from "./series.mjs";
|
|
21
28
|
import { Tile } from "./Tile.mjs";
|
|
22
29
|
import { useBoard } from "./useBoard.mjs";
|
|
23
30
|
import { useDashboard } from "./useDashboard.mjs";
|
|
24
31
|
import { useTiles } from "./useTiles.mjs";
|
|
25
|
-
export { ChangeList, Dashboard, DashboardList, DashboardsError, DashboardsProvider, ENGLISH, ENGLISH_REVIEW, EditBar, FilterBar, HistoryPanel, NumberTile,
|
|
32
|
+
export { ChangeList, Dashboard, DashboardList, DashboardTile, DashboardsError, DashboardsProvider, DrillPanel, ENGLISH, ENGLISH_DRILL, ENGLISH_REVIEW, EditBar, FilterBar, HistoryPanel, ListTile, NumberTile, OTHER_KEY, Panel, ReviewPanel, TableTile, Tile, VersionBar, WidgetBuilder, WidgetPreview, createDashboardsClient, drillFrom, formatBucket, formatCell, formatInstant, formatTick, plotValue, rowAt, toSeries, useBoard, useBuilder, useDashboard, useDashboards, useDraft, useDrill, useReview, useTiles };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DrillMessages } from "./drill/words.mjs";
|
|
1
2
|
import { ReviewMessages } from "./review-words.mjs";
|
|
2
3
|
import { ENGLISH } from "./english.mjs";
|
|
3
4
|
import { RelativeRange } from "derive-dashboards/core";
|
|
@@ -5,7 +6,7 @@ import { RelativeRange } from "derive-dashboards/core";
|
|
|
5
6
|
* Every word the built-in components show. English by default; pass `messages` to the
|
|
6
7
|
* provider to change any of them, for another language or another house style.
|
|
7
8
|
*/
|
|
8
|
-
export type Messages = ReviewMessages & {
|
|
9
|
+
export type Messages = ReviewMessages & DrillMessages & {
|
|
9
10
|
/** A dimension cell for the values a limit left out. */
|
|
10
11
|
other: string;
|
|
11
12
|
/** A dimension cell for every value: a total row. */
|
|
@@ -19,6 +20,8 @@ export type Messages = ReviewMessages & {
|
|
|
19
20
|
noData: string;
|
|
20
21
|
noRows: string;
|
|
21
22
|
dashboardFailed: string;
|
|
23
|
+
/** A dashboard already shown, while the server cannot be reached. */
|
|
24
|
+
dashboardUnreachable: string;
|
|
22
25
|
/** A dashboard this viewer cannot find: never published, removed, or not shared with them. */
|
|
23
26
|
dashboardMissing: string;
|
|
24
27
|
rowsFailed: string;
|
|
@@ -26,6 +29,8 @@ export type Messages = ReviewMessages & {
|
|
|
26
29
|
rows: string;
|
|
27
30
|
close: string;
|
|
28
31
|
showMore: string;
|
|
32
|
+
/** How many rows the rows panel shows, and whether there are more. */
|
|
33
|
+
rowsShowing: (n: number, more: boolean) => string;
|
|
29
34
|
reset: string;
|
|
30
35
|
rowsBehind: (title: string) => string;
|
|
31
36
|
notFilteredBy: (controls: readonly string[]) => string;
|
|
@@ -123,6 +128,8 @@ export type Messages = ReviewMessages & {
|
|
|
123
128
|
keepEditing: string;
|
|
124
129
|
/** An edit that never reached the server: offline, or the server is down. */
|
|
125
130
|
unreachable: string;
|
|
131
|
+
/** Said when a tile is removed while editing. */
|
|
132
|
+
removedTile: (title: string) => string;
|
|
126
133
|
/** A tile whose request failed before any answer came. */
|
|
127
134
|
tileUnreachable: string;
|
|
128
135
|
/** Said once a draft is discarded, as focus returns to Edit. */
|
|
@@ -136,6 +143,10 @@ export type Messages = ReviewMessages & {
|
|
|
136
143
|
untitledDashboard: string;
|
|
137
144
|
/** Beside a dashboard only its maker sees yet. */
|
|
138
145
|
unpublished: string;
|
|
146
|
+
/** Over the dashboards the app ships (`default:` ids), when the list has others too. */
|
|
147
|
+
builtIn: string;
|
|
148
|
+
/** Over the dashboards made in the app, under the built-in ones. */
|
|
149
|
+
madeHere: string;
|
|
139
150
|
dashboardTitle: string;
|
|
140
151
|
history: string;
|
|
141
152
|
noHistory: string;
|
|
@@ -152,8 +163,10 @@ export type Messages = ReviewMessages & {
|
|
|
152
163
|
previewFailed: string;
|
|
153
164
|
};
|
|
154
165
|
/** What formatting reads besides a cell and its column: the locale, and the words to show. */
|
|
166
|
+
/** What formatting a cell reads besides its column: the locale, the words, and the zone times show in. */
|
|
155
167
|
export type CellFormat = {
|
|
156
168
|
locale?: string | undefined;
|
|
157
169
|
messages?: Messages;
|
|
170
|
+
timeZone?: string | undefined;
|
|
158
171
|
};
|
|
159
172
|
export { ENGLISH };
|
|
@@ -1,17 +1,25 @@
|
|
|
1
|
+
import { LinkComponent } from "../context.mjs";
|
|
2
|
+
import { TileDrill } from "../drill/props.mjs";
|
|
1
3
|
import { Messages } from "../messages.mjs";
|
|
2
4
|
import { ReactNode } from "react";
|
|
3
5
|
import { TileAnswer, Widget } from "derive-dashboards/core";
|
|
4
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* What a renderer draws, and how: pass the props as `formatCell`'s format to use both. `drill`
|
|
8
|
+
* is there when drilling is on: spread `drill.props(row, entry)` on a mark to make it open.
|
|
9
|
+
*/
|
|
5
10
|
export type TileRendererProps = {
|
|
6
11
|
answer: TileAnswer;
|
|
7
12
|
widget: Widget;
|
|
8
13
|
locale?: string;
|
|
9
14
|
messages: Messages;
|
|
15
|
+
drill?: TileDrill;
|
|
16
|
+
/** The provider's link component, for a renderer that links rows into the app. */
|
|
17
|
+
link?: LinkComponent;
|
|
10
18
|
};
|
|
11
19
|
/** Draws one tile's answer. Register more by widget kind on the provider. */
|
|
12
20
|
export type TileRenderer = (props: TileRendererProps) => ReactNode;
|
|
13
21
|
/**
|
|
14
|
-
* The first value column, large, from the total row when there is one, else the first row;
|
|
22
|
+
* The first calc or value column, large, from the total row when there is one, else the first row;
|
|
15
23
|
* a change calc (a signed column) sits under it.
|
|
16
24
|
*/
|
|
17
25
|
export declare function NumberTile(props: TileRendererProps): import("react").JSX.Element;
|
|
@@ -1,29 +1,63 @@
|
|
|
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
|
+
/** The value of the period before, when the answer compares: it opens that period's rows. */
|
|
46
|
+
function Before(props) {
|
|
47
|
+
const { answer, index } = props;
|
|
48
|
+
const before = answer.compare?.rows[0];
|
|
49
|
+
const column = answer.columns[index];
|
|
50
|
+
if (before === void 0 || column === void 0) return null;
|
|
51
|
+
const marks = props.drill?.props(before, column.id);
|
|
52
|
+
const text = props.messages.drillBefore(formatCell(before[index] ?? null, column, props));
|
|
53
|
+
const named = marks === void 0 ? marks : {
|
|
54
|
+
...marks,
|
|
55
|
+
"aria-label": props.messages.drillMark(text)
|
|
56
|
+
};
|
|
57
|
+
return /* @__PURE__ */ jsx("span", {
|
|
58
|
+
className: "dd-number-before",
|
|
59
|
+
...named,
|
|
60
|
+
children: text
|
|
27
61
|
});
|
|
28
62
|
}
|
|
29
63
|
/** Cells as table cells: a run of equal marks is one cell spanning its columns. */
|
|
@@ -41,10 +75,13 @@ function spans(cells) {
|
|
|
41
75
|
return out;
|
|
42
76
|
}
|
|
43
77
|
/** One table row. A row that folds dimensions is a summary, labelled where it folds them. */
|
|
44
|
-
function Row({ cells, columns, format }) {
|
|
78
|
+
function Row({ cells, columns, format, drill }) {
|
|
45
79
|
const summary = cells.some((cell) => isMark(cell));
|
|
80
|
+
const whole = drill?.props(cells);
|
|
81
|
+
const cellMarks = (column) => whole === void 0 && column !== void 0 && isMeasure(column) ? drill?.props(cells, column.id) : void 0;
|
|
46
82
|
return /* @__PURE__ */ jsx("tr", {
|
|
47
83
|
className: summary ? "dd-table-summary" : void 0,
|
|
84
|
+
...whole,
|
|
48
85
|
children: spans(cells).map(({ cell, at, span }) => {
|
|
49
86
|
const column = columns[at];
|
|
50
87
|
const numeric = column !== void 0 && isMeasure(column);
|
|
@@ -55,7 +92,8 @@ function Row({ cells, columns, format }) {
|
|
|
55
92
|
}, column?.id ?? at);
|
|
56
93
|
return /* @__PURE__ */ jsx("td", {
|
|
57
94
|
"data-numeric": numeric,
|
|
58
|
-
|
|
95
|
+
...cellMarks(column),
|
|
96
|
+
children: cell === null && column !== void 0 && !numeric ? format.messages.drillNone(column.label) : formatCell(cell, column, format)
|
|
59
97
|
}, column?.id ?? at);
|
|
60
98
|
})
|
|
61
99
|
});
|
|
@@ -74,12 +112,14 @@ function TableTile(props) {
|
|
|
74
112
|
}, c.id)) }) }), /* @__PURE__ */ jsx("tbody", { children: answer.rows.map((cells) => /* @__PURE__ */ jsx(Row, {
|
|
75
113
|
cells,
|
|
76
114
|
columns,
|
|
77
|
-
format: props
|
|
115
|
+
format: props,
|
|
116
|
+
drill: props.drill
|
|
78
117
|
}, JSON.stringify(cells.slice(0, keys)))) })]
|
|
79
118
|
});
|
|
80
119
|
}
|
|
81
120
|
const BUILTIN_RENDERERS = {
|
|
82
121
|
number: NumberTile,
|
|
83
|
-
table: TableTile
|
|
122
|
+
table: TableTile,
|
|
123
|
+
list: ListTile
|
|
84
124
|
};
|
|
85
125
|
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,37 @@
|
|
|
1
|
+
import { CellFormat } from "./messages.mjs";
|
|
2
|
+
import { ResultColumn, TileAnswer } from "derive-dashboards/core";
|
|
3
|
+
/** One point of a chart: its x label and a number per series key. */
|
|
4
|
+
export type Point = {
|
|
5
|
+
x: string;
|
|
6
|
+
} & Record<string, number | string | null>;
|
|
7
|
+
export type Series = {
|
|
8
|
+
key: string;
|
|
9
|
+
label: string;
|
|
10
|
+
column: ResultColumn;
|
|
11
|
+
};
|
|
12
|
+
/** The series key a dimension's Other draws as. */
|
|
13
|
+
export declare const OTHER_KEY = "other";
|
|
14
|
+
/**
|
|
15
|
+
* Chart data from an answer. The first non-value column is the x axis (the time bucket when
|
|
16
|
+
* there is one). With a second key column, the first value is split into one series per
|
|
17
|
+
* value of it, and Other in that column is one more series; otherwise every value column is
|
|
18
|
+
* its own series. Other on the x axis is one more point; totals are not drawn.
|
|
19
|
+
*/
|
|
20
|
+
export declare function toSeries(answer: Pick<TileAnswer, "columns" | "rows">, format?: CellFormat): Drawn;
|
|
21
|
+
/**
|
|
22
|
+
* What a chart draws, and the way back from any chart kit's point to the answer's row:
|
|
23
|
+
* `rowAt(point, seriesKey)` gives the row's index in `answer.rows` (for a drill), or undefined
|
|
24
|
+
* for a point no row stands behind.
|
|
25
|
+
*/
|
|
26
|
+
export type Drawn = {
|
|
27
|
+
points: Point[];
|
|
28
|
+
series: Series[];
|
|
29
|
+
split: boolean;
|
|
30
|
+
rowAt: (point: number | Point, seriesKey: string) => number | undefined;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* The row of the answer behind a point of any chart kit's series, by the point's place (or the
|
|
34
|
+
* point) and the series key; undefined for a point no row stands behind. Pass it to
|
|
35
|
+
* `drill.open(row, series.column.id)` to open what is behind the point.
|
|
36
|
+
*/
|
|
37
|
+
export declare const rowAt: (drawn: Drawn, point: number | Point, seriesKey: string) => number | undefined;
|
|
@@ -0,0 +1,95 @@
|
|
|
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
|
+
/**
|
|
10
|
+
* Chart data from an answer. The first non-value column is the x axis (the time bucket when
|
|
11
|
+
* there is one). With a second key column, the first value is split into one series per
|
|
12
|
+
* value of it, and Other in that column is one more series; otherwise every value column is
|
|
13
|
+
* its own series. Other on the x axis is one more point; totals are not drawn.
|
|
14
|
+
*/
|
|
15
|
+
function toSeries(answer, format = {}) {
|
|
16
|
+
const at = /* @__PURE__ */ new Map();
|
|
17
|
+
const drawn = drawSeries(answer, format, (point, key, row) => {
|
|
18
|
+
at.set(`${String(point)}|${key}`, row);
|
|
19
|
+
});
|
|
20
|
+
return {
|
|
21
|
+
...drawn,
|
|
22
|
+
rowAt: (point, key) => {
|
|
23
|
+
const index = typeof point === "number" ? point : drawn.points.indexOf(point);
|
|
24
|
+
return at.get(`${String(index)}|${key}`) ?? at.get(`${String(index)}|*`);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function drawSeries(answer, format, seen) {
|
|
29
|
+
const keyCount = answer.columns.filter((c) => !isValue(c)).length;
|
|
30
|
+
const all = answer.columns.slice(keyCount);
|
|
31
|
+
const calcs = all.filter((c) => c.id.startsWith("c"));
|
|
32
|
+
const values = calcs.length > 0 ? calcs : all;
|
|
33
|
+
const rows = answer.rows.map((row, index) => ({
|
|
34
|
+
row,
|
|
35
|
+
index
|
|
36
|
+
})).filter(({ row }) => !row.some((cell) => isAll(cell)));
|
|
37
|
+
const keyText = (cell, column) => {
|
|
38
|
+
if (cell !== null && cell !== "") return formatCell(cell, column, format);
|
|
39
|
+
const words = format.messages ?? ENGLISH;
|
|
40
|
+
return column === void 0 ? words.empty : words.drillNone(column.label);
|
|
41
|
+
};
|
|
42
|
+
const xOf = (row) => keyText(row[0] ?? null, answer.columns[0]);
|
|
43
|
+
if (keyCount < 2) {
|
|
44
|
+
const series = values.map((column) => ({
|
|
45
|
+
key: column.id,
|
|
46
|
+
label: column.label,
|
|
47
|
+
column
|
|
48
|
+
}));
|
|
49
|
+
return {
|
|
50
|
+
points: rows.map(({ row, index }, i) => {
|
|
51
|
+
seen(i, "*", index);
|
|
52
|
+
return {
|
|
53
|
+
x: keyCount === 0 ? "" : xOf(row),
|
|
54
|
+
...Object.fromEntries(values.map((c) => [c.id, plotValue(row[answer.columns.indexOf(c)] ?? null)]))
|
|
55
|
+
};
|
|
56
|
+
}),
|
|
57
|
+
series,
|
|
58
|
+
split: false
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
const first = values[0];
|
|
62
|
+
if (first === void 0) return {
|
|
63
|
+
points: [],
|
|
64
|
+
series: [],
|
|
65
|
+
split: true
|
|
66
|
+
};
|
|
67
|
+
const byX = /* @__PURE__ */ new Map();
|
|
68
|
+
const names = /* @__PURE__ */ new Map();
|
|
69
|
+
for (const { row, index } of rows) {
|
|
70
|
+
const split = row[1] ?? null;
|
|
71
|
+
const key = isMark(split) ? split.mark : `s${JSON.stringify(split)}`;
|
|
72
|
+
names.set(key, keyText(split, answer.columns[1]));
|
|
73
|
+
const point = byX.get(xOf(row)) ?? { x: xOf(row) };
|
|
74
|
+
point[key] = plotValue(row[keyCount] ?? null);
|
|
75
|
+
byX.set(xOf(row), point);
|
|
76
|
+
seen([...byX.keys()].indexOf(xOf(row)), key, index);
|
|
77
|
+
}
|
|
78
|
+
const series = [...names].map(([key, label]) => ({
|
|
79
|
+
key,
|
|
80
|
+
label,
|
|
81
|
+
column: first
|
|
82
|
+
})).toSorted((a, b) => Number(a.key === OTHER_KEY) - Number(b.key === OTHER_KEY));
|
|
83
|
+
return {
|
|
84
|
+
points: [...byX.values()],
|
|
85
|
+
series,
|
|
86
|
+
split: true
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* The row of the answer behind a point of any chart kit's series, by the point's place (or the
|
|
91
|
+
* point) and the series key; undefined for a point no row stands behind. Pass it to
|
|
92
|
+
* `drill.open(row, series.column.id)` to open what is behind the point.
|
|
93
|
+
*/
|
|
94
|
+
const rowAt = (drawn, point, seriesKey) => drawn.rowAt(point, seriesKey);
|
|
95
|
+
export { OTHER_KEY, rowAt, toSeries };
|