derive-dashboards 0.5.1 → 0.7.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 +4 -2
- package/dist/body.mjs +2 -2
- package/dist/charts/data/buckets.d.mts +11 -0
- package/dist/charts/data/buckets.mjs +66 -0
- package/dist/charts/data/clean.mjs +55 -0
- package/dist/charts/data/format.d.mts +19 -0
- package/dist/charts/data/format.mjs +174 -0
- package/dist/charts/data/input-error.d.mts +5 -0
- package/dist/charts/data/input-error.mjs +11 -0
- package/dist/charts/data/range.mjs +14 -0
- package/dist/charts/data/rows.d.mts +13 -0
- package/dist/charts/data/rows.mjs +31 -0
- package/dist/charts/data/shares.mjs +55 -0
- package/dist/charts/data/types.d.mts +106 -0
- package/dist/charts/data/words.d.mts +44 -0
- package/dist/charts/data/words.mjs +31 -0
- package/dist/charts/describe.mjs +110 -0
- package/dist/charts/index.d.mts +34 -0
- package/dist/charts/index.mjs +24 -0
- package/dist/charts/kinds/area-marks.mjs +120 -0
- package/dist/charts/kinds/area.d.mts +23 -0
- package/dist/charts/kinds/area.mjs +71 -0
- package/dist/charts/kinds/bars-data.d.mts +11 -0
- package/dist/charts/kinds/bars-data.mjs +30 -0
- package/dist/charts/kinds/bars-layout.mjs +30 -0
- package/dist/charts/kinds/bars-marks.mjs +93 -0
- package/dist/charts/kinds/bars-words.mjs +56 -0
- package/dist/charts/kinds/bars.d.mts +17 -0
- package/dist/charts/kinds/bars.mjs +68 -0
- package/dist/charts/kinds/columns-data.mjs +116 -0
- package/dist/charts/kinds/columns-layout.mjs +29 -0
- package/dist/charts/kinds/columns-marks.mjs +200 -0
- package/dist/charts/kinds/columns-words.mjs +26 -0
- package/dist/charts/kinds/columns.d.mts +13 -0
- package/dist/charts/kinds/columns.mjs +80 -0
- package/dist/charts/kinds/dumbbell-data.d.mts +22 -0
- package/dist/charts/kinds/dumbbell-data.mjs +59 -0
- package/dist/charts/kinds/dumbbell-layout.mjs +113 -0
- package/dist/charts/kinds/dumbbell-marks.mjs +119 -0
- package/dist/charts/kinds/dumbbell-words.d.mts +7 -0
- package/dist/charts/kinds/dumbbell-words.mjs +94 -0
- package/dist/charts/kinds/dumbbell.d.mts +14 -0
- package/dist/charts/kinds/dumbbell.mjs +67 -0
- package/dist/charts/kinds/funnel-data.d.mts +11 -0
- package/dist/charts/kinds/funnel-data.mjs +70 -0
- package/dist/charts/kinds/funnel-layout.mjs +32 -0
- package/dist/charts/kinds/funnel-marks.mjs +204 -0
- package/dist/charts/kinds/funnel-words.mjs +77 -0
- package/dist/charts/kinds/funnel.d.mts +11 -0
- package/dist/charts/kinds/funnel.mjs +75 -0
- package/dist/charts/kinds/grid-data.d.mts +18 -0
- package/dist/charts/kinds/grid-data.mjs +35 -0
- package/dist/charts/kinds/grid-layout.mjs +77 -0
- package/dist/charts/kinds/grid-marks.mjs +140 -0
- package/dist/charts/kinds/grid-time.mjs +41 -0
- package/dist/charts/kinds/grid-words.mjs +86 -0
- package/dist/charts/kinds/grid.d.mts +22 -0
- package/dist/charts/kinds/grid.mjs +55 -0
- package/dist/charts/kinds/histogram-data.mjs +142 -0
- package/dist/charts/kinds/histogram-layout.mjs +144 -0
- package/dist/charts/kinds/histogram-marks.mjs +110 -0
- package/dist/charts/kinds/histogram-words.mjs +104 -0
- package/dist/charts/kinds/histogram.d.mts +15 -0
- package/dist/charts/kinds/histogram.mjs +47 -0
- package/dist/charts/kinds/line-marks.mjs +36 -0
- package/dist/charts/kinds/line.d.mts +17 -0
- package/dist/charts/kinds/line.mjs +52 -0
- package/dist/charts/kinds/multiples-grid.mjs +107 -0
- package/dist/charts/kinds/multiples-head.mjs +44 -0
- package/dist/charts/kinds/multiples-layout.mjs +159 -0
- package/dist/charts/kinds/multiples-marks.mjs +95 -0
- package/dist/charts/kinds/multiples-words.mjs +110 -0
- package/dist/charts/kinds/multiples.d.mts +26 -0
- package/dist/charts/kinds/multiples.mjs +42 -0
- package/dist/charts/kinds/row-chart.mjs +112 -0
- package/dist/charts/kinds/row-marks.mjs +121 -0
- package/dist/charts/kinds/scatter-data.d.mts +18 -0
- package/dist/charts/kinds/scatter-data.mjs +123 -0
- package/dist/charts/kinds/scatter-layout.mjs +189 -0
- package/dist/charts/kinds/scatter-marks.mjs +149 -0
- package/dist/charts/kinds/scatter-words.mjs +80 -0
- package/dist/charts/kinds/scatter.d.mts +21 -0
- package/dist/charts/kinds/scatter.mjs +72 -0
- package/dist/charts/kinds/stat-data.mjs +91 -0
- package/dist/charts/kinds/stat-layout.mjs +108 -0
- package/dist/charts/kinds/stat-marks.mjs +85 -0
- package/dist/charts/kinds/stat-words.mjs +57 -0
- package/dist/charts/kinds/stat.d.mts +28 -0
- package/dist/charts/kinds/stat.mjs +35 -0
- package/dist/charts/kinds/time-chart.mjs +74 -0
- package/dist/charts/kinds/time-frame.mjs +113 -0
- package/dist/charts/kinds/time-notes.mjs +36 -0
- package/dist/charts/kinds/time-plan.d.mts +8 -0
- package/dist/charts/kinds/time-plan.mjs +57 -0
- package/dist/charts/kinds/time-plot.mjs +56 -0
- package/dist/charts/kinds/time-stops.mjs +56 -0
- package/dist/charts/kinds/value-plot.mjs +33 -0
- package/dist/charts/kinds/waterfall-data.d.mts +7 -0
- package/dist/charts/kinds/waterfall-data.mjs +71 -0
- package/dist/charts/kinds/waterfall-layout.mjs +38 -0
- package/dist/charts/kinds/waterfall-marks.mjs +82 -0
- package/dist/charts/kinds/waterfall-words.mjs +118 -0
- package/dist/charts/kinds/waterfall.d.mts +17 -0
- package/dist/charts/kinds/waterfall.mjs +66 -0
- package/dist/charts/layout/boxes.mjs +28 -0
- package/dist/charts/layout/dodge.mjs +75 -0
- package/dist/charts/layout/extent.mjs +25 -0
- package/dist/charts/layout/frame.mjs +97 -0
- package/dist/charts/layout/place-labels.mjs +101 -0
- package/dist/charts/layout/stack.mjs +31 -0
- package/dist/charts/marks/axes.mjs +137 -0
- package/dist/charts/marks/dot.mjs +31 -0
- package/dist/charts/marks/end-labels.mjs +124 -0
- package/dist/charts/marks/legend.mjs +141 -0
- package/dist/charts/marks/lines.d.mts +2 -0
- package/dist/charts/marks/lines.mjs +38 -0
- package/dist/charts/marks/lit.d.mts +3 -0
- package/dist/charts/marks/lit.mjs +63 -0
- package/dist/charts/marks/more.mjs +18 -0
- package/dist/charts/marks/notes.mjs +253 -0
- package/dist/charts/marks/series-line.mjs +110 -0
- package/dist/charts/marks/thin.mjs +138 -0
- package/dist/charts/marks/x-axis.mjs +32 -0
- package/dist/charts/scale/calendar.mjs +174 -0
- package/dist/charts/scale/time-ticks.mjs +154 -0
- package/dist/charts/scale/time.mjs +33 -0
- package/dist/charts/scale/value.mjs +161 -0
- package/dist/charts/scene/defs.mjs +33 -0
- package/dist/charts/scene/markup.mjs +35 -0
- package/dist/charts/scene/nearest.d.mts +11 -0
- package/dist/charts/scene/nearest.mjs +49 -0
- package/dist/charts/scene/paint.d.mts +12 -0
- package/dist/charts/scene/paint.mjs +13 -0
- package/dist/charts/scene/svg.d.mts +18 -0
- package/dist/charts/scene/svg.mjs +185 -0
- package/dist/charts/scene/types.d.mts +177 -0
- package/dist/charts/text/measure.d.mts +9 -0
- package/dist/charts/text/measure.mjs +123 -0
- package/dist/charts/theme.d.mts +47 -0
- package/dist/charts/theme.mjs +239 -0
- package/dist/charts-react/Chart.d.mts +91 -0
- package/dist/charts-react/Chart.mjs +166 -0
- package/dist/charts-react/Overlay.mjs +171 -0
- package/dist/charts-react/Picture.mjs +22 -0
- package/dist/charts-react/Reader.mjs +147 -0
- package/dist/charts-react/bucket-names.mjs +29 -0
- package/dist/charts-react/chart-unlayered.css +1 -0
- package/dist/charts-react/chart-unlayered.css.d.ts +1 -0
- package/dist/charts-react/chart.css +1 -0
- package/dist/charts-react/chart.css.d.ts +1 -0
- package/dist/charts-react/events.mjs +72 -0
- package/dist/charts-react/exact-sum.mjs +24 -0
- package/dist/charts-react/from-answer.mjs +185 -0
- package/dist/charts-react/index.d.mts +3 -0
- package/dist/charts-react/index.mjs +4 -0
- package/dist/charts-react/keys.mjs +117 -0
- package/dist/charts-react/opens.mjs +28 -0
- package/dist/charts-react/plan-bars.mjs +95 -0
- package/dist/charts-react/plan-funnel.mjs +120 -0
- package/dist/charts-react/plan-grid.mjs +121 -0
- package/dist/charts-react/plan-parts.d.mts +2 -0
- package/dist/charts-react/plan-parts.mjs +30 -0
- package/dist/charts-react/plan-time.mjs +84 -0
- package/dist/charts-react/plan.d.mts +3 -0
- package/dist/charts-react/plan.mjs +37 -0
- package/dist/charts-react/point-keys.mjs +22 -0
- package/dist/charts-react/pointer.mjs +99 -0
- package/dist/charts-react/reader-page.d.mts +8 -0
- package/dist/charts-react/reader-page.mjs +116 -0
- package/dist/charts-react/tiles.d.mts +24 -0
- package/dist/charts-react/tiles.mjs +142 -0
- package/dist/charts-react/tip-place.mjs +107 -0
- package/dist/charts-react/tip-room.mjs +31 -0
- package/dist/charts-react/useClientLayoutEffect.mjs +8 -0
- package/dist/charts-react/useScene.mjs +76 -0
- package/dist/charts-react/useSize.mjs +44 -0
- package/dist/charts-react/useStop.mjs +68 -0
- package/dist/core/conformance/memory/aggregate.mjs +2 -1
- package/dist/core/conformance/memory/rows.mjs +1 -1
- package/dist/core/conformance/memory/source.mjs +3 -2
- package/dist/core/document/display-comparisons.mjs +49 -0
- package/dist/core/document/display-entries.mjs +2 -1
- package/dist/core/document/display-validation.d.mts +12 -0
- package/dist/core/document/display-validation.mjs +56 -0
- package/dist/core/document/display.d.mts +27 -12
- package/dist/core/document/display.mjs +40 -49
- package/dist/core/document/view-layout.mjs +16 -0
- package/dist/core/engine/access.mjs +4 -2
- package/dist/core/engine/context.mjs +5 -7
- package/dist/core/engine/custom/cells.mjs +1 -1
- package/dist/core/engine/custom/records.mjs +2 -1
- package/dist/core/engine/dialect.d.mts +2 -0
- package/dist/core/engine/index.mjs +1 -1
- package/dist/core/engine/levels.mjs +33 -1
- package/dist/core/engine/plan.d.mts +2 -0
- package/dist/core/engine/postgres.mjs +1 -0
- package/dist/core/engine/rank.mjs +1 -1
- package/dist/core/engine/reader.d.mts +4 -0
- package/dist/core/engine/sql-partition.mjs +45 -0
- package/dist/core/engine/sql-reads.mjs +4 -1
- package/dist/core/engine/statement.mjs +4 -4
- package/dist/core/engine/version.d.mts +1 -1
- package/dist/core/engine/version.mjs +1 -1
- package/dist/core/error/codes.d.mts +1 -1
- package/dist/core/error/codes.mjs +1 -1
- package/dist/core/exact/decimal.d.mts +1 -4
- package/dist/core/exact/decimal.mjs +1 -14
- package/dist/core/exact/text.d.mts +5 -0
- package/dist/core/exact/text.mjs +19 -0
- package/dist/core/index.d.mts +9 -6
- package/dist/core/index.mjs +11 -8
- package/dist/core/model/types.d.mts +2 -0
- package/dist/core/model/validate/fields.mjs +1 -1
- package/dist/core/model/validate/known-members.mjs +2 -0
- package/dist/core/model/validate/shape.mjs +5 -1
- package/dist/core/oracle/visibility.mjs +2 -2
- package/dist/core/policy/bind.mjs +29 -1
- package/dist/core/query/drill/compose.d.mts +2 -0
- package/dist/core/query/drill/compose.mjs +1 -1
- package/dist/core/query/drill/synthetic.mjs +2 -1
- package/dist/core/query/drill/types.d.mts +7 -0
- package/dist/core/query/drill/types.mjs +3 -1
- package/dist/core/result/number.mjs +2 -1
- package/dist/core/result/time-axis.mjs +2 -1
- package/dist/core/schema/answers.d.mts +1176 -362
- package/dist/core/schema/commands.mjs +2 -1
- package/dist/core/schema/document.mjs +27 -2
- package/dist/core/schema/drill-answers.mjs +19 -1
- package/dist/core/schema/drill.d.mts +21 -6
- package/dist/core/schema/drill.mjs +7 -1
- package/dist/core/schema/index.d.mts +2 -1
- package/dist/core/schema/index.mjs +2 -1
- package/dist/core/schema/null-ops.d.mts +6 -0
- package/dist/core/schema/null-ops.mjs +18 -0
- package/dist/core/schema/query.mjs +30 -4
- package/dist/core/schema/tools.mjs +13 -0
- package/dist/core/schema/union-error.mjs +38 -0
- package/dist/core/time/bucket.mjs +2 -1
- package/dist/core/time/index.d.mts +3 -2
- package/dist/core/time/instant.d.mts +1 -2
- package/dist/core/time/instant.mjs +2 -30
- package/dist/core/time/range.mjs +2 -1
- package/dist/core/time/stored.mjs +2 -1
- package/dist/core/time/text-time.d.mts +10 -0
- package/dist/core/time/text-time.mjs +80 -0
- package/dist/core/types/api.d.mts +1 -1
- package/dist/core/types/api.mjs +1 -1
- package/dist/core/types/drill-api.d.mts +22 -2
- package/dist/dashboard-documents.d.mts +8 -0
- package/dist/dashboard-documents.mjs +52 -0
- package/dist/drill-access.mjs +40 -3
- package/dist/drill-comparison.mjs +71 -0
- package/dist/drill-crumbs.mjs +21 -2
- package/dist/drill-group-seal.mjs +13 -0
- package/dist/drill-open.mjs +7 -1
- package/dist/drill-seal.mjs +4 -6
- package/dist/drill-views.mjs +5 -13
- package/dist/drill.mjs +28 -58
- package/dist/editing.mjs +1 -1
- package/dist/endpoints/drill.mjs +2 -3
- package/dist/endpoints/index.d.mts +20 -0
- package/dist/index.d.mts +2 -1
- package/dist/index.mjs +6 -27
- package/dist/llms.txt +1 -1
- package/dist/react/Cell.mjs +2 -2
- package/dist/react/DashboardList.mjs +3 -3
- package/dist/react/Editing.mjs +3 -3
- package/dist/react/Header.mjs +2 -2
- package/dist/react/History.mjs +3 -3
- package/dist/react/Parts.mjs +2 -2
- package/dist/react/RowBody.d.mts +2 -4
- package/dist/react/RowBody.mjs +14 -39
- package/dist/react/Tile.mjs +4 -5
- package/dist/react/builder/FilterEditor.mjs +2 -2
- package/dist/react/builder/Picker.mjs +3 -3
- package/dist/react/builder/RangeEditor.mjs +3 -3
- package/dist/react/builder/Time.mjs +3 -3
- package/dist/react/builder/Values.mjs +2 -2
- package/dist/react/builder/WidgetBuilder.mjs +2 -2
- package/dist/react/digits.mjs +1 -1
- package/dist/react/drill/Bars.mjs +34 -38
- package/dist/react/drill/Comparison.mjs +204 -0
- package/dist/react/drill/Controls.mjs +8 -12
- package/dist/react/drill/DrillDrawer.mjs +42 -0
- package/dist/react/drill/DrillPanel.mjs +61 -41
- package/dist/react/drill/Header.mjs +65 -35
- package/dist/react/drill/ItemLink.mjs +40 -0
- package/dist/react/drill/Items.d.mts +2 -1
- package/dist/react/drill/Items.mjs +126 -99
- package/dist/react/drill/ItemsBody.mjs +38 -0
- package/dist/react/drill/ItemsFoot.mjs +24 -19
- package/dist/react/drill/Notes.mjs +23 -13
- package/dist/react/drill/PanelBody.mjs +7 -25
- package/dist/react/drill/RecordRow.mjs +47 -0
- package/dist/react/drill/Trend.mjs +186 -0
- package/dist/react/drill/board.mjs +21 -11
- package/dist/react/drill/drawer-context.mjs +5 -0
- package/dist/react/drill/item-parts.mjs +53 -35
- package/dist/react/drill/item-type.d.mts +2 -2
- package/dist/react/drill/lazy.d.mts +1 -4
- package/dist/react/drill/lazy.mjs +29 -11
- package/dist/react/drill/panel-focus.mjs +18 -7
- package/dist/react/drill/props.d.mts +7 -1
- package/dist/react/drill/props.mjs +39 -8
- package/dist/react/drill/record-page.mjs +61 -0
- package/dist/react/drill/state.mjs +17 -2
- package/dist/react/drill/trend-touch.mjs +33 -0
- package/dist/react/drill/useDrill.d.mts +3 -3
- package/dist/react/drill/useDrill.mjs +35 -15
- package/dist/react/drill/words.d.mts +14 -0
- package/dist/react/drill/words.mjs +20 -8
- package/dist/react/english.d.mts +4 -1
- package/dist/react/english.mjs +17 -2
- package/dist/react/filters/chip.mjs +2 -2
- package/dist/react/filters/menu-search.mjs +5 -5
- package/dist/react/filters/menu.mjs +2 -2
- package/dist/react/filters/number.mjs +2 -2
- package/dist/react/filters/operator.mjs +2 -2
- package/dist/react/filters/phone.mjs +2 -2
- package/dist/react/filters/values.mjs +4 -4
- package/dist/react/format-time.d.mts +2 -1
- package/dist/react/format-time.mjs +42 -34
- package/dist/react/format.mjs +15 -3
- package/dist/react/index.d.mts +4 -3
- package/dist/react/index.mjs +4 -3
- package/dist/react/messages.d.mts +23 -2
- package/dist/react/renderers/entries.d.mts +11 -0
- package/dist/react/renderers/list.mjs +8 -10
- package/dist/react/renderers/table-cells.mjs +38 -9
- package/dist/react/renderers/table-measure.mjs +2 -0
- package/dist/react/renderers/table-row.mjs +64 -7
- package/dist/react/renderers/table-sort.mjs +2 -8
- package/dist/react/renderers/table.mjs +16 -15
- package/dist/react/series.mjs +8 -3
- package/dist/react/theme-unlayered.css +1 -3144
- package/dist/react/theme.css +1 -3146
- package/dist/recharts/parts.mjs +1 -1
- package/dist/skills/derive-dashboards/SKILL.md +10 -5
- package/dist/store/apply.mjs +2 -2
- package/dist/store/editor.mjs +2 -2
- package/dist/store/writer.mjs +2 -2
- package/package.json +27 -2
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { betterWay } from "./data/format.mjs";
|
|
2
|
+
import { BAD, GOOD, INK, MUTED, OTHER, RULE, SURFACE } from "./scene/paint.mjs";
|
|
3
|
+
// src/theme.ts
|
|
4
|
+
/** The palette's colours, `--dd-series-1` to `--dd-series-6`. */
|
|
5
|
+
const PALETTE = 6;
|
|
6
|
+
/**
|
|
7
|
+
* How a text is set by the job it does, in every kind: a name is plain ink, the value beside
|
|
8
|
+
* it carries the weight since the number is what is read, and an axis's numbers and a note are
|
|
9
|
+
* small and grey; then the three lines of a header. Each holds the font a text is measured in
|
|
10
|
+
* (its size in pixels, its weight) and the colour it is drawn in. This is the one owner of a
|
|
11
|
+
* text's size.
|
|
12
|
+
*/
|
|
13
|
+
const TEXT = {
|
|
14
|
+
name: {
|
|
15
|
+
size: 12,
|
|
16
|
+
weight: 500,
|
|
17
|
+
fill: INK
|
|
18
|
+
},
|
|
19
|
+
value: {
|
|
20
|
+
size: 12,
|
|
21
|
+
weight: 600,
|
|
22
|
+
fill: INK
|
|
23
|
+
},
|
|
24
|
+
tick: {
|
|
25
|
+
size: 11,
|
|
26
|
+
weight: 500,
|
|
27
|
+
fill: MUTED
|
|
28
|
+
},
|
|
29
|
+
title: {
|
|
30
|
+
size: 15,
|
|
31
|
+
weight: 600,
|
|
32
|
+
fill: INK
|
|
33
|
+
},
|
|
34
|
+
subtitle: {
|
|
35
|
+
size: 12.5,
|
|
36
|
+
fill: MUTED
|
|
37
|
+
},
|
|
38
|
+
source: {
|
|
39
|
+
size: 11,
|
|
40
|
+
fill: MUTED
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* The room one line of a text takes, its air included, so text is stacked the same way in
|
|
45
|
+
* every place: a header's two lines, a row of names (a legend's), two labels stacked at a
|
|
46
|
+
* line's end, and a line of the small grey text (a note, an axis's numbers, a source). Each
|
|
47
|
+
* follows its text's size.
|
|
48
|
+
*/
|
|
49
|
+
const LINE = {
|
|
50
|
+
title: TEXT.title.size + 5,
|
|
51
|
+
subtitle: TEXT.subtitle.size + 5.5,
|
|
52
|
+
name: TEXT.name.size + 6,
|
|
53
|
+
pair: TEXT.name.size + 3,
|
|
54
|
+
tick: TEXT.tick.size + 3,
|
|
55
|
+
source: TEXT.source.size + 3
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* The few numbers the look is made of, so every kind draws the same bar, line and dot: a bar's
|
|
59
|
+
* corner at its data end; a line's width, and a context line's; the hair of surface that
|
|
60
|
+
* parts two marks that touch (segments of a stack, bins, cells), and the least a mark with a
|
|
61
|
+
* value is drawn at (a column's height, a cell's side), so a value is never drawn as nothing; the surface ring that parts a
|
|
62
|
+
* dot from what is under it, and a hollow dot's own stroke; how strong the zero line is; how
|
|
63
|
+
* faint a mark that is not the point is drawn (a period still running, a comparison), and how
|
|
64
|
+
* strong a partial fill and a background wash are; and the dashes: of a line the data is read against, of a
|
|
65
|
+
* marked moment (finer, since it marks a time and not a value), of the comparison period's
|
|
66
|
+
* line, and of a step into or out of a period that is not whole.
|
|
67
|
+
*/
|
|
68
|
+
const MARK = {
|
|
69
|
+
round: 3,
|
|
70
|
+
line: 2,
|
|
71
|
+
context: 1.5,
|
|
72
|
+
hair: 1,
|
|
73
|
+
least: .5,
|
|
74
|
+
ring: 1.5,
|
|
75
|
+
hollow: 2,
|
|
76
|
+
zero: .4,
|
|
77
|
+
faint: .88,
|
|
78
|
+
areaFill: .85,
|
|
79
|
+
partialFill: .55,
|
|
80
|
+
wash: .2,
|
|
81
|
+
dash: "4 4",
|
|
82
|
+
moment: "2 3",
|
|
83
|
+
before: "2 4",
|
|
84
|
+
step: "1 5"
|
|
85
|
+
};
|
|
86
|
+
/** A bar's corners, clockwise from the top left: rounded at its data end, square where it stands. */
|
|
87
|
+
function roundedEnd(end) {
|
|
88
|
+
const r = MARK.round;
|
|
89
|
+
if (end === "up") return [
|
|
90
|
+
r,
|
|
91
|
+
r,
|
|
92
|
+
0,
|
|
93
|
+
0
|
|
94
|
+
];
|
|
95
|
+
if (end === "down") return [
|
|
96
|
+
0,
|
|
97
|
+
0,
|
|
98
|
+
r,
|
|
99
|
+
r
|
|
100
|
+
];
|
|
101
|
+
return end === "right" ? [
|
|
102
|
+
0,
|
|
103
|
+
r,
|
|
104
|
+
r,
|
|
105
|
+
0
|
|
106
|
+
] : [
|
|
107
|
+
r,
|
|
108
|
+
0,
|
|
109
|
+
0,
|
|
110
|
+
r
|
|
111
|
+
];
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* The room kept between things, in pixels: two labels along an axis; the names and the marks
|
|
115
|
+
* beside them; a bar's end and its number; a plot and the labels under it; an axis's numbers
|
|
116
|
+
* and the plot beside them.
|
|
117
|
+
*/
|
|
118
|
+
const SPACE = {
|
|
119
|
+
ticks: 12,
|
|
120
|
+
names: 12,
|
|
121
|
+
value: 7,
|
|
122
|
+
under: 9,
|
|
123
|
+
gutter: 8
|
|
124
|
+
};
|
|
125
|
+
/** A series' colour by its place in a list of colours; the quiet grey where the list has none. */
|
|
126
|
+
const paintAt = (paints, place) => paints[place] ?? "--dd-other";
|
|
127
|
+
/**
|
|
128
|
+
* The colour of a change, by the way it is written as having gone (above zero for up, below
|
|
129
|
+
* for down, zero for no change): good or bad by the way its measure says is better. A measure
|
|
130
|
+
* that says neither way is better takes `own`, the chart's own colour: no kind guesses that up
|
|
131
|
+
* is good. A change that reads as no change, in a chart that does colour good and bad, is the
|
|
132
|
+
* neutral grey. Every kind colours a change through this, with the sign it read once
|
|
133
|
+
* (`changeWritten`), so none colours what its own number shows as zero. Which way is better is
|
|
134
|
+
* `betterWay`'s to say, as it is for the words about a change.
|
|
135
|
+
*/
|
|
136
|
+
function signPaint(sign, measure, own) {
|
|
137
|
+
if (measure.better === void 0) return own;
|
|
138
|
+
const way = betterWay(sign, measure);
|
|
139
|
+
if (way === 0) return MUTED;
|
|
140
|
+
return way > 0 ? GOOD : BAD;
|
|
141
|
+
}
|
|
142
|
+
/** The palette's colour at a place. */
|
|
143
|
+
const seriesPaint = (place) => `--dd-series-${String(placeOf(place) + 1)}`;
|
|
144
|
+
/**
|
|
145
|
+
* A slot's place in the palette: whole, and from zero up, whatever number the slot is; the
|
|
146
|
+
* first place for a slot that is not a number.
|
|
147
|
+
*/
|
|
148
|
+
const placeOf = (slot) => Number.isFinite(slot) ? (Math.floor(slot) % 6 + 6) % 6 : 0;
|
|
149
|
+
/**
|
|
150
|
+
* The colour a thing brings with it, in every kind: its own colour, which a host gave it and
|
|
151
|
+
* which wins; else the quiet grey when it is Other; nothing when it is to be painted from the
|
|
152
|
+
* palette. The dashboards' other charts paint by the same rule.
|
|
153
|
+
*/
|
|
154
|
+
function ownPaint(thing) {
|
|
155
|
+
return thing.color ?? (thing.other === true ? "--dd-other" : void 0);
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Each thing's colour, in the things' order: its own, else Other's quiet grey, else the
|
|
159
|
+
* palette's at its place. With `own` (a chart whose things wear one colour unless they ask for
|
|
160
|
+
* another: ranked bars), a thing that asks for no place wears `own`, and only those with a
|
|
161
|
+
* slot take places.
|
|
162
|
+
*/
|
|
163
|
+
function paintsOf(things, own) {
|
|
164
|
+
const places = placesOf(things, own === void 0);
|
|
165
|
+
return things.map((thing, i) => {
|
|
166
|
+
const place = places.get(i);
|
|
167
|
+
return ownPaint(thing) ?? (place === void 0 ? own ?? seriesPaint(0) : seriesPaint(place));
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
/** Whether a thing is painted from the palette, and whether it holds a place there by its slot. */
|
|
171
|
+
const paletted = (thing) => thing.color === void 0 && thing.other !== true;
|
|
172
|
+
const slotted = (thing) => thing.other !== true && thing.slot !== void 0;
|
|
173
|
+
/**
|
|
174
|
+
* Each thing's place in the palette, by its place in the list. A thing takes its slot's
|
|
175
|
+
* place. Two slots a palette apart would take the same one, so the lowest slot keeps it (a
|
|
176
|
+
* value the model declares before one placed later, whatever order they are drawn in) and the
|
|
177
|
+
* other takes the first place still free, as a thing with no slot does when `all` are placed.
|
|
178
|
+
* A thing with its own colour still holds its slot's place, so no other is given the colour
|
|
179
|
+
* it would have worn. Only past the palette's six do two things share a colour. The same rule
|
|
180
|
+
* as the dashboards' own tiles, so a value wears one colour on every tile.
|
|
181
|
+
*/
|
|
182
|
+
function placesOf(things, all) {
|
|
183
|
+
const places = /* @__PURE__ */ new Map();
|
|
184
|
+
const taken = /* @__PURE__ */ new Set();
|
|
185
|
+
const take = (at, place) => {
|
|
186
|
+
places.set(at, place);
|
|
187
|
+
taken.add(place);
|
|
188
|
+
};
|
|
189
|
+
const free = () => Array.from({ length: 6 }, (_v, i) => i).find((i) => !taken.has(i));
|
|
190
|
+
const waiting = things.flatMap((s, at) => slotted(s) && s.slot !== void 0 ? [{
|
|
191
|
+
at,
|
|
192
|
+
slot: s.slot
|
|
193
|
+
}] : []).map((one) => ({
|
|
194
|
+
...one,
|
|
195
|
+
rank: Number.isNaN(one.slot) ? 0 : one.slot
|
|
196
|
+
})).toSorted((a, b) => a.rank - b.rank).filter(({ at, slot }) => {
|
|
197
|
+
if (taken.has(placeOf(slot))) return true;
|
|
198
|
+
take(at, placeOf(slot));
|
|
199
|
+
return false;
|
|
200
|
+
});
|
|
201
|
+
for (const { at, slot } of waiting) take(at, free() ?? placeOf(slot));
|
|
202
|
+
const unslotted = things.flatMap((s, at) => all && paletted(s) && s.slot === void 0 ? [at] : []);
|
|
203
|
+
for (const [n, at] of unslotted.entries()) take(at, free() ?? n);
|
|
204
|
+
return places;
|
|
205
|
+
}
|
|
206
|
+
/** The library's own themes: every token a scene names, as a colour. */
|
|
207
|
+
const THEMES = {
|
|
208
|
+
light: {
|
|
209
|
+
"--dd-surface": "#ffffff",
|
|
210
|
+
"--dd-ink": "#18181b",
|
|
211
|
+
"--dd-muted": "#626571",
|
|
212
|
+
"--dd-line": "#e4e4e7",
|
|
213
|
+
"--dd-other": "#737380",
|
|
214
|
+
"--dd-good": "#15803d",
|
|
215
|
+
"--dd-danger": "#b91c1c",
|
|
216
|
+
"--dd-series-1": "#4c6ba7",
|
|
217
|
+
"--dd-series-2": "#a3664c",
|
|
218
|
+
"--dd-series-3": "#2d5b51",
|
|
219
|
+
"--dd-series-4": "#675522",
|
|
220
|
+
"--dd-series-5": "#946379",
|
|
221
|
+
"--dd-series-6": "#6e5b86"
|
|
222
|
+
},
|
|
223
|
+
dark: {
|
|
224
|
+
"--dd-surface": "#18181b",
|
|
225
|
+
"--dd-ink": "#fafafa",
|
|
226
|
+
"--dd-muted": "#a1a1aa",
|
|
227
|
+
"--dd-line": "#27272a",
|
|
228
|
+
"--dd-other": "#93939e",
|
|
229
|
+
"--dd-good": "#4ade80",
|
|
230
|
+
"--dd-danger": "#f87171",
|
|
231
|
+
"--dd-series-1": "#91bcf5",
|
|
232
|
+
"--dd-series-2": "#d0947b",
|
|
233
|
+
"--dd-series-3": "#6ea59b",
|
|
234
|
+
"--dd-series-4": "#d9c68e",
|
|
235
|
+
"--dd-series-5": "#e8aeca",
|
|
236
|
+
"--dd-series-6": "#ae9dc9"
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
export { INK, LINE, MARK, MUTED, OTHER, PALETTE, RULE, SPACE, SURFACE, TEXT, THEMES, ownPaint, paintAt, paintsOf, roundedEnd, seriesPaint, signPaint };
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { ReaderPages } from "./reader-page.mjs";
|
|
2
|
+
import { ReactNode } from "react";
|
|
3
|
+
import { Env, HoverItem, HoverStop, Scene, TextMeasurer, Words } from "derive-dashboards/charts";
|
|
4
|
+
export type ChartProps = {
|
|
5
|
+
/** Include mark keys on the SVG, for hosts that style individual data marks. */
|
|
6
|
+
markKeys?: boolean;
|
|
7
|
+
/** Navigation text for paged reader tables. */
|
|
8
|
+
tablePages?: ReaderPages;
|
|
9
|
+
/** Shown instead of a bare picture when the data needs a larger plot. */
|
|
10
|
+
noPlot?: string;
|
|
11
|
+
/**
|
|
12
|
+
* Lays the chart out for a size: a chart kind with its data and options bound. The scene is
|
|
13
|
+
* made again only when the size or `draw` changes, so pass a stable function (`useCallback`).
|
|
14
|
+
* A server calls it too, for the chart's words: with the size given, and a usual tile's room
|
|
15
|
+
* (640 by 360) for a width or a height left to be measured.
|
|
16
|
+
*/
|
|
17
|
+
draw: (env: Env) => Scene;
|
|
18
|
+
/** The chart's height in pixels; the box's own height when left out. */
|
|
19
|
+
height?: number;
|
|
20
|
+
/**
|
|
21
|
+
* A fixed width in pixels: for tests and pictures made off screen. With `height` too, the box
|
|
22
|
+
* is not measured at all, and a server draws the picture; alone, it stands for the measured
|
|
23
|
+
* width.
|
|
24
|
+
*/
|
|
25
|
+
width?: number;
|
|
26
|
+
/** How wide a text is; a table of a system face's widths by default. */
|
|
27
|
+
measure?: TextMeasurer;
|
|
28
|
+
locale?: string;
|
|
29
|
+
words?: Words;
|
|
30
|
+
/**
|
|
31
|
+
* A value chosen, with its stop: by a click, the item nearest the pointer, among all of the
|
|
32
|
+
* stop's items; by a finger, a tap on the item it already lit (the first tap lights it and
|
|
33
|
+
* shows its tooltip); by Enter or Space, the item the keyboard chose. The arrow keys across
|
|
34
|
+
* the way the stops run move between a stop's items: up and down where the stops run across
|
|
35
|
+
* the chart (over time), left and right where they run down it (a dumbbell's two values in a
|
|
36
|
+
* row).
|
|
37
|
+
*/
|
|
38
|
+
onSelect?: (stop: HoverStop, item: HoverItem) => void;
|
|
39
|
+
/**
|
|
40
|
+
* Whether a value opens; every value does when left out. A value that does not is never
|
|
41
|
+
* selected: a click on it does nothing, Enter on it does nothing, and the hint and the pointer
|
|
42
|
+
* cursor are not shown for it.
|
|
43
|
+
*/
|
|
44
|
+
selectable?: (stop: HoverStop, item: HoverItem) => boolean;
|
|
45
|
+
/**
|
|
46
|
+
* What selecting a value does, as the tooltip says it on screen ("Click to see what is behind
|
|
47
|
+
* it"), under a stop whose value nearest the pointer, or chosen by the keyboard, opens. Shown,
|
|
48
|
+
* never spoken: a screen reader hears `spoken`. Pass it with `onSelect`.
|
|
49
|
+
*/
|
|
50
|
+
hint?: string;
|
|
51
|
+
/**
|
|
52
|
+
* What a screen reader hears for a value that opens, said in place of the value as it reads
|
|
53
|
+
* when the keyboard chooses it: a name for it that says it opens ("Open, 36. Open what is
|
|
54
|
+
* behind it."). Left out, or undefined for a value, the value is said as it reads.
|
|
55
|
+
*/
|
|
56
|
+
spoken?: (stop: HoverStop, item: HoverItem) => string | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* How to move through the chart's values that open, in the reader's words ("Points to open
|
|
59
|
+
* (arrow keys move between them)"): the chart's description for a screen reader, when some
|
|
60
|
+
* value of it opens. With nothing to open there is no instruction.
|
|
61
|
+
*/
|
|
62
|
+
instruction?: string;
|
|
63
|
+
/** The hidden table's caption; the summary names the chart, and the table has none of its own. */
|
|
64
|
+
caption?: string;
|
|
65
|
+
/**
|
|
66
|
+
* What the hidden table writes for a value a stop does not have (a gap), and what the tooltip
|
|
67
|
+
* and the live region say at a stop with no value; blank when left out.
|
|
68
|
+
*/
|
|
69
|
+
noValue?: string;
|
|
70
|
+
/** The stop lit, or undefined when none is: for a caller that links charts. */
|
|
71
|
+
onHover?: (stop: HoverStop | undefined) => void;
|
|
72
|
+
className?: string;
|
|
73
|
+
/**
|
|
74
|
+
* What is shown under the picture, inside the chart's box (a tile's note). A measured chart
|
|
75
|
+
* draws its picture in the room the note leaves; a fixed `height` is the picture's own, and
|
|
76
|
+
* the note goes under it.
|
|
77
|
+
*/
|
|
78
|
+
children?: ReactNode;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* A chart, drawn from a scene. It is one tab stop: arrow keys along the way its stops run move
|
|
82
|
+
* through them (left and right where they run across, up and down where they run down, as
|
|
83
|
+
* bars do), Home and End jump to the ends, Escape clears, the arrow keys across that way
|
|
84
|
+
* choose among a stop's values when it has more than one, and Enter or Space selects the value
|
|
85
|
+
* chosen. A finger lights a value with one tap and selects it with the next, and moves the
|
|
86
|
+
* tooltip along as it drags across. Before its box is measured it has no picture: mounted in a
|
|
87
|
+
* browser it is an empty box of its height for less than a frame; on a server, and over a
|
|
88
|
+
* server's markup, the box already holds its summary and its table. Either way the page does
|
|
89
|
+
* not jump when the picture comes. Include `chart.css` for the tooltip's look and the focus ring.
|
|
90
|
+
*/
|
|
91
|
+
export declare function Chart(props: ChartProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { useChartEvents } from "./events.mjs";
|
|
2
|
+
import { LitLayer } from "./Overlay.mjs";
|
|
3
|
+
import { offers, opensAny, spokenOf } from "./opens.mjs";
|
|
4
|
+
import { Picture } from "./Picture.mjs";
|
|
5
|
+
import { Live, SceneTable, liveText, readerStyle } from "./Reader.mjs";
|
|
6
|
+
import { useScenes } from "./useScene.mjs";
|
|
7
|
+
import { useSize } from "./useSize.mjs";
|
|
8
|
+
import { useId, useMemo, useRef } from "react";
|
|
9
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
+
// src/Chart.tsx
|
|
11
|
+
/**
|
|
12
|
+
* The stage holds the picture and the layer over it, and takes the room the box has left over
|
|
13
|
+
* what is under it. No line box under the picture: an inline SVG would sit on a text baseline,
|
|
14
|
+
* a few pixels up.
|
|
15
|
+
*/
|
|
16
|
+
const STAGE = {
|
|
17
|
+
position: "relative",
|
|
18
|
+
lineHeight: 0,
|
|
19
|
+
flex: "1 1 0",
|
|
20
|
+
minHeight: 0,
|
|
21
|
+
overflow: "clip"
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* A stage with stops to move through keeps a finger's sideways drag for itself, to move the
|
|
25
|
+
* tooltip along, and leaves the page its scroll up and down and its pinch.
|
|
26
|
+
*/
|
|
27
|
+
const SCRUBBED = {
|
|
28
|
+
...STAGE,
|
|
29
|
+
touchAction: "pan-y pinch-zoom"
|
|
30
|
+
};
|
|
31
|
+
/** The stage, of a fixed height when one is given: the picture's own, not shared with what is under it. */
|
|
32
|
+
function stageOf(height, scene) {
|
|
33
|
+
const stage = (scene?.hover?.stops.length ?? 0) > 0 ? SCRUBBED : STAGE;
|
|
34
|
+
return height === void 0 ? stage : {
|
|
35
|
+
...stage,
|
|
36
|
+
flex: "none",
|
|
37
|
+
height
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The chart's box, named as the theme names a chart (`dd-chart`): named by the summary,
|
|
42
|
+
* described by how to move through its values that open when some do, one tab stop when it has
|
|
43
|
+
* stops to move through. Its stage has its height before anything is drawn in it, so the page
|
|
44
|
+
* does not jump. It is marked drillable as the theme marks a chart (`data-drillable`: some value of it
|
|
45
|
+
* opens), and `data-opens` while the value the lit stop means opens. It is a column: the
|
|
46
|
+
* stage, then what is shown under it (a tile's note), and in a column of its own it takes the
|
|
47
|
+
* room left.
|
|
48
|
+
*/
|
|
49
|
+
function boxOf(at) {
|
|
50
|
+
const { props, described } = at;
|
|
51
|
+
const stops = at.said?.hover?.stops.length ?? 0;
|
|
52
|
+
return {
|
|
53
|
+
className: props.className === void 0 ? "dd-chart" : `dd-chart ${props.className}`,
|
|
54
|
+
"aria-label": at.said?.summary,
|
|
55
|
+
"aria-describedby": described,
|
|
56
|
+
tabIndex: stops > 0 ? 0 : void 0,
|
|
57
|
+
"data-drillable": at.drillable,
|
|
58
|
+
"data-opens": at.open,
|
|
59
|
+
style: {
|
|
60
|
+
position: "relative",
|
|
61
|
+
display: "flex",
|
|
62
|
+
flexDirection: "column",
|
|
63
|
+
flex: "1 1 auto",
|
|
64
|
+
minHeight: 0,
|
|
65
|
+
height: props.height === void 0 ? "100%" : "auto",
|
|
66
|
+
width: props.width
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Whether some value of the scene opens, and then the id of the instruction that describes the
|
|
72
|
+
* chart, when there is one; with nothing to open, nothing describes it.
|
|
73
|
+
*/
|
|
74
|
+
function useDrillable(props, scene) {
|
|
75
|
+
const { onSelect, selectable, instruction } = props;
|
|
76
|
+
const drillable = useMemo(() => opensAny({
|
|
77
|
+
onSelect,
|
|
78
|
+
selectable
|
|
79
|
+
}, scene), [
|
|
80
|
+
onSelect,
|
|
81
|
+
selectable,
|
|
82
|
+
scene
|
|
83
|
+
]);
|
|
84
|
+
const id = `${useId()}-how`;
|
|
85
|
+
return {
|
|
86
|
+
drillable,
|
|
87
|
+
described: drillable && instruction !== void 0 ? id : void 0
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* A chart, drawn from a scene. It is one tab stop: arrow keys along the way its stops run move
|
|
92
|
+
* through them (left and right where they run across, up and down where they run down, as
|
|
93
|
+
* bars do), Home and End jump to the ends, Escape clears, the arrow keys across that way
|
|
94
|
+
* choose among a stop's values when it has more than one, and Enter or Space selects the value
|
|
95
|
+
* chosen. A finger lights a value with one tap and selects it with the next, and moves the
|
|
96
|
+
* tooltip along as it drags across. Before its box is measured it has no picture: mounted in a
|
|
97
|
+
* browser it is an empty box of its height for less than a frame; on a server, and over a
|
|
98
|
+
* server's markup, the box already holds its summary and its table. Either way the page does
|
|
99
|
+
* not jump when the picture comes. Include `chart.css` for the tooltip's look and the focus ring.
|
|
100
|
+
*/
|
|
101
|
+
function Chart(props) {
|
|
102
|
+
const stage = useRef(null);
|
|
103
|
+
const size = useSize(stage, {
|
|
104
|
+
width: props.width,
|
|
105
|
+
height: props.height
|
|
106
|
+
});
|
|
107
|
+
const { scene, said } = useScenes(props, size);
|
|
108
|
+
const { lit, stop, handlers } = useChartEvents(scene, props, stage);
|
|
109
|
+
const open = offers(props, lit, stop);
|
|
110
|
+
const spoken = spokenOf(props, lit, stop);
|
|
111
|
+
const { drillable, described } = useDrillable(props, said);
|
|
112
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
113
|
+
role: "group",
|
|
114
|
+
"aria-roledescription": "chart",
|
|
115
|
+
...boxOf({
|
|
116
|
+
props,
|
|
117
|
+
said,
|
|
118
|
+
drillable,
|
|
119
|
+
open,
|
|
120
|
+
described
|
|
121
|
+
}),
|
|
122
|
+
...handlers,
|
|
123
|
+
children: [
|
|
124
|
+
/* @__PURE__ */ jsxs("div", {
|
|
125
|
+
ref: stage,
|
|
126
|
+
className: "dd-c-stage",
|
|
127
|
+
style: stageOf(props.height, scene),
|
|
128
|
+
children: [/* @__PURE__ */ jsx(Picture, {
|
|
129
|
+
scene,
|
|
130
|
+
noPlot: props.noPlot,
|
|
131
|
+
markKeys: props.markKeys !== false
|
|
132
|
+
}), scene === void 0 ? null : /* @__PURE__ */ jsx(LitLayer, {
|
|
133
|
+
scene,
|
|
134
|
+
stop,
|
|
135
|
+
pointer: lit?.at,
|
|
136
|
+
hint: open ? props.hint : void 0,
|
|
137
|
+
chosen: lit?.item,
|
|
138
|
+
noValue: props.noValue,
|
|
139
|
+
more: props.words?.more
|
|
140
|
+
})]
|
|
141
|
+
}),
|
|
142
|
+
scene?.footnote === void 0 ? null : /* @__PURE__ */ jsx("p", {
|
|
143
|
+
className: "dd-chart-note",
|
|
144
|
+
children: scene.footnote
|
|
145
|
+
}),
|
|
146
|
+
props.children,
|
|
147
|
+
said === void 0 ? null : /* @__PURE__ */ jsx(SceneTable, {
|
|
148
|
+
scene: said,
|
|
149
|
+
caption: props.caption,
|
|
150
|
+
noValue: props.noValue,
|
|
151
|
+
pages: props.tablePages
|
|
152
|
+
}),
|
|
153
|
+
/* @__PURE__ */ jsx(Live, { said: liveText(lit, stop, {
|
|
154
|
+
said: spoken,
|
|
155
|
+
noValue: props.noValue
|
|
156
|
+
}) }),
|
|
157
|
+
described === void 0 ? null : /* @__PURE__ */ jsx("div", {
|
|
158
|
+
id: described,
|
|
159
|
+
className: "dd-sr-only",
|
|
160
|
+
style: readerStyle,
|
|
161
|
+
children: props.instruction
|
|
162
|
+
})
|
|
163
|
+
]
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
export { Chart };
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { anchorOf, tipPlace } from "./tip-place.mjs";
|
|
2
|
+
import { heldOf, roomFor } from "./tip-room.mjs";
|
|
3
|
+
import { useClientLayoutEffect } from "./useClientLayoutEffect.mjs";
|
|
4
|
+
import { useMemo, useRef, useState } from "react";
|
|
5
|
+
import { ENGLISH, litNodes, paintCss, renderNodes } from "derive-dashboards/charts";
|
|
6
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
// src/Overlay.tsx
|
|
8
|
+
/**
|
|
9
|
+
* Layout the overlay cannot do without, set inline so it holds without any stylesheet. The
|
|
10
|
+
* tooltip's look (its background, border and grid) is in `chart.css`.
|
|
11
|
+
*/
|
|
12
|
+
const LAYER = {
|
|
13
|
+
position: "absolute",
|
|
14
|
+
inset: 0,
|
|
15
|
+
pointerEvents: "none"
|
|
16
|
+
};
|
|
17
|
+
const TIP = {
|
|
18
|
+
position: "absolute",
|
|
19
|
+
left: 0,
|
|
20
|
+
top: 0,
|
|
21
|
+
pointerEvents: "none"
|
|
22
|
+
};
|
|
23
|
+
/** The marks of a lit stop, in the scene's own coordinates. */
|
|
24
|
+
function LitMarks({ scene, stop }) {
|
|
25
|
+
const marks = useMemo(() => renderNodes(litNodes(scene, stop)), [scene, stop]);
|
|
26
|
+
const { width, height } = scene;
|
|
27
|
+
return /* @__PURE__ */ jsx("svg", {
|
|
28
|
+
className: "dd-c-layer",
|
|
29
|
+
"aria-hidden": "true",
|
|
30
|
+
width,
|
|
31
|
+
height,
|
|
32
|
+
viewBox: `0 0 ${String(width)} ${String(height)}`,
|
|
33
|
+
style: LAYER,
|
|
34
|
+
dangerouslySetInnerHTML: { __html: marks }
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* One value of the tooltip: its swatch, its name, its value, and what it is read against;
|
|
39
|
+
* marked when it is the value the keyboard chose.
|
|
40
|
+
*/
|
|
41
|
+
function Row({ item, chosen }) {
|
|
42
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
43
|
+
className: "dd-c-tip-row",
|
|
44
|
+
"data-chosen": chosen ? "" : void 0,
|
|
45
|
+
children: [
|
|
46
|
+
/* @__PURE__ */ jsx("span", {
|
|
47
|
+
className: "dd-c-swatch",
|
|
48
|
+
style: { background: paintCss(item.color) }
|
|
49
|
+
}),
|
|
50
|
+
/* @__PURE__ */ jsx("span", {
|
|
51
|
+
className: "dd-c-tip-label",
|
|
52
|
+
children: item.label
|
|
53
|
+
}),
|
|
54
|
+
/* @__PURE__ */ jsx("span", {
|
|
55
|
+
className: "dd-c-tip-value",
|
|
56
|
+
children: item.value
|
|
57
|
+
}),
|
|
58
|
+
item.aside === void 0 ? null : /* @__PURE__ */ jsx("span", {
|
|
59
|
+
className: "dd-c-tip-aside",
|
|
60
|
+
children: item.aside
|
|
61
|
+
})
|
|
62
|
+
]
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* The stop's values a tooltip holds: all of them, or in a box too short for all, a run of
|
|
67
|
+
* `rows` of them with the chosen one among them, and under it how many are left out.
|
|
68
|
+
*/
|
|
69
|
+
function Values(at) {
|
|
70
|
+
const { stop, chosen, more = ENGLISH.more } = at;
|
|
71
|
+
const { from, to } = heldOf(stop.items.length, at.rows, chosen);
|
|
72
|
+
const left = stop.items.length - (to - from);
|
|
73
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [stop.items.slice(from, to).map((item, i) => /* @__PURE__ */ jsx(Row, {
|
|
74
|
+
item,
|
|
75
|
+
chosen: stop.items.length > 1 && from + i === chosen
|
|
76
|
+
}, item.key)), left === 0 ? null : /* @__PURE__ */ jsx("div", {
|
|
77
|
+
className: "dd-c-tip-more",
|
|
78
|
+
children: more(left)
|
|
79
|
+
})] });
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* The tooltip. It is placed once it is drawn, when its own size is known: beside the stop,
|
|
83
|
+
* flipped to the left near the right edge, or for a ranked bar beside the pointer past every
|
|
84
|
+
* row's reach, else over its row; always inside the chart's box. A box too short for all of a
|
|
85
|
+
* stop's values holds as many as it has room for, the chosen one among them, and counts the
|
|
86
|
+
* rest (`tip-room.ts`). A stop with no value says `noValue` under its title. Hidden from
|
|
87
|
+
* screen readers, which hear the stop from the chart's live region instead.
|
|
88
|
+
*/
|
|
89
|
+
function Tip({ scene, stop, pointer, hint, chosen, noValue, more }) {
|
|
90
|
+
const ref = useRef(null);
|
|
91
|
+
const [room, setRoom] = useState();
|
|
92
|
+
const rows = room?.stop === stop ? room.rows : stop.items.length;
|
|
93
|
+
useClientLayoutEffect(() => {
|
|
94
|
+
const tip = ref.current;
|
|
95
|
+
const { hover, width, height } = scene;
|
|
96
|
+
if (tip === null || hover === void 0) return;
|
|
97
|
+
const fits = roomFor(tip, height);
|
|
98
|
+
if (fits !== void 0) {
|
|
99
|
+
setRoom({
|
|
100
|
+
stop,
|
|
101
|
+
rows: fits
|
|
102
|
+
});
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
tip.style.pointerEvents = tip.scrollHeight > tip.clientHeight ? "auto" : "none";
|
|
106
|
+
const place = tipPlace(anchorOf(hover, stop, pointer), {
|
|
107
|
+
width: tip.offsetWidth,
|
|
108
|
+
height: tip.offsetHeight
|
|
109
|
+
}, {
|
|
110
|
+
width,
|
|
111
|
+
height
|
|
112
|
+
});
|
|
113
|
+
tip.style.transform = `translate(${String(Math.round(place.left))}px, ${String(Math.round(place.top))}px)`;
|
|
114
|
+
}, [
|
|
115
|
+
scene,
|
|
116
|
+
stop,
|
|
117
|
+
pointer,
|
|
118
|
+
hint,
|
|
119
|
+
chosen,
|
|
120
|
+
noValue,
|
|
121
|
+
rows
|
|
122
|
+
]);
|
|
123
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
124
|
+
ref,
|
|
125
|
+
className: "dd-c-tip",
|
|
126
|
+
"data-single": stop.items.length === 1 || void 0,
|
|
127
|
+
"aria-hidden": "true",
|
|
128
|
+
style: TIP,
|
|
129
|
+
children: [
|
|
130
|
+
/* @__PURE__ */ jsxs("div", {
|
|
131
|
+
className: "dd-c-tip-title",
|
|
132
|
+
children: [stop.title, stop.note === void 0 ? null : /* @__PURE__ */ jsx("span", {
|
|
133
|
+
className: "dd-c-tip-note",
|
|
134
|
+
children: stop.note
|
|
135
|
+
})]
|
|
136
|
+
}),
|
|
137
|
+
/* @__PURE__ */ jsx(Values, {
|
|
138
|
+
stop,
|
|
139
|
+
chosen,
|
|
140
|
+
more,
|
|
141
|
+
rows
|
|
142
|
+
}),
|
|
143
|
+
stop.items.length > 0 || noValue === void 0 ? null : /* @__PURE__ */ jsx("div", {
|
|
144
|
+
className: "dd-c-tip-empty",
|
|
145
|
+
children: noValue
|
|
146
|
+
}),
|
|
147
|
+
hint === void 0 || stop.items.length === 0 ? null : /* @__PURE__ */ jsx("div", {
|
|
148
|
+
className: "dd-c-tip-hint",
|
|
149
|
+
children: hint
|
|
150
|
+
})
|
|
151
|
+
]
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
/** The lit stop's marks and tooltip, over the picture: a tooltip's own props, with no stop when none is lit. */
|
|
155
|
+
function LitLayer(at) {
|
|
156
|
+
const { scene, stop } = at;
|
|
157
|
+
if (scene.hover === void 0 || stop === void 0) return null;
|
|
158
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(LitMarks, {
|
|
159
|
+
scene,
|
|
160
|
+
stop
|
|
161
|
+
}), /* @__PURE__ */ jsx(Tip, {
|
|
162
|
+
scene,
|
|
163
|
+
stop,
|
|
164
|
+
pointer: at.pointer,
|
|
165
|
+
hint: at.hint,
|
|
166
|
+
chosen: at.chosen,
|
|
167
|
+
noValue: at.noValue,
|
|
168
|
+
more: at.more
|
|
169
|
+
})] });
|
|
170
|
+
}
|
|
171
|
+
export { LitLayer, Tip };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { usePicture } from "./useScene.mjs";
|
|
2
|
+
import { memo } from "react";
|
|
3
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
// src/Picture.tsx
|
|
5
|
+
/** The SVG is stable while the pointer moves. The overlay is its sibling. */
|
|
6
|
+
const Picture = memo(function Picture({ scene, noPlot, markKeys }) {
|
|
7
|
+
const svg = usePicture(scene, markKeys);
|
|
8
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("div", {
|
|
9
|
+
className: "dd-chart-picture",
|
|
10
|
+
"aria-hidden": "true",
|
|
11
|
+
dangerouslySetInnerHTML: { __html: svg }
|
|
12
|
+
}), noPlot !== void 0 && scene?.nodes.length === 0 ? /* @__PURE__ */ jsx("span", {
|
|
13
|
+
className: "dd-tile-state",
|
|
14
|
+
style: {
|
|
15
|
+
position: "absolute",
|
|
16
|
+
inset: 0,
|
|
17
|
+
lineHeight: "normal"
|
|
18
|
+
},
|
|
19
|
+
children: noPlot
|
|
20
|
+
}) : null] });
|
|
21
|
+
});
|
|
22
|
+
export { Picture };
|