@fundar/data-chart-telling 1.16.0 → 1.18.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/CHANGELOG.md +56 -0
- package/dist/configuration/ConfigVars.svelte +14 -0
- package/dist/configuration/ConfigVars.svelte.d.ts +3 -0
- package/dist/configuration/config.svelte.d.ts +5 -0
- package/dist/configuration/config.svelte.js +20 -6
- package/dist/configuration/themes/dark.js +1 -1
- package/dist/configuration/themes/editorial.js +1 -1
- package/dist/index.d.ts +12 -4
- package/dist/index.js +4 -1
- package/dist/layout/base/BasePlotLayout.svelte +1 -1
- package/dist/layout/figure/Figure.svelte +5 -12
- package/dist/layout/figure/FigureChrome.svelte +2 -10
- package/dist/layout/geometry/GeometryLayout.svelte +219 -44
- package/dist/layout/hover/HoverDefaults.d.ts +52 -0
- package/dist/layout/hover/HoverDefaults.js +96 -0
- package/dist/layout/hover/HoverLayers.d.ts +35 -0
- package/dist/layout/hover/HoverLayers.js +122 -0
- package/dist/layout/hover/HoverSettings.js +4 -1
- package/dist/layout/hover/HoverShapes.d.ts +44 -0
- package/dist/layout/hover/HoverShapes.js +103 -0
- package/dist/layout/hover/PlotHover.svelte.d.ts +18 -0
- package/dist/layout/hover/PlotHover.svelte.js +54 -1
- package/dist/layout/legend/DisabledStyle.d.ts +1 -1
- package/dist/layout/legend/DisabledStyle.js +1 -1
- package/dist/layout/legend/DiscreteBadgeItem.svelte +1 -1
- package/dist/layout/legend/DiscreteSection.svelte +1 -1
- package/dist/layout/legend/LegendState.svelte.d.ts +14 -2
- package/dist/layout/legend/LegendState.svelte.js +23 -4
- package/dist/layout/legend/LegendText.d.ts +4 -1
- package/dist/layout/legend/LegendText.js +7 -1
- package/dist/layout/margins/PlotMargins.svelte.d.ts +2 -2
- package/dist/layout/margins/PlotMargins.svelte.js +2 -2
- package/dist/layout/plot/Core.svelte +2 -2
- package/dist/layout/plot/Plot.svelte +4 -2
- package/dist/layout/plot/Plot.svelte.d.ts +2 -1
- package/dist/layout/plot/PublicPlotContext.d.ts +6 -0
- package/dist/layout/plot/PublicPlotContext.js +8 -0
- package/dist/layout/scales/ScalesLayout.svelte +1 -1
- package/dist/layout/styles/ValueLabels.d.ts +43 -4
- package/dist/layout/styles/ValueLabels.js +87 -19
- package/dist/layout/timeline/Timeline.svelte +5 -1
- package/dist/layout/tooltip/TooltipState.svelte.d.ts +8 -9
- package/dist/layout/tooltip/TooltipState.svelte.js +28 -29
- package/dist/markers/MarkerKinds.d.ts +5 -0
- package/dist/markers/MarkerKinds.js +1 -0
- package/dist/markers/area/AreaMarker.svelte +3 -0
- package/dist/markers/arrow/ArrowMarker.svelte +9 -5
- package/dist/markers/band/BandMarker.svelte +74 -0
- package/dist/markers/band/BandMarker.svelte.d.ts +7 -0
- package/dist/markers/band/Bands.d.ts +16 -0
- package/dist/markers/band/Bands.js +48 -0
- package/dist/markers/bar/BarMarker.svelte +50 -96
- package/dist/markers/bollinger/BollingerMarker.svelte +3 -0
- package/dist/markers/box/BoxMarker.svelte +3 -1
- package/dist/markers/cell/CellMarker.svelte +11 -7
- package/dist/markers/contour/ContourMarker.svelte +3 -0
- package/dist/markers/delaunay/DelaunayLinkMarker.svelte +9 -5
- package/dist/markers/delaunay/DelaunayMeshMarker.svelte +3 -0
- package/dist/markers/density/DensityMarker.svelte +3 -0
- package/dist/markers/difference/DifferenceMarker.svelte +3 -0
- package/dist/markers/dot/DotMarker.svelte +11 -6
- package/dist/markers/geo/GraticuleMarker.svelte +3 -0
- package/dist/markers/geo/SphereMarker.svelte +3 -0
- package/dist/markers/hover/HoverMarker.svelte +7 -249
- package/dist/markers/hover/HoverMarker.svelte.d.ts +4 -27
- package/dist/markers/hull/HullMarker.svelte +3 -0
- package/dist/markers/image/ImageMarker.svelte +3 -0
- package/dist/markers/line/LineMarker.svelte +3 -0
- package/dist/markers/link/LinkMarker.svelte +3 -0
- package/dist/markers/raster/RasterMarker.svelte +3 -0
- package/dist/markers/rect/RectMarker.svelte +25 -17
- package/dist/markers/regression/RegressionMarker.svelte +3 -0
- package/dist/markers/rule/RuleMarker.svelte +15 -5
- package/dist/markers/text/TextFit.d.ts +44 -0
- package/dist/markers/text/TextFit.js +86 -0
- package/dist/markers/text/TextMarker.svelte +186 -90
- package/dist/markers/text/TextMarker.svelte.d.ts +2 -0
- package/dist/markers/tick/TickMarker.svelte +9 -3
- package/dist/markers/trail/TrailMarker.svelte +3 -0
- package/dist/markers/utils/BoxLabel.d.ts +58 -0
- package/dist/markers/utils/BoxLabel.js +175 -0
- package/dist/markers/utils/MarkerEvents.d.ts +23 -0
- package/dist/markers/utils/MarkerEvents.js +44 -0
- package/dist/markers/utils/MarkerLabel.svelte +33 -0
- package/dist/markers/utils/MarkerLabel.svelte.d.ts +10 -0
- package/dist/markers/utils/PointPixel.d.ts +37 -0
- package/dist/markers/utils/PointPixel.js +44 -0
- package/dist/markers/utils/RowStroke.d.ts +9 -21
- package/dist/markers/utils/RowStroke.js +10 -21
- package/dist/markers/utils/RowStyle.d.ts +26 -0
- package/dist/markers/utils/RowStyle.js +55 -0
- package/dist/markers/vector/VectorMarker.svelte +3 -0
- package/dist/markers/voronoi/VoronoiMarker.svelte +9 -5
- package/dist/markers/voronoi/VoronoiMeshMarker.svelte +3 -0
- package/dist/markers/waffle/WaffleMarker.svelte +9 -5
- package/dist/phases/Pipeline.d.ts +10 -8
- package/dist/phases/Pipeline.js +13 -9
- package/dist/phases/context/ContextPhase.d.ts +22 -0
- package/dist/phases/context/ContextPhase.js +23 -0
- package/dist/phases/context/RowContext.d.ts +35 -0
- package/dist/phases/context/RowContext.js +95 -0
- package/dist/phases/data/DataPhase.d.ts +4 -4
- package/dist/phases/data/DataPhase.js +53 -12
- package/dist/phases/hover/HoverPhase.d.ts +6 -7
- package/dist/phases/hover/HoverPhase.js +28 -15
- package/dist/phases/mapping/MappingPhase.d.ts +4 -4
- package/dist/phases/mapping/MappingPhase.js +4 -3
- package/dist/phases/markers/MarkerStyles.d.ts +26 -0
- package/dist/phases/markers/MarkerStyles.js +126 -0
- package/dist/phases/markers/MarkersPhase.d.ts +5 -5
- package/dist/phases/markers/MarkersPhase.js +8 -6
- package/dist/phases/scales/ScalesPhase.d.ts +4 -4
- package/dist/phases/scales/ScalesPhase.js +4 -4
- package/dist/phases/sharedScales/SharedScalesPhase.d.ts +2 -2
- package/dist/phases/sharedScales/SharedScalesPhase.js +2 -2
- package/dist/phases/statistics/MarkerGrouping.d.ts +0 -9
- package/dist/phases/statistics/MarkerGrouping.js +0 -16
- package/dist/phases/statistics/StatisticsPhase.js +1 -1
- package/dist/phases/styles/StylesPhase.d.ts +3 -3
- package/dist/phases/styles/StylesPhase.js +2 -2
- package/dist/phases/tooltip/TooltipPhase.d.ts +4 -4
- package/dist/phases/tooltip/TooltipPhase.js +10 -7
- package/dist/phases/transforms/Transforms.js +3 -1
- package/dist/phases/transforms/TransformsPhase.d.ts +3 -3
- package/dist/phases/transforms/TransformsPhase.js +60 -6
- package/dist/phases/transforms/methods/TreemapTransform.d.ts +28 -0
- package/dist/phases/transforms/methods/TreemapTransform.js +119 -0
- package/dist/plots/correlation/heatmap/defaults.d.ts +2 -2
- package/dist/plots/correlation/heatmap/defaults.js +23 -8
- package/dist/plots/correlation/heatmap/markers.d.ts +2 -10
- package/dist/plots/correlation/heatmap/markers.js +11 -37
- package/dist/plots/correlation/scatter/defaults.d.ts +2 -2
- package/dist/plots/correlation/scatter/defaults.js +9 -3
- package/dist/plots/correlation/scatter/markers.d.ts +3 -3
- package/dist/plots/correlation/scatter/markers.js +6 -5
- package/dist/plots/distribution/box/BoxSummaries.d.ts +17 -8
- package/dist/plots/distribution/box/BoxSummaries.js +90 -40
- package/dist/plots/distribution/box/defaults.d.ts +2 -2
- package/dist/plots/distribution/box/defaults.js +9 -6
- package/dist/plots/distribution/box/markers.d.ts +2 -2
- package/dist/plots/distribution/box/markers.js +3 -3
- package/dist/plots/distribution/density/defaults.d.ts +2 -2
- package/dist/plots/distribution/density/defaults.js +17 -1
- package/dist/plots/distribution/density/markers.d.ts +2 -2
- package/dist/plots/distribution/density/markers.js +4 -4
- package/dist/plots/distribution/histogram/defaults.d.ts +2 -2
- package/dist/plots/distribution/histogram/defaults.js +22 -27
- package/dist/plots/distribution/histogram/markers.d.ts +3 -12
- package/dist/plots/distribution/histogram/markers.js +21 -62
- package/dist/plots/distribution/pyramid/defaults.d.ts +2 -2
- package/dist/plots/distribution/pyramid/defaults.js +7 -4
- package/dist/plots/distribution/pyramid/markers.d.ts +2 -12
- package/dist/plots/distribution/pyramid/markers.js +16 -66
- package/dist/plots/distribution/violin/defaults.d.ts +2 -2
- package/dist/plots/distribution/violin/defaults.js +9 -7
- package/dist/plots/distribution/violin/markers.d.ts +2 -2
- package/dist/plots/distribution/violin/markers.js +4 -4
- package/dist/plots/evolution/area/defaults.d.ts +2 -2
- package/dist/plots/evolution/area/defaults.js +1 -1
- package/dist/plots/evolution/area/markers.d.ts +2 -2
- package/dist/plots/evolution/area/markers.js +4 -4
- package/dist/plots/evolution/line/defaults.d.ts +2 -2
- package/dist/plots/evolution/line/defaults.js +1 -1
- package/dist/plots/evolution/line/markers.d.ts +2 -2
- package/dist/plots/evolution/line/markers.js +3 -3
- package/dist/plots/evolution/slope/defaults.d.ts +2 -2
- package/dist/plots/evolution/slope/defaults.js +8 -4
- package/dist/plots/evolution/slope/markers.d.ts +2 -2
- package/dist/plots/evolution/slope/markers.js +3 -3
- package/dist/plots/evolution/sparkline/defaults.d.ts +2 -2
- package/dist/plots/evolution/sparkline/defaults.js +5 -2
- package/dist/plots/evolution/sparkline/markers.d.ts +2 -2
- package/dist/plots/evolution/sparkline/markers.js +3 -3
- package/dist/plots/map/geo/Core.svelte +3 -3
- package/dist/plots/map/geo/defaults.d.ts +2 -2
- package/dist/plots/map/geo/phases/data.d.ts +1 -1
- package/dist/plots/map/geo/phases/data.js +1 -1
- package/dist/plots/map/geo/phases/hover.d.ts +2 -2
- package/dist/plots/map/geo/phases/hover.js +3 -3
- package/dist/plots/map/geo/phases/markers.d.ts +2 -2
- package/dist/plots/map/geo/phases/markers.js +5 -4
- package/dist/plots/map/geo/phases/scales.d.ts +2 -2
- package/dist/plots/map/geo/phases/scales.js +2 -2
- package/dist/plots/part-of-a-whole/treemap/Plot.svelte +47 -0
- package/dist/plots/part-of-a-whole/treemap/Plot.svelte.d.ts +26 -0
- package/dist/plots/part-of-a-whole/treemap/defaults.d.ts +10 -0
- package/dist/plots/part-of-a-whole/treemap/defaults.js +183 -0
- package/dist/plots/ranking/bar/defaults.d.ts +2 -2
- package/dist/plots/ranking/bar/defaults.js +15 -9
- package/dist/plots/ranking/bar/markers.d.ts +4 -14
- package/dist/plots/ranking/bar/markers.js +45 -86
- package/dist/plots/ranking/bullet/defaults.d.ts +2 -2
- package/dist/plots/ranking/bullet/defaults.js +4 -4
- package/dist/plots/ranking/bullet/markers.d.ts +3 -3
- package/dist/plots/ranking/bullet/markers.js +11 -12
- package/dist/plots/ranking/cleveland/ClevelandMarkers.d.ts +3 -3
- package/dist/plots/ranking/cleveland/ClevelandMarkers.js +28 -23
- package/dist/plots/ranking/cleveland/defaults.d.ts +2 -2
- package/dist/plots/ranking/cleveland/defaults.js +7 -4
- package/dist/plots/ranking/dumbbell/defaults.d.ts +2 -2
- package/dist/plots/ranking/forest/defaults.d.ts +2 -2
- package/dist/plots/ranking/lollipop/defaults.d.ts +2 -2
- package/dist/types/configuration/styling.d.ts +31 -2
- package/dist/types/layout/context.d.ts +21 -0
- package/dist/types/layout/context.js +1 -0
- package/dist/types/layout/hover.d.ts +3 -0
- package/dist/types/layout/legend.d.ts +8 -1
- package/dist/types/layout/mapping.d.ts +12 -3
- package/dist/types/layout/scales.d.ts +6 -0
- package/dist/types/layout/styles/values.d.ts +8 -2
- package/dist/types/layout/tooltip.d.ts +11 -4
- package/dist/types/markers/axis/arrow.d.ts +2 -8
- package/dist/types/markers/axis/axisBasedMarkersConfig.d.ts +2 -1
- package/dist/types/markers/axis/band.d.ts +24 -0
- package/dist/types/markers/axis/band.js +1 -0
- package/dist/types/markers/axis/bar.d.ts +6 -10
- package/dist/types/markers/axis/cell.d.ts +5 -5
- package/dist/types/markers/axis/delaunayLink.d.ts +2 -2
- package/dist/types/markers/axis/hover.d.ts +60 -15
- package/dist/types/markers/axis/rect.d.ts +4 -8
- package/dist/types/markers/axis/rule.d.ts +2 -16
- package/dist/types/markers/axis/tick.d.ts +2 -2
- package/dist/types/markers/axis/voronoi.d.ts +2 -2
- package/dist/types/markers/axis/waffle.d.ts +4 -3
- package/dist/types/markers/basic/dot.d.ts +2 -2
- package/dist/types/markers/basic/text.d.ts +56 -14
- package/dist/types/markers/channels/commonMarkerConfig.d.ts +8 -1
- package/dist/types/markers/channels/commonMarkerConfigWithArea.d.ts +1 -2
- package/dist/types/markers/channels/commonMarkerConfigWithLabel.d.ts +10 -0
- package/dist/types/markers/channels/commonMarkerConfigWithLabel.js +1 -0
- package/dist/types/markers/channels/commonMarkerEvents.d.ts +17 -0
- package/dist/types/markers/channels/commonMarkerEvents.js +13 -0
- package/dist/types/markers/common.d.ts +1 -0
- package/dist/types/markers/common.js +1 -0
- package/dist/types/markers/geo/contour.d.ts +2 -1
- package/dist/types/markers/geo/graticule.d.ts +2 -1
- package/dist/types/markers/geo/link.d.ts +2 -1
- package/dist/types/markers/geo/sphere.d.ts +2 -1
- package/dist/types/markers/geo/vector.d.ts +2 -1
- package/dist/types/phases/context/phase.d.ts +7 -0
- package/dist/types/phases/context/phase.js +1 -0
- package/dist/types/phases/data/phase.d.ts +7 -2
- package/dist/types/phases/hover/phase.d.ts +10 -5
- package/dist/types/phases/index.d.ts +2 -1
- package/dist/types/phases/kind.d.ts +11 -8
- package/dist/types/phases/mapping/phase.d.ts +2 -2
- package/dist/types/phases/markers/phase.d.ts +3 -3
- package/dist/types/phases/scales/phase.d.ts +4 -4
- package/dist/types/phases/stage.d.ts +3 -3
- package/dist/types/phases/state.d.ts +8 -1
- package/dist/types/phases/statistics/phase.d.ts +2 -1
- package/dist/types/phases/styles/phase.d.ts +3 -2
- package/dist/types/phases/transforms/phase.d.ts +13 -2
- package/dist/types/plots/constants.d.ts +17 -19
- package/dist/types/plots/correlation/heatmap/props.d.ts +3 -3
- package/dist/types/plots/correlation/heatmap/state.d.ts +2 -2
- package/dist/types/plots/correlation/scatter/props.d.ts +3 -3
- package/dist/types/plots/correlation/scatter/state.d.ts +2 -2
- package/dist/types/plots/data/common.d.ts +19 -6
- package/dist/types/plots/data/geo.d.ts +1 -1
- package/dist/types/plots/distribution/box/props.d.ts +25 -3
- package/dist/types/plots/distribution/box/state.d.ts +6 -17
- package/dist/types/plots/distribution/density/props.d.ts +3 -11
- package/dist/types/plots/distribution/density/state.d.ts +2 -2
- package/dist/types/plots/distribution/histogram/props.d.ts +16 -11
- package/dist/types/plots/distribution/histogram/state.d.ts +2 -2
- package/dist/types/plots/distribution/pyramid/props.d.ts +3 -3
- package/dist/types/plots/distribution/pyramid/state.d.ts +2 -2
- package/dist/types/plots/distribution/violin/props.d.ts +4 -3
- package/dist/types/plots/distribution/violin/state.d.ts +2 -2
- package/dist/types/plots/evolution/area/props.d.ts +3 -3
- package/dist/types/plots/evolution/area/state.d.ts +2 -2
- package/dist/types/plots/evolution/line/props.d.ts +3 -3
- package/dist/types/plots/evolution/line/state.d.ts +2 -2
- package/dist/types/plots/evolution/slope/state.d.ts +2 -2
- package/dist/types/plots/evolution/sparkline/state.d.ts +2 -2
- package/dist/types/plots/map/geo/state.d.ts +1 -1
- package/dist/types/plots/part-of-a-whole/treemap/props.d.ts +29 -0
- package/dist/types/plots/part-of-a-whole/treemap/props.js +1 -0
- package/dist/types/plots/part-of-a-whole/treemap/state.d.ts +6 -0
- package/dist/types/plots/part-of-a-whole/treemap/state.js +1 -0
- package/dist/types/plots/props.d.ts +10 -4
- package/dist/types/plots/ranking/bar/props.d.ts +3 -3
- package/dist/types/plots/ranking/bar/state.d.ts +2 -2
- package/dist/types/plots/ranking/bullet/state.d.ts +2 -2
- package/dist/types/plots/ranking/cleveland/props.d.ts +3 -3
- package/dist/types/plots/ranking/cleveland/state.d.ts +2 -2
- package/dist/types/plots/ranking/dumbbell/props.d.ts +3 -3
- package/dist/types/plots/ranking/dumbbell/state.d.ts +2 -2
- package/dist/types/plots/ranking/forest/props.d.ts +3 -3
- package/dist/types/plots/ranking/forest/state.d.ts +2 -2
- package/dist/types/plots/ranking/lollipop/props.d.ts +3 -3
- package/dist/types/plots/ranking/lollipop/state.d.ts +2 -2
- package/dist/types/plots/styling.d.ts +24 -0
- package/dist/types/transforms/index.d.ts +3 -1
- package/dist/types/transforms/treemap.d.ts +32 -0
- package/dist/types/transforms/treemap.js +5 -0
- package/dist/utils/color/ColorTones.d.ts +19 -0
- package/dist/utils/color/ColorTones.js +64 -0
- package/dist/utils/color/CssColor.d.ts +14 -5
- package/dist/utils/color/CssColor.js +69 -27
- package/dist/utils/color/index.d.ts +4 -0
- package/dist/utils/color/index.js +4 -0
- package/dist/utils/grouping.d.ts +18 -1
- package/dist/utils/grouping.js +31 -0
- package/docs/concepts.md +3 -2
- package/docs/legend.md +8 -5
- package/docs/markers.md +110 -28
- package/docs/plots/evolution/line.md +1 -1
- package/docs/plots/evolution/slope.md +1 -1
- package/docs/plots/part-of-a-whole/treemap.md +103 -0
- package/docs/plots/ranking/bar.md +2 -1
- package/docs/plots/ranking/cleveland.md +1 -1
- package/docs/plots.md +21 -20
- package/docs/scales.md +3 -0
- package/docs/state.md +34 -1
- package/docs/styles-and-segments.md +20 -19
- package/docs/theming.md +6 -12
- package/docs/tooltip-and-hover.md +81 -3
- package/docs/transforms-and-statistics.md +17 -16
- package/examples/LineDates.svelte +1 -1
- package/examples/ResponsiveLine.svelte +3 -1
- package/examples/Treemap.svelte +13 -0
- package/examples/TreemapHover.svelte +25 -0
- package/examples/ValueLabels.svelte +1 -1
- package/examples/datasets/economic-activity.ts +40 -0
- package/examples/datasets/index.ts +1 -0
- package/llms-full.txt +11 -9
- package/llms.txt +4 -1
- package/package.json +3 -1
package/dist/utils/grouping.js
CHANGED
|
@@ -1,4 +1,35 @@
|
|
|
1
1
|
import { resolveAccessor } from './accessors';
|
|
2
|
+
/**
|
|
3
|
+
* A plot's `grouping`, read into its levels. A dotted name is a field of the rows when they have one by that
|
|
4
|
+
* name, and the fields of its levels otherwise. Rows grouped by several levels make one key of them, dotted
|
|
5
|
+
* too (`'Tertiary.Finance'`), which is how `segments` names them.
|
|
6
|
+
*/
|
|
7
|
+
export class Grouping {
|
|
8
|
+
/** The separator between the levels of a grouping, and of the key they make together. */
|
|
9
|
+
static SEPARATOR = '.';
|
|
10
|
+
/** The levels `grouping` names, outermost first: none when it is unset. */
|
|
11
|
+
static levels(grouping, rows = []) {
|
|
12
|
+
if (grouping === undefined)
|
|
13
|
+
return [];
|
|
14
|
+
if (typeof grouping !== 'string' || !grouping.includes(Grouping.SEPARATOR))
|
|
15
|
+
return [grouping];
|
|
16
|
+
if (rows.some((row) => grouping in row))
|
|
17
|
+
return [grouping];
|
|
18
|
+
return grouping.split(Grouping.SEPARATOR);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The key rows split into series by: a single level as it is - a field stays its name - and several as
|
|
22
|
+
* the key their values make together. `nested` takes the outermost level alone, for a plot that draws
|
|
23
|
+
* the inner ones itself (a treemap).
|
|
24
|
+
*/
|
|
25
|
+
static key(grouping, rows = [], nested = false) {
|
|
26
|
+
const levels = Grouping.levels(grouping, rows);
|
|
27
|
+
if (levels.length <= 1 || nested)
|
|
28
|
+
return levels[0];
|
|
29
|
+
const reads = levels.map((level) => resolveAccessor(level));
|
|
30
|
+
return (row) => reads.map((read) => String(read(row))).join(Grouping.SEPARATOR);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
2
33
|
/**
|
|
3
34
|
* Splits rows into ordered groups keyed by the stringified accessor value.
|
|
4
35
|
* Insertion order of first appearance is preserved, which keeps colours stable
|
package/docs/concepts.md
CHANGED
|
@@ -39,13 +39,14 @@ A **channel** maps a field of each row to a visual property. Each channel takes
|
|
|
39
39
|
| ---------- | ----------------------------------------------------------- | ---------------------- |
|
|
40
40
|
| `x`, `y` | Position on the horizontal and vertical axis | `scales.x`, `scales.y` |
|
|
41
41
|
| `color` | A color: categorical (one per value) or continuous (a ramp) | `scales.color` |
|
|
42
|
-
| `grouping` | Which series the row belongs to
|
|
42
|
+
| `grouping` | Which series the row belongs to (`'a.b'`: several levels) | `scales.grouping` |
|
|
43
43
|
| `opacity` | A fill or stroke opacity | `scales.opacity` |
|
|
44
44
|
| `symbol` | A marker shape (categorical) | `scales.symbol` |
|
|
45
45
|
| `r` | A dot radius, scaled so that area follows the value | `scales.r` |
|
|
46
46
|
| `length` | A vector or spike length | `scales.length` |
|
|
47
|
+
| `value` | What a row amounts to as a part of a whole (a treemap tile) | - |
|
|
47
48
|
|
|
48
|
-
`grouping` splits `data` into series. When it is unset, `color` groups too, so one accessor both separates and colors the series - the usual case. Pass both to group by one field and color by another:
|
|
49
|
+
`grouping` splits `data` into series. Fields joined by dots are one grouping of several levels, outermost first: a plot that nests its rows ([TreemapPlot](plots/part-of-a-whole/treemap.md)) nests them by those levels, and any other splits them by the combination of the levels (`'region.sex'` is one series per region and sex, named `'CABA.F'`, which is how `segments` keys it). A dotted name is a field when the rows have one by that name; a function is a single level. When it is unset, `color` groups too, so one accessor both separates and colors the series - the usual case. Pass both to group by one field and color by another:
|
|
49
50
|
|
|
50
51
|
```svelte
|
|
51
52
|
<ScatterPlot data={rows} x="gdp" y="life" grouping="country" color="temperature" {width} {height} />
|
package/docs/legend.md
CHANGED
|
@@ -71,11 +71,14 @@ Items become clickable with `interactive` on the series section. `disabled` says
|
|
|
71
71
|
|
|
72
72
|

|
|
73
73
|
|
|
74
|
-
| `disabled.mode` | A hidden series...
|
|
75
|
-
| ----------------- |
|
|
76
|
-
| `'dim'` (default) | stays, faded (`style` sets how: opacity, fill, ...; default `legend.disabledOpacity`)
|
|
77
|
-
| `'hide'` | becomes transparent, the axes keep its range
|
|
78
|
-
| `'omit'` | is removed and the axes refit to the rest
|
|
74
|
+
| `disabled.mode` | A hidden series... |
|
|
75
|
+
| ----------------- | -------------------------------------------------------------------------------------- |
|
|
76
|
+
| `'dim'` (default) | stays, faded (`style` sets how: opacity, fill, ...; default `legend.disabledOpacity`) |
|
|
77
|
+
| `'hide'` | becomes transparent, the axes keep its range |
|
|
78
|
+
| `'omit'` | is removed and the axes refit to the rest; a part of a whole keeps its share and place |
|
|
79
|
+
| `'rescale'` | is removed, and the parts left make the whole again (see below) |
|
|
80
|
+
|
|
81
|
+
A plot uses one mode for all its series. `'omit'` and `'rescale'` differ on a plot of parts of a whole. With `'omit'` the other parts keep their values: a stack closes over the hidden series and its top drops, and a [treemap](plots/part-of-a-whole/treemap.md)'s tiles keep their place and their share of the whole economy, leaving the room empty. With `'rescale'` the parts left are the new 100%: each category of a stack (`stackY`/`stackX`) is scaled back up to the total it had, and a treemap's tiles fill the plot again, each share of what is left. On any other plot, `'rescale'` is an `'omit'`.
|
|
79
82
|
|
|
80
83
|
`interactive.legendStyle` is `'badge'` (default: pills filled with the series color and an eye toggle) or `'basic'` (swatches). `showIcon` toggles the symbol in a badge.
|
|
81
84
|
|
package/docs/markers.md
CHANGED
|
@@ -68,32 +68,33 @@ Many markers also take channel fields (`color`, `fill`, `opacity`, `r`, `symbol`
|
|
|
68
68
|
|
|
69
69
|
## Catalog for axis-based plots
|
|
70
70
|
|
|
71
|
-
| `type` | Draws
|
|
72
|
-
| -------------------------------------------------------- |
|
|
73
|
-
| `dot` | A point per row; `r`, `color`, `symbol`, `styles` (`DotStyle`)
|
|
74
|
-
| `text` | A label per row; `text` (string or function), `styles` (`FontStyle`), `declutter`, `edgeAware`, `fitMargins`
|
|
75
|
-
| `line` | A line through the rows
|
|
76
|
-
| `rule` | A reference line: `axis: 'x' \| 'y'`, `value` (a list draws a line at each, or a function with `data`), `styles
|
|
77
|
-
| `
|
|
78
|
-
| `
|
|
79
|
-
| `
|
|
80
|
-
| `
|
|
81
|
-
| `
|
|
82
|
-
| `
|
|
83
|
-
| `
|
|
84
|
-
| `
|
|
85
|
-
| `
|
|
86
|
-
| `
|
|
87
|
-
| `
|
|
88
|
-
| `
|
|
89
|
-
| `
|
|
90
|
-
| `
|
|
91
|
-
| `
|
|
92
|
-
| `
|
|
93
|
-
| `
|
|
94
|
-
| `
|
|
95
|
-
| `
|
|
96
|
-
| `
|
|
71
|
+
| `type` | Draws |
|
|
72
|
+
| -------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
73
|
+
| `dot` | A point per row; `r`, `color`, `symbol`, `styles` (`DotStyle`) |
|
|
74
|
+
| `text` | A label per row; `text` (string or function), `styles` (`FontStyle`), `declutter`, `edgeAware`, `fitMargins`, `fit` |
|
|
75
|
+
| `line` | A line through the rows |
|
|
76
|
+
| `rule` | A reference line: `axis: 'x' \| 'y'`, `value` (a list draws a line at each, or a function with `data`), `styles` (`StrokeStyle`, and `inset`, `insetTop`, ... to pull it in from its ends) |
|
|
77
|
+
| `band` | The band of a category across the whole other axis: `axis: 'x' \| 'y'`, `value` (a list, or a function with `data`), `slice`, `styles` (`AreaStyle`). Only on a band scale |
|
|
78
|
+
| `tick` | A short tick per row along one axis |
|
|
79
|
+
| `bar` | A bar; `rect`, `cell`: rectangles and heatmap cells |
|
|
80
|
+
| `rect` | A rectangle from `x1`/`x2`/`y1`/`y2`; `interval` turns `x`/`y` into ranges; `styles` (`AreaStyle`, and `inset`, `insetLeft`, ...); `label`, a text in each (`cell`, `bar` and `waffle` take it too) |
|
|
81
|
+
| `area` | A filled area under a curve, or between `y1` and `y2`; `curve` |
|
|
82
|
+
| `difference` | The area between two series, colored by which one is on top |
|
|
83
|
+
| `arrow` | An arrow from `x1,y1` to `x2,y2`; `bend`, `headAngle`, `headLength`, `styles` (`StrokeStyle`, and `inset`, `insetStart`, `insetEnd`) |
|
|
84
|
+
| `trail` | A variable-width ribbon along a path, its width set by `r` |
|
|
85
|
+
| `delta` | The distance between two series (or a series and a fixed value) at a position - or at each of a list of them, `at: [1980, 2000]` - as a line and a label |
|
|
86
|
+
| `hull` | The convex hull around a cluster of points |
|
|
87
|
+
| `density` | 2D density contour bands |
|
|
88
|
+
| `box` | A box plot; sub-marks styled through `bar`, `rule`, `dot`, `tickMedian`, `tickMinMax`; `thickness` sets its width in pixels, `slot` its share of a band |
|
|
89
|
+
| `violin` | A violin per category of its rows: the mirrored density of `y` (or `x`), `kernel`, `bandwidth`, `trim`, `peak`, `slot`; add a narrow `box` over the same rows for the box inside |
|
|
90
|
+
| `regression`, `bollinger` | A fitted curve, a moving-average band |
|
|
91
|
+
| `waffle` | The value as a grid of unit squares; `unit`, `multiple`, `gap` |
|
|
92
|
+
| `voronoi`, `voronoiMesh`, `delaunayLink`, `delaunayMesh` | Voronoi cells and Delaunay triangulation |
|
|
93
|
+
| `image` | An image per row; `src`, `width`, `height` |
|
|
94
|
+
| `raster` | A field sampled over a rectangle, drawn to a canvas |
|
|
95
|
+
| `brush` | A drag-to-select rectangle with `onbrushstart`, `onbrush`, `onbrushend` |
|
|
96
|
+
| `hover` | The in-plot hover highlight (see below) |
|
|
97
|
+
| `component` | Your own Svelte component (see below) |
|
|
97
98
|
|
|
98
99
|
## Markers in some facets
|
|
99
100
|
|
|
@@ -101,7 +102,7 @@ On a plot with a [`facet`](facets.md#markers-and-segments-in-some-panels), every
|
|
|
101
102
|
|
|
102
103
|
## Several positions at once
|
|
103
104
|
|
|
104
|
-
A `rule`
|
|
105
|
+
A `rule` and a `band` take a list as their `value`, and a `delta` a list as its `at`. One marker then draws one line, or one delta, at each position, all with the same style and the same ends - instead of one marker for each.
|
|
105
106
|
|
|
106
107
|
```ts
|
|
107
108
|
markers={[
|
|
@@ -123,9 +124,90 @@ A delta's `stroke`, `text` and `dot` can be functions of the position, to style
|
|
|
123
124
|
|
|
124
125
|
Every other marker draws from `data` rows, one mark per row, so it already takes many positions.
|
|
125
126
|
|
|
127
|
+
## Bands
|
|
128
|
+
|
|
129
|
+
`{ type: 'band', axis: 'x', value: 'Salta' }` fills the band of a category on a band scale, across the whole of the other axis: a column behind a bar plot's bars, a row across a horizontal one. With `data`, `value` is a field key or a function of the row, and the rows that name the same category draw one band. `slice` fills part of the band, as the fractions of its width left out at its start and its end (`{ start: 0.5, end: 0 }` is its second half), or a function of the row for each one's; a band several rows share fills what all of their slices do. `styles` take `AreaStyle`, each field a value or a function of the row, over `band` in the [configuration](theming.md). A band takes the pointer only with a handler of its own (`onclick`...), so one behind a plot's shapes leaves them their hover. On an axis that is not a band scale it draws nothing.
|
|
130
|
+
|
|
131
|
+
```ts
|
|
132
|
+
markers={[
|
|
133
|
+
// The two provinces of the story, behind their bars.
|
|
134
|
+
{ type: 'band', axis: 'x', value: ['Salta', 'Jujuy'], styles: { fill: '#fde68a', fillOpacity: 0.5 } }
|
|
135
|
+
]}
|
|
136
|
+
```
|
|
137
|
+
|
|
126
138
|
## Hover highlight
|
|
127
139
|
|
|
128
|
-
`{ type: 'hover' }` draws a crosshair, a dot and a label at the hovered point. It makes the plot hoverable on its own; add `tooltip` for a floating box too. Fields: `strategy`, `sync`, `
|
|
140
|
+
`{ type: 'hover' }` draws the plot's own hover: a crosshair, a dot and a label at the hovered point on most plots, the hovered category's band on a bar plot. It makes the plot hoverable on its own; add `tooltip` for a floating box too. Fields: `strategy`, `sync`, `series`, `scope`; `back` and `front`, the markers it draws behind the plot's shapes and in front of them, over the hovered points (they replace the plot's); `active` and `others`, which restyle the hovered shapes and the rest; and `format` and the number fields `decimals`, `prefix`, `suffix` and `signDisplay`, which write each point's label. See [Tooltip and hover](tooltip-and-hover.md#in-plot-hover).
|
|
141
|
+
|
|
142
|
+
```ts
|
|
143
|
+
// A crosshair only at the hovered point, and its value in bold, without a dot.
|
|
144
|
+
{ type: 'hover', back: [{ type: 'rule', axis: 'x', points: 'active' }], front: [{ type: 'text', styles: { fontWeight: 'bold' } }] }
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Every marker takes `hover`, which links it to the plot's hover:
|
|
148
|
+
|
|
149
|
+
- `'trigger'` makes it a hit area: the pointer over one of its shapes hovers that shape's row.
|
|
150
|
+
- `'style'` has its shapes take the hover marker's `active` and `others`.
|
|
151
|
+
- `true` does both.
|
|
152
|
+
|
|
153
|
+
```ts
|
|
154
|
+
markers={[
|
|
155
|
+
{ type: 'hover', active: { stroke: 'black', strokeWidth: 2 }, others: { fillOpacity: 0.3 } },
|
|
156
|
+
{ type: 'rect', data: eras, x1: 'from', x2: 'to', y1: 0, y2: 100, hover: true }
|
|
157
|
+
]}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
A plot's own shapes are linked already where its kind does it: the tiles, cells, bars, bins and dots of `TreemapPlot`, `HeatmapPlot`, `BarPlot`, `BulletPlot`, `PyramidPlot`, `HistogramPlot`, `ScatterPlot` and the Cleveland family. The `Layout/Hover` stories show every feature of the hover on every plot kind.
|
|
161
|
+
|
|
162
|
+
## Styles that depend on the row
|
|
163
|
+
|
|
164
|
+
Everything a marker is drawn with goes in its `styles` - its colors, strokes and insets - and none of it sits beside `type`, `data` and the channels.
|
|
165
|
+
|
|
166
|
+
On the markers that draw a shape for each row - `rect`, `bar`, `cell`, `waffle`, `dot`, `tick`, `rule`, `arrow`, `voronoi` and `delaunayLink` - any field of `styles` can be a function of the row in place of a value, so each shape gets its own (`rect`, `cell`, `rule` and `arrow` take the insets that way too; `bar`'s are fractions of its band, the same for all):
|
|
167
|
+
|
|
168
|
+
```ts
|
|
169
|
+
{ type: 'rect', data: eras, x1: 'from', x2: 'to', y1: 0, y2: 100,
|
|
170
|
+
styles: { fill: 'steelblue', fillOpacity: (era) => (era.name === locked ? 0.55 : 0.12) } }
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
A color or an opacity the function returns is drawn as it is, not mapped through a scale. Where the function would only read a field, name the field: a number (`strokeWidth`, `fillOpacity`, an inset...) given as a string is the field of the rows, and so is a color when the rows have a field of that name - `fill: 'tint'` reads `row.tint`, but `fill: 'tomato'` is the color unless some row has a `tomato` field. A `text` marker does the same with `fill`, `fillOpacity`, `stroke`, `strokeWidth`, `fontWeight` and `fontStyle`; the other fields place and measure the labels, so they are one value for all. The markers that draw one shape for many rows (`line`, `area`, `density`, `hull`, a mesh) take plain values.
|
|
174
|
+
|
|
175
|
+
## A label in each shape
|
|
176
|
+
|
|
177
|
+
A `rect`, `cell`, `bar` or `waffle` marker takes a `label`: a text written in the middle of each shape, with every option of a `text` marker but `type`, `data`, `x` and `y`, which the shape sets. It never takes the pointer from the shape under it, so `onclick` and the hover go on as they were.
|
|
178
|
+
|
|
179
|
+
```ts
|
|
180
|
+
{ type: 'rect', data: tiles, x1: 'x1', x2: 'x2', y1: 'y1', y2: 'y2',
|
|
181
|
+
label: { text: 'name', styles: { fill: 'white' }, fit: { fallback: 'value' } } }
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
`anchor` puts the label against an edge (`'top'`, `'bottom'`, `'left'`, `'right'`) or in a corner (`'top-left'`...) instead of the middle, and `outside` puts one anchored to an edge beyond it; `gap` is its distance from the edge. A label outside is not fitted, and `fitMargins: true` grows the plot's margins to hold it where it would run past them. A label with a handler of its own (`onpointerenter`...) listens for the pointer; the others leave it to the shape. Its styles take functions of the row, to dim the label of a series, say. A label inside its shape with no `fill` of its own is written in the color that reads best on the shape's own - white on a dark one, near black on a light one - picked per row from the configuration's `text.label.contrast` (`['#ffffff', '#111827']`), or white or black where neither reaches the WCAG AA ratio of 4.5:1. The shape is read as it is seen: a `fillOpacity` under 1 blends it with the plot's `background`. One outside keeps its plot's color.
|
|
185
|
+
|
|
186
|
+
The label is fitted to its shape unless `fit` is `false`. One too big is written smaller, down to `minFontSize`; at that size it breaks into the lines the shape holds and the last one is cut short with an ellipsis; when fewer than `minLetters` letters would show, `fallback` - a value, a field or a function of the row - is written instead; and when not even that fits, nothing is. `padding` is the room kept free inside each edge. The defaults of `gap`, `padding`, `minFontSize` (8) and `minLetters` (3) are the configuration's `text.label`: `setConfiguration({ text: { label: { gap: 6 } } })`. A `text` marker of your own takes the same `fit` with a box of its own (`x1`, `x2`, `y1`, `y2`), which is rarely what you want.
|
|
187
|
+
|
|
188
|
+
## Events
|
|
189
|
+
|
|
190
|
+
Every marker takes handlers for the pointer:
|
|
191
|
+
|
|
192
|
+
```svelte
|
|
193
|
+
<LinePlot
|
|
194
|
+
...
|
|
195
|
+
markers={[
|
|
196
|
+
{
|
|
197
|
+
type: 'rect',
|
|
198
|
+
data: eras,
|
|
199
|
+
x1: 'from',
|
|
200
|
+
x2: 'to',
|
|
201
|
+
y1: 0,
|
|
202
|
+
y2: 100,
|
|
203
|
+
onclick: (event, era) => select(era)
|
|
204
|
+
}
|
|
205
|
+
]}
|
|
206
|
+
/>
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
- `onclick`, `ondblclick`, `oncontextmenu`, `onpointerdown`, `onpointerup`, `onpointerenter`, `onpointerleave`, `onpointermove`, `onmouseenter` and `onmouseleave` are called with the event, the row the shape draws and its index.
|
|
210
|
+
- Every marker that draws a svelteplot shape takes them (`brush`, `hover`, `inset`, `delta` and the map's `features` and `geo-hover` have events of their own). svelteplot documents them on all its marks, but its code wires them up on some only today: `rect`, `bar`, `cell`, `area`, `arrow`, `dot`, `trail`, `vector`, `link`, `line`, `delaunayLink` and `voronoi`. On the others they do nothing yet.
|
|
129
211
|
|
|
130
212
|
## Custom components
|
|
131
213
|
|
|
@@ -20,7 +20,7 @@ One line per series. Rows with a missing value (`null`, `undefined`, `NaN`) brea
|
|
|
20
20
|
x="date"
|
|
21
21
|
y="index"
|
|
22
22
|
color="commodity"
|
|
23
|
-
styles={{ values: { show: true, format: (v,
|
|
23
|
+
styles={{ values: { show: true, format: (v, _number, context) => `${context.series}: ${v}` } }}
|
|
24
24
|
/>
|
|
25
25
|
```
|
|
26
26
|
|
|
@@ -32,7 +32,7 @@ A line per series between two positions of a category axis, a dot on each end, t
|
|
|
32
32
|
|
|
33
33
|
- `x` is always a category axis (a point scale, so the first and last positions reach the plot's edges), even for numbers or dates: each distinct value is a position, in the order the data gives them (`scales.x.domain` sets it).
|
|
34
34
|
- `grouping` (or `color`) names the series; the legend toggles them like any other.
|
|
35
|
-
- `styles.values` writes each series' first and last value (`select` picks others: `'first'`, `'last'`, `'min'`, `'max'`). Each label sits out in the margin on a lane, joined to its dot by a connector. The text is `format` of the value and series
|
|
35
|
+
- `styles.values` writes each series' first and last value (`select` picks others: `'first'`, `'last'`, `'min'`, `'max'`). Each label sits out in the margin on a lane, joined to its dot by a connector. The text is `format` of the value, `number` and the row's context, with its `series`.
|
|
36
36
|
- The value axis is hidden, since the labels carry the values; `scales.y.axisDisplay: 'visible'` brings it back. It fits the values without reaching for zero; pin `scales.y.domain` to start it there.
|
|
37
37
|
- The stroke width, dot radius and padding come from `slope` in the [configuration](../../theming.md); `padding` leaves room outside the first and last position. The positions sit at the plot's edges, and the margins grow to fit the labels.
|
|
38
38
|
- `segments` restyle chosen series (`styles: { stroke: { strokeWidth: 4 } }`), as in a line plot.
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# TreemapPlot
|
|
2
|
+
|
|
3
|
+
Part of [Plots](../../plots.md).
|
|
4
|
+
|
|
5
|
+
A part-to-whole made of rectangles: each row is a tile whose **area** is its `value`, and the tiles are nested by `grouping`, so a group's tiles sit together. `value` is the field (or function) giving a tile's size; the last level of `grouping` names it. The plot is the [`treemap` transform](../../transforms-and-statistics.md) drawn as `rect` markers, each with a `label`.
|
|
6
|
+
|
|
7
|
+
<!-- example: examples/Treemap.svelte -->
|
|
8
|
+
|
|
9
|
+
```svelte
|
|
10
|
+
<script lang="ts">
|
|
11
|
+
import { TreemapPlot } from '@fundar/data-chart-telling';
|
|
12
|
+
import { ACTIVITY_BRANCHES } from './datasets';
|
|
13
|
+
</script>
|
|
14
|
+
|
|
15
|
+
<!-- One tile per branch, sized by its value and colored by its sector. -->
|
|
16
|
+
<TreemapPlot
|
|
17
|
+
width={760}
|
|
18
|
+
height={440}
|
|
19
|
+
data={ACTIVITY_BRANCHES}
|
|
20
|
+
value="value"
|
|
21
|
+
grouping="sector.branch"
|
|
22
|
+
/>
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
<!-- /example -->
|
|
26
|
+
|
|
27
|
+

|
|
28
|
+
|
|
29
|
+
- A row without a positive `value` has no tile.
|
|
30
|
+
- `grouping` is the **whole path** of a tile, its fields joined by dots, outermost first: `grouping="sector.kind.branch"` nests the tiles by sector, then by kind, and names each one after its branch. A function is a single level. Rows with the same path are one tile, their values added up, so `grouping="sector"` alone makes three big tiles. The outermost level colors the tiles and is what the [legend](../../legend.md) lists; `scales.color` sets the colors, as in any plot. Without `grouping`, `color` groups the tiles, as it groups the series of any plot. `scales.color.depth` colors deeper levels as tones of their sector's color: `2` a tone per kind, `3` per branch (see [Scales](../../scales.md#color)).
|
|
31
|
+
- How a rectangle is split among its tiles is an option of the plot's own `treemap` transform: `transforms={[{ type: 'treemap', tile: 'binary' }]}` sets it over the one the plot builds from `value` and `grouping`. `tile` is `'squarify'` (the default, which keeps them close to squares), `'binary'`, `'slice'`, `'dice'` or `'sliceDice'`.
|
|
32
|
+
- Tiles have no axes.
|
|
33
|
+
|
|
34
|
+
## Labels
|
|
35
|
+
|
|
36
|
+
Each tile is labelled with its name and its **share of the whole**, in percent, as `styles.values` asks (`decimals`, `prefix`, `suffix`, `signDisplay`; one decimal and a `%` suffix unless you set otherwise, or `numbers.decimals` says). A label is fitted to the tile it is written on:
|
|
37
|
+
|
|
38
|
+
1. The name over the value, in as many lines as the tile has room for - at a smaller font size first, when that writes the whole name.
|
|
39
|
+
2. The name cut short with an ellipsis on its last line, when it still does not fit.
|
|
40
|
+
3. The value alone, when almost none of the name would show.
|
|
41
|
+
4. Nothing, when not even the value fits.
|
|
42
|
+
|
|
43
|
+
`styles.values.format(value, number, context)` writes the tile's whole text instead (`value` is the share, in percent; `number` writes it as the display fields ask; `context` holds the tile's `series`, `name`, `path` and `share`), and `styles.values.show: false` leaves the tiles bare. The label's `fontStyle` sets `fontSize` (the biggest it takes), `fontWeight` and `fill`; `treemap` in the [configuration](../../theming.md) sets the lines between tiles, the label color and the room kept around it.
|
|
44
|
+
|
|
45
|
+
## Style
|
|
46
|
+
|
|
47
|
+
`styles.area` styles every tile - `fillOpacity`, `stroke`, `strokeWidth`, `strokeDasharray`, `borderRadius` - over the color of its group (a `fill` there wins over it). A group turned off in the [legend](../../legend.md) dims its tiles and their labels. With `disabled: { mode: 'omit' }` its tiles are gone and the rest keep their place and share, and with `{ mode: 'rescale' }` the rest fill the plot as the new whole, each share of what is left.
|
|
48
|
+
|
|
49
|
+
## Segments
|
|
50
|
+
|
|
51
|
+
`segments` are keyed by series - the outermost `grouping` level - or `default` for every one, and style a group's tiles together: a highlighted sector against the rest faded, an outlined one, a recolored one. A key can also be the **path** of a tile, its levels joined by dots - `'Tertiary.Finance'`, `'Tertiary.Finance.Insurance'` - and the most specific one wins. A segment sets no `areas`, as a tile has no position on an axis. A named key wins over `default`, and both over `styles.area` (see [Styles and segments](../../styles-and-segments.md)).
|
|
52
|
+
|
|
53
|
+
```svelte
|
|
54
|
+
<!-- Tertiary at some strength, its Finance tiles at full strength and outlined, every other sector faded. -->
|
|
55
|
+
<TreemapPlot
|
|
56
|
+
{data}
|
|
57
|
+
value="value"
|
|
58
|
+
grouping="sector.kind.branch"
|
|
59
|
+
segments={{
|
|
60
|
+
default: [{ styles: { fillOpacity: 0.25 } }],
|
|
61
|
+
Tertiary: [{ styles: { fillOpacity: 0.6 } }],
|
|
62
|
+
'Tertiary.Finance': [{ styles: { fillOpacity: 1, stroke: 'gold' } }]
|
|
63
|
+
}}
|
|
64
|
+
/>
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Hover and tooltip
|
|
68
|
+
|
|
69
|
+
Hovering a tile matches it alone - an invisible `rect` over each tile drives the plot's hover - and `tooltip` shows its name and share. `tooltip.format(row, number, context)` writes it by hand: `row` is the tile's row, with the fields of every level and its summed `value`, and `context` what the library works out about it - its `series` (the outermost level), its `name`, `path`, summed `value` and `share` of the whole, from 0 to 100 (see [Row context](../../state.md#row-context)). The share is worked out from the values, in whatever unit they are, so a dataset whose `value` is a percentage already reads the same.
|
|
70
|
+
|
|
71
|
+
A `hover` marker draws no crosshair, dot or label over a treemap, since a tile has no axes and writes its own label: it outlines the hovered tile, in the configuration's `hover.active`. The tiles are linked to the hover, so its `active` and `others` restyle them: the hovered tile lightened and outlined, the rest faded, each label still on its tile and written in the color that reads best on its new one. A tile the legend dims stays hoverable and keeps its dimmed fill; one it hides, omits or rescales away is never hovered. See [Tooltip and hover](../../tooltip-and-hover.md#restyling-the-hovered-shapes).
|
|
72
|
+
|
|
73
|
+
<!-- example: examples/TreemapHover.svelte -->
|
|
74
|
+
|
|
75
|
+
```svelte
|
|
76
|
+
<script lang="ts">
|
|
77
|
+
import { TreemapPlot } from '@fundar/data-chart-telling';
|
|
78
|
+
import { ACTIVITY_BRANCHES } from './datasets';
|
|
79
|
+
</script>
|
|
80
|
+
|
|
81
|
+
<!--
|
|
82
|
+
The hover marker restyles the tiles themselves: the hovered one at full strength and outlined, every other
|
|
83
|
+
faded. Each label is still written on its tile, in the color that reads best on it.
|
|
84
|
+
-->
|
|
85
|
+
<TreemapPlot
|
|
86
|
+
width={760}
|
|
87
|
+
height={440}
|
|
88
|
+
data={ACTIVITY_BRANCHES}
|
|
89
|
+
value="value"
|
|
90
|
+
grouping="sector.branch"
|
|
91
|
+
styles={{ area: { fillOpacity: 0.85 } }}
|
|
92
|
+
tooltip
|
|
93
|
+
markers={[
|
|
94
|
+
{
|
|
95
|
+
type: 'hover',
|
|
96
|
+
active: { fillOpacity: 1, stroke: '#111827', strokeWidth: 2 },
|
|
97
|
+
others: { fillOpacity: 0.35 }
|
|
98
|
+
}
|
|
99
|
+
]}
|
|
100
|
+
/>
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
<!-- /example -->
|
|
@@ -55,5 +55,6 @@ Bars where one axis holds the categories and the other the values. Categories on
|
|
|
55
55
|
- Several series sharing a category sit side by side, each in its slice of the category band. The gap between them is `bar.seriesPadding` in the configuration.
|
|
56
56
|
- `transforms={[{ type: 'stackY' }]}` stacks the series instead. Stacking is always `stackY`, also for horizontal bars, because the value channel is the one stacked.
|
|
57
57
|
- `scales.x.paddingInner` / `paddingOuter` set the spacing between category bands.
|
|
58
|
-
- `styles.values.show` labels each bar; `styles.values.anchor` places the label (`'outside'`, `'
|
|
58
|
+
- `styles.values.show` labels each bar; `styles.values.anchor` places the label (`'outside'`, `'middle'`, `'top'`, `'bottom'`, `'left'`, `'right'`, a corner such as `'top-left'`, or `'tip'` and `'base'`, the ends of the bar away from zero and on it).
|
|
59
59
|
- The tooltip triggers anywhere over a bar's whole band, not just over the visible bar.
|
|
60
|
+
- A `hover` marker draws the hovered category's band behind its bars (its series' slice, when grouped and the bar alone is hovered), and with `active` and `others` restyles the hovered bars and the rest. See [Tooltip and hover](../../tooltip-and-hover.md#in-plot-hover).
|
|
@@ -33,7 +33,7 @@ The general form of the family: per category, one dot for each series that has a
|
|
|
33
33
|
- The connector spans the lowest and the highest dot of each category, so a series the legend omits leaves the range.
|
|
34
34
|
- The value axis fits the values without reaching for zero; pin `scales.y.domain` to start it at zero.
|
|
35
35
|
- Its defaults come from `cleveland` in the [configuration](../../theming.md): the connector is a neutral gray, 5 px thick.
|
|
36
|
-
- `styles.values` writes each value: past the highest dot and the lowest of its category, and beside those between them. `select` (`'first'`, `'last'`, `'min'`, `'max'`, or a list) labels only those dots of each category, `series` only those series, and `color: 'series'` writes each label in its dot's series color. `format(value,
|
|
36
|
+
- `styles.values` writes each value: past the highest dot and the lowest of its category, and beside those between them. `select` (`'first'`, `'last'`, `'min'`, `'max'`, or a list) labels only those dots of each category, `series` only those series, and `color: 'series'` writes each label in its dot's series color. `format(value, number, context)` also gets the row in `context.row`, so a label can name its category (see [Styles and segments](../../styles-and-segments.md#value-labels)).
|
|
37
37
|
- `segments` restyle the dots of chosen categories, as in [`DumbbellPlot`](dumbbell.md).
|
|
38
38
|
- The tooltip reads one category at a time, listing every series.
|
|
39
39
|
|
package/docs/plots.md
CHANGED
|
@@ -2,25 +2,26 @@
|
|
|
2
2
|
|
|
3
3
|
Every plot kind shares one set of props (see [Concepts](concepts.md)). They differ in what they draw, which channels they need and how they hover.
|
|
4
4
|
|
|
5
|
-
| Category
|
|
6
|
-
|
|
|
7
|
-
| Distribution
|
|
8
|
-
| Distribution
|
|
9
|
-
| Distribution
|
|
10
|
-
| Distribution
|
|
11
|
-
| Distribution
|
|
12
|
-
| Correlation
|
|
13
|
-
| Correlation
|
|
14
|
-
| Ranking
|
|
15
|
-
| Ranking
|
|
16
|
-
| Ranking
|
|
17
|
-
| Ranking
|
|
18
|
-
| Ranking
|
|
19
|
-
| Ranking
|
|
20
|
-
| Evolution
|
|
21
|
-
| Evolution
|
|
22
|
-
| Evolution
|
|
23
|
-
| Evolution
|
|
24
|
-
|
|
|
5
|
+
| Category | Plot | Draws | Needs |
|
|
6
|
+
| --------------- | ------------------------------------------------ | -------------------------------------------------------------- | ------------------------------------------------------- |
|
|
7
|
+
| Distribution | [DensityPlot](plots/distribution/density.md) | A smoothed distribution of a numeric field | `x` or `y` |
|
|
8
|
+
| Distribution | [HistogramPlot](plots/distribution/histogram.md) | Counts of a numeric field in bins | `x` or `y` |
|
|
9
|
+
| Distribution | [BoxPlot](plots/distribution/box.md) | The distribution of values per category | a category channel and a value channel |
|
|
10
|
+
| Distribution | [ViolinPlot](plots/distribution/violin.md) | The mirrored density of values per category, with a box inside | a category channel and a value channel |
|
|
11
|
+
| Distribution | [PyramidPlot](plots/distribution/pyramid.md) | Two series mirrored around zero | a category channel, a value channel, two series |
|
|
12
|
+
| Correlation | [HeatmapPlot](plots/correlation/heatmap.md) | A grid of colored cells | `x`, `y`, `color` |
|
|
13
|
+
| Correlation | [ScatterPlot](plots/correlation/scatter.md) | A point per row | `x`, `y` |
|
|
14
|
+
| Ranking | [BarPlot](plots/ranking/bar.md) | Bars, grouped, stacked or horizontal | a category channel and a value channel |
|
|
15
|
+
| Ranking | [BulletPlot](plots/ranking/bullet.md) | A bar against a target, over graded ranges | a category channel, a value channel, `target`, `ranges` |
|
|
16
|
+
| Ranking | [LollipopPlot](plots/ranking/lollipop.md) | One dot on a stem per category | a category channel and a value channel |
|
|
17
|
+
| Ranking | [DumbbellPlot](plots/ranking/dumbbell.md) | Two dots per category, joined | a category channel, a value channel, two series |
|
|
18
|
+
| Ranking | [ClevelandPlot](plots/ranking/cleveland.md) | Any number of dots per category, joined | a category channel, a value channel, a series per dot |
|
|
19
|
+
| Ranking | [ForestPlot](plots/ranking/forest.md) | One dot on an interval per row | a category channel, a value channel, `lower`/`upper` |
|
|
20
|
+
| Evolution | [LinePlot](plots/evolution/line.md) | A line per series | `x`, `y` |
|
|
21
|
+
| Evolution | [AreaPlot](plots/evolution/area.md) | A filled area per series | `x`, `y` |
|
|
22
|
+
| Evolution | [SparklinePlot](plots/evolution/sparkline.md) | A small line with its last value, no axes | `x`, `y` |
|
|
23
|
+
| Evolution | [SlopePlot](plots/evolution/slope.md) | A line per series between two positions | a category channel with two values, a value channel |
|
|
24
|
+
| Part of a whole | [TreemapPlot](plots/part-of-a-whole/treemap.md) | A tile per row, its area its value, nested by `grouping` | `value`, `grouping` |
|
|
25
|
+
| Map | [GeoPlot](geo.md) | A map from GeoJSON or TopoJSON | `data` (see [Maps](geo.md)) |
|
|
25
26
|
|
|
26
27
|
All of them accept `data` with `grouping`/`color`, or pre-built `series`.
|
package/docs/scales.md
CHANGED
|
@@ -80,9 +80,12 @@ A numeric axis takes `prefix`, `suffix`, `decimals` and `signDisplay` to write i
|
|
|
80
80
|
| `schemeRange` | The part of a named `scheme` to use, as `[from, to]` fractions of it (default `[0, 1]`): `[0.3, 1]` skips the near-white start of a ramp like `'blues'` |
|
|
81
81
|
| `pivot` | Splits an array `scheme` into two halves meeting at this value (a diverging ramp) |
|
|
82
82
|
| `unknown` | Color of a value outside the mapping (default `#ccc`) |
|
|
83
|
+
| `depth` | With a `grouping` of several levels, the level the colors reach (default `1`, a color per outermost value); deeper, each value down to it takes a tone of its outermost value's color |
|
|
83
84
|
|
|
84
85
|
A continuous ramp is set with `scheme: [colorA, colorB]`. Categorical colors come from the configuration's `palette` unless `scheme` is a category-to-color record. Series that follow one another (years, say) read better on a named sequential ramp, which is sampled across the series in order: `scheme: 'blues', schemeRange: [0.3, 1]`.
|
|
85
86
|
|
|
87
|
+
With `grouping: 'sector.kind.branch'`, `depth: 2` keeps each sector's color and gives every kind under it a tone of it; `depth: 3` gives every branch its own tone, those of one kind next to each other. A plot that splits its series by every level (a line per `'continent.country'`) colors them the same way, and a [treemap](plots/part-of-a-whole/treemap.md), which nests them, colors its tiles. The tones are `ColorTones` (`colorTones(color, count)` and `hierarchicalColors(paths, depth, colorOf)` in the package), for any page of your own that colors a hierarchy.
|
|
88
|
+
|
|
86
89
|
A marker can carry its own `scales.color`, independent of the plot's, so two ramps can coexist in one plot.
|
|
87
90
|
|
|
88
91
|
## Grouping
|
package/docs/state.md
CHANGED
|
@@ -7,7 +7,7 @@ A plot's state - its hover, legend, timeline, margins, scales, rows and size - c
|
|
|
7
7
|
Works anywhere inside a figure, including the `header`, `footer` and `content` snippets of a plot or composer. It returns:
|
|
8
8
|
|
|
9
9
|
- `hover` - `activeX`, `activeY`, `activeSeries`, `strategy`, `sync`, `source` (the id of the plot owning the hover).
|
|
10
|
-
- `legend` (or `null`) - `entries`, `range`, `off` (names of hidden series), `isOff(name)`, `turnOff(name, action)`, `turnOn(name)`, `toggle(name, action)`. `action` is `{ mode: 'dim' | 'hide' | 'omit' }`; `'omit'` removes the series and refits the axes
|
|
10
|
+
- `legend` (or `null`) - `entries`, `range`, `off` (names of hidden series), `isOff(name)`, `turnOff(name, action)`, `turnOn(name)`, `toggle(name, action)`. `action` is `{ mode: 'dim' | 'hide' | 'omit' | 'rescale' }`; `'omit'` removes the series and refits the axes, and `'rescale'` also makes the parts left of a whole (a stack, a treemap) the new 100%.
|
|
11
11
|
- `timeline` (or `null`) - `enabled`, `steps`, `value`, `index`, `progress`, `playing`, `loop`, `speed`, `speeds`, `controls`, and `seek`, `seekIndex`, `seekValue`, `next`, `previous`, `play`, `pause`, `toggle`, `setLoop`, `setSpeed`, `cycleSpeed`. On a timeline of dates, `steps` and `value` are `Date`s and `seekValue` takes a `Date` or a date string.
|
|
12
12
|
|
|
13
13
|
A footer that toggles series through the legend:
|
|
@@ -42,6 +42,7 @@ Works inside a plot - in a [`component` marker](markers.md#custom-components), w
|
|
|
42
42
|
|
|
43
43
|
- `hover.points`, `hover.activePoint`, `hover.tooltip` (`visible`, `position`, `rows`) for this plot;
|
|
44
44
|
- `margins`, `scales`, `axes`, `data`, `width`, `height`;
|
|
45
|
+
- `contextOf(row)` - what the plot knows of one of its rows (see [Row context](#row-context));
|
|
45
46
|
- `svelteplot` - svelteplot's own `usePlot()` state for this plot.
|
|
46
47
|
|
|
47
48
|
```svelte
|
|
@@ -66,6 +67,38 @@ Works inside a plot - in a [`component` marker](markers.md#custom-components), w
|
|
|
66
67
|
/>
|
|
67
68
|
```
|
|
68
69
|
|
|
70
|
+
## Row context
|
|
71
|
+
|
|
72
|
+
A plot works out a context for every row it draws, once, as it reads its data: the `series` the row is drawn in, its `x` and `y` (its own values, not a stack's running total, or where the plot's transforms put it), the `value` it shows on the value axis, the `row` itself, and whatever the plot kind works out for it. Everything that writes about a row reads the same context, so a value the plot computes - a tile's share, a density's estimate, a bin's count - is there to read without working it out again:
|
|
73
|
+
|
|
74
|
+
- `tooltip.format(row, number, context)`;
|
|
75
|
+
- `styles.values.format(value, number, context)`;
|
|
76
|
+
- the `hover` marker's points (`point.context`), in its `format` and in its `back` and `front` markers;
|
|
77
|
+
- `usePlot().contextOf(row)` in a `component` marker, and `RowContext.of(row)` anywhere, from a row the plot drew or a copy of it (the one a mark's accessor gets).
|
|
78
|
+
|
|
79
|
+
What each plot kind adds:
|
|
80
|
+
|
|
81
|
+
| Plot | `value` | Also |
|
|
82
|
+
| ----------------------- | ------------------------------------- | ------------------------------------------------------------------------------- |
|
|
83
|
+
| Most plots | the row's own value | - |
|
|
84
|
+
| `DensityPlot` | the estimated density | `x` (or `y` when horizontal) is the point it is estimated at |
|
|
85
|
+
| `HistogramPlot` | the bin's count | `count`, `from`, `to` (the bin's edges) |
|
|
86
|
+
| `BoxPlot`, `ViolinPlot` | the value (a hovered box: its median) | the box's `category`, `min`, `p25`, `median`, `p75`, `max`, `count`, `outliers` |
|
|
87
|
+
| `TreemapPlot` | the tile's summed value | `name`, `path`, `share` (0 to 100); no `x` or `y` |
|
|
88
|
+
| `HeatmapPlot` | the cell's color value | - |
|
|
89
|
+
|
|
90
|
+
```svelte
|
|
91
|
+
<HistogramPlot
|
|
92
|
+
data={ages}
|
|
93
|
+
x="age"
|
|
94
|
+
tooltip={{
|
|
95
|
+
format: (_row, number, context) => `${context.from}-${context.to}: ${number(context.count)}`
|
|
96
|
+
}}
|
|
97
|
+
/>
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
The types are `PlotRowContext`, and per kind `TreemapRowContext`, `HistogramRowContext` and `BoxRowContext`.
|
|
101
|
+
|
|
69
102
|
## When to use them
|
|
70
103
|
|
|
71
104
|
Reach for these instead of re-implementing a legend, a timeline control or a hover readout beside the plot: the figure already holds that state, and a widget reading it stays in step with the plot. [examples/LegendReader.svelte](../examples/LegendReader.svelte) is a runnable reader, and the Storybook group _Configuration / State_ has both patterns.
|