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,47 @@
|
|
|
1
|
+
import { finiteRange } from "../data/clean.mjs";
|
|
2
|
+
import { percentText } from "../data/format.mjs";
|
|
3
|
+
import { bare, headerNodes, roomy } from "../layout/frame.mjs";
|
|
4
|
+
import { seriesPaint } from "../theme.mjs";
|
|
5
|
+
import { finiteOf, taken } from "./histogram-data.mjs";
|
|
6
|
+
import { layoutOf } from "./histogram-layout.mjs";
|
|
7
|
+
import { histogramNodes } from "./histogram-marks.mjs";
|
|
8
|
+
import { describeHistogram, stopsOf } from "./histogram-words.mjs";
|
|
9
|
+
// src/kinds/histogram.ts
|
|
10
|
+
/** A histogram of some values: how many fall in each bin of one measure. */
|
|
11
|
+
function histogramChart(given, options, env) {
|
|
12
|
+
const values = finiteOf(given);
|
|
13
|
+
const highlight = finiteRange(options.highlight);
|
|
14
|
+
const layout = layoutOf(values, options, env);
|
|
15
|
+
const at = {
|
|
16
|
+
layout,
|
|
17
|
+
measure: options.measure,
|
|
18
|
+
own: seriesPaint(options.slot ?? 0),
|
|
19
|
+
lit: taken(layout.bins, highlight),
|
|
20
|
+
percent: percentText(env.locale),
|
|
21
|
+
env
|
|
22
|
+
};
|
|
23
|
+
const roomy$1 = values.length > 0 && roomy(layout.plot);
|
|
24
|
+
const summary = describeHistogram({
|
|
25
|
+
given,
|
|
26
|
+
layout,
|
|
27
|
+
lit: at.lit
|
|
28
|
+
}, {
|
|
29
|
+
measure: at.measure,
|
|
30
|
+
percent: at.percent,
|
|
31
|
+
highlight,
|
|
32
|
+
shown: roomy$1 ? layout.bins.length : 0
|
|
33
|
+
});
|
|
34
|
+
if (!roomy$1) return bare(env, options, summary);
|
|
35
|
+
return {
|
|
36
|
+
width: env.width,
|
|
37
|
+
height: env.height,
|
|
38
|
+
plot: layout.plot,
|
|
39
|
+
summary,
|
|
40
|
+
nodes: [...headerNodes(env, options), ...histogramNodes(at, options)],
|
|
41
|
+
hover: {
|
|
42
|
+
snap: "x",
|
|
43
|
+
stops: stopsOf(at)
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export { histogramChart };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { zeroIn } from "../marks/axes.mjs";
|
|
2
|
+
import { pointsOf, seriesLine } from "../marks/series-line.mjs";
|
|
3
|
+
// src/kinds/line-marks.ts
|
|
4
|
+
/** The lines: grey context first, then the series in reverse, so the first is drawn on top. */
|
|
5
|
+
function lineNodes(drawn, at) {
|
|
6
|
+
const { frame } = at;
|
|
7
|
+
const { plot, place, time } = frame;
|
|
8
|
+
const where = {
|
|
9
|
+
buckets: frame.buckets,
|
|
10
|
+
center: time.center,
|
|
11
|
+
place
|
|
12
|
+
};
|
|
13
|
+
const washed = at.wash ?? drawn.length === 1;
|
|
14
|
+
const base = zeroIn(plot, place);
|
|
15
|
+
const nodes = [...drawn.filter((d) => d.quiet), ...drawn.filter((d) => !d.quiet).toReversed()].map(({ series, color, quiet }) => ({
|
|
16
|
+
kind: "group",
|
|
17
|
+
part: "series",
|
|
18
|
+
key: series.key,
|
|
19
|
+
children: seriesLine(series, where, {
|
|
20
|
+
color,
|
|
21
|
+
curve: at.curve ?? "straight",
|
|
22
|
+
...quiet ? { quiet } : {},
|
|
23
|
+
...washed && !quiet ? { washTo: base } : {}
|
|
24
|
+
})
|
|
25
|
+
}));
|
|
26
|
+
const points = new Map(drawn.map(({ series }) => [series, pointsOf(series.values, where)]));
|
|
27
|
+
return {
|
|
28
|
+
nodes,
|
|
29
|
+
labelY: (i) => {
|
|
30
|
+
const value = drawn[i]?.series.values.findLast((v) => v !== null) ?? null;
|
|
31
|
+
return value === null ? void 0 : place(value);
|
|
32
|
+
},
|
|
33
|
+
dotY: (series, i) => points.get(series)?.[i]?.y
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export { lineNodes };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Env, Header, TimeTable } from "../data/types.mjs";
|
|
2
|
+
import { Scene } from "../scene/types.mjs";
|
|
3
|
+
import { Curve } from "../marks/lines.mjs";
|
|
4
|
+
import { Naming, TimeNotes } from "./time-plan.mjs";
|
|
5
|
+
export type LineOptions = Header & TimeNotes & {
|
|
6
|
+
curve?: Curve;
|
|
7
|
+
/** Where series are named: at their lines' ends (the default with room), or in a legend. */
|
|
8
|
+
naming?: Naming;
|
|
9
|
+
/** A wash under the line. On for a single series. */
|
|
10
|
+
wash?: boolean;
|
|
11
|
+
/** Keep zero on the axis even when the values sit far above it. */
|
|
12
|
+
zero?: boolean;
|
|
13
|
+
/** The series to keep in colour, by key; the others are drawn as grey context. */
|
|
14
|
+
focus?: readonly string[];
|
|
15
|
+
};
|
|
16
|
+
/** A line chart of series over time. */
|
|
17
|
+
export declare function lineChart(given: TimeTable, options: LineOptions, env: Env): Scene;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { cleanTable } from "../data/clean.mjs";
|
|
2
|
+
import { OTHER } from "../scene/paint.mjs";
|
|
3
|
+
import { paintAt, paintsOf } from "../theme.mjs";
|
|
4
|
+
import { namingOf } from "./time-plan.mjs";
|
|
5
|
+
import { valuesOf } from "./time-plot.mjs";
|
|
6
|
+
import { lineNodes } from "./line-marks.mjs";
|
|
7
|
+
import { timeChart } from "./time-chart.mjs";
|
|
8
|
+
// src/kinds/line.ts
|
|
9
|
+
/** Each series with its colour: the palette's, or grey when another series has the focus. */
|
|
10
|
+
function linesOf(table, options) {
|
|
11
|
+
const paints = paintsOf(table.series);
|
|
12
|
+
const focus = options.focus;
|
|
13
|
+
return table.series.map((series, i) => {
|
|
14
|
+
const quiet = focus !== void 0 && !focus.includes(series.key);
|
|
15
|
+
return {
|
|
16
|
+
series,
|
|
17
|
+
quiet,
|
|
18
|
+
color: quiet ? OTHER : paintAt(paints, i)
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
/** A line chart of series over time. */
|
|
23
|
+
function lineChart(given, options, env) {
|
|
24
|
+
const table = cleanTable(given);
|
|
25
|
+
const lines = linesOf(table, options);
|
|
26
|
+
const bright = lines.flatMap((d, i) => d.quiet ? [] : [i]);
|
|
27
|
+
return timeChart({
|
|
28
|
+
what: "Line chart",
|
|
29
|
+
table,
|
|
30
|
+
header: options,
|
|
31
|
+
notes: options,
|
|
32
|
+
paints: lines.map((d) => d.color),
|
|
33
|
+
naming: namingOf(options.naming, {
|
|
34
|
+
series: lines.length,
|
|
35
|
+
named: bright.length,
|
|
36
|
+
atEnds: true,
|
|
37
|
+
header: options,
|
|
38
|
+
env
|
|
39
|
+
}),
|
|
40
|
+
named: bright,
|
|
41
|
+
swatch: "line",
|
|
42
|
+
...options.focus === void 0 ? {} : { focusLabels: lines.flatMap((d) => d.quiet ? [] : [d.series.label]) },
|
|
43
|
+
values: valuesOf(table),
|
|
44
|
+
zero: options.zero === true ? "always" : "near",
|
|
45
|
+
bands: false
|
|
46
|
+
}, env, (frame) => lineNodes(lines, {
|
|
47
|
+
frame,
|
|
48
|
+
curve: options.curve,
|
|
49
|
+
wash: options.wash
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
export { lineChart };
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { least, most } from "../data/range.mjs";
|
|
2
|
+
import { endTicks } from "../scale/time-ticks.mjs";
|
|
3
|
+
import { TEXT } from "../theme.mjs";
|
|
4
|
+
// src/kinds/multiples-grid.ts
|
|
5
|
+
/**
|
|
6
|
+
* The gaps between panels: across, enough to part one panel's last label from the next panel's
|
|
7
|
+
* first; down, more, since the time under a panel is written in it.
|
|
8
|
+
*/
|
|
9
|
+
const GAP = {
|
|
10
|
+
x: 20,
|
|
11
|
+
y: 26
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* A panel's least and greatest width, its least height, and the least width asked-for columns
|
|
15
|
+
* may give. These are small multiples' own: a panel holds a name, a value and a line, and is
|
|
16
|
+
* read beside others, so it is smaller than any other kind's plot.
|
|
17
|
+
*/
|
|
18
|
+
const PANEL = {
|
|
19
|
+
narrowest: 150,
|
|
20
|
+
widest: 320,
|
|
21
|
+
lowest: 60,
|
|
22
|
+
thinnest: 48
|
|
23
|
+
};
|
|
24
|
+
/** The shape a panel is best at: a little wider than tall. */
|
|
25
|
+
const ASPECT = 1.6;
|
|
26
|
+
/**
|
|
27
|
+
* The column counts worth trying: those the width allows, or the one asked for (`across`, how
|
|
28
|
+
* many panels across). `inset` is the room a panel keeps beside its plot (its own numbers, the
|
|
29
|
+
* dot at its line's end): a panel is never so narrow that its plot is thinner than the least a
|
|
30
|
+
* plot may be.
|
|
31
|
+
*/
|
|
32
|
+
function choices(count, width, at) {
|
|
33
|
+
const { across } = at;
|
|
34
|
+
const wide = Math.max(1, count);
|
|
35
|
+
const room = Math.max(1, Math.floor((width + GAP.x) / (PANEL.thinnest + at.inset + GAP.x)));
|
|
36
|
+
if (across !== void 0 && Number.isFinite(across)) return [Math.max(1, Math.min(wide, room, Math.round(across)))];
|
|
37
|
+
const narrowest = Math.max(PANEL.narrowest, PANEL.thinnest + at.inset);
|
|
38
|
+
const many = Math.max(1, Math.floor((width + GAP.x) / (narrowest + GAP.x)));
|
|
39
|
+
const few = Math.min(wide, many, Math.max(1, Math.ceil((width + GAP.x) / (PANEL.widest + GAP.x))));
|
|
40
|
+
const last = Math.min(many, Math.max(few, wide));
|
|
41
|
+
return Array.from({ length: last - few + 1 }, (_v, i) => few + i);
|
|
42
|
+
}
|
|
43
|
+
/** The grid for some columns: as many rows as the series need and the height has room for. */
|
|
44
|
+
function gridWith(count, room, columns) {
|
|
45
|
+
const fit = Math.max(1, Math.floor((room.height + GAP.y) / (PANEL.lowest + GAP.y)));
|
|
46
|
+
const rows = Math.max(1, Math.min(Math.ceil(count / columns), fit));
|
|
47
|
+
return {
|
|
48
|
+
columns,
|
|
49
|
+
rows,
|
|
50
|
+
shown: Math.min(count, rows * columns),
|
|
51
|
+
width: Math.max(1, (room.width - (columns - 1) * GAP.x) / columns),
|
|
52
|
+
height: Math.max(1, (room.height - (rows - 1) * GAP.y) / rows)
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/** How far a panel is from the shape it is best at. */
|
|
56
|
+
const misfit = (grid) => Math.abs(Math.log(grid.width / grid.height / ASPECT));
|
|
57
|
+
/**
|
|
58
|
+
* The grid that draws the most series, and of those, the one whose panels are best shaped.
|
|
59
|
+
* `inset` is the room a panel keeps beside its plot: its own numbers, when it has its own axis,
|
|
60
|
+
* and the dot at its line's end.
|
|
61
|
+
*/
|
|
62
|
+
function panelGrid(count, room, at = {}) {
|
|
63
|
+
const ask = {
|
|
64
|
+
...at.across === void 0 ? {} : { across: at.across },
|
|
65
|
+
inset: at.inset ?? 0
|
|
66
|
+
};
|
|
67
|
+
return choices(count, room.width, ask).map((c) => gridWith(count, room, c)).reduce((best, grid) => grid.shown > best.shown || grid.shown === best.shown && misfit(grid) < misfit(best) ? grid : best);
|
|
68
|
+
}
|
|
69
|
+
/** The box of the panel at a place in the grid, counted across and then down. */
|
|
70
|
+
function cellOf(grid, room, index) {
|
|
71
|
+
const column = index % grid.columns;
|
|
72
|
+
const row = Math.floor(index / grid.columns);
|
|
73
|
+
return {
|
|
74
|
+
x: room.x + column * (grid.width + GAP.x),
|
|
75
|
+
y: room.y + row * (grid.height + GAP.y),
|
|
76
|
+
width: grid.width,
|
|
77
|
+
height: grid.height
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/** The box around some boxes; a sliver at the room's top left when there are none. */
|
|
81
|
+
function around(boxes, room) {
|
|
82
|
+
const left = least(boxes.map((b) => b.x), room.x);
|
|
83
|
+
const top = least(boxes.map((b) => b.y), room.y + room.height);
|
|
84
|
+
const right = most(boxes.map((b) => b.x + b.width), left + 1);
|
|
85
|
+
const bottom = most(boxes.map((b) => b.y + b.height), top + 1);
|
|
86
|
+
return {
|
|
87
|
+
x: left,
|
|
88
|
+
y: top,
|
|
89
|
+
width: right - left,
|
|
90
|
+
height: bottom - top
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* The time under a panel: its first and last bucket as a time axis names them (the first alone
|
|
95
|
+
* when the two would touch), each only when it fits across the panel.
|
|
96
|
+
*/
|
|
97
|
+
function endsUnder(x, at) {
|
|
98
|
+
const { plot, env } = at;
|
|
99
|
+
return endTicks(x, {
|
|
100
|
+
center: at.center,
|
|
101
|
+
min: plot.x,
|
|
102
|
+
max: plot.x + plot.width,
|
|
103
|
+
measure: env.measure,
|
|
104
|
+
...env.locale === void 0 ? {} : { locale: env.locale }
|
|
105
|
+
}).filter((tick) => env.measure(tick.text, TEXT.tick) <= plot.width);
|
|
106
|
+
}
|
|
107
|
+
export { around, cellOf, endsUnder, panelGrid };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { textAt } from "../data/format.mjs";
|
|
2
|
+
import { lastAt } from "../data/rows.mjs";
|
|
3
|
+
import { fitOrNone } from "../text/measure.mjs";
|
|
4
|
+
import { SPACE, TEXT } from "../theme.mjs";
|
|
5
|
+
// src/kinds/multiples-head.ts
|
|
6
|
+
/** The name cut to a width, when even its cut form fits there; none for an empty name. */
|
|
7
|
+
const nameIn = (label, width, env) => label === "" ? void 0 : fitOrNone(label, {
|
|
8
|
+
width,
|
|
9
|
+
font: TEXT.name,
|
|
10
|
+
measure: env.measure
|
|
11
|
+
});
|
|
12
|
+
/**
|
|
13
|
+
* The name at the left of the panel's head and the last value at its right. The name comes
|
|
14
|
+
* first: the value is left out when the name, cut to the room it leaves, would not fit.
|
|
15
|
+
*/
|
|
16
|
+
function headNodes(at, env) {
|
|
17
|
+
const { head, series } = at;
|
|
18
|
+
const value = textAt(series, lastAt(series.values));
|
|
19
|
+
const valueWidth = value === void 0 ? 0 : env.measure(value, TEXT.value);
|
|
20
|
+
const beside = value === void 0 ? void 0 : nameIn(series.label, head.width - valueWidth - SPACE.names, env);
|
|
21
|
+
const name = beside ?? nameIn(series.label, head.width, env);
|
|
22
|
+
const top = {
|
|
23
|
+
y: head.y,
|
|
24
|
+
baseline: "hanging"
|
|
25
|
+
};
|
|
26
|
+
const showValue = value !== void 0 && (beside !== void 0 || name === void 0 && valueWidth <= head.width);
|
|
27
|
+
return [...name === void 0 ? [] : [{
|
|
28
|
+
kind: "text",
|
|
29
|
+
part: "name",
|
|
30
|
+
x: head.x,
|
|
31
|
+
text: name,
|
|
32
|
+
...TEXT.name,
|
|
33
|
+
...top
|
|
34
|
+
}], ...showValue ? [{
|
|
35
|
+
kind: "text",
|
|
36
|
+
part: "value",
|
|
37
|
+
x: head.x + head.width,
|
|
38
|
+
text: value,
|
|
39
|
+
...TEXT.value,
|
|
40
|
+
anchor: "end",
|
|
41
|
+
...top
|
|
42
|
+
}] : []];
|
|
43
|
+
}
|
|
44
|
+
export { headNodes };
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { contentBox } from "../layout/frame.mjs";
|
|
2
|
+
import { X_ROOM, gutterOf } from "../marks/axes.mjs";
|
|
3
|
+
import { timeScale } from "../scale/time.mjs";
|
|
4
|
+
import { placeOn, tickCount, valueAxis } from "../scale/value.mjs";
|
|
5
|
+
import { LINE } from "../theme.mjs";
|
|
6
|
+
import { around, cellOf, endsUnder, panelGrid } from "./multiples-grid.mjs";
|
|
7
|
+
import { END_ROOM, anyValueIn, valuesOf } from "./time-plot.mjs";
|
|
8
|
+
// src/kinds/multiples-layout.ts
|
|
9
|
+
/**
|
|
10
|
+
* The room the name and value take over a panel's plot: their line, and a gap of small
|
|
11
|
+
* multiples' own so the name reads as the panel's title and not as a label on its top grid line.
|
|
12
|
+
*/
|
|
13
|
+
const HEAD = LINE.name + 4;
|
|
14
|
+
/**
|
|
15
|
+
* The room under the panels for the line that counts the rest: its line, and a gap of its own
|
|
16
|
+
* that keeps it apart from the lowest panels' time.
|
|
17
|
+
*/
|
|
18
|
+
const MORE = LINE.tick + 6;
|
|
19
|
+
/**
|
|
20
|
+
* Each series' axis: one over them all, or each its own, reaching the references too (and zero,
|
|
21
|
+
* when asked to keep it), with about `count` ticks.
|
|
22
|
+
*/
|
|
23
|
+
function axesOf(table, at) {
|
|
24
|
+
const marks = (at.options.references ?? []).map((r) => r.value);
|
|
25
|
+
const axisOf = (series) => valueAxis([...valuesOf({
|
|
26
|
+
x: table.x,
|
|
27
|
+
series
|
|
28
|
+
}), ...marks], {
|
|
29
|
+
zero: at.options.zero === true ? "always" : "near",
|
|
30
|
+
count: at.count,
|
|
31
|
+
reads: series[0]?.measure
|
|
32
|
+
});
|
|
33
|
+
const all = axisOf(table.series);
|
|
34
|
+
return table.series.map((s) => at.options.shared === false ? axisOf([s]) : all);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Whether a room holds a panel's name over a plot worth reading, beside its own numbers and the
|
|
38
|
+
* room its line's end dot takes at its right.
|
|
39
|
+
*/
|
|
40
|
+
const fits = (room, inset) => room.height >= HEAD + 24 && room.width - inset - END_ROOM >= 24;
|
|
41
|
+
/** The room for the grid: under the header, right of a shared axis's numbers, over the time. */
|
|
42
|
+
function roomOf(table, axes, { options, env }) {
|
|
43
|
+
const gutter = table.series.reduce((widest, s, i) => Math.max(widest, gutterOf(axes[i] ?? {
|
|
44
|
+
min: 0,
|
|
45
|
+
max: 1,
|
|
46
|
+
ticks: []
|
|
47
|
+
}, s.measure, env.measure)), 0);
|
|
48
|
+
const content = contentBox(env, options);
|
|
49
|
+
const x = options.shared === false ? 0 : gutter;
|
|
50
|
+
return {
|
|
51
|
+
gutter,
|
|
52
|
+
whole: {
|
|
53
|
+
x,
|
|
54
|
+
y: content.y,
|
|
55
|
+
width: env.width - x,
|
|
56
|
+
height: content.height - X_ROOM
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/** The panels' places for an axis of about `count` ticks. */
|
|
61
|
+
function placed(table, options, at) {
|
|
62
|
+
const shared = options.shared !== false;
|
|
63
|
+
const axes = axesOf(table, {
|
|
64
|
+
options,
|
|
65
|
+
count: at.count
|
|
66
|
+
});
|
|
67
|
+
const { gutter, whole } = roomOf(table, axes, {
|
|
68
|
+
options,
|
|
69
|
+
env: at.env
|
|
70
|
+
});
|
|
71
|
+
const count = table.series.length;
|
|
72
|
+
const none = {
|
|
73
|
+
panels: [],
|
|
74
|
+
room: whole,
|
|
75
|
+
hidden: count
|
|
76
|
+
};
|
|
77
|
+
const inset = shared ? 0 : gutter;
|
|
78
|
+
const ask = {
|
|
79
|
+
...options.across === void 0 ? {} : { across: options.across },
|
|
80
|
+
inset: inset + END_ROOM
|
|
81
|
+
};
|
|
82
|
+
if (!anyValueIn(table) || !fits(whole, inset)) return none;
|
|
83
|
+
const all = panelGrid(count, whole, ask);
|
|
84
|
+
const room = all.shown < count ? {
|
|
85
|
+
...whole,
|
|
86
|
+
height: whole.height - MORE
|
|
87
|
+
} : whole;
|
|
88
|
+
const grid = all.shown < count ? panelGrid(count, room, ask) : all;
|
|
89
|
+
if (!fits(room, inset) || grid.width - inset - END_ROOM < 24) return none;
|
|
90
|
+
return {
|
|
91
|
+
panels: table.series.slice(0, grid.shown).map((series, i) => {
|
|
92
|
+
const cell = cellOf(grid, room, i);
|
|
93
|
+
const left = shared && i % grid.columns === 0 ? cell.x - gutter : cell.x;
|
|
94
|
+
const plot = {
|
|
95
|
+
x: cell.x + inset,
|
|
96
|
+
y: cell.y + HEAD,
|
|
97
|
+
width: Math.max(1, cell.width - inset - END_ROOM),
|
|
98
|
+
height: Math.max(1, cell.height - HEAD)
|
|
99
|
+
};
|
|
100
|
+
const axis = axes[i] ?? {
|
|
101
|
+
min: 0,
|
|
102
|
+
max: 1,
|
|
103
|
+
ticks: []
|
|
104
|
+
};
|
|
105
|
+
const time = timeScale(table.x, {
|
|
106
|
+
from: plot.x,
|
|
107
|
+
to: plot.x + plot.width
|
|
108
|
+
}, false);
|
|
109
|
+
const lowest = i + grid.columns >= grid.shown;
|
|
110
|
+
return {
|
|
111
|
+
series,
|
|
112
|
+
cell,
|
|
113
|
+
head: {
|
|
114
|
+
x: left,
|
|
115
|
+
y: cell.y,
|
|
116
|
+
width: cell.x + cell.width - left,
|
|
117
|
+
height: LINE.name
|
|
118
|
+
},
|
|
119
|
+
plot,
|
|
120
|
+
axis,
|
|
121
|
+
place: placeOn(axis, plot.y + plot.height, plot.y),
|
|
122
|
+
time,
|
|
123
|
+
ticks: !shared || i % grid.columns === 0,
|
|
124
|
+
times: lowest ? endsUnder(table.x, {
|
|
125
|
+
plot,
|
|
126
|
+
center: time.center,
|
|
127
|
+
env: at.env
|
|
128
|
+
}) : []
|
|
129
|
+
};
|
|
130
|
+
}),
|
|
131
|
+
room,
|
|
132
|
+
hidden: count - grid.shown
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* The panels' places: the grid in the room the header, the left ticks and the time leave. How
|
|
137
|
+
* many ticks a panel has room for depends on its height, and its height on the room the ticks'
|
|
138
|
+
* numbers leave; so the panels are placed with the fewest ticks first, then with as many as
|
|
139
|
+
* that height has room for. Wider numbers can leave a panel a little lower, its ticks closer.
|
|
140
|
+
*/
|
|
141
|
+
function layoutOf(table, options, env) {
|
|
142
|
+
const fewest = placed(table, options, {
|
|
143
|
+
env,
|
|
144
|
+
count: tickCount(0)
|
|
145
|
+
});
|
|
146
|
+
const count = tickCount(fewest.panels[0]?.plot.height ?? 0);
|
|
147
|
+
const more = count === tickCount(0) ? fewest : placed(table, options, {
|
|
148
|
+
env,
|
|
149
|
+
count
|
|
150
|
+
});
|
|
151
|
+
const { panels, room, hidden } = more.panels.length === 0 ? fewest : more;
|
|
152
|
+
return {
|
|
153
|
+
panels,
|
|
154
|
+
plot: around(panels.map((p) => p.plot), room),
|
|
155
|
+
hidden,
|
|
156
|
+
moreY: room.y + room.height + X_ROOM + MORE / 2
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
export { layoutOf };
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { tickUnder, valueGrid, zeroIn, zeroLine } from "../marks/axes.mjs";
|
|
2
|
+
import { alongLine, levelNotes, marked } from "../marks/notes.mjs";
|
|
3
|
+
import { pointsOf, seriesLine } from "../marks/series-line.mjs";
|
|
4
|
+
import { ownPaint } from "../theme.mjs";
|
|
5
|
+
import { headNodes } from "./multiples-head.mjs";
|
|
6
|
+
// src/kinds/multiples-marks.ts
|
|
7
|
+
/**
|
|
8
|
+
* A panel's colour: the chart's own, since each panel is named and colour would tell nothing
|
|
9
|
+
* more; a series that brings its own colour keeps it, and Other with none is the quiet grey. A
|
|
10
|
+
* series' `slot` is not read.
|
|
11
|
+
*/
|
|
12
|
+
const colorOf = (series, at) => ownPaint(series) ?? at.own;
|
|
13
|
+
/** The places along a panel's line, its points as it is drawn: what a level's name keeps clear of where it can. */
|
|
14
|
+
const traced = ({ series, place, time }, look) => alongLine(pointsOf(series.values, {
|
|
15
|
+
buckets: look.x.buckets,
|
|
16
|
+
center: time.center,
|
|
17
|
+
place
|
|
18
|
+
}));
|
|
19
|
+
/**
|
|
20
|
+
* The time under a panel, as the shared end ticks name it. Two ends are set from the plot's
|
|
21
|
+
* edges inward, where the end ticks hold them: the panels' time axes stand in one row, and a
|
|
22
|
+
* row of centred ticks reads as one axis, on which the same day under two panels would be a
|
|
23
|
+
* number written twice.
|
|
24
|
+
*/
|
|
25
|
+
function timeLabels(at) {
|
|
26
|
+
const { plot, times } = at;
|
|
27
|
+
const [first, last] = times;
|
|
28
|
+
if (first === void 0 || last === void 0) return times.map((t) => tickUnder(t, plot));
|
|
29
|
+
return [tickUnder({
|
|
30
|
+
x: plot.x,
|
|
31
|
+
text: first.text
|
|
32
|
+
}, plot, "start"), tickUnder({
|
|
33
|
+
x: plot.x + plot.width,
|
|
34
|
+
text: last.text
|
|
35
|
+
}, plot, "end")];
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The levels the panel is read against: a dashed line each, with its name where that fits,
|
|
39
|
+
* clear of the panel's line where it can be.
|
|
40
|
+
*/
|
|
41
|
+
function levels(at, look) {
|
|
42
|
+
const room = {
|
|
43
|
+
plot: at.plot,
|
|
44
|
+
measure: look.env.measure,
|
|
45
|
+
lines: traced(at, look)
|
|
46
|
+
};
|
|
47
|
+
const notes = levelNotes(look.references, {
|
|
48
|
+
place: at.place,
|
|
49
|
+
text: at.series.measure.text
|
|
50
|
+
}, room);
|
|
51
|
+
return marked(notes, room);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* A panel: its grid (with its numbers when it names them), line, wash, levels, name, value and
|
|
55
|
+
* time. All of it is one group, the series': a panel is a series in a frame of its own.
|
|
56
|
+
*/
|
|
57
|
+
function panelNodes(at, look) {
|
|
58
|
+
const { plot, place, series } = at;
|
|
59
|
+
const grid = valueGrid(at.axis, {
|
|
60
|
+
plot,
|
|
61
|
+
place,
|
|
62
|
+
reads: series.measure,
|
|
63
|
+
numbers: at.ticks
|
|
64
|
+
});
|
|
65
|
+
const base = zeroIn(plot, place);
|
|
66
|
+
const line = seriesLine(series, {
|
|
67
|
+
buckets: look.x.buckets,
|
|
68
|
+
center: at.time.center,
|
|
69
|
+
place
|
|
70
|
+
}, {
|
|
71
|
+
color: colorOf(series, look),
|
|
72
|
+
curve: look.curve,
|
|
73
|
+
washTo: base
|
|
74
|
+
});
|
|
75
|
+
const notes = levels(at, look);
|
|
76
|
+
const children = [
|
|
77
|
+
...grid,
|
|
78
|
+
...line,
|
|
79
|
+
...zeroLine(at.axis, {
|
|
80
|
+
plot,
|
|
81
|
+
place
|
|
82
|
+
}),
|
|
83
|
+
...notes.lines,
|
|
84
|
+
...at.ticks ? notes.names : [],
|
|
85
|
+
...headNodes(at, look.env),
|
|
86
|
+
...timeLabels(at)
|
|
87
|
+
];
|
|
88
|
+
return [{
|
|
89
|
+
kind: "group",
|
|
90
|
+
part: "series",
|
|
91
|
+
key: series.key,
|
|
92
|
+
children
|
|
93
|
+
}];
|
|
94
|
+
}
|
|
95
|
+
export { colorOf, panelNodes };
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { textAt, topAsWritten } from "../data/format.mjs";
|
|
2
|
+
import { lastAt, pairKey, rankable } from "../data/rows.mjs";
|
|
3
|
+
import { coursesSaid, missingOf, openingOf, shownOf, soFar, summary } from "../describe.mjs";
|
|
4
|
+
import { pointsOf } from "../marks/series-line.mjs";
|
|
5
|
+
import { bucketTitles } from "../scale/calendar.mjs";
|
|
6
|
+
import { colorOf } from "./multiples-marks.mjs";
|
|
7
|
+
import { timeStops } from "./time-stops.mjs";
|
|
8
|
+
// src/kinds/multiples-words.ts
|
|
9
|
+
/**
|
|
10
|
+
* Each panel's stops: the shared stops of a chart over time, over a table of the panel's one
|
|
11
|
+
* series, each set at its value's place, so the nearest stop to a pointer is the point it is
|
|
12
|
+
* over. Near a panel's edge, a point of the panel beside it may be nearer. A stop is keyed by
|
|
13
|
+
* its series and its bucket, and carries its panel's plot, so the lit line runs down that panel.
|
|
14
|
+
*/
|
|
15
|
+
function hoverOf(table, panels, at) {
|
|
16
|
+
const titles = bucketTitles(table.x, at.env.locale);
|
|
17
|
+
const rows = table.x.buckets.map((bucket, i) => ({
|
|
18
|
+
key: bucket.label,
|
|
19
|
+
label: titles[i] ?? bucket.label
|
|
20
|
+
}));
|
|
21
|
+
return {
|
|
22
|
+
snap: "nearest",
|
|
23
|
+
stops: panels.flatMap(({ series, place, time, plot }, column) => {
|
|
24
|
+
const points = pointsOf(series.values, {
|
|
25
|
+
buckets: table.x.buckets,
|
|
26
|
+
center: time.center,
|
|
27
|
+
place
|
|
28
|
+
});
|
|
29
|
+
return timeStops({
|
|
30
|
+
x: table.x,
|
|
31
|
+
series: [series]
|
|
32
|
+
}, at.env, {
|
|
33
|
+
plot,
|
|
34
|
+
center: time.center,
|
|
35
|
+
y: (_s, i) => points[i]?.y,
|
|
36
|
+
titles,
|
|
37
|
+
paints: [colorOf(series, at)]
|
|
38
|
+
}).flatMap((stop, row) => {
|
|
39
|
+
const heading = rows[row];
|
|
40
|
+
if (column === 0 && heading !== void 0 && stop.note !== void 0) heading.label += " (" + stop.note + ")";
|
|
41
|
+
const [item] = stop.items;
|
|
42
|
+
const key = pairKey(series.key, stop.key);
|
|
43
|
+
return item === void 0 ? [] : [{
|
|
44
|
+
...stop,
|
|
45
|
+
key,
|
|
46
|
+
y: item.y,
|
|
47
|
+
plot,
|
|
48
|
+
cell: [row, column]
|
|
49
|
+
}];
|
|
50
|
+
});
|
|
51
|
+
}),
|
|
52
|
+
matrix: {
|
|
53
|
+
rows,
|
|
54
|
+
columns: panels.map(({ series }) => ({
|
|
55
|
+
key: series.key,
|
|
56
|
+
label: series.label
|
|
57
|
+
}))
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The series' last values: the highest and the lowest at the end, by name, "so far" when that
|
|
63
|
+
* value's period is still running. Other is never ranked. Each is named only when it reads
|
|
64
|
+
* above (or below) every other ranked series' last value as written, so a tie names no one; a
|
|
65
|
+
* chart of one ranked series names none.
|
|
66
|
+
*/
|
|
67
|
+
function ends(table) {
|
|
68
|
+
const last = rankable(table.series).flatMap((s) => {
|
|
69
|
+
const at = lastAt(s.values);
|
|
70
|
+
const value = s.values[at] ?? null;
|
|
71
|
+
const open = soFar(table.x.buckets[at]);
|
|
72
|
+
return value === null ? [] : [{
|
|
73
|
+
s,
|
|
74
|
+
value,
|
|
75
|
+
text: `${textAt(s, at) ?? ""}${open}`
|
|
76
|
+
}];
|
|
77
|
+
});
|
|
78
|
+
const reads = last[0]?.s.measure.text;
|
|
79
|
+
if (reads === void 0) return [];
|
|
80
|
+
const high = topAsWritten(last, (end) => end.value, reads);
|
|
81
|
+
const low = topAsWritten(last, (end) => -end.value, (value) => reads(-value));
|
|
82
|
+
return [high === void 0 ? void 0 : `Highest at the end: ${high.s.label}, ${high.text}`, low === void 0 ? void 0 : `Lowest at the end: ${low.s.label}, ${low.text}`].filter((line) => line !== void 0);
|
|
83
|
+
}
|
|
84
|
+
/** The wording of a chart asked for one scale or each its own (`shared`), in a place. */
|
|
85
|
+
const wordingOf = (table, options, env) => ({
|
|
86
|
+
shared: options.shared !== false,
|
|
87
|
+
titles: bucketTitles(table.x, env.locale)
|
|
88
|
+
});
|
|
89
|
+
/**
|
|
90
|
+
* What the chart shows, in words: opened as every chart over time's summary is, with how many
|
|
91
|
+
* series were shown when some were drawn and some left out; then what each series did, as
|
|
92
|
+
* every chart over time says it; whether the panels share a scale; the ends; and what had no
|
|
93
|
+
* value to draw.
|
|
94
|
+
*/
|
|
95
|
+
function describeMultiples(table, at) {
|
|
96
|
+
const { titles } = at;
|
|
97
|
+
const total = table.series.length;
|
|
98
|
+
const count = at.shown > 0 && at.shown < total ? shownOf(total, at.shown, "series", "series") : void 0;
|
|
99
|
+
return summary(openingOf(table, {
|
|
100
|
+
what: "Small multiples",
|
|
101
|
+
titles,
|
|
102
|
+
count
|
|
103
|
+
}), [
|
|
104
|
+
coursesSaid(table, titles),
|
|
105
|
+
at.shared ? void 0 : "Each panel has its own scale, so heights cannot be compared across panels",
|
|
106
|
+
...ends(table),
|
|
107
|
+
...missingOf(table)
|
|
108
|
+
]);
|
|
109
|
+
}
|
|
110
|
+
export { describeMultiples, hoverOf, wordingOf };
|