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,137 @@
|
|
|
1
|
+
import { INK, RULE } from "../scene/paint.mjs";
|
|
2
|
+
import { widest } from "../text/measure.mjs";
|
|
3
|
+
import { LINE, MARK, SPACE, TEXT } from "../theme.mjs";
|
|
4
|
+
// src/marks/axes.ts
|
|
5
|
+
/** The room the labels under a plot take: the gap above them, their height, and a little under. */
|
|
6
|
+
const X_ROOM = SPACE.under + LINE.tick;
|
|
7
|
+
/**
|
|
8
|
+
* How an axis's ticks read: the measure's short form, unless that reads two ticks alike (1M, 1M
|
|
9
|
+
* for values a few hundred apart), in which case its full form.
|
|
10
|
+
*/
|
|
11
|
+
function tickTexts(axis, reads) {
|
|
12
|
+
if (reads === void 0) return String;
|
|
13
|
+
const short = axis.ticks.map((t) => reads.tick(t));
|
|
14
|
+
return new Set(short).size === short.length ? reads.tick : reads.text;
|
|
15
|
+
}
|
|
16
|
+
/** The left margin a value axis needs: its widest label and the gutter. */
|
|
17
|
+
function gutterOf(axis, reads, measure) {
|
|
18
|
+
const tick = tickTexts(axis, reads);
|
|
19
|
+
const texts = axis.ticks.map((t) => tick(t));
|
|
20
|
+
return Math.ceil(widest(texts, TEXT.tick, measure)) + SPACE.gutter;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A level hairline at each tick, and each tick's number at its left, written by the rule of
|
|
24
|
+
* every value axis (`writtenOf`): a number left out keeps its hairline.
|
|
25
|
+
*/
|
|
26
|
+
function valueGrid(axis, at) {
|
|
27
|
+
const { plot, place } = at;
|
|
28
|
+
const tick = tickTexts(axis, at.reads);
|
|
29
|
+
const texts = axis.ticks.map((value) => tick(value));
|
|
30
|
+
const named = axis.ticks.map((value, i) => ({
|
|
31
|
+
value,
|
|
32
|
+
text: texts[i] ?? ""
|
|
33
|
+
}));
|
|
34
|
+
const written = new Set(at.numbers === false ? [] : writtenOf(named, {
|
|
35
|
+
place: (one) => -place(one.value),
|
|
36
|
+
half: () => TEXT.tick.size / 2,
|
|
37
|
+
min: Number.NEGATIVE_INFINITY,
|
|
38
|
+
max: Number.POSITIVE_INFINITY
|
|
39
|
+
}));
|
|
40
|
+
return named.flatMap((one) => [{
|
|
41
|
+
kind: "line",
|
|
42
|
+
part: "grid",
|
|
43
|
+
x1: plot.x,
|
|
44
|
+
x2: plot.x + plot.width,
|
|
45
|
+
y1: place(one.value),
|
|
46
|
+
y2: place(one.value),
|
|
47
|
+
stroke: RULE
|
|
48
|
+
}, ...written.has(one) ? [{
|
|
49
|
+
kind: "text",
|
|
50
|
+
part: "tick",
|
|
51
|
+
x: plot.x - SPACE.gutter,
|
|
52
|
+
y: place(one.value),
|
|
53
|
+
text: one.text,
|
|
54
|
+
...TEXT.tick,
|
|
55
|
+
anchor: "end",
|
|
56
|
+
baseline: "middle"
|
|
57
|
+
}] : []]);
|
|
58
|
+
}
|
|
59
|
+
/** Where a line across the plot at a place runs: level, or upright along its span. */
|
|
60
|
+
function across(place, at) {
|
|
61
|
+
const { plot } = at;
|
|
62
|
+
const from = at.span?.from;
|
|
63
|
+
const to = at.span?.to;
|
|
64
|
+
return at.upright === true ? {
|
|
65
|
+
x1: place,
|
|
66
|
+
x2: place,
|
|
67
|
+
y1: from ?? plot.y,
|
|
68
|
+
y2: to ?? plot.y + plot.height
|
|
69
|
+
} : {
|
|
70
|
+
x1: from ?? plot.x,
|
|
71
|
+
x2: to ?? plot.x + plot.width,
|
|
72
|
+
y1: place,
|
|
73
|
+
y2: place
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Where zero stands, held inside the plot: zero's own place when the axis has it, else the
|
|
78
|
+
* plot's edge nearest it. What a wash under a line runs down to, and what bars side by side
|
|
79
|
+
* stand on, on an axis that leaves zero out.
|
|
80
|
+
*/
|
|
81
|
+
const zeroIn = (plot, place) => Math.min(plot.y + plot.height, Math.max(plot.y, place(0)));
|
|
82
|
+
/** The zero line, when zero is on the axis: drawn over the marks that stand on it. */
|
|
83
|
+
function zeroLine(axis, at) {
|
|
84
|
+
if (axis.min > 0 || axis.max < 0) return [];
|
|
85
|
+
return [{
|
|
86
|
+
kind: "line",
|
|
87
|
+
part: "zero",
|
|
88
|
+
...across(at.place(0), at),
|
|
89
|
+
stroke: INK,
|
|
90
|
+
opacity: MARK.zero
|
|
91
|
+
}];
|
|
92
|
+
}
|
|
93
|
+
/** A label under the plot at `x`: centred on it, or set from it. */
|
|
94
|
+
function tickUnder(tick, plot, anchor = "middle") {
|
|
95
|
+
return {
|
|
96
|
+
kind: "text",
|
|
97
|
+
part: "tick",
|
|
98
|
+
x: tick.x,
|
|
99
|
+
y: plot.y + plot.height + SPACE.under,
|
|
100
|
+
text: tick.text,
|
|
101
|
+
...TEXT.tick,
|
|
102
|
+
anchor,
|
|
103
|
+
baseline: "hanging"
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/** Labels under the plot, each centred on its place. */
|
|
107
|
+
function labelsUnder(ticks, plot) {
|
|
108
|
+
return ticks.map((tick) => tickUnder(tick, plot));
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* The numbers written along a value axis, up its side or along its foot: one number alone
|
|
112
|
+
* gives no scale, and may name an end nothing is near, so then none is written.
|
|
113
|
+
*/
|
|
114
|
+
const scaled = (numbers) => numbers.length === 1 ? [] : numbers;
|
|
115
|
+
/**
|
|
116
|
+
* The labels along an axis that can be read, in order: each clear of the one before by the
|
|
117
|
+
* house gap, and inside its room; one that is not is left out, though its hairline stays.
|
|
118
|
+
* `half` is half of a label's extent along the axis: its width across, its height down.
|
|
119
|
+
*/
|
|
120
|
+
function readable(labels, at) {
|
|
121
|
+
let end = Number.NEGATIVE_INFINITY;
|
|
122
|
+
return labels.filter((label) => {
|
|
123
|
+
const from = at.place(label) - at.half(label);
|
|
124
|
+
const to = at.place(label) + at.half(label);
|
|
125
|
+
if (from < Math.max(end + SPACE.ticks, at.min) || to > at.max) return false;
|
|
126
|
+
end = to;
|
|
127
|
+
return true;
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* The ticks whose numbers a value axis writes, in order along it, up a plot's side or along its
|
|
132
|
+
* foot: a number that reads the same as the one before it (values too fine for the measure to
|
|
133
|
+
* tell apart) is not written twice, one with no room clear of the last written, or outside the
|
|
134
|
+
* axis's room, is left out, and when only one would be left none is written.
|
|
135
|
+
*/
|
|
136
|
+
const writtenOf = (ticks, at) => scaled(readable(ticks.filter((one, i) => one.text !== ticks[i - 1]?.text), at));
|
|
137
|
+
export { X_ROOM, gutterOf, labelsUnder, scaled, tickTexts, tickUnder, valueGrid, writtenOf, zeroIn, zeroLine };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { SURFACE } from "../scene/paint.mjs";
|
|
2
|
+
import { MARK } from "../theme.mjs";
|
|
3
|
+
// src/marks/dot.ts
|
|
4
|
+
/**
|
|
5
|
+
* How far a dot reaches from its centre: its radius and the half of its stroke that lies
|
|
6
|
+
* outside it (its surface ring, or its own stroke when it is hollow). The room any kind keeps
|
|
7
|
+
* for a dot.
|
|
8
|
+
*/
|
|
9
|
+
const dotReach = (r, hollow = false) => r + (hollow ? MARK.hollow : MARK.ring) / 2;
|
|
10
|
+
/**
|
|
11
|
+
* How far a dot reaches when it may be filled or hollow: the wider of its two strokes. The room
|
|
12
|
+
* a kind keeps for dots that may be either.
|
|
13
|
+
*/
|
|
14
|
+
const widestReach = (r) => Math.max(dotReach(r), dotReach(r, true));
|
|
15
|
+
/** A dot at a place. */
|
|
16
|
+
function dot(at) {
|
|
17
|
+
const hollow = at.hollow === true;
|
|
18
|
+
return {
|
|
19
|
+
kind: "circle",
|
|
20
|
+
part: at.part,
|
|
21
|
+
...at.key === void 0 ? {} : { key: at.key },
|
|
22
|
+
cx: at.x,
|
|
23
|
+
cy: at.y,
|
|
24
|
+
r: at.r,
|
|
25
|
+
fill: hollow ? SURFACE : at.color,
|
|
26
|
+
stroke: hollow ? at.color : SURFACE,
|
|
27
|
+
strokeWidth: hollow ? MARK.hollow : MARK.ring,
|
|
28
|
+
...at.opacity === void 0 ? {} : { opacity: at.opacity }
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export { dot, dotReach, widestReach };
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { dodge, roomFor } from "../layout/dodge.mjs";
|
|
2
|
+
import { fitOrNone } from "../text/measure.mjs";
|
|
3
|
+
import { LINE, MARK, TEXT } from "../theme.mjs";
|
|
4
|
+
import { END_REACH } from "./series-line.mjs";
|
|
5
|
+
// src/marks/end-labels.ts
|
|
6
|
+
/** The height of one label of the two stacked at a line's end. */
|
|
7
|
+
const LABEL_LINE = LINE.pair;
|
|
8
|
+
/** Room kept between two labels moved apart: a pixel, since each label's line already has air around its text. */
|
|
9
|
+
const APART = 1;
|
|
10
|
+
/** How many labels fit beside a plot this tall, one to a line. */
|
|
11
|
+
const endLines = (height) => roomFor(LABEL_LINE, {
|
|
12
|
+
min: -LABEL_LINE / 2,
|
|
13
|
+
max: height + LABEL_LINE / 2,
|
|
14
|
+
gap: APART
|
|
15
|
+
});
|
|
16
|
+
/** How a label's value is set: a run of the label's own text, at its size, in the value's weight. */
|
|
17
|
+
const VALUE_RUN = {
|
|
18
|
+
size: TEXT.name.size,
|
|
19
|
+
weight: TEXT.value.weight
|
|
20
|
+
};
|
|
21
|
+
/** From the plot's edge to the label: the reach of the dot at a line's end, and the air after it. */
|
|
22
|
+
const LEAD = END_REACH + 5.5;
|
|
23
|
+
/** The space between a name and its value: about a word space. */
|
|
24
|
+
const BETWEEN = 5;
|
|
25
|
+
/** A leader starts just clear of the dot at the line's end and stops clear of the label's text. */
|
|
26
|
+
const CLEAR = {
|
|
27
|
+
dot: END_REACH + .5,
|
|
28
|
+
text: 3
|
|
29
|
+
};
|
|
30
|
+
/** A label moved less than this still reads as beside its line, and needs no leader. */
|
|
31
|
+
const MOVED = 3;
|
|
32
|
+
/** The least room a name is worth cutting to: two letters and an ellipsis. */
|
|
33
|
+
const LEAST_NAME = 22;
|
|
34
|
+
const widthOf = (label, measure) => (label.name === void 0 ? 0 : measure(label.name, TEXT.name) + BETWEEN) + measure(label.value, VALUE_RUN);
|
|
35
|
+
/**
|
|
36
|
+
* The right margin the labels need, never more than `most`: a longer name is cut to fit.
|
|
37
|
+
* Nothing when there are no labels.
|
|
38
|
+
*/
|
|
39
|
+
function endRoom(labels, at) {
|
|
40
|
+
if (labels.length === 0) return 0;
|
|
41
|
+
const widest = labels.reduce((most, label) => Math.max(most, widthOf(label, at.measure)), 0);
|
|
42
|
+
return Math.min(at.most, Math.ceil(LEAD + widest));
|
|
43
|
+
}
|
|
44
|
+
/** A label's runs: the name plain and its value carrying the weight, as beside every other mark. */
|
|
45
|
+
function runsOf(name, value) {
|
|
46
|
+
const strong = {
|
|
47
|
+
fill: TEXT.value.fill,
|
|
48
|
+
weight: TEXT.value.weight
|
|
49
|
+
};
|
|
50
|
+
return name === void 0 ? [{
|
|
51
|
+
text: value,
|
|
52
|
+
...strong
|
|
53
|
+
}] : [{
|
|
54
|
+
text: name,
|
|
55
|
+
fill: TEXT.name.fill
|
|
56
|
+
}, {
|
|
57
|
+
text: ` ${value}`,
|
|
58
|
+
...strong
|
|
59
|
+
}];
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The labels beside the plot's right edge, spread so none overlap. A label whose line ends
|
|
63
|
+
* short of the edge (its `x`) is tied to where the line stops by a leader.
|
|
64
|
+
*/
|
|
65
|
+
function endLabels(labels, at) {
|
|
66
|
+
const { plot, measure } = at;
|
|
67
|
+
const edge = plot.x + plot.width;
|
|
68
|
+
const centres = dodge(labels.map((label) => ({
|
|
69
|
+
at: label.y,
|
|
70
|
+
size: LABEL_LINE
|
|
71
|
+
})), {
|
|
72
|
+
min: plot.y - LABEL_LINE / 2,
|
|
73
|
+
max: plot.y + plot.height + LABEL_LINE / 2,
|
|
74
|
+
gap: APART
|
|
75
|
+
});
|
|
76
|
+
return labels.flatMap((label, i) => {
|
|
77
|
+
const y = centres[i] ?? label.y;
|
|
78
|
+
const x = edge + LEAD;
|
|
79
|
+
const valueWidth = measure(label.value, VALUE_RUN);
|
|
80
|
+
if (LEAD + valueWidth > at.room + .5) return [];
|
|
81
|
+
const nameRoom = at.room - LEAD - BETWEEN - valueWidth;
|
|
82
|
+
const runs = runsOf(label.name === void 0 ? void 0 : fitOrNone(label.name, {
|
|
83
|
+
width: nameRoom,
|
|
84
|
+
least: LEAST_NAME,
|
|
85
|
+
font: TEXT.name,
|
|
86
|
+
measure
|
|
87
|
+
}), label.value);
|
|
88
|
+
const ends = Math.min(edge, label.x ?? edge);
|
|
89
|
+
return [...leader({
|
|
90
|
+
from: ends + CLEAR.dot,
|
|
91
|
+
to: x - CLEAR.text,
|
|
92
|
+
y: label.y,
|
|
93
|
+
moved: y,
|
|
94
|
+
apart: edge - ends,
|
|
95
|
+
color: label.color
|
|
96
|
+
}), {
|
|
97
|
+
kind: "text",
|
|
98
|
+
part: "end-label",
|
|
99
|
+
key: label.key,
|
|
100
|
+
x,
|
|
101
|
+
y,
|
|
102
|
+
text: runs.map((run) => run.text).join(""),
|
|
103
|
+
runs,
|
|
104
|
+
...TEXT.name,
|
|
105
|
+
baseline: "middle",
|
|
106
|
+
halo: true
|
|
107
|
+
}];
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* A thin line from where the series ends to its label, when the label is off it: moved up or
|
|
112
|
+
* down to clear another, or `apart` from marks that end short of the plot's edge.
|
|
113
|
+
*/
|
|
114
|
+
function leader(at) {
|
|
115
|
+
if (Math.abs(at.moved - at.y) < MOVED && at.apart < MOVED) return [];
|
|
116
|
+
return [{
|
|
117
|
+
kind: "path",
|
|
118
|
+
part: "leader",
|
|
119
|
+
d: `M${String(at.from)},${String(at.y)}L${String(at.to)},${String(at.moved)}`,
|
|
120
|
+
stroke: at.color,
|
|
121
|
+
opacity: MARK.faint
|
|
122
|
+
}];
|
|
123
|
+
}
|
|
124
|
+
export { endLabels, endLines, endRoom };
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { headerHeight } from "../layout/frame.mjs";
|
|
2
|
+
import { fitText } from "../text/measure.mjs";
|
|
3
|
+
import { LINE, MARK, TEXT } from "../theme.mjs";
|
|
4
|
+
import { dot, dotReach } from "./dot.mjs";
|
|
5
|
+
import { moreLine } from "./more.mjs";
|
|
6
|
+
// src/marks/legend.ts
|
|
7
|
+
/** A swatch's size, its corner (its own: a bar's corner would make so small a square a blob), and the room after it. */
|
|
8
|
+
const SWATCH = 8;
|
|
9
|
+
const CORNER = 2;
|
|
10
|
+
/** The height one row of the legend takes. */
|
|
11
|
+
const LEGEND_LINE = LINE.name;
|
|
12
|
+
/** A legend's rows at most, in every kind: past them it counts what it has no room to name. */
|
|
13
|
+
const LEGEND_ROWS = 2;
|
|
14
|
+
/** The room between two entries in a row, and before the count of those left out: wider than a swatch's room, so an entry reads as one. */
|
|
15
|
+
const BETWEEN = 16;
|
|
16
|
+
/** The most of a row one name takes, in every kind's legend: a longer one is cut. */
|
|
17
|
+
const NAME_MOST = 140;
|
|
18
|
+
/**
|
|
19
|
+
* A legend tried in the house's rows, then in one: the first try that `holds`, nothing when
|
|
20
|
+
* neither does. Every kind that names things in a legend gives way by this, a row before the
|
|
21
|
+
* plot gives up its room.
|
|
22
|
+
*/
|
|
23
|
+
const firstLegend = (tried, holds) => [LEGEND_ROWS, 1].map((rows) => tried(rows)).find((one) => holds(one));
|
|
24
|
+
/** Room under the legend before the plot: the legend's own, less than the header's gap since the legend belongs to the plot. */
|
|
25
|
+
const UNDER = 8;
|
|
26
|
+
/** The width an entry's swatch and the room after it take, before its name. */
|
|
27
|
+
const SWATCH_ROOM = 14;
|
|
28
|
+
/** An entry's swatch, its left edge at `x`, its middle at `mid`. */
|
|
29
|
+
function swatch(item, x, mid) {
|
|
30
|
+
if (item.shape === "line") return {
|
|
31
|
+
kind: "line",
|
|
32
|
+
part: "legend",
|
|
33
|
+
key: item.key,
|
|
34
|
+
x1: x,
|
|
35
|
+
x2: x + SWATCH,
|
|
36
|
+
y1: mid,
|
|
37
|
+
y2: mid,
|
|
38
|
+
stroke: item.color,
|
|
39
|
+
strokeWidth: MARK.line
|
|
40
|
+
};
|
|
41
|
+
if (item.shape === "dot" || item.shape === "ring") {
|
|
42
|
+
const hollow = item.shape === "ring";
|
|
43
|
+
return dot({
|
|
44
|
+
x: x + SWATCH / 2,
|
|
45
|
+
y: mid,
|
|
46
|
+
r: SWATCH / 2 - dotReach(0, hollow),
|
|
47
|
+
color: item.color,
|
|
48
|
+
hollow,
|
|
49
|
+
part: "legend",
|
|
50
|
+
key: item.key
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
kind: "rect",
|
|
55
|
+
part: "legend",
|
|
56
|
+
key: item.key,
|
|
57
|
+
x,
|
|
58
|
+
y: mid - SWATCH / 2,
|
|
59
|
+
width: SWATCH,
|
|
60
|
+
height: SWATCH,
|
|
61
|
+
radius: CORNER,
|
|
62
|
+
fill: item.color
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/** Where a legend stands in every kind: under the header, across the whole picture. */
|
|
66
|
+
const underHeader = (header, env) => ({
|
|
67
|
+
x: 0,
|
|
68
|
+
y: headerHeight(header),
|
|
69
|
+
width: env.width
|
|
70
|
+
});
|
|
71
|
+
/** The legend's items in rows from `x`, `y`, wrapped to `width`. */
|
|
72
|
+
function legend(items, at) {
|
|
73
|
+
let left = 0;
|
|
74
|
+
let row = 0;
|
|
75
|
+
return {
|
|
76
|
+
nodes: items.flatMap((item) => {
|
|
77
|
+
const room = Math.min(NAME_MOST, at.width - SWATCH_ROOM);
|
|
78
|
+
const label = fitText(item.label, room, TEXT.name, at.measure);
|
|
79
|
+
const width = SWATCH_ROOM + at.measure(label, TEXT.name);
|
|
80
|
+
if (left > 0 && left + width > at.width) {
|
|
81
|
+
left = 0;
|
|
82
|
+
row += 1;
|
|
83
|
+
}
|
|
84
|
+
const x = at.x + left;
|
|
85
|
+
const mid = at.y + row * LEGEND_LINE + LEGEND_LINE / 2;
|
|
86
|
+
left += width + BETWEEN;
|
|
87
|
+
return [swatch(item, x, mid), {
|
|
88
|
+
kind: "text",
|
|
89
|
+
part: "legend",
|
|
90
|
+
x: x + SWATCH_ROOM,
|
|
91
|
+
y: mid,
|
|
92
|
+
text: label,
|
|
93
|
+
...TEXT.name,
|
|
94
|
+
baseline: "middle"
|
|
95
|
+
}];
|
|
96
|
+
}),
|
|
97
|
+
height: items.length === 0 ? 0 : (row + 1) * LEGEND_LINE + UNDER
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/** The legend of the first `count` items, the count of the rest after its last name, and whether that fits. */
|
|
101
|
+
function withRest(items, count, at) {
|
|
102
|
+
const { env } = at;
|
|
103
|
+
const made = legend(items.slice(0, count), {
|
|
104
|
+
...at,
|
|
105
|
+
measure: env.measure
|
|
106
|
+
});
|
|
107
|
+
const left = items.length - count;
|
|
108
|
+
const last = made.nodes.findLast((node) => node.kind === "text");
|
|
109
|
+
if (left === 0 || last?.kind !== "text") return {
|
|
110
|
+
made,
|
|
111
|
+
fits: left === 0
|
|
112
|
+
};
|
|
113
|
+
const x = last.x + env.measure(last.text, TEXT.name) + BETWEEN;
|
|
114
|
+
const more = moreLine(left, {
|
|
115
|
+
x,
|
|
116
|
+
y: last.y,
|
|
117
|
+
width: at.x + at.width,
|
|
118
|
+
env
|
|
119
|
+
});
|
|
120
|
+
const words = more.find((node) => node.kind === "text");
|
|
121
|
+
const fits = words?.kind === "text" && x + env.measure(words.text, TEXT.tick) <= at.x + at.width;
|
|
122
|
+
return {
|
|
123
|
+
made: {
|
|
124
|
+
...made,
|
|
125
|
+
nodes: [...made.nodes, ...more]
|
|
126
|
+
},
|
|
127
|
+
fits
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* A legend held to some rows: the first items that fit, in order, then a count of the rest
|
|
132
|
+
* ("and 3 more"). Nothing when not even one item and the count fit.
|
|
133
|
+
*/
|
|
134
|
+
function cappedLegend(items, at) {
|
|
135
|
+
const most = at.rows * LEGEND_LINE + UNDER;
|
|
136
|
+
for (let count = items.length; count > 0; count--) {
|
|
137
|
+
const { made, fits } = withRest(items, count, at);
|
|
138
|
+
if (fits && made.height <= most) return made;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
export { cappedLegend, firstLegend, legend, underHeader };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { follows } from "../data/buckets.mjs";
|
|
2
|
+
import { area, curveLinear, curveMonotoneX, curveStepAfter, line } from "d3-shape";
|
|
3
|
+
// src/marks/lines.ts
|
|
4
|
+
const CURVES = {
|
|
5
|
+
straight: curveLinear,
|
|
6
|
+
smooth: curveMonotoneX,
|
|
7
|
+
step: curveStepAfter
|
|
8
|
+
};
|
|
9
|
+
/** The points with a break put in wherever the data skips a bucket, so a path stops there. */
|
|
10
|
+
function broken(points, buckets) {
|
|
11
|
+
return points.flatMap((point, i) => i > 0 && !follows(buckets, i) ? [void 0, point] : [point]);
|
|
12
|
+
}
|
|
13
|
+
/** The path through the points. */
|
|
14
|
+
function linePath(points, curve) {
|
|
15
|
+
return line().defined((p) => p !== void 0).x((p) => p?.x ?? 0).y((p) => p?.y ?? 0).curve(CURVES[curve])([...points]) ?? "";
|
|
16
|
+
}
|
|
17
|
+
/** The shape between the points and a level `base`. */
|
|
18
|
+
function areaPath(points, base, curve) {
|
|
19
|
+
return area().defined((p) => p !== void 0).x((p) => p?.x ?? 0).y1((p) => p?.y ?? 0).y0(base).curve(CURVES[curve])([...points]) ?? "";
|
|
20
|
+
}
|
|
21
|
+
/** The shape between two runs of points, place for place: one band of a stack. */
|
|
22
|
+
function bandPath(top, bottom, curve) {
|
|
23
|
+
return area().defined((i) => top[i] !== void 0 && bottom[i] !== void 0).x((i) => top[i]?.x ?? 0).y1((i) => top[i]?.y ?? 0).y0((i) => bottom[i]?.y ?? 0).curve(CURVES[curve])(top.map((_p, i) => i)) ?? "";
|
|
24
|
+
}
|
|
25
|
+
/** The points that stand alone, with no value either side: a path draws nothing for them, so a dot does. */
|
|
26
|
+
function alone(points) {
|
|
27
|
+
return points.flatMap((p, i) => p !== void 0 && points[i - 1] === void 0 && points[i + 1] === void 0 ? [p] : []);
|
|
28
|
+
}
|
|
29
|
+
/** The last point there is, and its place in the list. */
|
|
30
|
+
function lastOf(points) {
|
|
31
|
+
const index = points.findLastIndex((p) => p !== void 0);
|
|
32
|
+
const at = points[index];
|
|
33
|
+
return at === void 0 ? void 0 : {
|
|
34
|
+
at,
|
|
35
|
+
index
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export { alone, areaPath, bandPath, broken, lastOf, linePath };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { INK, MUTED } from "../scene/paint.mjs";
|
|
2
|
+
import { MARK } from "../theme.mjs";
|
|
3
|
+
import { dot, dotReach } from "./dot.mjs";
|
|
4
|
+
// src/marks/lit.ts
|
|
5
|
+
/** How strong the soft box and the hairline are, and the radius of the dot on a value along a line. */
|
|
6
|
+
const BAND = .06;
|
|
7
|
+
const GUIDE = .6;
|
|
8
|
+
const DOT = 4;
|
|
9
|
+
/** The surface left between a dot's own ring and the ring that lights it. */
|
|
10
|
+
const HALO = 2;
|
|
11
|
+
/** The hairline down a stop's plot: for stops along x, and for a stop that names its own plot. */
|
|
12
|
+
function guide(scene, stop) {
|
|
13
|
+
if (scene.hover?.snap !== "x" && stop.plot === void 0) return [];
|
|
14
|
+
const plot = stop.plot ?? scene.plot;
|
|
15
|
+
const x = Math.round(stop.x) + .5;
|
|
16
|
+
return [{
|
|
17
|
+
kind: "line",
|
|
18
|
+
part: "guide",
|
|
19
|
+
x1: x,
|
|
20
|
+
x2: x,
|
|
21
|
+
y1: plot.y,
|
|
22
|
+
y2: plot.y + plot.height,
|
|
23
|
+
stroke: MUTED,
|
|
24
|
+
opacity: GUIDE
|
|
25
|
+
}];
|
|
26
|
+
}
|
|
27
|
+
/** A stop's items, one for each place: several values of one mark (a dot's x, y and size) light it once. */
|
|
28
|
+
const placesOf = (stop) => stop.items.filter((item, i) => stop.items.findIndex((one) => one.x === item.x && one.y === item.y) === i);
|
|
29
|
+
/** The marks to draw over a picture while one of its stops is lit. */
|
|
30
|
+
function litNodes(scene, stop) {
|
|
31
|
+
if (stop.band !== void 0) return [{
|
|
32
|
+
kind: "rect",
|
|
33
|
+
part: "guide",
|
|
34
|
+
...stop.band,
|
|
35
|
+
radius: MARK.round,
|
|
36
|
+
fill: INK,
|
|
37
|
+
opacity: BAND
|
|
38
|
+
}];
|
|
39
|
+
return [...guide(scene, stop), ...placesOf(stop).flatMap((item) => {
|
|
40
|
+
const at = {
|
|
41
|
+
x: item.x,
|
|
42
|
+
y: item.y,
|
|
43
|
+
color: item.color
|
|
44
|
+
};
|
|
45
|
+
return item.r === void 0 ? [dot({
|
|
46
|
+
...at,
|
|
47
|
+
r: DOT,
|
|
48
|
+
part: "dot",
|
|
49
|
+
key: item.key
|
|
50
|
+
})] : [dot({
|
|
51
|
+
...at,
|
|
52
|
+
r: dotReach(item.r) + HALO,
|
|
53
|
+
hollow: true,
|
|
54
|
+
part: "guide"
|
|
55
|
+
}), dot({
|
|
56
|
+
...at,
|
|
57
|
+
r: item.r,
|
|
58
|
+
part: "dot",
|
|
59
|
+
key: item.key
|
|
60
|
+
})];
|
|
61
|
+
})];
|
|
62
|
+
}
|
|
63
|
+
export { litNodes };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { wordsOf } from "../data/words.mjs";
|
|
2
|
+
import { fitText } from "../text/measure.mjs";
|
|
3
|
+
import { TEXT } from "../theme.mjs";
|
|
4
|
+
// src/marks/more.ts
|
|
5
|
+
/** The line that says how many things there was no room for, its middle at `y`; nothing for none. */
|
|
6
|
+
function moreLine(left, at) {
|
|
7
|
+
if (left <= 0) return [];
|
|
8
|
+
return [{
|
|
9
|
+
kind: "text",
|
|
10
|
+
part: "more",
|
|
11
|
+
x: at.x ?? 0,
|
|
12
|
+
y: at.y,
|
|
13
|
+
text: fitText(wordsOf(at.env).more(left), at.width, TEXT.tick, at.env.measure),
|
|
14
|
+
...TEXT.tick,
|
|
15
|
+
baseline: "middle"
|
|
16
|
+
}];
|
|
17
|
+
}
|
|
18
|
+
export { moreLine };
|