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,68 @@
|
|
|
1
|
+
import { bare, headerNodes } from "../layout/frame.mjs";
|
|
2
|
+
import { paintsOf, seriesPaint } from "../theme.mjs";
|
|
3
|
+
import { cleaned, ordered } from "./bars-data.mjs";
|
|
4
|
+
import { rowsMore, rowsZero } from "./row-marks.mjs";
|
|
5
|
+
import { layoutOf } from "./bars-layout.mjs";
|
|
6
|
+
import { rowNodes } from "./bars-marks.mjs";
|
|
7
|
+
import { describeBars, stopOf } from "./bars-words.mjs";
|
|
8
|
+
import { hasRoom } from "./row-chart.mjs";
|
|
9
|
+
// src/kinds/bars.ts
|
|
10
|
+
/** Ranked bars of one measure by category. */
|
|
11
|
+
function barChart(rows, options, env) {
|
|
12
|
+
const { measure, focus } = options;
|
|
13
|
+
const all = ordered(cleaned(rows), options.sort);
|
|
14
|
+
const { frame, reach, x, kept, moreSlot, drawn, numbers, plot } = layoutOf(all, options, env);
|
|
15
|
+
const roomy = hasRoom(frame, reach, drawn);
|
|
16
|
+
const summary = describeBars(all, {
|
|
17
|
+
shown: roomy ? kept.length : 0,
|
|
18
|
+
measure,
|
|
19
|
+
focus
|
|
20
|
+
});
|
|
21
|
+
if (!roomy) return bare(env, options, summary);
|
|
22
|
+
const own = seriesPaint(options.slot ?? 0);
|
|
23
|
+
const tones = paintsOf(all, own);
|
|
24
|
+
const at = {
|
|
25
|
+
frame,
|
|
26
|
+
x,
|
|
27
|
+
measure,
|
|
28
|
+
focus,
|
|
29
|
+
own,
|
|
30
|
+
paints: new Map(all.map((row, i) => [row, tones[i] ?? own])),
|
|
31
|
+
numbers,
|
|
32
|
+
env
|
|
33
|
+
};
|
|
34
|
+
const placed = kept.map(({ row, slot }) => ({
|
|
35
|
+
row,
|
|
36
|
+
slot,
|
|
37
|
+
nodes: rowNodes(row, slot, at)
|
|
38
|
+
}));
|
|
39
|
+
return {
|
|
40
|
+
width: env.width,
|
|
41
|
+
height: env.height,
|
|
42
|
+
plot,
|
|
43
|
+
summary,
|
|
44
|
+
nodes: [
|
|
45
|
+
...headerNodes(env, options),
|
|
46
|
+
...placed.flatMap(({ nodes }) => nodes),
|
|
47
|
+
...rowsZero(placed.map(({ slot }) => slot), {
|
|
48
|
+
frame,
|
|
49
|
+
x,
|
|
50
|
+
plot
|
|
51
|
+
}),
|
|
52
|
+
...rowsMore(all.length - placed.length, {
|
|
53
|
+
frame,
|
|
54
|
+
env,
|
|
55
|
+
slot: moreSlot
|
|
56
|
+
})
|
|
57
|
+
],
|
|
58
|
+
hover: {
|
|
59
|
+
snap: "y",
|
|
60
|
+
stops: placed.map(({ row, slot, nodes }) => stopOf(row, slot, {
|
|
61
|
+
...at,
|
|
62
|
+
againstLabel: options.againstLabel,
|
|
63
|
+
nodes
|
|
64
|
+
}))
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
export { barChart };
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { least } from "../data/range.mjs";
|
|
2
|
+
import { stackHeights } from "../layout/stack.mjs";
|
|
3
|
+
// src/kinds/columns-data.ts
|
|
4
|
+
/** A column fills this much of its bucket's band. */
|
|
5
|
+
const FILL = .72;
|
|
6
|
+
/** A width a float's rounding under what is needed is wide enough. */
|
|
7
|
+
const ROUNDING = 1e-9;
|
|
8
|
+
/**
|
|
9
|
+
* How many buckets a column holds so that it is `needed` pixels wide, where one bucket's band
|
|
10
|
+
* is `band` wide: the fewest that are enough, and one when a bucket's own column is.
|
|
11
|
+
*/
|
|
12
|
+
const sizeFor = (band, needed, fill = FILL) => band > 0 ? Math.max(1, Math.ceil(needed / (band * fill) - ROUNDING)) : 1;
|
|
13
|
+
/** Every bucket in a column of its own. */
|
|
14
|
+
const apart = (x) => ({
|
|
15
|
+
size: 1,
|
|
16
|
+
slots: x.buckets.map((bucket, i) => ({
|
|
17
|
+
from: i,
|
|
18
|
+
to: i + 1,
|
|
19
|
+
start: bucket.from,
|
|
20
|
+
end: bucket.to,
|
|
21
|
+
label: bucket.label,
|
|
22
|
+
partial: bucket.partial !== void 0
|
|
23
|
+
})),
|
|
24
|
+
slotOf: x.buckets.map((_bucket, i) => i)
|
|
25
|
+
});
|
|
26
|
+
/**
|
|
27
|
+
* The buckets in columns of `size`: time is cut into equal stretches, each as long as `size` of
|
|
28
|
+
* the shortest bucket, from the first bucket's start; a bucket is drawn in the stretch its
|
|
29
|
+
* middle falls in, and the last stretch runs to the end, so no column is narrower than the
|
|
30
|
+
* rest. A stretch with no bucket has no column: a gap that wide still shows.
|
|
31
|
+
*/
|
|
32
|
+
function mergeOf(x, size) {
|
|
33
|
+
const [first] = x.buckets;
|
|
34
|
+
const last = x.buckets.at(-1);
|
|
35
|
+
const span = size * least(x.buckets.map((bucket) => bucket.to - bucket.from));
|
|
36
|
+
if (size <= 1 || first === void 0 || last === void 0 || !(span > 0)) return apart(x);
|
|
37
|
+
const count = Math.max(1, Math.floor((last.to - first.from) / span));
|
|
38
|
+
const stretch = x.buckets.map((bucket) => Math.min(count - 1, Math.floor(((bucket.from + bucket.to) / 2 - first.from) / span)));
|
|
39
|
+
const slots = [];
|
|
40
|
+
return {
|
|
41
|
+
size,
|
|
42
|
+
slots,
|
|
43
|
+
slotOf: x.buckets.map((bucket, i) => {
|
|
44
|
+
const at = stretch[i] ?? 0;
|
|
45
|
+
if (at !== stretch[i - 1]) {
|
|
46
|
+
const start = first.from + at * span;
|
|
47
|
+
const end = at === count - 1 ? last.to : start + span;
|
|
48
|
+
slots.push({
|
|
49
|
+
from: i,
|
|
50
|
+
to: i + 1,
|
|
51
|
+
start,
|
|
52
|
+
end,
|
|
53
|
+
label: bucket.label,
|
|
54
|
+
partial: false
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
const slot = slots.at(-1);
|
|
58
|
+
if (slot !== void 0) {
|
|
59
|
+
slot.to = i + 1;
|
|
60
|
+
slot.partial ||= bucket.partial !== void 0;
|
|
61
|
+
}
|
|
62
|
+
return slots.length - 1;
|
|
63
|
+
})
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/** How many of a column's buckets have a value in any series: what a stack's parts are averaged over. */
|
|
67
|
+
function valuedIn(series, slot) {
|
|
68
|
+
let count = 0;
|
|
69
|
+
for (let i = slot.from; i < slot.to; i++) if (series.some((one) => (one.values[i] ?? null) !== null)) count += 1;
|
|
70
|
+
return count;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The average of a series' values in a column; none when it has no value there. Over `of`
|
|
74
|
+
* buckets when given (a stack's part counts as nothing where it is missing and another part
|
|
75
|
+
* is not, as it does in a column of one bucket), else over the buckets where it has a value.
|
|
76
|
+
* Worked out as it goes, so values near the largest a float holds do not add up past it.
|
|
77
|
+
*/
|
|
78
|
+
function meanIn(values, slot, of) {
|
|
79
|
+
let mean = 0;
|
|
80
|
+
let count = 0;
|
|
81
|
+
for (let i = slot.from; i < slot.to; i++) {
|
|
82
|
+
const value = values[i] ?? null;
|
|
83
|
+
if (value === null) continue;
|
|
84
|
+
count += 1;
|
|
85
|
+
mean += value / count - mean / count;
|
|
86
|
+
}
|
|
87
|
+
if (count === 0) return null;
|
|
88
|
+
return of === void 0 ? mean : mean * (count / of);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* The series as their columns are drawn: one value a column, the average of the column's
|
|
92
|
+
* buckets. With every bucket in a column of its own, the series as they are.
|
|
93
|
+
*/
|
|
94
|
+
function mergedSeries(series, merge, stack) {
|
|
95
|
+
if (merge.size <= 1) return [...series];
|
|
96
|
+
const over = merge.slots.map((slot) => stack ? valuedIn(series, slot) : void 0);
|
|
97
|
+
return series.map((one) => {
|
|
98
|
+
const { previous: _previous, texts: _texts, ...rest } = one;
|
|
99
|
+
return {
|
|
100
|
+
...rest,
|
|
101
|
+
values: merge.slots.map((slot, k) => meanIn(one.values, slot, over[k]))
|
|
102
|
+
};
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
/** Every height the axis must reach: the stacks' ends, or each bar's own value. */
|
|
106
|
+
function heightsOf(series, stack, places) {
|
|
107
|
+
const values = series.map((s) => s.values);
|
|
108
|
+
return stack ? stackHeights(values, places) : values.flat().filter((v) => v !== null);
|
|
109
|
+
}
|
|
110
|
+
/** How many buckets a column holds, when every column holds as many; nothing when they differ. */
|
|
111
|
+
function evenSize(merge) {
|
|
112
|
+
const sizes = new Set(merge.slots.map((slot) => slot.to - slot.from));
|
|
113
|
+
const [size] = sizes;
|
|
114
|
+
return sizes.size === 1 ? size : void 0;
|
|
115
|
+
}
|
|
116
|
+
export { FILL, evenSize, heightsOf, meanIn, mergeOf, mergedSeries, sizeFor };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { mergeOf, sizeFor } from "./columns-data.mjs";
|
|
2
|
+
// src/kinds/columns-layout.ts
|
|
3
|
+
/**
|
|
4
|
+
* The buckets in columns at least `needed` pixels wide each, and the frame they are drawn in.
|
|
5
|
+
* `framed` frames the chart for buckets in columns of a size, with a least left margin. With
|
|
6
|
+
* no room for a frame, every bucket is in a column of its own: nothing is drawn, so nothing is
|
|
7
|
+
* said to be merged.
|
|
8
|
+
*/
|
|
9
|
+
function columnsFor(x, needed, framed) {
|
|
10
|
+
let merge = mergeOf(x, 1);
|
|
11
|
+
let gutter = 0;
|
|
12
|
+
for (;;) {
|
|
13
|
+
const room = framed(merge, gutter);
|
|
14
|
+
if (room === void 0) return {
|
|
15
|
+
merge: mergeOf(x, 1),
|
|
16
|
+
gutter: 0,
|
|
17
|
+
room
|
|
18
|
+
};
|
|
19
|
+
const size = sizeFor(room.frame.time.band, needed);
|
|
20
|
+
if (size <= merge.size || merge.slots.length <= 1) return {
|
|
21
|
+
merge,
|
|
22
|
+
gutter,
|
|
23
|
+
room
|
|
24
|
+
};
|
|
25
|
+
merge = mergeOf(x, size);
|
|
26
|
+
gutter = Math.max(gutter, room.frame.plot.x);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export { columnsFor };
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { pairKey } from "../data/rows.mjs";
|
|
2
|
+
import { stacked } from "../layout/stack.mjs";
|
|
3
|
+
import { zeroIn } from "../marks/axes.mjs";
|
|
4
|
+
import { MARK, paintAt, roundedEnd } from "../theme.mjs";
|
|
5
|
+
import { FILL } from "./columns-data.mjs";
|
|
6
|
+
// src/kinds/columns-marks.ts
|
|
7
|
+
/** A column is never wider than this. */
|
|
8
|
+
const WIDEST = 56;
|
|
9
|
+
/** The room a pointer lights around a column, past its own width. */
|
|
10
|
+
const LIT = 10;
|
|
11
|
+
/**
|
|
12
|
+
* What the columns of a frame are drawn with. A bucket's own column is all one width, the
|
|
13
|
+
* shortest bucket's; a column of several buckets fills its share of the stretch it stands over.
|
|
14
|
+
*/
|
|
15
|
+
function columnAt(frame, paints, rows) {
|
|
16
|
+
const { time } = frame;
|
|
17
|
+
const own = Math.max(1, Math.min(WIDEST, time.band * FILL));
|
|
18
|
+
const stands = rows.merge.slots.map((slot) => {
|
|
19
|
+
const across = time.at(slot.end) - time.at(slot.start);
|
|
20
|
+
return {
|
|
21
|
+
center: (time.at(slot.start) + time.at(slot.end)) / 2,
|
|
22
|
+
width: rows.merge.size > 1 ? across * FILL : own,
|
|
23
|
+
label: slot.label,
|
|
24
|
+
faint: slot.partial
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
const lit = rows.merge.size > 1 ? time.band : Math.min(time.band, own + LIT);
|
|
28
|
+
return {
|
|
29
|
+
frame,
|
|
30
|
+
paints,
|
|
31
|
+
stands,
|
|
32
|
+
given: rows.given,
|
|
33
|
+
slotOf: rows.merge.slotOf,
|
|
34
|
+
lit
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/** A bar's identity: its series and its column's first bucket, as the data names them; none for a column that is not there. */
|
|
38
|
+
function barKey(series, stand) {
|
|
39
|
+
return stand === void 0 ? {} : { key: pairKey(series.key, stand.label) };
|
|
40
|
+
}
|
|
41
|
+
/** A column the data covers only part of, at either end, is drawn faint. */
|
|
42
|
+
const faint = (stand, color) => stand.faint ? {
|
|
43
|
+
opacity: MARK.partialFill,
|
|
44
|
+
stroke: color,
|
|
45
|
+
strokeWidth: MARK.hair,
|
|
46
|
+
dash: MARK.moment
|
|
47
|
+
} : {};
|
|
48
|
+
/** The column a series' value at a bucket is drawn in, and the series' place among those drawn. */
|
|
49
|
+
function drawnAt(at, one, bucket) {
|
|
50
|
+
const slot = at.slotOf[bucket];
|
|
51
|
+
const place = at.given.indexOf(one);
|
|
52
|
+
const stand = slot === void 0 ? void 0 : at.stands[slot];
|
|
53
|
+
return slot === void 0 || stand === void 0 || place < 0 ? void 0 : {
|
|
54
|
+
slot,
|
|
55
|
+
place,
|
|
56
|
+
stand
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/** One segment of a stack: a hair of surface under it, and its outer end rounded when it is the last. */
|
|
60
|
+
function segment(span, at) {
|
|
61
|
+
const { frame, stand } = at;
|
|
62
|
+
const top = frame.place(Math.max(span.from, span.to));
|
|
63
|
+
const bottom = frame.place(Math.min(span.from, span.to));
|
|
64
|
+
const up = span.to > span.from;
|
|
65
|
+
const height = Math.max(MARK.least, bottom - top - (span.from === 0 ? 0 : MARK.hair));
|
|
66
|
+
const y = up ? Math.min(top, frame.place(0) - height) : top;
|
|
67
|
+
return {
|
|
68
|
+
kind: "rect",
|
|
69
|
+
part: "bar",
|
|
70
|
+
...barKey(at.series, stand),
|
|
71
|
+
x: stand.center - stand.width / 2,
|
|
72
|
+
y,
|
|
73
|
+
width: stand.width,
|
|
74
|
+
height,
|
|
75
|
+
fill: at.fill,
|
|
76
|
+
...at.outer ? { radius: roundedEnd(up ? "up" : "down") } : {},
|
|
77
|
+
...faint(stand, at.fill)
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* One column per bucket, its series stacked. Each series is named beside its last segment.
|
|
82
|
+
* `series` are the series as drawn: a value a column.
|
|
83
|
+
*/
|
|
84
|
+
function stackedBars(series, at) {
|
|
85
|
+
const places = at.stands.length;
|
|
86
|
+
const spans = stacked(series.map((s) => s.values), places);
|
|
87
|
+
const outer = (s, i, up) => spans.slice(s + 1).every((later) => {
|
|
88
|
+
const span = later[i];
|
|
89
|
+
return span === void 0 || span.to > span.from !== up;
|
|
90
|
+
});
|
|
91
|
+
const nodes = spans.flatMap((row, s) => row.flatMap((span, i) => {
|
|
92
|
+
const [one, stand] = [series[s], at.stands[i]];
|
|
93
|
+
if (span === void 0 || one === void 0 || stand === void 0) return [];
|
|
94
|
+
if (span.from === span.to) return [];
|
|
95
|
+
const end = outer(s, i, span.to > span.from);
|
|
96
|
+
const fill = paintAt(at.paints, s);
|
|
97
|
+
return [segment(span, {
|
|
98
|
+
frame: at.frame,
|
|
99
|
+
fill,
|
|
100
|
+
series: one,
|
|
101
|
+
stand,
|
|
102
|
+
outer: end
|
|
103
|
+
})];
|
|
104
|
+
}));
|
|
105
|
+
const middle = (s, i) => {
|
|
106
|
+
const span = spans[s]?.[i];
|
|
107
|
+
return span === void 0 ? void 0 : at.frame.place((span.from + span.to) / 2);
|
|
108
|
+
};
|
|
109
|
+
return {
|
|
110
|
+
nodes,
|
|
111
|
+
band: at.lit,
|
|
112
|
+
labelY: (s) => middle(s, places - 1),
|
|
113
|
+
markAt: (one, i) => {
|
|
114
|
+
const drawn = drawnAt(at, one, i);
|
|
115
|
+
const y = drawn === void 0 ? void 0 : middle(drawn.place, drawn.slot);
|
|
116
|
+
return y === void 0 ? void 0 : {
|
|
117
|
+
x: at.frame.time.center(i),
|
|
118
|
+
y
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Each bucket's series side by side, every bar from zero. `series` are the series as drawn: a
|
|
125
|
+
* value a column.
|
|
126
|
+
*/
|
|
127
|
+
function groupedBars(series, at) {
|
|
128
|
+
const { frame } = at;
|
|
129
|
+
const zero = zeroIn(frame.plot, frame.place);
|
|
130
|
+
const count = Math.max(1, series.length);
|
|
131
|
+
/** A series' bar in a column: its left edge and its width. */
|
|
132
|
+
const barIn = (stand, place) => {
|
|
133
|
+
const each = stand.width / count;
|
|
134
|
+
return {
|
|
135
|
+
x: stand.center - stand.width / 2 + place * each,
|
|
136
|
+
width: Math.max(1, each - MARK.hair)
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
return {
|
|
140
|
+
nodes: series.flatMap((s, n) => s.values.flatMap((value, i) => {
|
|
141
|
+
const stand = at.stands[i];
|
|
142
|
+
if (value === null || stand === void 0) return [];
|
|
143
|
+
const height = Math.max(MARK.least, Math.abs(zero - frame.place(value)));
|
|
144
|
+
return [{
|
|
145
|
+
kind: "rect",
|
|
146
|
+
part: "bar",
|
|
147
|
+
...barKey(s, stand),
|
|
148
|
+
...barIn(stand, n),
|
|
149
|
+
y: value >= 0 ? zero - height : zero,
|
|
150
|
+
height,
|
|
151
|
+
fill: paintAt(at.paints, n),
|
|
152
|
+
radius: roundedEnd(value >= 0 ? "up" : "down"),
|
|
153
|
+
...faint(stand, paintAt(at.paints, n))
|
|
154
|
+
}];
|
|
155
|
+
})),
|
|
156
|
+
band: at.lit,
|
|
157
|
+
labelY: () => void 0,
|
|
158
|
+
markAt: (one, i) => {
|
|
159
|
+
const drawn = drawnAt(at, one, i);
|
|
160
|
+
const value = drawn === void 0 ? null : series[drawn.place]?.values[drawn.slot] ?? null;
|
|
161
|
+
const bar = drawn === void 0 ? void 0 : barIn(drawn.stand, drawn.place);
|
|
162
|
+
return bar === void 0 || value === null ? void 0 : {
|
|
163
|
+
x: bar.x + bar.width / 2,
|
|
164
|
+
y: (zero + frame.place(value)) / 2
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
/** A shared column's rectangle belongs to every original reading that contributed to it. */
|
|
170
|
+
function mergedTargets(painted, merge) {
|
|
171
|
+
if (merge.size <= 1) return painted;
|
|
172
|
+
const points = /* @__PURE__ */ new Map();
|
|
173
|
+
for (const mark of painted.nodes) {
|
|
174
|
+
if (mark.kind !== "rect" || mark.key === void 0) continue;
|
|
175
|
+
const { x, y, width, height } = mark;
|
|
176
|
+
points.set(mark.key, {
|
|
177
|
+
x: x + width / 2,
|
|
178
|
+
y: y + height / 2,
|
|
179
|
+
bounds: {
|
|
180
|
+
x,
|
|
181
|
+
y,
|
|
182
|
+
width,
|
|
183
|
+
height
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
const slotAt = (i) => merge.slots[merge.slotOf[i] ?? -1];
|
|
188
|
+
return {
|
|
189
|
+
...painted,
|
|
190
|
+
spanAt: (i) => {
|
|
191
|
+
const slot = slotAt(i);
|
|
192
|
+
return slot === void 0 || slot.to <= slot.from + 1 ? void 0 : [slot.from, slot.to];
|
|
193
|
+
},
|
|
194
|
+
markAt: (series, i) => {
|
|
195
|
+
const slot = slotAt(i);
|
|
196
|
+
return (slot === void 0 ? void 0 : points.get(pairKey(series.key, slot.label))) ?? painted.markAt?.(series, i);
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
export { columnAt, groupedBars, mergedTargets, stackedBars };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { wordsOf } from "../data/words.mjs";
|
|
2
|
+
import { counted } from "../describe.mjs";
|
|
3
|
+
import { evenSize } from "./columns-data.mjs";
|
|
4
|
+
// src/kinds/columns-words.ts
|
|
5
|
+
/**
|
|
6
|
+
* What a chart whose columns hold several buckets says of it; nothing for a chart with a
|
|
7
|
+
* column a bucket. The summary says how many buckets a column averages ("about" when the
|
|
8
|
+
* columns do not all hold as many: months of different lengths, a longer last column); each
|
|
9
|
+
* bucket's stop says how many its own column does.
|
|
10
|
+
*/
|
|
11
|
+
function mergedWords(merge, x, env) {
|
|
12
|
+
if (merge.size <= 1) return {};
|
|
13
|
+
const words = wordsOf(env);
|
|
14
|
+
const each = counted(merge.size, x.grain);
|
|
15
|
+
const said = evenSize(merge) === merge.size ? each : `about ${each}`;
|
|
16
|
+
return {
|
|
17
|
+
footnote: words.merged(merge.size, x.grain, evenSize(merge) !== merge.size),
|
|
18
|
+
also: [`Merged: each column is the average of ${said}`],
|
|
19
|
+
noteAt: (bucket) => {
|
|
20
|
+
const slot = merge.slots[merge.slotOf[bucket] ?? -1];
|
|
21
|
+
const held = slot === void 0 ? 1 : slot.to - slot.from;
|
|
22
|
+
return held > 1 ? words.averaged(held) : void 0;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export { mergedWords };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Env, Header, TimeTable } from "../data/types.mjs";
|
|
2
|
+
import { Scene } from "../scene/types.mjs";
|
|
3
|
+
import { Naming, TimeNotes } from "./time-plan.mjs";
|
|
4
|
+
export type ColumnOptions = Header & TimeNotes & {
|
|
5
|
+
/**
|
|
6
|
+
* Stacked (the default for values that add up), side by side, or as shares of the whole:
|
|
7
|
+
* its scale ends at 100%, and a level marked outside 0 to 100% is not drawn.
|
|
8
|
+
*/
|
|
9
|
+
arrange?: "stacked" | "grouped" | "share";
|
|
10
|
+
naming?: Naming;
|
|
11
|
+
};
|
|
12
|
+
/** A column chart of series over time. */
|
|
13
|
+
export declare function columnChart(given: TimeTable, options: ColumnOptions, env: Env): Scene;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { cleanTable } from "../data/clean.mjs";
|
|
2
|
+
import { addsUp, asShares, levelsOfShares, stackOrder } from "../data/shares.mjs";
|
|
3
|
+
import { paintsOf } from "../theme.mjs";
|
|
4
|
+
import { heightsOf, mergedSeries } from "./columns-data.mjs";
|
|
5
|
+
import { columnsFor } from "./columns-layout.mjs";
|
|
6
|
+
import { columnAt, groupedBars, mergedTargets, stackedBars } from "./columns-marks.mjs";
|
|
7
|
+
import { mergedWords } from "./columns-words.mjs";
|
|
8
|
+
import { namingOf, reachEnd } from "./time-plan.mjs";
|
|
9
|
+
import { framedChart, framedOf } from "./time-chart.mjs";
|
|
10
|
+
// src/kinds/columns.ts
|
|
11
|
+
/** The series to draw and how: shares are stacked; values that do not add up stand side by side. */
|
|
12
|
+
function arranged(table, options, env) {
|
|
13
|
+
const wanted = options.arrange ?? "stacked";
|
|
14
|
+
const series = stackOrder(table.series);
|
|
15
|
+
if (wanted === "grouped" || !addsUp(series)) return {
|
|
16
|
+
series,
|
|
17
|
+
stack: false
|
|
18
|
+
};
|
|
19
|
+
if (wanted === "stacked") return {
|
|
20
|
+
series,
|
|
21
|
+
stack: true
|
|
22
|
+
};
|
|
23
|
+
return {
|
|
24
|
+
series: asShares(series, table.x.buckets.length, env.locale),
|
|
25
|
+
stack: true,
|
|
26
|
+
share: true
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/** What a bucket's own column must be wide to be drawn: a pixel, or side by side a pixel a series. */
|
|
30
|
+
const neededOf = (shape) => shape.stack ? 1 : Math.max(1, shape.series.length);
|
|
31
|
+
/** A column chart of series over time. */
|
|
32
|
+
function columnChart(given, options, env) {
|
|
33
|
+
const table = cleanTable(given);
|
|
34
|
+
const shape = arranged(table, options, env);
|
|
35
|
+
const paints = paintsOf(shape.series);
|
|
36
|
+
const count = shape.series.length;
|
|
37
|
+
const base = {
|
|
38
|
+
what: "Column chart",
|
|
39
|
+
table: {
|
|
40
|
+
x: table.x,
|
|
41
|
+
series: shape.series
|
|
42
|
+
},
|
|
43
|
+
header: options,
|
|
44
|
+
notes: shape.share === true ? {
|
|
45
|
+
...options,
|
|
46
|
+
references: levelsOfShares(options.references)
|
|
47
|
+
} : options,
|
|
48
|
+
paints,
|
|
49
|
+
naming: namingOf(options.naming, {
|
|
50
|
+
series: count,
|
|
51
|
+
named: count,
|
|
52
|
+
atEnds: shape.stack && count > 1 && reachEnd(shape.series),
|
|
53
|
+
header: options,
|
|
54
|
+
env
|
|
55
|
+
}),
|
|
56
|
+
zero: "always",
|
|
57
|
+
bands: true
|
|
58
|
+
};
|
|
59
|
+
/** The plan with its buckets drawn in some columns: the axis reaches the columns' heights. */
|
|
60
|
+
const planOf = (merge, gutter) => ({
|
|
61
|
+
...base,
|
|
62
|
+
...mergedWords(merge, table.x, env),
|
|
63
|
+
values: heightsOf(mergedSeries(shape.series, merge, shape.stack), shape.stack, merge.slots.length),
|
|
64
|
+
gutter
|
|
65
|
+
});
|
|
66
|
+
const { merge, gutter, room } = columnsFor(table.x, neededOf(shape), (tried, left) => framedOf(planOf(tried, left), env));
|
|
67
|
+
const paint = (frame) => {
|
|
68
|
+
const at = columnAt(frame, paints, {
|
|
69
|
+
given: shape.series,
|
|
70
|
+
merge
|
|
71
|
+
});
|
|
72
|
+
const drawn = mergedSeries(shape.series, merge, shape.stack);
|
|
73
|
+
return mergedTargets(shape.stack ? stackedBars(drawn, at) : groupedBars(drawn, at), merge);
|
|
74
|
+
};
|
|
75
|
+
return framedChart(planOf(merge, gutter), env, {
|
|
76
|
+
room,
|
|
77
|
+
paint
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
export { columnChart };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Points } from "../data/format.mjs";
|
|
2
|
+
import { Named } from "../data/rows.mjs";
|
|
3
|
+
import { Measure, Value } from "../data/types.mjs";
|
|
4
|
+
export type DumbbellRow = Named & {
|
|
5
|
+
/** Where it was, and where it is now. */
|
|
6
|
+
from: Value;
|
|
7
|
+
to: Value;
|
|
8
|
+
/** The rest of the rows, as one: it is put last and never named as having moved most. */
|
|
9
|
+
other?: boolean;
|
|
10
|
+
};
|
|
11
|
+
/** How the rows are put in order: by the value now or the change, largest first, or as given. */
|
|
12
|
+
export type DumbbellSort = "value" | "change" | "given";
|
|
13
|
+
/** What a row's change is read by: the measure, and the host's way of writing points for a share. */
|
|
14
|
+
export type Says = {
|
|
15
|
+
measure: Measure;
|
|
16
|
+
/**
|
|
17
|
+
* How a change is written when the values are shares: "4 pts" for a size of 4, never signed.
|
|
18
|
+
* Without it a change is written as its two values ("78% → 88%"), never as a difference that
|
|
19
|
+
* reads as a share.
|
|
20
|
+
*/
|
|
21
|
+
points?: Points | undefined;
|
|
22
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { drawable } from "../data/clean.mjs";
|
|
2
|
+
import { arrowed, changeWritten, movedAsWritten } from "../data/format.mjs";
|
|
3
|
+
import { ranked } from "../data/rows.mjs";
|
|
4
|
+
// src/kinds/dumbbell-data.ts
|
|
5
|
+
/** The rows as they can be drawn: an end that is not a finite number is missing. */
|
|
6
|
+
const cleaned = (rows) => rows.map((row) => ({
|
|
7
|
+
...row,
|
|
8
|
+
from: drawable(row.from),
|
|
9
|
+
to: drawable(row.to)
|
|
10
|
+
}));
|
|
11
|
+
/** A row's change, from then to now; nothing when an end is missing. */
|
|
12
|
+
const changeOf = (row) => row.from === null || row.to === null ? null : row.to - row.from;
|
|
13
|
+
/**
|
|
14
|
+
* A row's change as it is written, with no sign, and which way it reads as having gone, by the
|
|
15
|
+
* shared rule: a share's change in points when the host says how, and no text otherwise, as
|
|
16
|
+
* its two values say it; any other measure moved the way its two values read. No way at all
|
|
17
|
+
* when an end is missing. The arrow, the colour, the sign of a change in points and the row
|
|
18
|
+
* named as moved most all go by this one `sign`.
|
|
19
|
+
*/
|
|
20
|
+
function changeAsWritten(row, says) {
|
|
21
|
+
const { from, to } = row;
|
|
22
|
+
if (from === null || to === null) return {
|
|
23
|
+
text: void 0,
|
|
24
|
+
sign: 0
|
|
25
|
+
};
|
|
26
|
+
const { measure } = says;
|
|
27
|
+
return changeWritten({
|
|
28
|
+
from,
|
|
29
|
+
to
|
|
30
|
+
}, measure, {
|
|
31
|
+
points: says.points,
|
|
32
|
+
own: () => ({
|
|
33
|
+
text: void 0,
|
|
34
|
+
sign: movedAsWritten(from, to, measure.text)
|
|
35
|
+
})
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The rows in drawing order: by the value now or by the change, largest first, rows with none
|
|
40
|
+
* after them; or in the order given. Other is last either way.
|
|
41
|
+
*/
|
|
42
|
+
const ordered = (rows, sort) => ranked(rows, {
|
|
43
|
+
value: (row) => sort === "value" ? row.to : changeOf(row),
|
|
44
|
+
given: sort === "given",
|
|
45
|
+
last: (row) => row.other === true
|
|
46
|
+
});
|
|
47
|
+
/** Whether any row has a value to draw: a dot at either end. */
|
|
48
|
+
const anyValue = (rows) => rows.some((row) => row.from !== null || row.to !== null);
|
|
49
|
+
/** How many rows have no value at either end (no dot at all), and how many lack one end (one dot). */
|
|
50
|
+
const missingEnds = (rows) => ({
|
|
51
|
+
both: rows.filter((row) => row.from === null && row.to === null).length,
|
|
52
|
+
one: rows.filter((row) => row.from === null !== (row.to === null)).length
|
|
53
|
+
});
|
|
54
|
+
/**
|
|
55
|
+
* The number beside the dot now: the arrow that says which way it moved as written, then its
|
|
56
|
+
* value ("↑ 88%"); its value alone when it did not move.
|
|
57
|
+
*/
|
|
58
|
+
const nowText = (row, to, says) => arrowed(changeAsWritten(row, says).sign, says.measure.text(to));
|
|
59
|
+
export { anyValue, changeAsWritten, cleaned, missingEnds, nowText, ordered };
|