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,204 @@
|
|
|
1
|
+
import { arrowed } from "../data/format.mjs";
|
|
2
|
+
import { keyOf } from "../data/rows.mjs";
|
|
3
|
+
import { wordsOf } from "../data/words.mjs";
|
|
4
|
+
import { MUTED } from "../scene/paint.mjs";
|
|
5
|
+
import { MARK, SPACE, TEXT, signPaint } from "../theme.mjs";
|
|
6
|
+
import { rateWay, stepText } from "./funnel-data.mjs";
|
|
7
|
+
import { rowBar, rowName } from "./row-marks.mjs";
|
|
8
|
+
// src/kinds/funnel-marks.ts
|
|
9
|
+
/** A step's colour: every step of a funnel is one thing, counted further along, so all share one. */
|
|
10
|
+
const colorOf = (_step, at) => at.own;
|
|
11
|
+
/** One row: its name, and its bars and words when it has a value. */
|
|
12
|
+
function rowNodes(step, slot, at) {
|
|
13
|
+
const name = rowName(step.label, {
|
|
14
|
+
frame: at.layout.frame,
|
|
15
|
+
slot,
|
|
16
|
+
env: at.env,
|
|
17
|
+
key: keyOf(step)
|
|
18
|
+
});
|
|
19
|
+
return step.value === null ? [name] : [name, ...barNodes(step, step.value, slot, at)];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The pale bar of the step before, this step's bar over it, and its words when the numbers have
|
|
23
|
+
* room. The pale bar is the same colour, faint, so the bar on it reads first and what was lost is
|
|
24
|
+
* the pale remainder.
|
|
25
|
+
*/
|
|
26
|
+
function barNodes(step, value, slot, at) {
|
|
27
|
+
const { layout } = at;
|
|
28
|
+
const mid = layout.frame.middle(slot);
|
|
29
|
+
const before = at.flow.before[slot] ?? null;
|
|
30
|
+
const bar = (length, opacity) => rowBar({
|
|
31
|
+
from: layout.x(0),
|
|
32
|
+
to: layout.x(length),
|
|
33
|
+
mid,
|
|
34
|
+
thick: layout.thick,
|
|
35
|
+
fill: colorOf(step, at),
|
|
36
|
+
key: keyOf(step),
|
|
37
|
+
...opacity === void 0 ? {} : { opacity }
|
|
38
|
+
});
|
|
39
|
+
return [
|
|
40
|
+
...before === null ? [] : [{
|
|
41
|
+
...bar(before, MARK.wash),
|
|
42
|
+
part: "lost"
|
|
43
|
+
}],
|
|
44
|
+
bar(value),
|
|
45
|
+
...layout.numbers ? labelNodes(value, slot, {
|
|
46
|
+
...at,
|
|
47
|
+
mid,
|
|
48
|
+
text: stepText(step, at.measure)
|
|
49
|
+
}) : []
|
|
50
|
+
];
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Where a row's words go: in the pale remainder when they fit there whole, else past it, with
|
|
54
|
+
* the share when both fit and the value alone when only it does; nowhere when not even the
|
|
55
|
+
* value fits. `widths` is how wide the value is alone, and with its share.
|
|
56
|
+
*/
|
|
57
|
+
function wordsPlace(value, slot, at, widths) {
|
|
58
|
+
const { env, layout } = at;
|
|
59
|
+
const end = layout.x(value) + SPACE.value;
|
|
60
|
+
const before = at.flow.before[slot] ?? null;
|
|
61
|
+
const lost = before === null ? 0 : layout.x(before);
|
|
62
|
+
const pale = Math.max(end, lost + SPACE.value);
|
|
63
|
+
const inside = (width) => end + width <= (pale === end ? env.width : lost - SPACE.value);
|
|
64
|
+
const past = (width) => pale + width <= env.width;
|
|
65
|
+
const onPale = pale !== end;
|
|
66
|
+
return [
|
|
67
|
+
{
|
|
68
|
+
x: end,
|
|
69
|
+
share: true,
|
|
70
|
+
onPale,
|
|
71
|
+
ok: inside(widths.both)
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
x: pale,
|
|
75
|
+
share: true,
|
|
76
|
+
onPale: false,
|
|
77
|
+
ok: past(widths.both)
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
x: end,
|
|
81
|
+
share: false,
|
|
82
|
+
onPale,
|
|
83
|
+
ok: inside(widths.wide)
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
x: pale,
|
|
87
|
+
share: false,
|
|
88
|
+
onPale: false,
|
|
89
|
+
ok: past(widths.wide)
|
|
90
|
+
}
|
|
91
|
+
].find((place) => place.ok);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* The value past the bar's end, then its share of the first step (from the third step on). Both
|
|
95
|
+
* sit in the pale remainder when they fit there whole, else past it; the share is left out when
|
|
96
|
+
* it fits nowhere.
|
|
97
|
+
* Both are in ink on the pale remainder; past it the share is a tick's grey.
|
|
98
|
+
*/
|
|
99
|
+
function labelNodes(value, slot, at) {
|
|
100
|
+
const { env, text } = at;
|
|
101
|
+
const wide = env.measure(text, TEXT.value);
|
|
102
|
+
const share = at.flow.share[slot] ?? null;
|
|
103
|
+
const ofAll = share === null || slot <= 1 ? "" : wordsOf(env).funnel.ofAll(at.percent(share));
|
|
104
|
+
const place = wordsPlace(value, slot, at, {
|
|
105
|
+
wide,
|
|
106
|
+
both: ofAll === "" ? wide : wide + SPACE.value + env.measure(ofAll, TEXT.tick)
|
|
107
|
+
});
|
|
108
|
+
if (place === void 0) return [];
|
|
109
|
+
const line = {
|
|
110
|
+
kind: "text",
|
|
111
|
+
y: at.mid,
|
|
112
|
+
baseline: "middle"
|
|
113
|
+
};
|
|
114
|
+
const node = {
|
|
115
|
+
...line,
|
|
116
|
+
part: "value",
|
|
117
|
+
x: place.x,
|
|
118
|
+
text,
|
|
119
|
+
...TEXT.value
|
|
120
|
+
};
|
|
121
|
+
if (!place.share || ofAll === "") return [node];
|
|
122
|
+
const x = place.x + wide + SPACE.value;
|
|
123
|
+
const font = place.onPale ? {
|
|
124
|
+
...TEXT.tick,
|
|
125
|
+
fill: TEXT.value.fill
|
|
126
|
+
} : TEXT.tick;
|
|
127
|
+
return [node, {
|
|
128
|
+
...line,
|
|
129
|
+
part: "share",
|
|
130
|
+
x,
|
|
131
|
+
text: ofAll,
|
|
132
|
+
...font
|
|
133
|
+
}];
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* How the step that lost the most is set when its words say so. It is a drop, so it is coloured
|
|
137
|
+
* as a change down by the measure's better way and set with a value's weight; a measure that
|
|
138
|
+
* says no way is better leaves it in the tick's style, and the words alone say it.
|
|
139
|
+
*/
|
|
140
|
+
function leakFont(measure) {
|
|
141
|
+
if (measure.better === void 0) return TEXT.tick;
|
|
142
|
+
return {
|
|
143
|
+
...TEXT.tick,
|
|
144
|
+
fill: signPaint(-1, measure, MUTED),
|
|
145
|
+
weight: TEXT.value.weight
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
/** A rate's plain words: its arrow, the way the number went, and the share that went on. */
|
|
149
|
+
const rateWords = (rate, at) => arrowed(rateWay(rate, at.percent), wordsOf(at.env).funnel.continues(at.percent(rate)));
|
|
150
|
+
/** Where the words between two rows start (off the zero line by the room a number keeps from its bar), and the room they have. */
|
|
151
|
+
function rateRoom(at) {
|
|
152
|
+
const x = at.layout.reach.from + SPACE.value;
|
|
153
|
+
return {
|
|
154
|
+
x,
|
|
155
|
+
room: at.env.width - x
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Whether the rates between the rows drawn are written: every one, or none. They are written
|
|
160
|
+
* when the gaps between the bars hold words and the widest rate fits across: a rate left out
|
|
161
|
+
* beside others would read as a rate that is not known.
|
|
162
|
+
*/
|
|
163
|
+
function ratesWritten(at) {
|
|
164
|
+
if (!at.layout.talks) return false;
|
|
165
|
+
const { room } = rateRoom(at);
|
|
166
|
+
return at.layout.kept.every((_step, slot) => {
|
|
167
|
+
const rate = at.flow.rate[slot] ?? null;
|
|
168
|
+
return rate === null || at.env.measure(rateWords(rate, at), TEXT.tick) <= room;
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* The share that went on from the step before, on the line between two rows, its arrow the way
|
|
173
|
+
* the number went. The step that lost the most is coloured only when the words that say so fit:
|
|
174
|
+
* with no room for them it is written like any other step, since colour alone would say nothing.
|
|
175
|
+
*/
|
|
176
|
+
function rateNodes(slot, at) {
|
|
177
|
+
const rate = at.flow.rate[slot] ?? null;
|
|
178
|
+
if (rate === null || !at.rates) return [];
|
|
179
|
+
const plain = rateWords(rate, at);
|
|
180
|
+
const { x, room } = rateRoom(at);
|
|
181
|
+
const told = {
|
|
182
|
+
text: `${plain} · ${wordsOf(at.env).funnel.largestDrop}`,
|
|
183
|
+
font: leakFont(at.measure),
|
|
184
|
+
part: "leak"
|
|
185
|
+
};
|
|
186
|
+
const quiet = {
|
|
187
|
+
text: plain,
|
|
188
|
+
font: TEXT.tick,
|
|
189
|
+
part: "rate"
|
|
190
|
+
};
|
|
191
|
+
const fitting = (at.flow.leak === slot ? [told, quiet] : [quiet]).find((t) => at.env.measure(t.text, t.font) <= room);
|
|
192
|
+
if (fitting === void 0) return [];
|
|
193
|
+
const { frame } = at.layout;
|
|
194
|
+
return [{
|
|
195
|
+
kind: "text",
|
|
196
|
+
part: fitting.part,
|
|
197
|
+
x,
|
|
198
|
+
y: frame.top + slot * frame.rowHeight,
|
|
199
|
+
text: fitting.text,
|
|
200
|
+
...fitting.font,
|
|
201
|
+
baseline: "middle"
|
|
202
|
+
}];
|
|
203
|
+
}
|
|
204
|
+
export { colorOf, rateNodes, ratesWritten, rowNodes };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { keyOf } from "../data/rows.mjs";
|
|
2
|
+
import { wordsOf } from "../data/words.mjs";
|
|
3
|
+
import { noValue, shownOf, summary, worthSaid } from "../describe.mjs";
|
|
4
|
+
import { stepText } from "./funnel-data.mjs";
|
|
5
|
+
import { colorOf } from "./funnel-marks.mjs";
|
|
6
|
+
import { rowStop } from "./row-marks.mjs";
|
|
7
|
+
// src/kinds/funnel-words.ts
|
|
8
|
+
/** What a pointer finds on a row: its value, read against the first step and the one before. */
|
|
9
|
+
function stopOf(step, slot, at) {
|
|
10
|
+
const { layout, flow } = at;
|
|
11
|
+
const words = wordsOf(at.env).funnel;
|
|
12
|
+
const share = flow.share[slot] ?? null;
|
|
13
|
+
const rate = flow.rate[slot] ?? null;
|
|
14
|
+
const aside = [...share === null || slot === 0 ? [] : [words.ofFirstStep(at.percent(share))], ...rate === null || slot === 1 ? [] : [words.ofStepBefore(at.percent(rate))]].join(", ");
|
|
15
|
+
const items = step.value === null ? [] : [{
|
|
16
|
+
key: "value",
|
|
17
|
+
label: at.measure.label,
|
|
18
|
+
value: stepText(step, at.measure),
|
|
19
|
+
color: colorOf(step, at),
|
|
20
|
+
x: layout.x(step.value),
|
|
21
|
+
y: layout.frame.middle(slot),
|
|
22
|
+
...aside === "" ? {} : { aside }
|
|
23
|
+
}];
|
|
24
|
+
return rowStop(step.label, {
|
|
25
|
+
frame: layout.frame,
|
|
26
|
+
slot,
|
|
27
|
+
key: keyOf(step),
|
|
28
|
+
items,
|
|
29
|
+
nodes: at.nodes,
|
|
30
|
+
env: at.env
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* How many of the first step reached the last, or why that is not known: a step with no value
|
|
35
|
+
* at either end, or a first step of zero, of which no share can be taken.
|
|
36
|
+
*/
|
|
37
|
+
function overallOf(steps, { flow, percent }) {
|
|
38
|
+
const first = steps[0];
|
|
39
|
+
const last = steps.at(-1);
|
|
40
|
+
if (first === void 0 || last === void 0 || steps.length < 2) return void 0;
|
|
41
|
+
const head = `Overall: ${first.label} to ${last.label}`;
|
|
42
|
+
const overall = flow.share.at(-1) ?? null;
|
|
43
|
+
if (overall !== null) return `${head}, ${percent(overall)} continue`;
|
|
44
|
+
return `${head}, not known, as ${first.value === null ? `${first.label} has no value` : last.value === null ? `${last.label} has no value` : `${first.label} is zero`}`;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* "Largest drop: Visited to Trial, 49.7% continue, which is worse"; nothing when no step
|
|
48
|
+
* dropped. A drop is a loss, so it is said to be worse where more is better and better where
|
|
49
|
+
* fewer is, as its colour says in the picture.
|
|
50
|
+
*/
|
|
51
|
+
function dropOf(steps, { flow, percent, measure }) {
|
|
52
|
+
if (flow.leak === null) return void 0;
|
|
53
|
+
const rate = flow.rate[flow.leak] ?? null;
|
|
54
|
+
const from = steps[flow.leak - 1];
|
|
55
|
+
const to = steps[flow.leak];
|
|
56
|
+
if (rate === null || from === void 0 || to === void 0) return void 0;
|
|
57
|
+
const worth = worthSaid(-1, measure);
|
|
58
|
+
return `Largest drop: ${from.label} to ${to.label}, ${percent(rate)} continue${worth}`;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The funnel in words: how many steps, how many of the first reached the last, the drop, and
|
|
62
|
+
* how many steps had no value (a step below zero among them: the funnel takes it as missing).
|
|
63
|
+
* It is handed the flow the picture is drawn from, so the two cannot disagree.
|
|
64
|
+
*/
|
|
65
|
+
function describeFunnel(data, at) {
|
|
66
|
+
const { steps } = data;
|
|
67
|
+
const told = {
|
|
68
|
+
...at,
|
|
69
|
+
flow: data.flow
|
|
70
|
+
};
|
|
71
|
+
return summary([`Funnel of ${at.measure.label}`, shownOf(steps.length, at.shown, "step")], [
|
|
72
|
+
overallOf(steps, told),
|
|
73
|
+
dropOf(steps, told),
|
|
74
|
+
noValue(steps.filter((step) => step.value === null).length, "step")
|
|
75
|
+
]);
|
|
76
|
+
}
|
|
77
|
+
export { describeFunnel, stopOf };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Env, Header, Measure } from "../data/types.mjs";
|
|
2
|
+
import { Scene } from "../scene/types.mjs";
|
|
3
|
+
import { FunnelStep } from "./funnel-data.mjs";
|
|
4
|
+
export type FunnelOptions = Header & {
|
|
5
|
+
measure: Measure;
|
|
6
|
+
/** The palette place of the bars' colour. */
|
|
7
|
+
slot?: number;
|
|
8
|
+
};
|
|
9
|
+
/** A funnel of steps in order, each read against the first and the one before it. */
|
|
10
|
+
export declare function funnelChart(given: readonly FunnelStep[], options: FunnelOptions, env: Env): Scene;
|
|
11
|
+
export type { FunnelStep };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { bare, headerNodes } from "../layout/frame.mjs";
|
|
2
|
+
import { seriesPaint } from "../theme.mjs";
|
|
3
|
+
import { rowsMore, rowsZero } from "./row-marks.mjs";
|
|
4
|
+
import { cleaned, flowOf, sharePercent } from "./funnel-data.mjs";
|
|
5
|
+
import { layoutOf } from "./funnel-layout.mjs";
|
|
6
|
+
import { rateNodes, ratesWritten, rowNodes } from "./funnel-marks.mjs";
|
|
7
|
+
import { describeFunnel, stopOf } from "./funnel-words.mjs";
|
|
8
|
+
import { hasRoom } from "./row-chart.mjs";
|
|
9
|
+
// src/kinds/funnel.ts
|
|
10
|
+
/** A funnel of steps in order, each read against the first and the one before it. */
|
|
11
|
+
function funnelChart(given, options, env) {
|
|
12
|
+
const { measure } = options;
|
|
13
|
+
const steps = cleaned(given);
|
|
14
|
+
const percent = sharePercent(env.locale);
|
|
15
|
+
const flow = flowOf(steps.map((s) => s.value), {
|
|
16
|
+
measure,
|
|
17
|
+
percent
|
|
18
|
+
});
|
|
19
|
+
const layout = layoutOf(steps, options, env);
|
|
20
|
+
const { frame, kept, plot } = layout;
|
|
21
|
+
const roomy = hasRoom(frame, layout.reach, layout.drawn);
|
|
22
|
+
const summary = describeFunnel({
|
|
23
|
+
steps,
|
|
24
|
+
flow
|
|
25
|
+
}, {
|
|
26
|
+
measure,
|
|
27
|
+
percent,
|
|
28
|
+
shown: roomy ? kept.length : 0
|
|
29
|
+
});
|
|
30
|
+
if (!roomy) return bare(env, options, summary);
|
|
31
|
+
const drawn = {
|
|
32
|
+
layout,
|
|
33
|
+
flow,
|
|
34
|
+
own: seriesPaint(options.slot ?? 0),
|
|
35
|
+
measure,
|
|
36
|
+
percent,
|
|
37
|
+
env
|
|
38
|
+
};
|
|
39
|
+
const at = {
|
|
40
|
+
...drawn,
|
|
41
|
+
rates: ratesWritten(drawn)
|
|
42
|
+
};
|
|
43
|
+
const placed = kept.map((step, slot) => ({
|
|
44
|
+
step,
|
|
45
|
+
slot,
|
|
46
|
+
nodes: rowNodes(step, slot, at)
|
|
47
|
+
}));
|
|
48
|
+
return {
|
|
49
|
+
width: env.width,
|
|
50
|
+
height: env.height,
|
|
51
|
+
plot,
|
|
52
|
+
summary,
|
|
53
|
+
nodes: [
|
|
54
|
+
...headerNodes(env, options),
|
|
55
|
+
...placed.flatMap(({ slot, nodes }) => [...rateNodes(slot, at), ...nodes]),
|
|
56
|
+
...rowsZero(placed.map(({ slot }) => slot), {
|
|
57
|
+
frame,
|
|
58
|
+
x: layout.x,
|
|
59
|
+
plot
|
|
60
|
+
}),
|
|
61
|
+
...rowsMore(steps.length - placed.length, {
|
|
62
|
+
frame,
|
|
63
|
+
env
|
|
64
|
+
})
|
|
65
|
+
],
|
|
66
|
+
hover: {
|
|
67
|
+
snap: "y",
|
|
68
|
+
stops: placed.map(({ step, slot, nodes }) => stopOf(step, slot, {
|
|
69
|
+
...at,
|
|
70
|
+
nodes
|
|
71
|
+
}))
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
export { funnelChart };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Named } from "../data/rows.mjs";
|
|
2
|
+
import { Value } from "../data/types.mjs";
|
|
3
|
+
export type GridData = {
|
|
4
|
+
/** The rows and the columns, each by its label and, when two may share one, its key. */
|
|
5
|
+
rows: readonly Named[];
|
|
6
|
+
/** How neighbouring time buckets were averaged across the grid, when applicable. */
|
|
7
|
+
mergeNote?: string;
|
|
8
|
+
columns: readonly (Named & {
|
|
9
|
+
note?: string;
|
|
10
|
+
})[];
|
|
11
|
+
/** `values[row][column]`. */
|
|
12
|
+
values: readonly (readonly Value[])[];
|
|
13
|
+
/**
|
|
14
|
+
* `texts[row][column]`: a value as the host writes it, where it has its own text for it (an
|
|
15
|
+
* exact amount keeps every digit a float would lose); the measure's text where left out.
|
|
16
|
+
*/
|
|
17
|
+
texts?: readonly (readonly (string | undefined)[])[];
|
|
18
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { drawable, finiteRange } from "../data/clean.mjs";
|
|
2
|
+
import { fractionAlong, least, most } from "../data/range.mjs";
|
|
3
|
+
// src/kinds/grid-data.ts
|
|
4
|
+
/** The grid as it can be drawn: a value that is not a finite number is none. */
|
|
5
|
+
const cleaned = (data) => ({
|
|
6
|
+
...data,
|
|
7
|
+
values: data.values.map((row) => row.map((v) => drawable(v)))
|
|
8
|
+
});
|
|
9
|
+
/**
|
|
10
|
+
* How dark a value's cell is, from 0 to 1 across the range given, else the data's own. A range
|
|
11
|
+
* of one value (every cell alike, or one cell) is opened from zero to it, as a value axis opens
|
|
12
|
+
* a flat span: values all alike and above zero are drawn deep, not as the lowest there could be.
|
|
13
|
+
*/
|
|
14
|
+
function shadeOf(from, to) {
|
|
15
|
+
const [low, high] = from === to ? [Math.min(0, from), Math.max(0, to)] : [from, to];
|
|
16
|
+
const fraction = fractionAlong(low, high);
|
|
17
|
+
return (value) => Math.max(0, Math.min(1, fraction(value)));
|
|
18
|
+
}
|
|
19
|
+
/** A shared zero and equal strength at equal distances from it on a mixed-sign heatmap. */
|
|
20
|
+
function colorsOf(data, range, diverging = false) {
|
|
21
|
+
const all = data.values.flat().filter((v) => v !== null);
|
|
22
|
+
const [low, high] = finiteRange(range) ?? [least(all), most(all)];
|
|
23
|
+
if (diverging && low < 0 && high > 0) {
|
|
24
|
+
const magnitude = Math.max(-low, high);
|
|
25
|
+
return {
|
|
26
|
+
mixed: true,
|
|
27
|
+
shade: (value) => Math.min(1, Math.abs(value) / magnitude)
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
mixed: false,
|
|
32
|
+
shade: shadeOf(low, high)
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export { cleaned, colorsOf };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { keyOf, pairKey } from "../data/rows.mjs";
|
|
2
|
+
import { widest } from "../text/measure.mjs";
|
|
3
|
+
import { LINE, MARK, TEXT } from "../theme.mjs";
|
|
4
|
+
import { rowFrame, rowPlot } from "./row-chart.mjs";
|
|
5
|
+
// src/kinds/grid-layout.ts
|
|
6
|
+
/** The room the column names take over the cells: a line of them, and the grid's own gap under it. */
|
|
7
|
+
const HEAD = LINE.tick + 6;
|
|
8
|
+
/** A row is this tall at most. */
|
|
9
|
+
const TALLEST = 30;
|
|
10
|
+
/** The room a cell keeps around its number, across and down. */
|
|
11
|
+
const INSET = {
|
|
12
|
+
across: 6,
|
|
13
|
+
down: 4
|
|
14
|
+
};
|
|
15
|
+
/** Whether a cell's number fits inside it. */
|
|
16
|
+
const fits = (cell, measure, env) => env.measure(measure.tick(cell.value), TEXT.value) <= cell.box.width - INSET.across && cell.box.height >= TEXT.value.size + INSET.down;
|
|
17
|
+
/** Where the rows, the sizes and the cells go. */
|
|
18
|
+
function layoutOf(data, options, env) {
|
|
19
|
+
const frame = rowFrame(data.rows.map((row) => row.label), {
|
|
20
|
+
header: options,
|
|
21
|
+
above: HEAD,
|
|
22
|
+
most: TALLEST,
|
|
23
|
+
...options.rowTitle === void 0 ? {} : { also: [options.rowTitle] }
|
|
24
|
+
}, env);
|
|
25
|
+
const sized = options.sizes === void 0 ? [] : [...options.sizes, options.sizeTitle ?? ""];
|
|
26
|
+
const sizes = sized.length === 0 ? 0 : Math.ceil(widest(sized, TEXT.name, env.measure)) + 14;
|
|
27
|
+
const x = frame.left + sizes;
|
|
28
|
+
const width = Math.max(1, env.width - x);
|
|
29
|
+
const across = {
|
|
30
|
+
from: x,
|
|
31
|
+
to: x + width
|
|
32
|
+
};
|
|
33
|
+
const placed = {
|
|
34
|
+
frame,
|
|
35
|
+
sizes,
|
|
36
|
+
step: width / Math.max(1, data.columns.length),
|
|
37
|
+
plot: rowPlot(frame, across, frame.shown)
|
|
38
|
+
};
|
|
39
|
+
const filled = cellsOf(data, placed);
|
|
40
|
+
return {
|
|
41
|
+
...placed,
|
|
42
|
+
kept: data.rows.slice(0, frame.shown),
|
|
43
|
+
across,
|
|
44
|
+
filled,
|
|
45
|
+
empty: emptyOf(data, placed),
|
|
46
|
+
drawn: data.values.some((row) => row.some((value) => value !== null)),
|
|
47
|
+
numbers: filled.every((cell) => fits(cell, options.measure, env))
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/** The box of the cell at a row and a column of those drawn. */
|
|
51
|
+
const boxAt = (at, layout) => ({
|
|
52
|
+
x: layout.plot.x + at.column * layout.step,
|
|
53
|
+
y: layout.plot.y + at.row * layout.frame.rowHeight,
|
|
54
|
+
width: Math.max(MARK.least, layout.step - MARK.hair),
|
|
55
|
+
height: Math.max(MARK.least, layout.frame.rowHeight - MARK.hair)
|
|
56
|
+
});
|
|
57
|
+
/** Every place of the rows drawn, with the value the data has there, if any. */
|
|
58
|
+
const placesOf = (data, shown) => data.rows.slice(0, shown).flatMap((named, row) => data.columns.map((across, column) => ({
|
|
59
|
+
row,
|
|
60
|
+
column,
|
|
61
|
+
key: pairKey(keyOf(named), keyOf(across)),
|
|
62
|
+
value: data.values[row]?.[column] ?? null
|
|
63
|
+
})));
|
|
64
|
+
/** Every cell of the rows drawn that has a value, with its box. */
|
|
65
|
+
function cellsOf(data, layout) {
|
|
66
|
+
return placesOf(data, layout.frame.shown).flatMap((place) => place.value === null ? [] : [{
|
|
67
|
+
...place,
|
|
68
|
+
value: place.value,
|
|
69
|
+
box: boxAt(place, layout)
|
|
70
|
+
}]);
|
|
71
|
+
}
|
|
72
|
+
/** Every place of the rows drawn that has no value, with its box. */
|
|
73
|
+
const emptyOf = (data, layout) => placesOf(data, layout.frame.shown).flatMap(({ value, ...place }) => value === null ? [{
|
|
74
|
+
...place,
|
|
75
|
+
box: boxAt(place, layout)
|
|
76
|
+
}] : []);
|
|
77
|
+
export { layoutOf };
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { keyOf } from "../data/rows.mjs";
|
|
2
|
+
import { MUTED, SURFACE } from "../scene/paint.mjs";
|
|
3
|
+
import { fitOrNone, fitText } from "../text/measure.mjs";
|
|
4
|
+
import { LINE, MARK, SPACE, TEXT } from "../theme.mjs";
|
|
5
|
+
import { rowName } from "./row-marks.mjs";
|
|
6
|
+
// src/kinds/grid-marks.ts
|
|
7
|
+
/** How far over the cells the middle of their columns' names sits: half a line of them. */
|
|
8
|
+
const OVER = LINE.tick / 2;
|
|
9
|
+
/**
|
|
10
|
+
* How strong the hue is in the palest and the deepest cell. The deepest stops short of the full
|
|
11
|
+
* hue, so the ink a cell's number is written in reads on every cell, in a light and a dark theme.
|
|
12
|
+
*/
|
|
13
|
+
const PALEST = .08;
|
|
14
|
+
const DEEPEST_WITH_TEXT = .51;
|
|
15
|
+
const DEEPEST_WITHOUT_TEXT = .85;
|
|
16
|
+
/**
|
|
17
|
+
* The columns' names over the cells: every one when they fit side by side, else the first at
|
|
18
|
+
* the left and the last at the right, each cut to its half, so no two ever touch.
|
|
19
|
+
*/
|
|
20
|
+
function columnNames(data, layout, env) {
|
|
21
|
+
const { plot, step } = layout;
|
|
22
|
+
const wide = (text) => env.measure(text, TEXT.tick);
|
|
23
|
+
const names = data.columns.map((column) => column.label);
|
|
24
|
+
if (names.every((name) => wide(name) <= step - MARK.hair)) return names.map((text, i) => ({
|
|
25
|
+
text,
|
|
26
|
+
x: plot.x + (i + .5) * step,
|
|
27
|
+
anchor: "middle"
|
|
28
|
+
}));
|
|
29
|
+
const half = (plot.width - SPACE.ticks) / 2;
|
|
30
|
+
const cut = (text) => text === void 0 ? void 0 : fitOrNone(text, {
|
|
31
|
+
width: half,
|
|
32
|
+
font: TEXT.tick,
|
|
33
|
+
measure: env.measure
|
|
34
|
+
});
|
|
35
|
+
const first = cut(names[0]);
|
|
36
|
+
const last = cut(names.length > 1 ? names.at(-1) : void 0);
|
|
37
|
+
return [...first === void 0 ? [] : [{
|
|
38
|
+
text: first,
|
|
39
|
+
x: plot.x,
|
|
40
|
+
anchor: "start"
|
|
41
|
+
}], ...last === void 0 ? [] : [{
|
|
42
|
+
text: last,
|
|
43
|
+
x: plot.x + plot.width,
|
|
44
|
+
anchor: "end"
|
|
45
|
+
}]];
|
|
46
|
+
}
|
|
47
|
+
/** The words over the grid: the title over the names, the one over the sizes, and the columns' names. */
|
|
48
|
+
function heads(data, options, at) {
|
|
49
|
+
const { layout, env } = at;
|
|
50
|
+
const { names } = layout.frame;
|
|
51
|
+
const fit = (text, room) => fitText(text, room, TEXT.tick, env.measure);
|
|
52
|
+
return [...[...options.rowTitle === void 0 ? [] : [{
|
|
53
|
+
text: fit(options.rowTitle, names),
|
|
54
|
+
x: 0,
|
|
55
|
+
anchor: "start"
|
|
56
|
+
}], ...options.sizeTitle === void 0 ? [] : [{
|
|
57
|
+
text: fit(options.sizeTitle, layout.sizes - 14),
|
|
58
|
+
x: names + layout.sizes,
|
|
59
|
+
anchor: "end"
|
|
60
|
+
}]], ...columnNames(data, layout, env)].filter((word) => word.text !== "").map((word) => ({
|
|
61
|
+
kind: "text",
|
|
62
|
+
part: "column",
|
|
63
|
+
y: layout.plot.y - OVER,
|
|
64
|
+
...TEXT.tick,
|
|
65
|
+
...word
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
68
|
+
/** Each row's name at the left, and its size beside it. */
|
|
69
|
+
function sides(options, at) {
|
|
70
|
+
const { frame, kept } = at.layout;
|
|
71
|
+
return [...kept.map((row, slot) => rowName(row.label, {
|
|
72
|
+
frame,
|
|
73
|
+
slot,
|
|
74
|
+
env: at.env,
|
|
75
|
+
key: keyOf(row)
|
|
76
|
+
})), ...(options.sizes ?? []).slice(0, kept.length).map((text, slot) => ({
|
|
77
|
+
kind: "text",
|
|
78
|
+
part: "size",
|
|
79
|
+
x: frame.names + at.layout.sizes,
|
|
80
|
+
y: frame.middle(slot),
|
|
81
|
+
text,
|
|
82
|
+
...TEXT.tick,
|
|
83
|
+
anchor: "end",
|
|
84
|
+
baseline: "middle"
|
|
85
|
+
}))];
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* The cells with no value: each an outline in the hairline's colour on the bare surface. The
|
|
89
|
+
* palest shade is close to the surface, so an empty cell is drawn as empty, and never left to
|
|
90
|
+
* be told from a low value by its shade alone.
|
|
91
|
+
*/
|
|
92
|
+
const emptyNodes = (layout) => layout.empty.map(({ key, box }) => ({
|
|
93
|
+
kind: "rect",
|
|
94
|
+
part: "grid",
|
|
95
|
+
key,
|
|
96
|
+
x: box.x + MARK.hair / 2,
|
|
97
|
+
y: box.y + MARK.hair / 2,
|
|
98
|
+
width: Math.max(0, box.width - MARK.hair),
|
|
99
|
+
height: Math.max(0, box.height - MARK.hair),
|
|
100
|
+
radius: MARK.round,
|
|
101
|
+
fill: SURFACE,
|
|
102
|
+
stroke: MUTED,
|
|
103
|
+
strokeWidth: MARK.hair
|
|
104
|
+
}));
|
|
105
|
+
/** A cell's colour: the grid's one hue, whatever its value. What its stop's swatch wears too. */
|
|
106
|
+
const colorOf = (cell, at) => at.mixed && cell.value < 0 ? at.negative : at.own;
|
|
107
|
+
/** How a cell is filled: its colour, as strong as its value is high. */
|
|
108
|
+
function shadeOf(cell, at) {
|
|
109
|
+
const deepest = at.layout.numbers ? DEEPEST_WITH_TEXT : DEEPEST_WITHOUT_TEXT;
|
|
110
|
+
return {
|
|
111
|
+
fill: colorOf(cell, at),
|
|
112
|
+
opacity: PALEST + (deepest - PALEST) * at.shade(cell.value)
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* A cell: its shade, and its number when the cells' numbers are written. They are written in
|
|
117
|
+
* every cell or in none, so a cell with no number is never taken for a cell with no value.
|
|
118
|
+
*/
|
|
119
|
+
function cellNodes(cell, at) {
|
|
120
|
+
const { box } = cell;
|
|
121
|
+
const text = at.measure.tick(cell.value);
|
|
122
|
+
return [{
|
|
123
|
+
kind: "rect",
|
|
124
|
+
part: "cell",
|
|
125
|
+
key: cell.key,
|
|
126
|
+
...box,
|
|
127
|
+
radius: MARK.round,
|
|
128
|
+
...shadeOf(cell, at)
|
|
129
|
+
}, ...at.layout.numbers ? [{
|
|
130
|
+
kind: "text",
|
|
131
|
+
part: "value",
|
|
132
|
+
x: box.x + box.width / 2,
|
|
133
|
+
y: box.y + box.height / 2,
|
|
134
|
+
text,
|
|
135
|
+
...TEXT.value,
|
|
136
|
+
anchor: "middle",
|
|
137
|
+
baseline: "middle"
|
|
138
|
+
}] : []];
|
|
139
|
+
}
|
|
140
|
+
export { cellNodes, colorOf, emptyNodes, heads, sides };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ChartInputError } from "../data/input-error.mjs";
|
|
2
|
+
import { keyOf, pairKey } from "../data/rows.mjs";
|
|
3
|
+
import { wordsOf } from "../data/words.mjs";
|
|
4
|
+
import { timeScale } from "../scale/time.mjs";
|
|
5
|
+
import { evenSize, meanIn, mergeOf, sizeFor } from "./columns-data.mjs";
|
|
6
|
+
// src/kinds/grid-time.ts
|
|
7
|
+
/** A heat cell needs three pixels including its gutter. Unlike a bar it fills its entire band. */
|
|
8
|
+
const CELL = 3;
|
|
9
|
+
/** The same time stretches and finite means as columns. A singleton keeps its exact text and drill key. */
|
|
10
|
+
function fitTimeGrid(data, time, env) {
|
|
11
|
+
if (data.columns.length !== time.buckets.length) throw new ChartInputError("columns", "Expected one grid column per time bucket.");
|
|
12
|
+
const width = Math.max(1, env.width);
|
|
13
|
+
if (data.columns.length * CELL <= width) return data;
|
|
14
|
+
const scale = timeScale(time, {
|
|
15
|
+
from: 0,
|
|
16
|
+
to: width
|
|
17
|
+
}, true);
|
|
18
|
+
const size = sizeFor(scale.band, CELL, 1);
|
|
19
|
+
const merge = mergeOf(time, size);
|
|
20
|
+
const { slots } = merge;
|
|
21
|
+
if (slots.length === data.columns.length) return data;
|
|
22
|
+
const words = wordsOf(env);
|
|
23
|
+
const columns = slots.map(({ from, to }) => {
|
|
24
|
+
const first = data.columns[from];
|
|
25
|
+
const last = data.columns[to - 1];
|
|
26
|
+
if (first === void 0 || last === void 0) throw new ChartInputError("columns", "A time grid needs one column per time bucket.");
|
|
27
|
+
return to === from + 1 ? first : {
|
|
28
|
+
key: pairKey(keyOf(first), keyOf(last)),
|
|
29
|
+
label: first.label + " – " + last.label,
|
|
30
|
+
note: words.averaged(to - from)
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
return {
|
|
34
|
+
rows: data.rows,
|
|
35
|
+
columns,
|
|
36
|
+
mergeNote: words.merged(size, time.grain, evenSize(merge) !== size),
|
|
37
|
+
values: data.values.map((row) => slots.map((slot) => meanIn(row, slot))),
|
|
38
|
+
...data.texts === void 0 ? {} : { texts: data.texts.map((row) => slots.map(({ from, to }) => to === from + 1 ? row[from] : void 0)) }
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export { fitTimeGrid };
|