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,154 @@
|
|
|
1
|
+
import { spaced } from "../text/measure.mjs";
|
|
2
|
+
import { SPACE, TEXT } from "../theme.mjs";
|
|
3
|
+
import { dateWriter, partsOf, tickText } from "./calendar.mjs";
|
|
4
|
+
// src/scale/time-ticks.ts
|
|
5
|
+
const every = () => true;
|
|
6
|
+
const dayStart = (p) => p.hour === 0;
|
|
7
|
+
const monthStart = (p, b) => dayStart(p, b) && (p.day === 1 || b !== void 0 && (b.month !== p.month || b.year !== p.year));
|
|
8
|
+
const monthIn = (step) => (p, b) => monthStart(p, b) && (p.month - 1) % step === 0;
|
|
9
|
+
const yearStart = (p, b) => monthStart(p, b) && p.month === 1 || b !== void 0 && b.year !== p.year;
|
|
10
|
+
const yearIn = (step) => (p, b) => yearStart(p, b) && p.year % step === 0;
|
|
11
|
+
const hourIn = (step) => (p) => p.hour % step === 0;
|
|
12
|
+
const monday = (p, b) => dayStart(p, b) && p.weekday === 1;
|
|
13
|
+
const YEARS = [
|
|
14
|
+
1,
|
|
15
|
+
2,
|
|
16
|
+
5,
|
|
17
|
+
10,
|
|
18
|
+
20,
|
|
19
|
+
50,
|
|
20
|
+
100
|
|
21
|
+
].map((step) => ({
|
|
22
|
+
kind: "year",
|
|
23
|
+
pick: yearIn(step)
|
|
24
|
+
}));
|
|
25
|
+
const MONTHS = [
|
|
26
|
+
1,
|
|
27
|
+
3,
|
|
28
|
+
6
|
|
29
|
+
].map((step) => ({
|
|
30
|
+
kind: "month",
|
|
31
|
+
pick: monthIn(step)
|
|
32
|
+
}));
|
|
33
|
+
/** Each grain's levels, finest first. */
|
|
34
|
+
const LEVELS = {
|
|
35
|
+
hour: [
|
|
36
|
+
{
|
|
37
|
+
kind: "hour",
|
|
38
|
+
pick: every
|
|
39
|
+
},
|
|
40
|
+
...[
|
|
41
|
+
3,
|
|
42
|
+
6,
|
|
43
|
+
12
|
|
44
|
+
].map((step) => ({
|
|
45
|
+
kind: "hour",
|
|
46
|
+
pick: hourIn(step)
|
|
47
|
+
})),
|
|
48
|
+
{
|
|
49
|
+
kind: "day",
|
|
50
|
+
pick: dayStart
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
kind: "day",
|
|
54
|
+
pick: monday
|
|
55
|
+
},
|
|
56
|
+
...MONTHS,
|
|
57
|
+
...YEARS
|
|
58
|
+
],
|
|
59
|
+
day: [
|
|
60
|
+
{
|
|
61
|
+
kind: "day",
|
|
62
|
+
pick: every
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
kind: "day",
|
|
66
|
+
pick: monday
|
|
67
|
+
},
|
|
68
|
+
...MONTHS,
|
|
69
|
+
...YEARS
|
|
70
|
+
],
|
|
71
|
+
week: [
|
|
72
|
+
{
|
|
73
|
+
kind: "day",
|
|
74
|
+
pick: every
|
|
75
|
+
},
|
|
76
|
+
...MONTHS,
|
|
77
|
+
...YEARS
|
|
78
|
+
],
|
|
79
|
+
month: [...MONTHS, ...YEARS],
|
|
80
|
+
quarter: [{
|
|
81
|
+
kind: "month",
|
|
82
|
+
pick: every
|
|
83
|
+
}, ...YEARS],
|
|
84
|
+
year: YEARS
|
|
85
|
+
};
|
|
86
|
+
/** The least room a tick takes: labels are never packed tighter. */
|
|
87
|
+
const PER_TICK = 56;
|
|
88
|
+
/** The ticks a time axis draws: the finest level that fits, else its first and last bucket. */
|
|
89
|
+
function timeTicks(x, room) {
|
|
90
|
+
const parts = partsOf(x);
|
|
91
|
+
const write = dateWriter(room.locale);
|
|
92
|
+
const most = Math.max(2, Math.floor((room.max - room.min) / PER_TICK));
|
|
93
|
+
for (const level of LEVELS[x.grain]) {
|
|
94
|
+
const picked = parts.flatMap((p, i) => level.pick(p, parts[i - 1]) ? [i] : []);
|
|
95
|
+
if (picked.length < 2 || picked.length > most) continue;
|
|
96
|
+
const ticks = labelled(picked, parts, {
|
|
97
|
+
kind: level.kind,
|
|
98
|
+
room,
|
|
99
|
+
write
|
|
100
|
+
});
|
|
101
|
+
if (fits(ticks, room)) return ticks;
|
|
102
|
+
}
|
|
103
|
+
return ends(parts, {
|
|
104
|
+
kind: LEVELS[x.grain][0]?.kind ?? "day",
|
|
105
|
+
room,
|
|
106
|
+
write
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
/** The ticks of some buckets, each named as shortly as the tick before it allows. */
|
|
110
|
+
function labelled(picked, parts, how) {
|
|
111
|
+
const { kind, room } = how;
|
|
112
|
+
return picked.flatMap((index, at) => {
|
|
113
|
+
const own = parts[index];
|
|
114
|
+
if (own === void 0) return [];
|
|
115
|
+
const before = parts[picked[at - 1] ?? -1];
|
|
116
|
+
const text = tickText(kind, {
|
|
117
|
+
parts: own,
|
|
118
|
+
...before === void 0 ? {} : { before }
|
|
119
|
+
}, how.write);
|
|
120
|
+
return [{
|
|
121
|
+
index,
|
|
122
|
+
text,
|
|
123
|
+
x: held(room.center(index), text, room)
|
|
124
|
+
}];
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
/** A label's middle, moved so the whole label stays inside the room. */
|
|
128
|
+
function held(center, text, room) {
|
|
129
|
+
const half = room.measure(text, TEXT.tick) / 2;
|
|
130
|
+
return Math.min(Math.max(center, room.min + half), room.max - half);
|
|
131
|
+
}
|
|
132
|
+
/** Whether every label clears the one before it. */
|
|
133
|
+
function fits(ticks, room) {
|
|
134
|
+
return spaced(ticks.map((tick) => ({
|
|
135
|
+
x: tick.x,
|
|
136
|
+
width: room.measure(tick.text, TEXT.tick)
|
|
137
|
+
})), SPACE.ticks);
|
|
138
|
+
}
|
|
139
|
+
/** The first and last bucket, or the first alone when the two would touch. */
|
|
140
|
+
function ends(parts, how) {
|
|
141
|
+
if (parts.length === 0) return [];
|
|
142
|
+
const both = labelled(parts.length > 1 ? [0, parts.length - 1] : [0], parts, how);
|
|
143
|
+
return fits(both, how.room) ? both : both.slice(0, 1);
|
|
144
|
+
}
|
|
145
|
+
/** The first and last bucket of a time axis, named as its ticks would be, or the first alone when the two would touch. */
|
|
146
|
+
function endTicks(x, room) {
|
|
147
|
+
const parts = partsOf(x);
|
|
148
|
+
return ends(parts, {
|
|
149
|
+
kind: parts[0]?.year !== parts.at(-1)?.year ? "year" : LEVELS[x.grain][0]?.kind ?? "day",
|
|
150
|
+
room,
|
|
151
|
+
write: dateWriter(room.locale)
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
export { endTicks, timeTicks };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { least } from "../data/range.mjs";
|
|
2
|
+
// src/scale/time.ts
|
|
3
|
+
const middle = (b) => (b.from + b.to) / 2;
|
|
4
|
+
/**
|
|
5
|
+
* The scale for some buckets over a pixel range. With `bands`, the range runs from the first
|
|
6
|
+
* bucket's start to the last one's end, so every bar is whole; without, from the first middle
|
|
7
|
+
* to the last, so a line touches both edges.
|
|
8
|
+
*/
|
|
9
|
+
function timeScale(x, range, bands) {
|
|
10
|
+
const first = x.buckets[0];
|
|
11
|
+
const last = x.buckets.at(-1);
|
|
12
|
+
if (first === void 0 || last === void 0) return flat(range);
|
|
13
|
+
const start = bands ? first.from : middle(first);
|
|
14
|
+
const end = bands ? last.to : middle(last);
|
|
15
|
+
if (end <= start) return flat(range);
|
|
16
|
+
const perMs = (range.to - range.from) / (end - start);
|
|
17
|
+
const at = (ms) => range.from + (ms - start) * perMs;
|
|
18
|
+
return {
|
|
19
|
+
at,
|
|
20
|
+
band: least(x.buckets.map((b) => b.to - b.from)) * perMs,
|
|
21
|
+
center: (i) => at(middle(x.buckets[i] ?? first))
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/** One bucket, or none: everything sits in the middle of the range. */
|
|
25
|
+
function flat(range) {
|
|
26
|
+
const mid = (range.from + range.to) / 2;
|
|
27
|
+
return {
|
|
28
|
+
at: () => mid,
|
|
29
|
+
band: range.to - range.from,
|
|
30
|
+
center: () => mid
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export { timeScale };
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { fractionAlong, least, most } from "../data/range.mjs";
|
|
2
|
+
import { tickStep } from "d3-array";
|
|
3
|
+
import { scaleLinear } from "d3-scale";
|
|
4
|
+
// src/scale/value.ts
|
|
5
|
+
/** A plot this tall has room for about this many ticks: one every 44 pixels, from 2 to 6. */
|
|
6
|
+
const tickCount = (height) => Math.max(2, Math.min(6, Math.floor(height / 44)));
|
|
7
|
+
/** An axis this long along the bottom has room for about this many: one every 90 pixels, from 2 to 8. */
|
|
8
|
+
const ticksAcross = (width) => Math.max(2, Math.min(8, Math.floor(width / 90)));
|
|
9
|
+
/** The axis for some values: its ends on round numbers past the data, and its ticks. */
|
|
10
|
+
function valueAxis(values, rule) {
|
|
11
|
+
const [low, high] = spanOf(values, rule.zero);
|
|
12
|
+
if (!Number.isFinite(high - low)) return {
|
|
13
|
+
min: low,
|
|
14
|
+
max: high,
|
|
15
|
+
ticks: [
|
|
16
|
+
low,
|
|
17
|
+
0,
|
|
18
|
+
high
|
|
19
|
+
]
|
|
20
|
+
};
|
|
21
|
+
if (rule.reads?.whole === true && tickStep(low, high, rule.count) < 1) return wholeAxis(low, high, rule.count);
|
|
22
|
+
return roundAxis(low, high, rule.count);
|
|
23
|
+
}
|
|
24
|
+
/** Whether a span has zero in it: the rule kept it, or the values lie on both sides. */
|
|
25
|
+
const holdsZero = (low, high) => low <= 0 && high >= 0;
|
|
26
|
+
/**
|
|
27
|
+
* Whether rounded ends stretch a span too far: to more than twice its length, which would
|
|
28
|
+
* flatten the values into half the plot; or, for a span that left zero out, back to zero or
|
|
29
|
+
* across it, which would undo the rule that left it out.
|
|
30
|
+
*/
|
|
31
|
+
const stretched = (ends, low, high) => ends.max - ends.min > 2 * (high - low) || !holdsZero(low, high) && holdsZero(ends.min, ends.max);
|
|
32
|
+
/**
|
|
33
|
+
* The axis on round numbers with no more ticks than the plot has room for. D3 picks the round
|
|
34
|
+
* step nearest the count asked for, which can be nearly twice as many; so fewer are asked for
|
|
35
|
+
* until what comes back fits. When even one step is too many, the axis is its two round ends;
|
|
36
|
+
* when round ends would stretch the span too far, it keeps the values' own ends.
|
|
37
|
+
*/
|
|
38
|
+
function roundAxis(low, high, count) {
|
|
39
|
+
for (let ask = count; ask >= 1; ask--) {
|
|
40
|
+
const scale = scaleLinear().domain([low, high]).nice(ask);
|
|
41
|
+
const [from = low, to = high] = scale.domain();
|
|
42
|
+
const ends = {
|
|
43
|
+
min: Math.min(from, low),
|
|
44
|
+
max: Math.max(to, high)
|
|
45
|
+
};
|
|
46
|
+
const ticks = scale.ticks(ask);
|
|
47
|
+
if (ticks.length >= 2 && ticks.length <= count + 1 && Number.isFinite(ends.min) && Number.isFinite(ends.max) && !stretched(ends, low, high)) return {
|
|
48
|
+
...ends,
|
|
49
|
+
ticks
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
const ends = roundEnds(low, high);
|
|
53
|
+
return stretched(ends, low, high) ? ownEnds(low, high, count) : ends;
|
|
54
|
+
}
|
|
55
|
+
/** How many more ticks than the plot has room to write an axis on its values' own ends may ask for. */
|
|
56
|
+
const SPARE = 3;
|
|
57
|
+
/**
|
|
58
|
+
* An axis that ends where its values do, naming the round numbers between: for a plot too
|
|
59
|
+
* short for round ends that would not stretch the span. It takes the fewest round numbers that
|
|
60
|
+
* are at least two, though that be one more than the plot has room to write: where numbers
|
|
61
|
+
* are written, one with no room is left out and its hairline stays.
|
|
62
|
+
*/
|
|
63
|
+
function ownEnds(low, high, count) {
|
|
64
|
+
const scale = scaleLinear().domain([low, high]);
|
|
65
|
+
for (let ask = 1; ask <= count + SPARE; ask++) {
|
|
66
|
+
const ticks = scale.ticks(ask);
|
|
67
|
+
if (ticks.length >= 2) return {
|
|
68
|
+
min: low,
|
|
69
|
+
max: high,
|
|
70
|
+
ticks
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
min: low,
|
|
75
|
+
max: high,
|
|
76
|
+
ticks: [low, high]
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* An axis whose ticks are its two ends, on the round step that holds the span: 0 and 5K for
|
|
81
|
+
* 4,870. Where the span crosses zero, zero is a tick too: the zero line is the one line a chart
|
|
82
|
+
* always draws, so it is never the one line with no number.
|
|
83
|
+
*/
|
|
84
|
+
function roundEnds(low, high) {
|
|
85
|
+
const span = high - low;
|
|
86
|
+
const power = 10 ** Math.floor(Math.log10(span));
|
|
87
|
+
const step = [
|
|
88
|
+
1,
|
|
89
|
+
2,
|
|
90
|
+
5,
|
|
91
|
+
10
|
|
92
|
+
].map((m) => m * power).find((s) => s >= span) ?? span;
|
|
93
|
+
const min = Math.floor(low / step) * step;
|
|
94
|
+
const max = Math.ceil(high / step) * step;
|
|
95
|
+
if (!Number.isFinite(min) || !Number.isFinite(max) || !(max > min && min <= low && max >= high)) return {
|
|
96
|
+
min: low,
|
|
97
|
+
max: high,
|
|
98
|
+
ticks: [low, high]
|
|
99
|
+
};
|
|
100
|
+
return {
|
|
101
|
+
min,
|
|
102
|
+
max,
|
|
103
|
+
ticks: min < 0 && max > 0 ? [
|
|
104
|
+
min,
|
|
105
|
+
0,
|
|
106
|
+
max
|
|
107
|
+
] : [min, max]
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/** An axis of whole numbers, one apart or as far apart as the count needs. */
|
|
111
|
+
function wholeAxis(low, high, count) {
|
|
112
|
+
const min = Math.floor(low);
|
|
113
|
+
const top = Math.max(min + 1, Math.ceil(high));
|
|
114
|
+
const step = Math.max(1, Math.ceil((top - min) / count));
|
|
115
|
+
const steps = Math.ceil((top - min) / step);
|
|
116
|
+
return {
|
|
117
|
+
min,
|
|
118
|
+
max: min + steps * step,
|
|
119
|
+
ticks: Array.from({ length: steps + 1 }, (_v, i) => min + i * step)
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
const TINY = 2 ** -1022;
|
|
123
|
+
/** A value as a scale places it: one nearer zero than the smallest normal number is zero, since no scale can divide such a span. */
|
|
124
|
+
const placeable = (value) => Math.abs(value) < TINY ? 0 : value;
|
|
125
|
+
/** A third of the data's range: values nearer zero than this keep zero on the axis. */
|
|
126
|
+
const NEAR = 1 / 3;
|
|
127
|
+
/** Whether zero stays on the axis: always for lengths, and for positions when the values sit near it. */
|
|
128
|
+
function keepsZero(low, high, zero) {
|
|
129
|
+
if (zero === "always") return true;
|
|
130
|
+
const room = (high - low) * NEAR;
|
|
131
|
+
return low >= 0 && low <= room || high <= 0 && -high <= room;
|
|
132
|
+
}
|
|
133
|
+
/** The values' span, with zero taken in when the rule says so; a flat or empty span is opened. */
|
|
134
|
+
function spanOf(values, zero) {
|
|
135
|
+
const finite = values.filter((v) => Number.isFinite(v)).map((v) => placeable(v));
|
|
136
|
+
if (finite.length === 0) return [0, 1];
|
|
137
|
+
const low = least(finite);
|
|
138
|
+
const high = most(finite);
|
|
139
|
+
const keep = keepsZero(low, high, zero);
|
|
140
|
+
const from = keep ? Math.min(0, low) : low;
|
|
141
|
+
const to = keep ? Math.max(0, high) : high;
|
|
142
|
+
if (from !== to) return [from, to];
|
|
143
|
+
if (from === 0) return [0, 1];
|
|
144
|
+
return from > 0 ? [0, from] : [from, 0];
|
|
145
|
+
}
|
|
146
|
+
/** Places values along a pixel range: `from` is where the axis's `min` sits. */
|
|
147
|
+
function placeOn(axis, from, to) {
|
|
148
|
+
const fraction = fractionAlong(axis.min, axis.max);
|
|
149
|
+
return (value) => from + fraction(value) * (to - from);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Places lengths between two pixels, zero always among them and no room wasted on round ends:
|
|
153
|
+
* for bars that carry their own numbers and have no axis to read across to.
|
|
154
|
+
*/
|
|
155
|
+
function lengthsOn(values, from, to) {
|
|
156
|
+
const kept = values.map((v) => placeable(v));
|
|
157
|
+
const low = least(kept, 0);
|
|
158
|
+
const fraction = fractionAlong(low, most(kept, 0));
|
|
159
|
+
return (value) => from + fraction(placeable(value)) * (to - from);
|
|
160
|
+
}
|
|
161
|
+
export { lengthsOn, placeOn, placeable, tickCount, ticksAcross, valueAxis };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { attrs } from "./markup.mjs";
|
|
2
|
+
// src/scene/defs.ts
|
|
3
|
+
/** The distinct values some nodes hold, each with an id. */
|
|
4
|
+
function ids(values, prefix) {
|
|
5
|
+
const keys = [...new Set(values.map((value) => JSON.stringify(value)))];
|
|
6
|
+
return new Map(keys.map((key, i) => [key, `${prefix}${String(i)}`]));
|
|
7
|
+
}
|
|
8
|
+
/** The fades and clip boxes the picture refers to. */
|
|
9
|
+
function defs(fades, clips, paint) {
|
|
10
|
+
const stop = (color, at, opacity) => `<stop${attrs({
|
|
11
|
+
offset: at,
|
|
12
|
+
"stop-color": color,
|
|
13
|
+
"stop-opacity": opacity
|
|
14
|
+
})}/>`;
|
|
15
|
+
const gradients = [...fades].map(([key, id]) => {
|
|
16
|
+
const fade = JSON.parse(key);
|
|
17
|
+
const color = paint(fade.fade);
|
|
18
|
+
return `<linearGradient${attrs({
|
|
19
|
+
id,
|
|
20
|
+
x1: 0,
|
|
21
|
+
y1: 0,
|
|
22
|
+
x2: 0,
|
|
23
|
+
y2: 1
|
|
24
|
+
})}>${stop(color, 0, fade.from)}${stop(color, 1, fade.to)}</linearGradient>`;
|
|
25
|
+
});
|
|
26
|
+
const boxes = [...clips].map(([key, id]) => {
|
|
27
|
+
const box = JSON.parse(key);
|
|
28
|
+
return `<clipPath${attrs({ id })}><rect${attrs({ ...box })}/></clipPath>`;
|
|
29
|
+
});
|
|
30
|
+
const all = [...gradients, ...boxes];
|
|
31
|
+
return all.length === 0 ? "" : `<defs>${all.join("")}</defs>`;
|
|
32
|
+
}
|
|
33
|
+
export { defs, ids };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// src/scene/markup.ts
|
|
2
|
+
/** A number as SVG writes it: two decimals at most. */
|
|
3
|
+
const round = (value) => String(Math.round(value * 100) / 100);
|
|
4
|
+
/** Whether XML allows a character: tab, line feed and carriage return and nothing else below a space, and no half of a pair. */
|
|
5
|
+
function allowed(char) {
|
|
6
|
+
const code = char.codePointAt(0) ?? 0;
|
|
7
|
+
if (code === 9 || code === 10 || code === 13) return true;
|
|
8
|
+
if (code >= 55296 && code <= 57343) return false;
|
|
9
|
+
return code >= 32 && code !== 65534 && code !== 65535;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* A text with nothing to leave out and nothing to escape, as nearly every text of a picture is
|
|
13
|
+
* (path data, numbers, names): every character one XML allows, and none of `&`, `<`, `>`, `"`.
|
|
14
|
+
* Such a text is written as it is, with no pass over its characters one by one.
|
|
15
|
+
*/
|
|
16
|
+
const PLAIN = /^[\t\n\r\u0020\u0021\u0023-\u0025\u0027-\u003B\u003D\u003F-\uD7FF\uE000-\uFFFD\u{10000}-\u{10FFFF}]*$/u;
|
|
17
|
+
/**
|
|
18
|
+
* A text safe inside an element or an attribute. Control characters XML does not allow are
|
|
19
|
+
* left out: a label holding one must not make the whole picture unreadable to a strict reader.
|
|
20
|
+
*/
|
|
21
|
+
const escapeText = (text) => PLAIN.test(text) ? text : Array.from(text).filter((char) => allowed(char)).join("").replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll("\"", """);
|
|
22
|
+
/**
|
|
23
|
+
* A short stamp of a text (FNV-1a), for the ids of a picture given no prefix: two different
|
|
24
|
+
* pictures on one page get different ids, and the same picture always gets the same ones.
|
|
25
|
+
*/
|
|
26
|
+
function stamp(text) {
|
|
27
|
+
let hash = 2166136261;
|
|
28
|
+
for (const char of text) hash = Math.imul(hash ^ (char.codePointAt(0) ?? 0), 16777619);
|
|
29
|
+
return (hash >>> 0).toString(36);
|
|
30
|
+
}
|
|
31
|
+
/** Attributes as text; one with no value is left out. */
|
|
32
|
+
const attrs = (given) => Object.entries(given).filter(([, value]) => value !== void 0).map(([name, value]) => {
|
|
33
|
+
return ` ${name}="${typeof value === "number" ? round(value) : escapeText(String(value))}"`;
|
|
34
|
+
}).join("");
|
|
35
|
+
export { attrs, escapeText, round, stamp };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Hover, HoverItem, HoverStop } from "./types.mjs";
|
|
2
|
+
/** The stop nearest a point, by the scene's snap; nothing for a scene with no stops. */
|
|
3
|
+
export declare function nearestStop(hover: Hover, x: number, y: number): HoverStop | undefined;
|
|
4
|
+
/**
|
|
5
|
+
* Of a stop's items, the one nearest a point: the value a click there means. Nothing when the
|
|
6
|
+
* stop has none (a gap). Of two items equally near, the first.
|
|
7
|
+
*/
|
|
8
|
+
export declare function nearestItem(items: readonly HoverItem[], at: {
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
}): HoverItem | undefined;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// src/scene/nearest.ts
|
|
2
|
+
/** The item with a painted column or segment under the pointer. */
|
|
3
|
+
function itemCovering(items, x, y) {
|
|
4
|
+
return items.find(({ bounds }) => bounds !== void 0 && x >= bounds.x && x <= bounds.x + bounds.width && y >= bounds.y && y <= bounds.y + bounds.height);
|
|
5
|
+
}
|
|
6
|
+
/** A merged bar can have gaps. Pick the period closest to the pointer where its own series has a reading. */
|
|
7
|
+
function coveredReading(stops, best, x, y) {
|
|
8
|
+
if (best?.span === void 0) return best;
|
|
9
|
+
const [from, to] = best.span;
|
|
10
|
+
let hit;
|
|
11
|
+
let distance = Number.POSITIVE_INFINITY;
|
|
12
|
+
for (let i = from; i < to; i++) {
|
|
13
|
+
const stop = stops[i];
|
|
14
|
+
if (stop === void 0 || itemCovering(stop.items, x, y) === void 0) continue;
|
|
15
|
+
const across = Math.abs(stop.x - x);
|
|
16
|
+
if (across < distance) {
|
|
17
|
+
distance = across;
|
|
18
|
+
hit = stop;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return hit ?? best;
|
|
22
|
+
}
|
|
23
|
+
/** The stop nearest a point, by the scene's snap; nothing for a scene with no stops. */
|
|
24
|
+
function nearestStop(hover, x, y) {
|
|
25
|
+
let best;
|
|
26
|
+
let least = Number.POSITIVE_INFINITY;
|
|
27
|
+
for (const stop of hover.stops) {
|
|
28
|
+
const across = Math.abs(stop.x - x);
|
|
29
|
+
const down = Math.abs(stop.y - y);
|
|
30
|
+
const far = hover.snap === "x" ? across : hover.snap === "y" ? down : Math.hypot(across, down);
|
|
31
|
+
if (far < least) {
|
|
32
|
+
least = far;
|
|
33
|
+
best = stop;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return coveredReading(hover.stops, best, x, y);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Of a stop's items, the one nearest a point: the value a click there means. Nothing when the
|
|
40
|
+
* stop has none (a gap). Of two items equally near, the first.
|
|
41
|
+
*/
|
|
42
|
+
function nearestItem(items, at) {
|
|
43
|
+
const hit = itemCovering(items, at.x, at.y);
|
|
44
|
+
if (hit !== void 0) return hit;
|
|
45
|
+
const far = (item) => Math.hypot(item.x - at.x, item.y - at.y);
|
|
46
|
+
const [first, ...rest] = items;
|
|
47
|
+
return first === void 0 ? first : rest.reduce((best, item) => far(item) < far(best) ? item : best, first);
|
|
48
|
+
}
|
|
49
|
+
export { coveredReading, itemCovering, nearestItem, nearestStop };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Paint } from "./types.mjs";
|
|
2
|
+
export declare const INK: Paint;
|
|
3
|
+
export declare const MUTED: Paint;
|
|
4
|
+
/** Hairlines: the grid, a row's rule. */
|
|
5
|
+
export declare const RULE: Paint;
|
|
6
|
+
export declare const SURFACE: Paint;
|
|
7
|
+
/** The quiet grey of what is not the point: Other, and marks out of focus. */
|
|
8
|
+
export declare const OTHER: Paint;
|
|
9
|
+
export declare const GOOD: Paint;
|
|
10
|
+
export declare const BAD: Paint;
|
|
11
|
+
/** A paint as a CSS colour: a token's variable on a page, or its colour in a theme that is given. */
|
|
12
|
+
export declare const paintCss: (paint: Paint, theme?: Readonly<Record<string, string>>) => string;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// src/scene/paint.ts
|
|
2
|
+
const INK = "--dd-ink";
|
|
3
|
+
const MUTED = "--dd-muted";
|
|
4
|
+
/** Hairlines: the grid, a row's rule. */
|
|
5
|
+
const RULE = "--dd-line";
|
|
6
|
+
const SURFACE = "--dd-surface";
|
|
7
|
+
/** The quiet grey of what is not the point: Other, and marks out of focus. */
|
|
8
|
+
const OTHER = "--dd-other";
|
|
9
|
+
const GOOD = "--dd-good";
|
|
10
|
+
const BAD = "--dd-danger";
|
|
11
|
+
/** A paint as a CSS colour: a token's variable on a page, or its colour in a theme that is given. */
|
|
12
|
+
const paintCss = (paint, theme) => paint.startsWith("--") ? theme?.[paint] ?? `var(${paint})` : paint;
|
|
13
|
+
export { BAD, GOOD, INK, MUTED, OTHER, RULE, SURFACE, paintCss };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Scene, SceneNode } from "./types.mjs";
|
|
2
|
+
export type SvgOptions = {
|
|
3
|
+
/** Keep mark identities as data-key attributes. Defaults to true. */
|
|
4
|
+
markKeys?: boolean;
|
|
5
|
+
/** A prefix for the ids the picture defines; unique on its page. */
|
|
6
|
+
id?: string;
|
|
7
|
+
/** A colour for each token, for a picture with no stylesheet. */
|
|
8
|
+
theme?: Readonly<Record<string, string>>;
|
|
9
|
+
/** The font family: the page's `--dd-font` by default, and the system's font in a picture given a `theme`. */
|
|
10
|
+
font?: string;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Some nodes as SVG text, with the fades and clip boxes they refer to and no `<svg>` around
|
|
14
|
+
* them: for a layer drawn over a picture, such as what lights at a hover stop.
|
|
15
|
+
*/
|
|
16
|
+
export declare function renderNodes(nodes: readonly SceneNode[], options?: SvgOptions): string;
|
|
17
|
+
/** The picture as SVG text. */
|
|
18
|
+
export declare function renderSvg(scene: Scene, options?: SvgOptions): string;
|