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
package/dist/recharts/charts.mjs
CHANGED
|
@@ -1,118 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { Bar, BarChart, CartesianGrid, Legend, Line, LineChart, ResponsiveContainer, Tooltip, XAxis, YAxis } from "recharts";
|
|
4
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { BarTile } from "./bar.mjs";
|
|
2
|
+
import { LineTile } from "./line.mjs";
|
|
5
3
|
// src/charts.tsx
|
|
6
|
-
/** A series' colour: the palette in order, and Other always the quiet grey. */
|
|
7
|
-
const color = (s, i) => s.key === "other" ? "var(--dd-other)" : `var(--dd-series-${i % 6 + 1})`;
|
|
8
|
-
function axisFormat(series, locale) {
|
|
9
|
-
const column = series[0]?.column;
|
|
10
|
-
return (value) => formatTick(value, column, locale);
|
|
11
|
-
}
|
|
12
|
-
function tooltipFormat(series, format) {
|
|
13
|
-
const column = series[0]?.column;
|
|
14
|
-
return (value) => typeof value === "number" ? formatCell(value, column, format) : String(value);
|
|
15
|
-
}
|
|
16
|
-
/** A line per series over the x axis, usually time buckets. */
|
|
17
|
-
function LineTile(props) {
|
|
18
|
-
const { answer, locale } = props;
|
|
19
|
-
const { points, series } = toSeries(answer, props);
|
|
20
|
-
return /* @__PURE__ */ jsx("div", {
|
|
21
|
-
className: "dd-chart",
|
|
22
|
-
children: /* @__PURE__ */ jsx(ResponsiveContainer, { children: /* @__PURE__ */ jsxs(LineChart, {
|
|
23
|
-
data: points,
|
|
24
|
-
margin: {
|
|
25
|
-
top: 4,
|
|
26
|
-
right: 8,
|
|
27
|
-
bottom: 0,
|
|
28
|
-
left: 0
|
|
29
|
-
},
|
|
30
|
-
children: [
|
|
31
|
-
/* @__PURE__ */ jsx(CartesianGrid, {
|
|
32
|
-
stroke: "var(--dd-line)",
|
|
33
|
-
vertical: false
|
|
34
|
-
}),
|
|
35
|
-
/* @__PURE__ */ jsx(XAxis, {
|
|
36
|
-
dataKey: "x",
|
|
37
|
-
tickLine: false,
|
|
38
|
-
axisLine: false,
|
|
39
|
-
stroke: "var(--dd-muted)",
|
|
40
|
-
minTickGap: 16
|
|
41
|
-
}),
|
|
42
|
-
/* @__PURE__ */ jsx(YAxis, {
|
|
43
|
-
tickLine: false,
|
|
44
|
-
axisLine: false,
|
|
45
|
-
stroke: "var(--dd-muted)",
|
|
46
|
-
width: 56,
|
|
47
|
-
tickFormatter: axisFormat(series, locale)
|
|
48
|
-
}),
|
|
49
|
-
/* @__PURE__ */ jsx(Tooltip, { formatter: tooltipFormat(series, props) }),
|
|
50
|
-
series.length > 1 ? /* @__PURE__ */ jsx(Legend, { itemSorter: null }) : null,
|
|
51
|
-
series.map((s, i) => /* @__PURE__ */ jsx(Line, {
|
|
52
|
-
dataKey: s.key,
|
|
53
|
-
name: s.label,
|
|
54
|
-
stroke: color(s, i),
|
|
55
|
-
strokeWidth: 2,
|
|
56
|
-
dot: false,
|
|
57
|
-
isAnimationActive: false
|
|
58
|
-
}, s.key))
|
|
59
|
-
]
|
|
60
|
-
}) })
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
/** Bars per x value; when a second field splits them, its values stack, Other on top. */
|
|
64
|
-
function BarTile(props) {
|
|
65
|
-
const { answer, locale } = props;
|
|
66
|
-
const { points, series, split } = toSeries(answer, props);
|
|
67
|
-
return /* @__PURE__ */ jsx("div", {
|
|
68
|
-
className: "dd-chart",
|
|
69
|
-
children: /* @__PURE__ */ jsx(ResponsiveContainer, { children: /* @__PURE__ */ jsxs(BarChart, {
|
|
70
|
-
data: points,
|
|
71
|
-
margin: {
|
|
72
|
-
top: 4,
|
|
73
|
-
right: 8,
|
|
74
|
-
bottom: 0,
|
|
75
|
-
left: 0
|
|
76
|
-
},
|
|
77
|
-
children: [
|
|
78
|
-
/* @__PURE__ */ jsx(CartesianGrid, {
|
|
79
|
-
stroke: "var(--dd-line)",
|
|
80
|
-
vertical: false
|
|
81
|
-
}),
|
|
82
|
-
/* @__PURE__ */ jsx(XAxis, {
|
|
83
|
-
dataKey: "x",
|
|
84
|
-
tickLine: false,
|
|
85
|
-
axisLine: false,
|
|
86
|
-
stroke: "var(--dd-muted)",
|
|
87
|
-
interval: "preserveStartEnd",
|
|
88
|
-
minTickGap: 12
|
|
89
|
-
}),
|
|
90
|
-
/* @__PURE__ */ jsx(YAxis, {
|
|
91
|
-
tickLine: false,
|
|
92
|
-
axisLine: false,
|
|
93
|
-
stroke: "var(--dd-muted)",
|
|
94
|
-
width: 56,
|
|
95
|
-
tickFormatter: axisFormat(series, locale)
|
|
96
|
-
}),
|
|
97
|
-
/* @__PURE__ */ jsx(Tooltip, { formatter: tooltipFormat(series, props) }),
|
|
98
|
-
series.length > 1 ? /* @__PURE__ */ jsx(Legend, { itemSorter: null }) : null,
|
|
99
|
-
series.map((s, i) => /* @__PURE__ */ jsx(Bar, {
|
|
100
|
-
dataKey: s.key,
|
|
101
|
-
name: s.label,
|
|
102
|
-
fill: color(s, i),
|
|
103
|
-
...split ? { stackId: "split" } : {},
|
|
104
|
-
radius: split && i < series.length - 1 ? 0 : [
|
|
105
|
-
4,
|
|
106
|
-
4,
|
|
107
|
-
0,
|
|
108
|
-
0
|
|
109
|
-
],
|
|
110
|
-
isAnimationActive: false
|
|
111
|
-
}, s.key))
|
|
112
|
-
]
|
|
113
|
-
}) })
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
4
|
/** Register with `<DashboardsProvider renderers={RECHARTS_RENDERERS}>`. */
|
|
117
5
|
const RECHARTS_RENDERERS = {
|
|
118
6
|
line: LineTile,
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
import { BarTile
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { BarTile } from "./bar.mjs";
|
|
2
|
+
import { LineTile } from "./line.mjs";
|
|
3
|
+
import { RECHARTS_RENDERERS } from "./charts.mjs";
|
|
4
|
+
import { Drawn, Point, Series, rowAt, toSeries } from "./series.mjs";
|
|
5
|
+
export { BarTile, type Drawn, LineTile, type Point, RECHARTS_RENDERERS, type Series, rowAt, toSeries };
|
package/dist/recharts/index.mjs
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
"use client";
|
|
2
|
+
import { RECHARTS_RENDERERS } from "./charts.mjs";
|
|
3
|
+
import { BarTile } from "./bar.mjs";
|
|
4
|
+
import { LineTile } from "./line.mjs";
|
|
5
|
+
import { rowAt, toSeries } from "./series.mjs";
|
|
6
|
+
export { BarTile, LineTile, RECHARTS_RENDERERS, rowAt, toSeries };
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { yAxes } from "./axes.mjs";
|
|
2
|
+
import { openPoint } from "./marks.mjs";
|
|
3
|
+
import { CHART, TOOLTIP, color, dashOf, legendText, runningLabel, tooltipFormat, tooltipLabel } from "./parts.mjs";
|
|
4
|
+
import { toSeries } from "./series.mjs";
|
|
5
|
+
import { Beside } from "./table.mjs";
|
|
6
|
+
import { useState } from "react";
|
|
7
|
+
import { CartesianGrid, Legend, Line, LineChart, ReferenceArea, ResponsiveContainer, Tooltip, XAxis } from "recharts";
|
|
8
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
// src/line.tsx
|
|
10
|
+
/** A line's dots: only the one the keyboard is on, ringed. */
|
|
11
|
+
const lineDot = (focused, key) => focused?.key === key ? (dot) => dot.index === focused.point ? /* @__PURE__ */ jsx("circle", {
|
|
12
|
+
className: "dd-chart-focus",
|
|
13
|
+
cx: dot.cx,
|
|
14
|
+
cy: dot.cy,
|
|
15
|
+
r: 5
|
|
16
|
+
}, dot.index) : /* @__PURE__ */ jsx("g", {}, dot.index) : false;
|
|
17
|
+
/** A click on a single line opens the point under it; with several, each opens from its own list. */
|
|
18
|
+
function lineClick(drill, drawn) {
|
|
19
|
+
const [only] = drawn.series;
|
|
20
|
+
return (state) => {
|
|
21
|
+
const point = Number(state.activeTooltipIndex);
|
|
22
|
+
if (only !== void 0 && drawn.series.length === 1 && Number.isInteger(point)) openPoint(drill, drawn, {
|
|
23
|
+
point,
|
|
24
|
+
series: only
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The bucket still running, shaded and saying so, so its low value reads as unfinished, not as
|
|
30
|
+
* a fall.
|
|
31
|
+
*/
|
|
32
|
+
function runningArea(props, points) {
|
|
33
|
+
const running = runningLabel(props, points);
|
|
34
|
+
const before = points.at(-2)?.x;
|
|
35
|
+
return running === void 0 || before === void 0 ? null : /* @__PURE__ */ jsx(ReferenceArea, {
|
|
36
|
+
yAxisId: "left",
|
|
37
|
+
x1: before,
|
|
38
|
+
x2: running,
|
|
39
|
+
fill: "var(--dd-line)",
|
|
40
|
+
fillOpacity: .35,
|
|
41
|
+
stroke: "none",
|
|
42
|
+
label: {
|
|
43
|
+
value: props.messages.soFar,
|
|
44
|
+
position: "insideTopRight",
|
|
45
|
+
fill: "var(--dd-muted)",
|
|
46
|
+
fontSize: 11
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
function LineTile(props) {
|
|
51
|
+
const { answer, locale, drill } = props;
|
|
52
|
+
const [focused, setFocused] = useState(null);
|
|
53
|
+
const drawn = toSeries(answer, props);
|
|
54
|
+
const { points, series } = drawn;
|
|
55
|
+
const onClick = lineClick(drill, drawn);
|
|
56
|
+
const running = runningLabel(props, points);
|
|
57
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
58
|
+
className: "dd-chart",
|
|
59
|
+
"data-drillable": drill !== void 0,
|
|
60
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
61
|
+
className: "dd-chart-picture",
|
|
62
|
+
"aria-hidden": "true",
|
|
63
|
+
children: /* @__PURE__ */ jsx(ResponsiveContainer, { children: /* @__PURE__ */ jsxs(LineChart, {
|
|
64
|
+
...CHART,
|
|
65
|
+
data: points,
|
|
66
|
+
...drill === void 0 ? {} : { onClick },
|
|
67
|
+
children: [
|
|
68
|
+
/* @__PURE__ */ jsx(CartesianGrid, {
|
|
69
|
+
stroke: "var(--dd-line)",
|
|
70
|
+
vertical: false
|
|
71
|
+
}),
|
|
72
|
+
/* @__PURE__ */ jsx(XAxis, {
|
|
73
|
+
dataKey: "x",
|
|
74
|
+
tickLine: false,
|
|
75
|
+
axisLine: false,
|
|
76
|
+
stroke: "var(--dd-muted)",
|
|
77
|
+
minTickGap: 16
|
|
78
|
+
}),
|
|
79
|
+
yAxes(drawn, locale),
|
|
80
|
+
/* @__PURE__ */ jsx(Tooltip, {
|
|
81
|
+
...TOOLTIP,
|
|
82
|
+
formatter: tooltipFormat(props, drawn),
|
|
83
|
+
labelFormatter: tooltipLabel(props, running)
|
|
84
|
+
}),
|
|
85
|
+
runningArea(props, points),
|
|
86
|
+
series.length > 1 ? /* @__PURE__ */ jsx(Legend, {
|
|
87
|
+
itemSorter: null,
|
|
88
|
+
formatter: legendText
|
|
89
|
+
}) : null,
|
|
90
|
+
series.map((s, i) => /* @__PURE__ */ jsx(Line, {
|
|
91
|
+
dataKey: s.key,
|
|
92
|
+
name: s.label,
|
|
93
|
+
yAxisId: s.axis,
|
|
94
|
+
stroke: color(props, s, i),
|
|
95
|
+
strokeWidth: 2,
|
|
96
|
+
...dashOf(i),
|
|
97
|
+
legendType: "plainline",
|
|
98
|
+
dot: lineDot(focused, s.key),
|
|
99
|
+
isAnimationActive: false
|
|
100
|
+
}, s.key))
|
|
101
|
+
]
|
|
102
|
+
}) })
|
|
103
|
+
}), /* @__PURE__ */ jsx(Beside, {
|
|
104
|
+
drawn,
|
|
105
|
+
props,
|
|
106
|
+
kind: "line",
|
|
107
|
+
onFocusMark: setFocused
|
|
108
|
+
})]
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
export { LineTile };
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from "react";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
// src/marks.tsx
|
|
4
|
+
/** The line a series draws: its own column, or for a split chart the value it splits. */
|
|
5
|
+
const entryOf = (s) => s.column.id;
|
|
6
|
+
/** Opens the drill of the row behind a point of a series, if a row stands behind it. */
|
|
7
|
+
function openPoint(drill, drawn, at) {
|
|
8
|
+
const row = drawn.rowAt(at.point, at.series.key);
|
|
9
|
+
if (drill !== void 0 && row !== void 0) drill.open(row, entryOf(at.series));
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Whether a pointer is down, read when a mark loses focus: a blur from a press waits for the
|
|
13
|
+
* click to land before the chart redraws, since a redraw between press and release would swallow
|
|
14
|
+
* the click on the bar pressed. A blur from the keyboard clears at once.
|
|
15
|
+
*/
|
|
16
|
+
function usePressing() {
|
|
17
|
+
const pressing = useRef(false);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
const down = () => {
|
|
20
|
+
pressing.current = true;
|
|
21
|
+
};
|
|
22
|
+
const up = () => {
|
|
23
|
+
queueMicrotask(() => {
|
|
24
|
+
pressing.current = false;
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
globalThis.addEventListener("pointerdown", down, true);
|
|
28
|
+
globalThis.addEventListener("pointerup", up, true);
|
|
29
|
+
return () => {
|
|
30
|
+
globalThis.removeEventListener("pointerdown", down, true);
|
|
31
|
+
globalThis.removeEventListener("pointerup", up, true);
|
|
32
|
+
};
|
|
33
|
+
}, []);
|
|
34
|
+
return (clear) => {
|
|
35
|
+
if (!pressing.current) {
|
|
36
|
+
clear();
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
globalThis.addEventListener("click", clear, { once: true });
|
|
40
|
+
globalThis.addEventListener("pointercancel", clear, { once: true });
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/** Where an arrow key moves along `count` marks from `at`; undefined for any other key. */
|
|
44
|
+
function nextMark(key, at, count) {
|
|
45
|
+
if (key === "ArrowRight" || key === "ArrowDown") return Math.min(at + 1, count - 1);
|
|
46
|
+
if (key === "ArrowLeft" || key === "ArrowUp") return Math.max(at - 1, 0);
|
|
47
|
+
if (key === "Home") return 0;
|
|
48
|
+
return key === "End" ? count - 1 : void 0;
|
|
49
|
+
}
|
|
50
|
+
/** The marks that open a row, in reading order: by point, then by series. */
|
|
51
|
+
function marksOf(drill, drawn, rows) {
|
|
52
|
+
return drawn.points.flatMap((_p, i) => drawn.series.flatMap((s) => {
|
|
53
|
+
const row = drawn.rowAt(i, s.key);
|
|
54
|
+
const props = row === void 0 || row >= rows ? void 0 : drill.props(row, entryOf(s));
|
|
55
|
+
if (props === void 0) return [];
|
|
56
|
+
const { role: _role, tabIndex: _tab, ...rest } = props;
|
|
57
|
+
return [{
|
|
58
|
+
key: `${String(i)}-${s.key}`,
|
|
59
|
+
point: i,
|
|
60
|
+
series: s.key,
|
|
61
|
+
props: rest
|
|
62
|
+
}];
|
|
63
|
+
}));
|
|
64
|
+
}
|
|
65
|
+
/** Arrow keys move focus along the list from the mark that has it, so the chart is one tab stop. */
|
|
66
|
+
function moveFocus(event) {
|
|
67
|
+
const buttons = [...event.currentTarget.querySelectorAll("button")];
|
|
68
|
+
const at = buttons.findIndex((b) => b === event.target);
|
|
69
|
+
const next = at < 0 ? void 0 : nextMark(event.key, at, buttons.length);
|
|
70
|
+
if (next === void 0) return;
|
|
71
|
+
event.preventDefault();
|
|
72
|
+
buttons[next]?.focus();
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Every mark that opens, as a list of buttons a keyboard reaches, so the chart opens without a
|
|
76
|
+
* pointer. The list is one tab stop: arrow keys, Home and End move along it, however many marks
|
|
77
|
+
* there are. It stays visually hidden and out of the chart's layout; the chart outlines the mark
|
|
78
|
+
* that has focus (`onFocusMark`). Each says its group and value, as a screen reader reads it.
|
|
79
|
+
* Nothing when drilling is off: the chart's data table carries its values then.
|
|
80
|
+
*/
|
|
81
|
+
function Marks(at) {
|
|
82
|
+
const clearAfterClick = usePressing();
|
|
83
|
+
const [current, setCurrent] = useState(0);
|
|
84
|
+
if (at.drill === void 0) return null;
|
|
85
|
+
const marks = marksOf(at.drill, at.drawn, at.rows);
|
|
86
|
+
if (marks.length === 0) return null;
|
|
87
|
+
const stop = Math.min(current, marks.length - 1);
|
|
88
|
+
return /* @__PURE__ */ jsx("ul", {
|
|
89
|
+
className: "dd-chart-marks",
|
|
90
|
+
"aria-label": at.label,
|
|
91
|
+
onKeyDown: moveFocus,
|
|
92
|
+
children: marks.map(({ key, point, series, props }, i) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx("button", {
|
|
93
|
+
type: "button",
|
|
94
|
+
...props,
|
|
95
|
+
tabIndex: i === stop ? 0 : -1,
|
|
96
|
+
onFocus: () => {
|
|
97
|
+
setCurrent(i);
|
|
98
|
+
at.onFocusMark({
|
|
99
|
+
point,
|
|
100
|
+
key: series
|
|
101
|
+
});
|
|
102
|
+
},
|
|
103
|
+
onBlur: () => {
|
|
104
|
+
clearAfterClick(() => {
|
|
105
|
+
at.onFocusMark(null);
|
|
106
|
+
});
|
|
107
|
+
},
|
|
108
|
+
children: String(props["aria-label"])
|
|
109
|
+
}) }, key))
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
export { Marks, nextMark, openPoint };
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { OTHER_KEY } from "./series.mjs";
|
|
2
|
+
import { cellText } from "./table.mjs";
|
|
3
|
+
import { lastBucketOpen } from "derive-dashboards/react";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
// src/parts.tsx
|
|
6
|
+
/** A series' colour: the palette in order, and Other always the quiet grey. */
|
|
7
|
+
/** Legend words in the text color: a series' hue marks its swatch, never its name. */
|
|
8
|
+
const legendText = (value) => /* @__PURE__ */ jsx("span", {
|
|
9
|
+
className: "dd-chart-legend",
|
|
10
|
+
children: value
|
|
11
|
+
});
|
|
12
|
+
/** A widget's own colors by series label (`display.colors`), else the palette in order. */
|
|
13
|
+
const colorsOf = (props) => {
|
|
14
|
+
const colors = props.widget.display?.["colors"];
|
|
15
|
+
return typeof colors === "object" && colors !== null ? new Map(Object.entries(colors)) : /* @__PURE__ */ new Map();
|
|
16
|
+
};
|
|
17
|
+
const color = (props, s, i) => {
|
|
18
|
+
const own = colorsOf(props).get(s.label);
|
|
19
|
+
if (typeof own === "string") return own;
|
|
20
|
+
return s.key === OTHER_KEY ? "var(--dd-other)" : `var(--dd-series-${i % 6 + 1})`;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* A tooltip's value: the answer's own cell behind the point, in its own series' column, so an
|
|
24
|
+
* exact amount reads exactly and each series keeps its unit. Only the pixels use the float.
|
|
25
|
+
*/
|
|
26
|
+
function tooltipFormat(props, drawn) {
|
|
27
|
+
return (value, _name, item) => {
|
|
28
|
+
const s = drawn.series.find((x) => x.key === item.dataKey);
|
|
29
|
+
if (s === void 0) return String(value);
|
|
30
|
+
const payload = item.payload;
|
|
31
|
+
const place = typeof payload === "object" && payload !== null && "#" in payload ? payload["#"] : void 0;
|
|
32
|
+
return cellText(props, drawn, {
|
|
33
|
+
place,
|
|
34
|
+
series: s,
|
|
35
|
+
value
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/** Each line's own stroke, so series part by shape as well as by color. */
|
|
40
|
+
const DASHES = [
|
|
41
|
+
void 0,
|
|
42
|
+
"6 4",
|
|
43
|
+
"2 3",
|
|
44
|
+
"10 3 2 3"
|
|
45
|
+
];
|
|
46
|
+
/** The i-th line's dash, or none for the first: a solid line takes no dash at all. */
|
|
47
|
+
const dashOf = (i) => {
|
|
48
|
+
const dash = DASHES[i % DASHES.length];
|
|
49
|
+
return dash === void 0 ? {} : { strokeDasharray: dash };
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* A tooltip's title: the point's name, "so far" on a time bucket still running, and what a
|
|
53
|
+
* click does when the chart drills.
|
|
54
|
+
*/
|
|
55
|
+
const tooltipLabel = (props, running) => (label) => [
|
|
56
|
+
String(label),
|
|
57
|
+
running !== void 0 && String(label) === running ? props.messages.soFar : void 0,
|
|
58
|
+
props.drill === void 0 ? void 0 : props.messages.drillHint
|
|
59
|
+
].filter((part) => part !== void 0).join(" · ");
|
|
60
|
+
/** The x label of the last point when its time bucket is still running. */
|
|
61
|
+
const runningLabel = (props, points) => lastBucketOpen(props.answer) ? points.at(-1)?.x : void 0;
|
|
62
|
+
/** The tooltip in the theme's colors, light and dark; the hover band a soft wash, not a gray slab. */
|
|
63
|
+
const TOOLTIP = {
|
|
64
|
+
separator: ": ",
|
|
65
|
+
contentStyle: {
|
|
66
|
+
background: "var(--dd-surface)",
|
|
67
|
+
border: "1px solid var(--dd-line)",
|
|
68
|
+
borderRadius: "var(--dd-radius)",
|
|
69
|
+
color: "var(--dd-ink)"
|
|
70
|
+
},
|
|
71
|
+
labelStyle: { color: "var(--dd-muted)" },
|
|
72
|
+
itemStyle: { color: "var(--dd-ink)" },
|
|
73
|
+
cursor: {
|
|
74
|
+
fill: "var(--dd-line)",
|
|
75
|
+
fillOpacity: .4,
|
|
76
|
+
stroke: "var(--dd-line)"
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
const CHART = {
|
|
80
|
+
accessibilityLayer: false,
|
|
81
|
+
margin: {
|
|
82
|
+
top: 4,
|
|
83
|
+
right: 8,
|
|
84
|
+
bottom: 0,
|
|
85
|
+
left: 0
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
export { CHART, TOOLTIP, color, dashOf, legendText, runningLabel, tooltipFormat, tooltipLabel };
|
|
@@ -1,22 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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
|
-
/**
|
|
13
|
-
* Chart data from an answer. The first non-value column is the x axis (the time bucket when
|
|
14
|
-
* there is one). With a second key column, the first value is split into one series per
|
|
15
|
-
* value of it, and Other in that column is one more series; otherwise every value column is
|
|
16
|
-
* its own series. Other on the x axis is one more point; totals are not drawn.
|
|
17
|
-
*/
|
|
18
|
-
export declare function toSeries(answer: Pick<TileAnswer, "columns" | "rows">, format?: CellFormat): {
|
|
19
|
-
points: Point[];
|
|
20
|
-
series: Series[];
|
|
21
|
-
split: boolean;
|
|
22
|
-
};
|
|
1
|
+
import { Drawn, Point, Series, rowAt, toSeries } from "derive-dashboards/react";
|
|
2
|
+
export { type Drawn, type Point, type Series, rowAt, toSeries };
|
package/dist/recharts/series.mjs
CHANGED
|
@@ -1,64 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { isMark } from "derive-dashboards/core";
|
|
3
|
-
// src/series.ts
|
|
4
|
-
const isValue = (c) => c.id.startsWith("m") || c.id.startsWith("c");
|
|
5
|
-
/** The series key a dimension's Other draws as. */
|
|
6
|
-
const OTHER_KEY = "other";
|
|
7
|
-
const isAll = (cell) => isMark(cell) && cell.mark === "all";
|
|
8
|
-
/**
|
|
9
|
-
* Chart data from an answer. The first non-value column is the x axis (the time bucket when
|
|
10
|
-
* there is one). With a second key column, the first value is split into one series per
|
|
11
|
-
* value of it, and Other in that column is one more series; otherwise every value column is
|
|
12
|
-
* its own series. Other on the x axis is one more point; totals are not drawn.
|
|
13
|
-
*/
|
|
14
|
-
function toSeries(answer, format = {}) {
|
|
15
|
-
const keyCount = answer.columns.filter((c) => !isValue(c)).length;
|
|
16
|
-
const all = answer.columns.slice(keyCount);
|
|
17
|
-
const calcs = all.filter((c) => c.id.startsWith("c"));
|
|
18
|
-
const values = calcs.length > 0 ? calcs : all;
|
|
19
|
-
const rows = answer.rows.filter((row) => !row.some((cell) => isAll(cell)));
|
|
20
|
-
const keyText = (cell, column) => cell === null || cell === "" ? (format.messages ?? ENGLISH).empty : formatCell(cell, column, format);
|
|
21
|
-
const xOf = (row) => keyText(row[0] ?? null, answer.columns[0]);
|
|
22
|
-
if (keyCount < 2) {
|
|
23
|
-
const series = values.map((column) => ({
|
|
24
|
-
key: column.id,
|
|
25
|
-
label: column.label,
|
|
26
|
-
column
|
|
27
|
-
}));
|
|
28
|
-
return {
|
|
29
|
-
points: rows.map((row) => ({
|
|
30
|
-
x: keyCount === 0 ? "" : xOf(row),
|
|
31
|
-
...Object.fromEntries(values.map((c) => [c.id, plotValue(row[answer.columns.indexOf(c)] ?? null)]))
|
|
32
|
-
})),
|
|
33
|
-
series,
|
|
34
|
-
split: false
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
const first = values[0];
|
|
38
|
-
if (first === void 0) return {
|
|
39
|
-
points: [],
|
|
40
|
-
series: [],
|
|
41
|
-
split: true
|
|
42
|
-
};
|
|
43
|
-
const byX = /* @__PURE__ */ new Map();
|
|
44
|
-
const names = /* @__PURE__ */ new Map();
|
|
45
|
-
for (const row of rows) {
|
|
46
|
-
const split = row[1] ?? null;
|
|
47
|
-
const key = isMark(split) ? split.mark : `s${JSON.stringify(split)}`;
|
|
48
|
-
names.set(key, keyText(split, answer.columns[1]));
|
|
49
|
-
const point = byX.get(xOf(row)) ?? { x: xOf(row) };
|
|
50
|
-
point[key] = plotValue(row[keyCount] ?? null);
|
|
51
|
-
byX.set(xOf(row), point);
|
|
52
|
-
}
|
|
53
|
-
const series = [...names].map(([key, label]) => ({
|
|
54
|
-
key,
|
|
55
|
-
label,
|
|
56
|
-
column: first
|
|
57
|
-
})).toSorted((a, b) => Number(a.key === OTHER_KEY) - Number(b.key === OTHER_KEY));
|
|
58
|
-
return {
|
|
59
|
-
points: [...byX.values()],
|
|
60
|
-
series,
|
|
61
|
-
split: true
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
export { OTHER_KEY, toSeries };
|
|
1
|
+
export { OTHER_KEY, rowAt, toSeries } from "derive-dashboards/react";
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { NotDrawn } from "./axes.mjs";
|
|
2
|
+
import { Marks } from "./marks.mjs";
|
|
3
|
+
import { formatCell } from "derive-dashboards/react";
|
|
4
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
// src/table.tsx
|
|
6
|
+
/**
|
|
7
|
+
* The answer's own cell behind a point of a series, formatted in its column, so an exact amount
|
|
8
|
+
* reads exactly and each series keeps its unit; the drawn number when no row stands behind it.
|
|
9
|
+
*/
|
|
10
|
+
function cellText(props, drawn, at) {
|
|
11
|
+
const { answer } = props;
|
|
12
|
+
const row = typeof at.place === "number" ? drawn.rowAt(at.place, at.series.key) : void 0;
|
|
13
|
+
const cell = row === void 0 ? void 0 : answer.rows[row]?.[answer.columns.indexOf(at.series.column)];
|
|
14
|
+
if (cell !== void 0) return formatCell(cell, at.series.column, props);
|
|
15
|
+
if (typeof at.value === "number") return formatCell(at.value, at.series.column, props);
|
|
16
|
+
const v = at.value;
|
|
17
|
+
return typeof v === "string" || typeof v === "boolean" || typeof v === "bigint" ? String(v) : "";
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The chart as a table, for screen readers: what a sighted reader gets from the picture and its
|
|
21
|
+
* tooltips, read with a screen reader's table keys. Visually hidden and out of the tab order, so
|
|
22
|
+
* a keyboard is never walked through every value; the picture itself is hidden from them.
|
|
23
|
+
*/
|
|
24
|
+
function ChartTable({ drawn, props, kind }) {
|
|
25
|
+
const { points, series } = drawn;
|
|
26
|
+
return /* @__PURE__ */ jsxs("table", {
|
|
27
|
+
className: "dd-sr-only",
|
|
28
|
+
children: [
|
|
29
|
+
/* @__PURE__ */ jsx("caption", { children: props.messages.chartTable({
|
|
30
|
+
title: props.widget.title,
|
|
31
|
+
kind,
|
|
32
|
+
points: points.length
|
|
33
|
+
}) }),
|
|
34
|
+
/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [/* @__PURE__ */ jsx("td", {}), series.map((s) => /* @__PURE__ */ jsx("th", {
|
|
35
|
+
scope: "col",
|
|
36
|
+
children: s.label
|
|
37
|
+
}, s.key))] }) }),
|
|
38
|
+
/* @__PURE__ */ jsx("tbody", { children: points.map((point, place) => /* @__PURE__ */ jsxs("tr", { children: [/* @__PURE__ */ jsx("th", {
|
|
39
|
+
scope: "row",
|
|
40
|
+
children: point.x
|
|
41
|
+
}), series.map((s) => /* @__PURE__ */ jsx("td", { children: cellText(props, drawn, {
|
|
42
|
+
place,
|
|
43
|
+
series: s,
|
|
44
|
+
value: point[s.key]
|
|
45
|
+
}) }, s.key))] }, point.x)) })
|
|
46
|
+
]
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/** What sits beside every chart: its keyboard path, what it does not draw, and its data table. */
|
|
50
|
+
function Beside(at) {
|
|
51
|
+
const { drawn, props } = at;
|
|
52
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
53
|
+
/* @__PURE__ */ jsx(Marks, {
|
|
54
|
+
drill: props.drill,
|
|
55
|
+
drawn,
|
|
56
|
+
rows: props.answer.rows.length,
|
|
57
|
+
label: props.messages.chartPoints,
|
|
58
|
+
onFocusMark: at.onFocusMark
|
|
59
|
+
}),
|
|
60
|
+
/* @__PURE__ */ jsx(NotDrawn, {
|
|
61
|
+
drawn,
|
|
62
|
+
props
|
|
63
|
+
}),
|
|
64
|
+
/* @__PURE__ */ jsx(ChartTable, {
|
|
65
|
+
drawn,
|
|
66
|
+
props,
|
|
67
|
+
kind: at.kind
|
|
68
|
+
})
|
|
69
|
+
] });
|
|
70
|
+
}
|
|
71
|
+
export { Beside, cellText };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { openCursor, sealCursor } from "./cursor-seal.mjs";
|
|
2
|
+
import { bind, reading } from "./execute.mjs";
|
|
3
|
+
import { recordColumns } from "derive-dashboards/core";
|
|
4
|
+
import { readRecords } from "derive-dashboards/core/engine";
|
|
5
|
+
// src/records-read.ts
|
|
6
|
+
/**
|
|
7
|
+
* A page of rows, its cursor sealed to the viewer's tenant and to everything that decides which
|
|
8
|
+
* rows come next: the query (a drill's filters in it), the columns and order read, the lock and
|
|
9
|
+
* required filters, and who asks (`by`), so a cursor never continues another population.
|
|
10
|
+
*/
|
|
11
|
+
async function readPage(x, page) {
|
|
12
|
+
const bound = bind(x);
|
|
13
|
+
const key = await x.rt.cursorKey;
|
|
14
|
+
const on = {
|
|
15
|
+
query: bound.input.query,
|
|
16
|
+
shape: page.shape ?? null,
|
|
17
|
+
lock: bound.lock,
|
|
18
|
+
required: bound.required,
|
|
19
|
+
by: page.by ?? null
|
|
20
|
+
};
|
|
21
|
+
const at = {
|
|
22
|
+
principal: x.principal,
|
|
23
|
+
on
|
|
24
|
+
};
|
|
25
|
+
const after = page.after === void 0 ? {} : { after: await openCursor(key, page.after, at) };
|
|
26
|
+
const shape = page.shape === void 0 ? {} : { shape: page.shape };
|
|
27
|
+
const { value } = await reading(x, page.limit, (reader) => readRecords(bound.input, {
|
|
28
|
+
limit: page.limit,
|
|
29
|
+
...after,
|
|
30
|
+
...shape
|
|
31
|
+
}, reader));
|
|
32
|
+
const next = value.next === void 0 ? {} : { next: await sealCursor(key, value.next, at) };
|
|
33
|
+
return {
|
|
34
|
+
...value,
|
|
35
|
+
...next,
|
|
36
|
+
columns: recordColumns(x.rt.options.model, x.query.source, value.columns)
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/** A page of the rows behind a query, under the same access, filters and range as its answer. */
|
|
40
|
+
async function executeRecords(x, page) {
|
|
41
|
+
const { keys: _keys, ...records } = await readPage(x, page);
|
|
42
|
+
return records;
|
|
43
|
+
}
|
|
44
|
+
export { executeRecords, readPage };
|