@mstone6969/graph 0.1.0 → 0.2.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 +111 -14
- package/dist/ExcelWriter-3ZSYUH4T.cjs +154 -0
- package/dist/GraphType.js +24 -38
- package/dist/PdfWriter-6HJFYMCO.cjs +205 -0
- package/dist/catalog-YWX6FHRM.cjs +8 -0
- package/dist/catalog.js +5 -1
- package/dist/charts/bars/index.js +2 -12
- package/dist/charts/comparison/EffectForestPlot.js +1 -1
- package/dist/charts/comparison/index.js +1 -8
- package/dist/charts/demography/Nomogram.js +3 -3
- package/dist/charts/density/HexbinChart.js +6 -4
- package/dist/charts/diagrams/ArchitectureCanvas.js +68 -0
- package/dist/charts/diagrams/ArchitectureDiagram.js +331 -0
- package/dist/charts/diagrams/ArchitectureLayout.js +106 -0
- package/dist/charts/diagrams/ArchitectureLinkLabels.js +78 -0
- package/dist/charts/diagrams/ArchitectureModel.js +108 -0
- package/dist/charts/diagrams/ArchitectureRouter.js +348 -0
- package/dist/charts/diagrams/ArchitectureSamples.js +312 -0
- package/dist/charts/diagrams/ArchitectureShapes.js +130 -0
- package/dist/charts/diagrams/ArchitectureText.js +25 -0
- package/dist/charts/diagrams/DiagramText.js +38 -0
- package/dist/charts/diagrams/EntityRelationshipDiagram.js +465 -0
- package/dist/charts/diagrams/ErCrowsFoot.js +33 -0
- package/dist/charts/diagrams/ErSamples.js +205 -0
- package/dist/charts/diagrams/ErSchema.js +122 -0
- package/dist/charts/diagrams/LogicCircuit.js +154 -0
- package/dist/charts/diagrams/LogicCircuitLayout.js +600 -0
- package/dist/charts/diagrams/LogicCircuitSamples.js +66 -0
- package/dist/charts/diagrams/LogicGateDiagram.js +216 -0
- package/dist/charts/diagrams/LogicGateSymbol.js +113 -0
- package/dist/charts/diagrams/NetworkTopologyDiagram.js +247 -0
- package/dist/charts/diagrams/SequenceDiagram.js +351 -0
- package/dist/charts/diagrams/SequenceLayout.js +422 -0
- package/dist/charts/diagrams/SequenceModel.js +221 -0
- package/dist/charts/diagrams/TopologyLayout.js +143 -0
- package/dist/charts/diagrams/architectureEnums.js +50 -0
- package/dist/charts/diagrams/index.js +26 -0
- package/dist/charts/diagrams/logicEnums.js +42 -0
- package/dist/charts/diagrams/sequenceEnums.js +40 -0
- package/dist/charts/distribution/HistogramChart.js +25 -3
- package/dist/charts/distribution/index.js +1 -3
- package/dist/charts/earthscience/HovmollerDiagram.js +477 -0
- package/dist/charts/earthscience/HovmollerEnums.js +42 -0
- package/dist/charts/earthscience/HovmollerField.js +180 -0
- package/dist/charts/earthscience/HovmollerSample.js +40 -0
- package/dist/charts/earthscience/HovmollerSpeed.js +71 -0
- package/dist/charts/earthscience/index.js +10 -2
- package/dist/charts/engineering/ConstellationDiagram.js +26 -6
- package/dist/charts/engineering/EyeDiagram.js +2 -1
- package/dist/charts/engineering/PoleZeroPlot.js +32 -8
- package/dist/charts/financial/RelativeStrengthRotation.js +434 -0
- package/dist/charts/financial/RelativeStrengthRotationMath.js +71 -0
- package/dist/charts/financial/RelativeStrengthRotationSamples.js +27 -0
- package/dist/charts/financial/index.js +5 -3
- package/dist/charts/flow/index.js +1 -5
- package/dist/charts/frameworks/AnsoffMatrix.js +523 -0
- package/dist/charts/frameworks/FrameworkText.js +98 -0
- package/dist/charts/frameworks/NpsGauge.js +279 -0
- package/dist/charts/frameworks/NpsSurvey.js +58 -0
- package/dist/charts/frameworks/PerceptualMap.js +419 -0
- package/dist/charts/frameworks/PerceptualProjection.js +142 -0
- package/dist/charts/frameworks/PositioningSamples.js +191 -0
- package/dist/charts/frameworks/RaciMatrix.js +458 -0
- package/dist/charts/frameworks/RaciPlan.js +81 -0
- package/dist/charts/frameworks/RaciSamples.js +76 -0
- package/dist/charts/frameworks/SwotMatrix.js +358 -0
- package/dist/charts/frameworks/SwotSamples.js +85 -0
- package/dist/charts/frameworks/VanWestendorpChart.js +187 -0
- package/dist/charts/frameworks/VanWestendorpSurvey.js +197 -0
- package/dist/charts/frameworks/index.js +26 -0
- package/dist/charts/frameworks/raciEnums.js +30 -0
- package/dist/charts/frameworks/swotEnums.js +34 -0
- package/dist/charts/genomics/CircosPlot.js +1 -1
- package/dist/charts/geoflows/GeoFlowChart.js +2 -2
- package/dist/charts/geoflows/GeoFlowSample.js +2 -1
- package/dist/charts/geomaps/FloorPlanMap.js +324 -0
- package/dist/charts/geomaps/FloorPlanModel.js +179 -0
- package/dist/charts/geomaps/FloorPlanSamples.js +416 -0
- package/dist/charts/geomaps/GeoLand.js +2 -2
- package/dist/charts/geomaps/GeoSamples.js +2 -1
- package/dist/charts/geomaps/GraticuleMap.js +2 -2
- package/dist/charts/geomaps/RoomLabelFit.js +200 -0
- package/dist/charts/geomaps/TissotMap.js +2 -2
- package/dist/charts/geomaps/index.js +8 -4
- package/dist/charts/hierarchy/SunburstChart.js +17 -10
- package/dist/charts/hierarchy/index.js +2 -11
- package/dist/charts/indicators/BulletChart.js +8 -2
- package/dist/charts/indicators/SpeedometerChart.js +1 -1
- package/dist/charts/indicators/ThermometerChart.js +1 -1
- package/dist/charts/lifescience/LoessFit.js +113 -0
- package/dist/charts/lifescience/MaPlot.js +337 -0
- package/dist/charts/lifescience/MaPlotSamples.js +35 -0
- package/dist/charts/lifescience/OncoGlyph.js +137 -0
- package/dist/charts/lifescience/OncoPrint.js +373 -0
- package/dist/charts/lifescience/OncoPrintMatrix.js +107 -0
- package/dist/charts/lifescience/OncoPrintSamples.js +142 -0
- package/dist/charts/lifescience/PedigreeChart.js +306 -0
- package/dist/charts/lifescience/PedigreeLayout.js +261 -0
- package/dist/charts/lifescience/PedigreeRows.js +70 -0
- package/dist/charts/lifescience/PedigreeSamples.js +161 -0
- package/dist/charts/lifescience/PedigreeSymbol.js +47 -0
- package/dist/charts/lifescience/RamachandranPlot.js +364 -0
- package/dist/charts/lifescience/RamachandranRegions.js +2712 -0
- package/dist/charts/lifescience/RamachandranSamples.js +235 -0
- package/dist/charts/lifescience/index.js +25 -0
- package/dist/charts/lifescience/pedigreeEnums.js +21 -0
- package/dist/charts/lifescience/ramachandranEnums.js +34 -0
- package/dist/charts/linesareas/DualAxisChart.js +1 -1
- package/dist/charts/linesareas/LineEnums.js +1 -15
- package/dist/charts/linesareas/MultiLineChart.js +1 -1
- package/dist/charts/linesareas/TrendChart.js +15 -5
- package/dist/charts/linesareas/index.js +2 -6
- package/dist/charts/massive/MassiveChart.js +3 -2
- package/dist/charts/mathematical/FourierSeriesChart.js +7 -1
- package/dist/charts/mathematical/index.js +2 -6
- package/dist/charts/matrix/GridPlot.js +27 -2
- package/dist/charts/matrix/TilegramChart.js +2 -2
- package/dist/charts/mlcharts/AttentionGrid.js +79 -0
- package/dist/charts/mlcharts/AttentionHeatmap.js +329 -0
- package/dist/charts/mlcharts/AttentionModel.js +132 -0
- package/dist/charts/mlcharts/AttentionSamples.js +82 -0
- package/dist/charts/mlcharts/CellNumber.js +8 -0
- package/dist/charts/mlcharts/CurveDiagnosticSamples.js +95 -0
- package/dist/charts/mlcharts/CurvePickMark.js +31 -0
- package/dist/charts/mlcharts/DecisionBoundaryChart.js +316 -0
- package/dist/charts/mlcharts/DecisionSamples.js +60 -0
- package/dist/charts/mlcharts/DecisionSurface.js +130 -0
- package/dist/charts/mlcharts/DistinctTicks.js +13 -0
- package/dist/charts/mlcharts/ElbowMath.js +153 -0
- package/dist/charts/mlcharts/ElbowPlot.js +273 -0
- package/dist/charts/mlcharts/ExplainabilitySamples.js +70 -0
- package/dist/charts/mlcharts/FeatureImportanceChart.js +150 -0
- package/dist/charts/mlcharts/ImportanceRanking.js +98 -0
- package/dist/charts/mlcharts/LearningCurveChart.js +276 -0
- package/dist/charts/mlcharts/LearningCurveMath.js +92 -0
- package/dist/charts/mlcharts/PartialDependence.js +92 -0
- package/dist/charts/mlcharts/PartialDependencePlot.js +225 -0
- package/dist/charts/mlcharts/WideLabel.js +28 -0
- package/dist/charts/mlcharts/curveDiagnosticEnums.js +37 -0
- package/dist/charts/mlcharts/index.js +32 -0
- package/dist/charts/proportion/index.js +5 -9
- package/dist/charts/scatter/CategoryScatterBase.js +1 -4
- package/dist/charts/scatter/ConnectedScatter.js +7 -4
- package/dist/charts/scatter/MarginalScatter.js +13 -8
- package/dist/charts/scatter/index.js +4 -17
- package/dist/charts/scientific/SpectrogramChart.js +9 -3
- package/dist/charts/scientific/index.js +2 -2
- package/dist/charts/signals/index.js +3 -13
- package/dist/charts/statistics/LorenzCurve.js +7 -4
- package/dist/charts/threebars/Candlestick3DChart.js +18 -2
- package/dist/charts/threeglobe/GlobeChart.js +2 -2
- package/dist/charts/threeglobe/GlobeSamples.js +2 -1
- package/dist/charts/threeglobe/RingGlobe.js +1 -1
- package/dist/charts/threenetwork/ConeTreeChart.js +2 -1
- package/dist/charts/threenetwork/Gantt3DChart.js +3 -2
- package/dist/charts/threesurfaces/Ridgeline3DChart.js +22 -4
- package/dist/charts/threevolume/LorenzAttractor.js +19 -0
- package/dist/charts/threevolume/VolumeRaycastChart.js +4 -3
- package/dist/charts/threevolume/volumeEnums.js +1 -0
- package/dist/charts/timeline/index.js +2 -10
- package/dist/chunk-753UBLV2.cjs +33 -0
- package/dist/chunk-VX54A7KA.cjs +17 -0
- package/dist/{chunk-W5GAAAZY.cjs → chunk-WAODDPYX.cjs} +24874 -17620
- package/dist/chunk-Z3JPIJSC.cjs +338 -0
- package/dist/core/CartesianChart.js +87 -11
- package/dist/core/Chart.js +63 -15
- package/dist/core/Chart2D.js +54 -17
- package/dist/core/Chart3D.js +56 -20
- package/dist/core/ChartExportError.js +2 -0
- package/dist/core/ChartExporter.js +50 -8
- package/dist/core/ColumnCheck.js +53 -0
- package/dist/core/Context2D.js +29 -15
- package/dist/core/Context3D.js +7 -2
- package/dist/core/ExcelWriter.js +152 -0
- package/dist/core/ExportText.js +28 -0
- package/dist/core/MarkOrigin.js +88 -0
- package/dist/core/MarkStyle.js +294 -0
- package/dist/core/Palette.js +27 -7
- package/dist/core/PdfPage.js +13 -0
- package/dist/core/PdfWriter.js +245 -0
- package/dist/core/Scales.js +52 -2
- package/dist/core/SceneOverlay.js +4 -4
- package/dist/core/TextFit.js +37 -0
- package/dist/core/Theme.js +28 -1
- package/dist/core/enums.js +33 -1
- package/dist/core/pathMorph.js +15 -0
- package/dist/data/SampleData.js +1 -17
- package/dist/data/WorldSample.js +23 -0
- package/dist/index.cjs +810 -691
- package/dist/index.d.cts +8390 -2925
- package/dist/index.d.ts +8392 -2927
- package/dist/index.js +106 -56
- package/dist/react/ChartView.js +18 -8
- package/dist/react/GraphHandle.js +2 -0
- package/dist/react/components.js +74 -116
- package/package.json +13 -3
- package/dist/catalog-4UP2YFNR.cjs +0 -7
- package/dist/charts/bars/BulletBar.js +0 -184
- package/dist/charts/bars/ErrorBarColumn.js +0 -147
- package/dist/charts/bars/HistogramBar.js +0 -217
- package/dist/charts/bars/MarimekkoBar.js +0 -191
- package/dist/charts/bars/ParetoBar.js +0 -143
- package/dist/charts/comparison/PanelChart.js +0 -70
- package/dist/charts/comparison/SmallMultipleBars.js +0 -134
- package/dist/charts/comparison/SpanChart.js +0 -118
- package/dist/charts/comparison/TrellisChart.js +0 -158
- package/dist/charts/distribution/RidgeSlabs3DChart.js +0 -169
- package/dist/charts/financial/Candlestick3D.js +0 -157
- package/dist/charts/flow/BumpFlow.js +0 -212
- package/dist/charts/flow/StreamFlow.js +0 -174
- package/dist/charts/geomaps/ThiessenMap.js +0 -106
- package/dist/charts/hierarchy/ConeTree3D.js +0 -135
- package/dist/charts/hierarchy/Hierarchy3DChart.js +0 -27
- package/dist/charts/hierarchy/SpherePack3D.js +0 -81
- package/dist/charts/hierarchy/SunburstTower3D.js +0 -93
- package/dist/charts/hierarchy/TreemapSkyline3D.js +0 -98
- package/dist/charts/linesareas/ConnectedScatterTime.js +0 -206
- package/dist/charts/linesareas/SmallMultipleLines.js +0 -153
- package/dist/charts/mathematical/ParametricSurface3D.js +0 -234
- package/dist/charts/mathematical/StrangeAttractor3D.js +0 -251
- package/dist/charts/proportion/ConeFunnel.js +0 -126
- package/dist/charts/proportion/ExtrudedPieChart.js +0 -123
- package/dist/charts/scatter/BeeswarmScatter.js +0 -151
- package/dist/charts/scatter/BinnedScatterBase.js +0 -51
- package/dist/charts/scatter/ContourScatter.js +0 -116
- package/dist/charts/scatter/GridBinScatter.js +0 -98
- package/dist/charts/scatter/HexbinScatter.js +0 -74
- package/dist/charts/scatter/StripScatter.js +0 -107
- package/dist/charts/scatter/SunflowerScatter.js +0 -109
- package/dist/charts/signals/ConstellationChart.js +0 -153
- package/dist/charts/signals/CorrelogramChart.js +0 -171
- package/dist/charts/signals/EyeDiagramChart.js +0 -155
- package/dist/charts/signals/PoleZeroChart.js +0 -164
- package/dist/charts/signals/SpectrogramChart.js +0 -79
- package/dist/charts/timeline/CalendarSkylineChart.js +0 -128
- package/dist/charts/timeline/ScheduleBlocksChart.js +0 -119
- package/dist/charts/timeline/SpiralTimeline.js +0 -154
- package/dist/charts/timeline/StreamTimeline.js +0 -141
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mstone6969/graph",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Class-based React chart library: 2D d3 and 3D three.js charts modelled as classes, enums and interfaces.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -30,7 +30,8 @@
|
|
|
30
30
|
],
|
|
31
31
|
"scripts": {
|
|
32
32
|
"dev": "vite gallery",
|
|
33
|
-
"generate": "node scripts/generate.mjs",
|
|
33
|
+
"generate": "node scripts/generate.mjs && node scripts/generate-docs.mjs",
|
|
34
|
+
"generate:docs": "node scripts/generate-docs.mjs",
|
|
34
35
|
"build": "rm -rf dist && vite build --config vite.lib.config.ts && tsup",
|
|
35
36
|
"build:gallery": "vite build gallery",
|
|
36
37
|
"typecheck": "tsc --noEmit",
|
|
@@ -43,7 +44,9 @@
|
|
|
43
44
|
"e2e:keyboard": "node e2e/keyboard.mjs",
|
|
44
45
|
"e2e:zoom": "node e2e/zoom.mjs",
|
|
45
46
|
"e2e:export": "node e2e/export.mjs",
|
|
46
|
-
"e2e:massive": "node e2e/massive.mjs"
|
|
47
|
+
"e2e:massive": "node e2e/massive.mjs",
|
|
48
|
+
"e2e:site": "node e2e/site.mjs",
|
|
49
|
+
"e2e:style": "node e2e/style.mjs"
|
|
47
50
|
},
|
|
48
51
|
"peerDependencies": {
|
|
49
52
|
"react": ">=18",
|
|
@@ -58,11 +61,15 @@
|
|
|
58
61
|
"d3-hexbin": "^0.2.2",
|
|
59
62
|
"d3-sankey": "^0.12.3",
|
|
60
63
|
"d3-transition": "^3.0.2",
|
|
64
|
+
"fflate": "^0.8.3",
|
|
61
65
|
"motion": "^14.9.1",
|
|
66
|
+
"pdf-lib": "^1.17.1",
|
|
62
67
|
"three": "^0.187.0",
|
|
63
68
|
"topojson-client": "^3.1.0"
|
|
64
69
|
},
|
|
65
70
|
"devDependencies": {
|
|
71
|
+
"@codemirror/lang-javascript": "^6.2.5",
|
|
72
|
+
"@codemirror/theme-one-dark": "^6.1.3",
|
|
66
73
|
"@tailwindcss/vite": "^4.3.4",
|
|
67
74
|
"@tanstack/react-virtual": "^3.14.26",
|
|
68
75
|
"@types/d3-cloud": "^1.2.9",
|
|
@@ -78,6 +85,7 @@
|
|
|
78
85
|
"clsx": "^2.1.1",
|
|
79
86
|
"cmdk": "^1.1.1",
|
|
80
87
|
"cn": "^0.5.2",
|
|
88
|
+
"codemirror": "^6.0.2",
|
|
81
89
|
"d3-cloud": "^2.0.0",
|
|
82
90
|
"esbuild": "^0.28.2",
|
|
83
91
|
"jsdom": "^30.1.3",
|
|
@@ -86,6 +94,8 @@
|
|
|
86
94
|
"radix-ui": "^1.8.1",
|
|
87
95
|
"react": "^19.3.1",
|
|
88
96
|
"react-dom": "^19.3.1",
|
|
97
|
+
"shiki": "^4.6.0",
|
|
98
|
+
"sucrase": "^3.35.1",
|
|
89
99
|
"tailwind-merge": "^3.7.0",
|
|
90
100
|
"tailwindcss": "^4.3.4",
|
|
91
101
|
"tsup": "^9.0.0",
|
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import { ChartFamily, DataShape, Dimension, LegendPosition, Orientation } from "../../core/enums.js";
|
|
2
|
-
import { SampleData } from "../../data/SampleData.js";
|
|
3
|
-
import { BandChart } from "./BandChart.js";
|
|
4
|
-
import { BarRows, BarSort } from "./BarRows.js";
|
|
5
|
-
import { descending, max, symbol, symbolTriangle } from "d3";
|
|
6
|
-
// src/charts/bars/BulletBar.ts
|
|
7
|
-
var BulletBarScale = /* @__PURE__ */ function(BulletBarScale) {
|
|
8
|
-
BulletBarScale["Shared"] = "shared";
|
|
9
|
-
BulletBarScale["Target"] = "target";
|
|
10
|
-
return BulletBarScale;
|
|
11
|
-
}({});
|
|
12
|
-
var BulletBarTarget = /* @__PURE__ */ function(BulletBarTarget) {
|
|
13
|
-
BulletBarTarget["Line"] = "line";
|
|
14
|
-
BulletBarTarget["Triangle"] = "triangle";
|
|
15
|
-
BulletBarTarget["Dot"] = "target-dot";
|
|
16
|
-
return BulletBarTarget;
|
|
17
|
-
}({});
|
|
18
|
-
var BulletBarMeasure = /* @__PURE__ */ function(BulletBarMeasure) {
|
|
19
|
-
BulletBarMeasure["Bar"] = "bar";
|
|
20
|
-
BulletBarMeasure["Dot"] = "measure-dot";
|
|
21
|
-
return BulletBarMeasure;
|
|
22
|
-
}({});
|
|
23
|
-
var sample = (seed) => {
|
|
24
|
-
const rows = SampleData.categories(seed, 5, 3);
|
|
25
|
-
return rows.filter((_, i) => i % 3 === 0).map((row, i) => {
|
|
26
|
-
const goal = +rows[i * 3 + 1].value + 15;
|
|
27
|
-
return {
|
|
28
|
-
category: row.category,
|
|
29
|
-
value: row.value,
|
|
30
|
-
target: goal,
|
|
31
|
-
poor: Math.round(goal * .5),
|
|
32
|
-
fair: Math.round(goal * .85),
|
|
33
|
-
good: Math.round(goal * 1.25)
|
|
34
|
-
};
|
|
35
|
-
});
|
|
36
|
-
};
|
|
37
|
-
/** Stephen Few's bullet graph: a measure against a target and qualitative ranges, in a compact row. */
|
|
38
|
-
var BulletBar = class extends BandChart {
|
|
39
|
-
static meta = {
|
|
40
|
-
id: "bar-bullet",
|
|
41
|
-
name: "Bullet bar",
|
|
42
|
-
family: ChartFamily.Indicator,
|
|
43
|
-
dimension: Dimension.Two,
|
|
44
|
-
shape: DataShape.Table,
|
|
45
|
-
description: "Shows a measure against its target and poor-to-good ranges, replacing gauges in tight dashboards.",
|
|
46
|
-
tags: [
|
|
47
|
-
"target",
|
|
48
|
-
"kpi",
|
|
49
|
-
"gauge alternative",
|
|
50
|
-
"few"
|
|
51
|
-
],
|
|
52
|
-
sample,
|
|
53
|
-
variants: {
|
|
54
|
-
orientation: [Orientation.Horizontal, Orientation.Vertical],
|
|
55
|
-
scale: ["shared", "target"],
|
|
56
|
-
targetMark: [
|
|
57
|
-
"line",
|
|
58
|
-
"triangle",
|
|
59
|
-
"target-dot"
|
|
60
|
-
],
|
|
61
|
-
rangeCount: [
|
|
62
|
-
3,
|
|
63
|
-
2,
|
|
64
|
-
0
|
|
65
|
-
],
|
|
66
|
-
measure: ["bar", "measure-dot"],
|
|
67
|
-
sort: [BarSort.Data, BarSort.Descending]
|
|
68
|
-
},
|
|
69
|
-
valid: (values) => !(values.rangeCount === 0 && values.measure === "measure-dot")
|
|
70
|
-
};
|
|
71
|
-
defaults() {
|
|
72
|
-
return {
|
|
73
|
-
x: "category",
|
|
74
|
-
y: "value",
|
|
75
|
-
target: "target",
|
|
76
|
-
ranges: [
|
|
77
|
-
"poor",
|
|
78
|
-
"fair",
|
|
79
|
-
"good"
|
|
80
|
-
],
|
|
81
|
-
rangeCount: 3,
|
|
82
|
-
orientation: Orientation.Horizontal,
|
|
83
|
-
scale: "shared",
|
|
84
|
-
targetMark: "line",
|
|
85
|
-
measure: "bar",
|
|
86
|
-
sort: BarSort.Data
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
get bullets() {
|
|
90
|
-
const { data, x, y, target, ranges, rangeCount, scale, sort } = this.options;
|
|
91
|
-
const fields = rangeCount ? ranges.slice(-rangeCount) : [];
|
|
92
|
-
const normal = scale === "target";
|
|
93
|
-
const rows = (data ?? []).flatMap((row) => {
|
|
94
|
-
const raw = BarRows.number(row[y]);
|
|
95
|
-
if (raw === null) return [];
|
|
96
|
-
const rawGoal = BarRows.number(row[target]) ?? raw;
|
|
97
|
-
const factor = normal ? 100 / (rawGoal || 1) : 1;
|
|
98
|
-
return [{
|
|
99
|
-
band: BarRows.label(row[x]),
|
|
100
|
-
raw,
|
|
101
|
-
rawGoal,
|
|
102
|
-
value: raw * factor,
|
|
103
|
-
goal: rawGoal * factor,
|
|
104
|
-
ranges: fields.map((field) => (BarRows.number(row[field]) ?? 0) * factor)
|
|
105
|
-
}];
|
|
106
|
-
});
|
|
107
|
-
const unique = [...new Map(rows.map((row) => [row.band, row])).values()];
|
|
108
|
-
return sort === BarSort.Descending ? unique.sort((a, b) => descending(a.raw / (a.rawGoal || 1), b.raw / (b.rawGoal || 1))) : unique;
|
|
109
|
-
}
|
|
110
|
-
bandNames() {
|
|
111
|
-
return this.bullets.map((bullet) => bullet.band);
|
|
112
|
-
}
|
|
113
|
-
bandPadding() {
|
|
114
|
-
return .22;
|
|
115
|
-
}
|
|
116
|
-
unit() {
|
|
117
|
-
return this.options.scale === "target" ? "%" : "";
|
|
118
|
-
}
|
|
119
|
-
valueExtent() {
|
|
120
|
-
const edges = this.bullets.flatMap((bullet) => [
|
|
121
|
-
bullet.value,
|
|
122
|
-
bullet.goal,
|
|
123
|
-
...bullet.ranges
|
|
124
|
-
]);
|
|
125
|
-
return [Math.min(0, ...edges), Math.max(0, max(edges) ?? 1)];
|
|
126
|
-
}
|
|
127
|
-
get legendPosition() {
|
|
128
|
-
return LegendPosition.None;
|
|
129
|
-
}
|
|
130
|
-
drawBands(ctx, frame) {
|
|
131
|
-
const { bullets } = this;
|
|
132
|
-
const { measure, targetMark, y } = this.options;
|
|
133
|
-
const color = ctx.palette.color(y);
|
|
134
|
-
const thick = Math.min(frame.thick, 34);
|
|
135
|
-
const start = (band) => frame.center(band) - thick / 2;
|
|
136
|
-
const shades = bullets.flatMap((bullet) => bullet.ranges.map((value, i, all) => ({
|
|
137
|
-
key: `${bullet.band}/${i}`,
|
|
138
|
-
band: bullet.band,
|
|
139
|
-
from: i ? all[i - 1] : 0,
|
|
140
|
-
to: value,
|
|
141
|
-
level: i,
|
|
142
|
-
levels: all.length
|
|
143
|
-
})));
|
|
144
|
-
const zones = ctx.marks("ranges", "path", shades, (d) => d.key).attr("fill", ctx.theme.inkMuted).attr("fill-opacity", (d) => .34 - .24 * d.level / Math.max(1, d.levels - 1));
|
|
145
|
-
ctx.set(zones, { d: (d) => frame.bar(start(d.band), thick, d.from, d.to, 0) }, { d: (d) => frame.bar(start(d.band), thick, d.from, d.from, 0) }, 10);
|
|
146
|
-
const inner = Math.max(3, thick * .36);
|
|
147
|
-
const bars = ctx.marks("measures", "path", measure === "bar" ? bullets : [], (d) => d.band).attr("fill", color);
|
|
148
|
-
ctx.set(bars, { d: (d) => frame.bar(frame.center(d.band) - inner / 2, inner, 0, d.value, 2) }, { d: (d) => frame.bar(frame.center(d.band) - inner / 2, inner, 0, 0, 2) }, 30);
|
|
149
|
-
const dots = ctx.marks("measure-dots", "circle", measure === "measure-dot" ? bullets : [], (d) => d.band).attr("r", Math.min(6, thick / 3)).attr("fill", color).attr("stroke", ctx.theme.surface).attr("stroke-width", 2);
|
|
150
|
-
ctx.set(dots, {
|
|
151
|
-
cx: (d) => frame.point(frame.center(d.band), d.value)[0],
|
|
152
|
-
cy: (d) => frame.point(frame.center(d.band), d.value)[1]
|
|
153
|
-
});
|
|
154
|
-
const tip = (d) => ({
|
|
155
|
-
title: d.band,
|
|
156
|
-
color,
|
|
157
|
-
rows: [
|
|
158
|
-
["Value", d.raw],
|
|
159
|
-
["Target", d.rawGoal],
|
|
160
|
-
["Attainment", `${Math.round(d.raw / (d.rawGoal || 1) * 100)}%`]
|
|
161
|
-
]
|
|
162
|
-
});
|
|
163
|
-
ctx.hover(bars, tip);
|
|
164
|
-
ctx.hover(dots, tip);
|
|
165
|
-
this.drawTargets(ctx, frame, bullets, targetMark, thick);
|
|
166
|
-
}
|
|
167
|
-
drawTargets(ctx, frame, bullets, mark, thick) {
|
|
168
|
-
const rules = ctx.marks("target-lines", "line", mark === "line" ? bullets : [], (d) => d.band).attr("stroke", ctx.theme.ink).attr("stroke-width", 2.5).attr("stroke-linecap", "round");
|
|
169
|
-
const rule = (d) => frame.rule(d.goal, frame.center(d.band) - thick * .36, frame.center(d.band) + thick * .36);
|
|
170
|
-
ctx.set(rules, {
|
|
171
|
-
x1: (d) => rule(d).x1,
|
|
172
|
-
y1: (d) => rule(d).y1,
|
|
173
|
-
x2: (d) => rule(d).x2,
|
|
174
|
-
y2: (d) => rule(d).y2
|
|
175
|
-
});
|
|
176
|
-
const offset = thick / 2 - 1;
|
|
177
|
-
const pin = (d) => frame.point(frame.center(d.band) + (mark === "triangle" ? offset : 0), d.goal);
|
|
178
|
-
const glyph = mark === "triangle" ? symbol(symbolTriangle, 60)() : "M-5,0A5,5 0 1 1 5,0A5,5 0 1 1 -5,0Z";
|
|
179
|
-
const spin = mark === "triangle" && frame.vertical ? " rotate(-90)" : "";
|
|
180
|
-
const pins = ctx.marks("target-pins", "path", mark === "line" ? [] : bullets, (d) => d.band).attr("d", glyph).attr("fill", ctx.theme.ink).attr("stroke", ctx.theme.surface).attr("stroke-width", 1.5);
|
|
181
|
-
ctx.set(pins, { transform: (d) => `translate(${pin(d).join(",")})${spin}` });
|
|
182
|
-
}
|
|
183
|
-
};
|
|
184
|
-
export { BulletBar, BulletBarMeasure, BulletBarScale, BulletBarTarget };
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import { ChartFamily, DataShape, Dimension, LegendPosition, Orientation } from "../../core/enums.js";
|
|
2
|
-
import { SampleData } from "../../data/SampleData.js";
|
|
3
|
-
import { BandChart } from "./BandChart.js";
|
|
4
|
-
import { BarRows, BarSort } from "./BarRows.js";
|
|
5
|
-
import { ascending, descending, deviation, max, mean, min } from "d3";
|
|
6
|
-
// src/charts/bars/ErrorBarColumn.ts
|
|
7
|
-
var ErrorBarInterval = /* @__PURE__ */ function(ErrorBarInterval) {
|
|
8
|
-
ErrorBarInterval["Deviation"] = "deviation";
|
|
9
|
-
ErrorBarInterval["StandardError"] = "standard-error";
|
|
10
|
-
ErrorBarInterval["Ci95"] = "ci95";
|
|
11
|
-
return ErrorBarInterval;
|
|
12
|
-
}({});
|
|
13
|
-
var ErrorBarMark = /* @__PURE__ */ function(ErrorBarMark) {
|
|
14
|
-
ErrorBarMark["Bar"] = "bar";
|
|
15
|
-
ErrorBarMark["Dot"] = "dot";
|
|
16
|
-
return ErrorBarMark;
|
|
17
|
-
}({});
|
|
18
|
-
/** Group means with their uncertainty, computed from raw rows, for experiment and survey results. */
|
|
19
|
-
var ErrorBarColumn = class extends BandChart {
|
|
20
|
-
static meta = {
|
|
21
|
-
id: "bar-error",
|
|
22
|
-
name: "Error bar column",
|
|
23
|
-
family: ChartFamily.Statistical,
|
|
24
|
-
dimension: Dimension.Two,
|
|
25
|
-
shape: DataShape.Table,
|
|
26
|
-
description: "Plots each group mean with a deviation, standard-error or 95% interval whisker computed from raw rows.",
|
|
27
|
-
tags: [
|
|
28
|
-
"mean",
|
|
29
|
-
"confidence interval",
|
|
30
|
-
"uncertainty"
|
|
31
|
-
],
|
|
32
|
-
sample: (seed) => SampleData.distribution(seed, 30, 6),
|
|
33
|
-
variants: {
|
|
34
|
-
orientation: [Orientation.Vertical, Orientation.Horizontal],
|
|
35
|
-
interval: [
|
|
36
|
-
"ci95",
|
|
37
|
-
"standard-error",
|
|
38
|
-
"deviation"
|
|
39
|
-
],
|
|
40
|
-
mark: ["bar", "dot"],
|
|
41
|
-
caps: [true, false],
|
|
42
|
-
sort: [BarSort.Data, BarSort.Descending]
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
defaults() {
|
|
46
|
-
return {
|
|
47
|
-
x: "group",
|
|
48
|
-
y: "value",
|
|
49
|
-
orientation: Orientation.Vertical,
|
|
50
|
-
interval: "ci95",
|
|
51
|
-
mark: "bar",
|
|
52
|
-
caps: true,
|
|
53
|
-
sort: BarSort.Data
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
get estimates() {
|
|
57
|
-
const { data, x, y, interval, sort } = this.options;
|
|
58
|
-
const rows = [...BarRows.values(data, x, y)].map(([band, values]) => {
|
|
59
|
-
const center = mean(values) ?? 0, spread = deviation(values) ?? 0, standard = spread / Math.sqrt(values.length);
|
|
60
|
-
const reach = interval === "deviation" ? spread : interval === "standard-error" ? standard : standard * 1.96;
|
|
61
|
-
return {
|
|
62
|
-
band,
|
|
63
|
-
center,
|
|
64
|
-
low: center - reach,
|
|
65
|
-
high: center + reach,
|
|
66
|
-
n: values.length
|
|
67
|
-
};
|
|
68
|
-
});
|
|
69
|
-
if (sort === BarSort.Descending) return rows.sort((a, b) => descending(a.center, b.center) || ascending(a.band, b.band));
|
|
70
|
-
return rows;
|
|
71
|
-
}
|
|
72
|
-
get dotted() {
|
|
73
|
-
return this.options.mark === "dot";
|
|
74
|
-
}
|
|
75
|
-
get legendPosition() {
|
|
76
|
-
return LegendPosition.None;
|
|
77
|
-
}
|
|
78
|
-
bandNames() {
|
|
79
|
-
return this.estimates.map((estimate) => estimate.band);
|
|
80
|
-
}
|
|
81
|
-
bandPadding() {
|
|
82
|
-
return .3;
|
|
83
|
-
}
|
|
84
|
-
baseline() {
|
|
85
|
-
return this.dotted ? null : 0;
|
|
86
|
-
}
|
|
87
|
-
reserve() {
|
|
88
|
-
return this.dotted ? [8, 8] : [0, 6];
|
|
89
|
-
}
|
|
90
|
-
valueExtent() {
|
|
91
|
-
const { estimates } = this;
|
|
92
|
-
const low = min(estimates, (estimate) => estimate.low) ?? 0, high = max(estimates, (estimate) => estimate.high) ?? 1;
|
|
93
|
-
return this.dotted ? [low, high] : [Math.min(0, low), Math.max(0, high)];
|
|
94
|
-
}
|
|
95
|
-
drawBands(ctx, frame) {
|
|
96
|
-
const { estimates } = this;
|
|
97
|
-
const { caps, y } = this.options;
|
|
98
|
-
const color = ctx.palette.color(y);
|
|
99
|
-
const at = (d) => frame.band(d.band) ?? 0;
|
|
100
|
-
const bars = ctx.marks("bars", "path", this.dotted ? [] : estimates, (d) => d.band).attr("fill", color);
|
|
101
|
-
ctx.set(bars, { d: (d) => frame.bar(at(d), frame.thick, 0, d.center) }, { d: (d) => frame.bar(at(d), frame.thick, 0, 0) }, 20);
|
|
102
|
-
const tip = (d) => ({
|
|
103
|
-
title: d.band,
|
|
104
|
-
color,
|
|
105
|
-
rows: [
|
|
106
|
-
["Mean", +d.center.toFixed(2)],
|
|
107
|
-
["Low", +d.low.toFixed(2)],
|
|
108
|
-
["High", +d.high.toFixed(2)],
|
|
109
|
-
["n", d.n]
|
|
110
|
-
]
|
|
111
|
-
});
|
|
112
|
-
ctx.hover(bars, tip);
|
|
113
|
-
const stroke = this.dotted ? color : ctx.theme.ink;
|
|
114
|
-
const whiskers = ctx.marks("whiskers", "line", estimates, (d) => d.band).attr("stroke", stroke).attr("stroke-width", 2).attr("stroke-linecap", "round");
|
|
115
|
-
const line = (d) => frame.stem(frame.center(d.band), d.low, d.high);
|
|
116
|
-
ctx.set(whiskers, {
|
|
117
|
-
x1: (d) => line(d).x1,
|
|
118
|
-
y1: (d) => line(d).y1,
|
|
119
|
-
x2: (d) => line(d).x2,
|
|
120
|
-
y2: (d) => line(d).y2
|
|
121
|
-
});
|
|
122
|
-
const ends = caps ? estimates.flatMap((d) => [{
|
|
123
|
-
key: `${d.band}/low`,
|
|
124
|
-
band: d.band,
|
|
125
|
-
value: d.low
|
|
126
|
-
}, {
|
|
127
|
-
key: `${d.band}/high`,
|
|
128
|
-
band: d.band,
|
|
129
|
-
value: d.high
|
|
130
|
-
}]) : [];
|
|
131
|
-
const tips = ctx.marks("caps", "line", ends, (d) => d.key).attr("stroke", stroke).attr("stroke-width", 2).attr("stroke-linecap", "round");
|
|
132
|
-
const cap = (d) => frame.rule(d.value, frame.center(d.band) - 5, frame.center(d.band) + 5);
|
|
133
|
-
ctx.set(tips, {
|
|
134
|
-
x1: (d) => cap(d).x1,
|
|
135
|
-
y1: (d) => cap(d).y1,
|
|
136
|
-
x2: (d) => cap(d).x2,
|
|
137
|
-
y2: (d) => cap(d).y2
|
|
138
|
-
});
|
|
139
|
-
const dots = ctx.marks("dots", "circle", this.dotted ? estimates : [], (d) => d.band).attr("r", 6).attr("fill", color).attr("stroke", ctx.theme.surface).attr("stroke-width", 2);
|
|
140
|
-
ctx.set(dots, {
|
|
141
|
-
cx: (d) => frame.point(frame.center(d.band), d.center)[0],
|
|
142
|
-
cy: (d) => frame.point(frame.center(d.band), d.center)[1]
|
|
143
|
-
});
|
|
144
|
-
ctx.hover(dots, tip);
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
export { ErrorBarColumn, ErrorBarInterval, ErrorBarMark };
|
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
import { CartesianChart } from "../../core/CartesianChart.js";
|
|
2
|
-
import { ChartFamily, CurveKind, DataShape, Dimension, LegendPosition, Orientation } from "../../core/enums.js";
|
|
3
|
-
import { Scales } from "../../core/Scales.js";
|
|
4
|
-
import { SampleData } from "../../data/SampleData.js";
|
|
5
|
-
import { BarFrame } from "./BarFrame.js";
|
|
6
|
-
import { BarRows } from "./BarRows.js";
|
|
7
|
-
import { ascending, bin, deviation, extent, line, max, quantile, scaleBand, scaleLinear, sum, thresholdFreedmanDiaconis, thresholdScott, thresholdSturges } from "d3";
|
|
8
|
-
// src/charts/bars/HistogramBar.ts
|
|
9
|
-
var HistogramBarBinning = /* @__PURE__ */ function(HistogramBarBinning) {
|
|
10
|
-
HistogramBarBinning["Sturges"] = "sturges";
|
|
11
|
-
HistogramBarBinning["Scott"] = "scott";
|
|
12
|
-
HistogramBarBinning["FreedmanDiaconis"] = "freedman-diaconis";
|
|
13
|
-
HistogramBarBinning["Sqrt"] = "sqrt";
|
|
14
|
-
return HistogramBarBinning;
|
|
15
|
-
}({});
|
|
16
|
-
var HistogramBarLayout = /* @__PURE__ */ function(HistogramBarLayout) {
|
|
17
|
-
HistogramBarLayout["Single"] = "single";
|
|
18
|
-
HistogramBarLayout["Stacked"] = "stacked";
|
|
19
|
-
HistogramBarLayout["Overlaid"] = "overlaid";
|
|
20
|
-
return HistogramBarLayout;
|
|
21
|
-
}({});
|
|
22
|
-
var ROUND_STEPS = [
|
|
23
|
-
1,
|
|
24
|
-
1.5,
|
|
25
|
-
2,
|
|
26
|
-
2.5,
|
|
27
|
-
3,
|
|
28
|
-
4,
|
|
29
|
-
5,
|
|
30
|
-
6,
|
|
31
|
-
8,
|
|
32
|
-
10
|
|
33
|
-
];
|
|
34
|
-
/** Snap a raw bin width to a round number, so bin edges read like 30–35 rather than 31.7–36.2. */
|
|
35
|
-
var roundStep = (raw) => {
|
|
36
|
-
const power = 10 ** Math.floor(Math.log10(raw));
|
|
37
|
-
return ROUND_STEPS.reduce((best, step) => Math.abs(step * power - raw) < Math.abs(best * power - raw) ? step : best) * power;
|
|
38
|
-
};
|
|
39
|
-
/** The shape of one numeric column, on rounded bins that are easy to read and quote. */
|
|
40
|
-
var HistogramBar = class extends CartesianChart {
|
|
41
|
-
static meta = {
|
|
42
|
-
id: "bar-histogram",
|
|
43
|
-
name: "Histogram",
|
|
44
|
-
family: ChartFamily.Distribution,
|
|
45
|
-
dimension: Dimension.Two,
|
|
46
|
-
shape: DataShape.Table,
|
|
47
|
-
description: "Counts values into rounded-range bins chosen by a standard rule, to show the shape of a distribution.",
|
|
48
|
-
tags: [
|
|
49
|
-
"bins",
|
|
50
|
-
"frequency",
|
|
51
|
-
"distribution",
|
|
52
|
-
"cumulative"
|
|
53
|
-
],
|
|
54
|
-
sample: (seed) => SampleData.distribution(seed),
|
|
55
|
-
variants: {
|
|
56
|
-
orientation: [Orientation.Vertical, Orientation.Horizontal],
|
|
57
|
-
binning: [
|
|
58
|
-
"sturges",
|
|
59
|
-
"scott",
|
|
60
|
-
"sqrt"
|
|
61
|
-
],
|
|
62
|
-
layout: [
|
|
63
|
-
"single",
|
|
64
|
-
"stacked",
|
|
65
|
-
"overlaid"
|
|
66
|
-
],
|
|
67
|
-
cumulative: [false, true],
|
|
68
|
-
density: [false, true]
|
|
69
|
-
},
|
|
70
|
-
valid: (values) => !(values.density && (values.cumulative || values.layout !== "single"))
|
|
71
|
-
};
|
|
72
|
-
defaults() {
|
|
73
|
-
return {
|
|
74
|
-
y: "value",
|
|
75
|
-
series: "group",
|
|
76
|
-
orientation: Orientation.Vertical,
|
|
77
|
-
binning: "sturges",
|
|
78
|
-
layout: "single",
|
|
79
|
-
cumulative: false,
|
|
80
|
-
density: false
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
get vertical() {
|
|
84
|
-
return this.options.orientation === Orientation.Vertical;
|
|
85
|
-
}
|
|
86
|
-
get legendPosition() {
|
|
87
|
-
return this.options.layout === "single" ? LegendPosition.None : super.legendPosition;
|
|
88
|
-
}
|
|
89
|
-
get values() {
|
|
90
|
-
const { data, y, series, layout } = this.options;
|
|
91
|
-
return (data ?? []).flatMap((row) => {
|
|
92
|
-
const value = BarRows.number(row[y]);
|
|
93
|
-
return value === null ? [] : [{
|
|
94
|
-
value,
|
|
95
|
-
series: layout === "single" ? "All" : BarRows.label(row[series])
|
|
96
|
-
}];
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
thresholds(values) {
|
|
100
|
-
const [low = 0, high = 1] = extent(values);
|
|
101
|
-
if (low === high) return [low, low + 1];
|
|
102
|
-
const { binning } = this.options;
|
|
103
|
-
const count = binning === "scott" ? thresholdScott(values, low, high) : binning === "freedman-diaconis" ? thresholdFreedmanDiaconis(values, low, high) : binning === "sqrt" ? Math.ceil(Math.sqrt(values.length)) : thresholdSturges(values);
|
|
104
|
-
const step = roundStep((high - low) / Math.max(1, count || 10));
|
|
105
|
-
const first = Math.floor(low / step), last = Math.ceil(high / step);
|
|
106
|
-
return Array.from({ length: last - first + 1 }, (_, i) => +((first + i) * step).toPrecision(10));
|
|
107
|
-
}
|
|
108
|
-
buckets() {
|
|
109
|
-
const { values } = this;
|
|
110
|
-
const edges = this.thresholds(values.map((item) => item.value));
|
|
111
|
-
const series = [...new Set(values.map((item) => item.series))];
|
|
112
|
-
const binner = bin().domain([edges[0], edges[edges.length - 1]]).thresholds(edges.slice(1, -1));
|
|
113
|
-
const counts = series.map((name) => binner(values.filter((item) => item.series === name).map((item) => item.value)));
|
|
114
|
-
const { cumulative, layout } = this.options;
|
|
115
|
-
const running = series.map(() => 0);
|
|
116
|
-
return {
|
|
117
|
-
buckets: (counts[0] ?? []).flatMap((_, b) => {
|
|
118
|
-
let stack = 0;
|
|
119
|
-
return series.map((name, s) => {
|
|
120
|
-
const bucket = counts[s][b];
|
|
121
|
-
running[s] += bucket.length;
|
|
122
|
-
const count = cumulative ? running[s] : bucket.length;
|
|
123
|
-
const start = layout === "stacked" ? stack : 0;
|
|
124
|
-
stack += count;
|
|
125
|
-
return {
|
|
126
|
-
x0: bucket.x0,
|
|
127
|
-
x1: bucket.x1,
|
|
128
|
-
series: name,
|
|
129
|
-
start,
|
|
130
|
-
end: start + count,
|
|
131
|
-
count
|
|
132
|
-
};
|
|
133
|
-
});
|
|
134
|
-
}),
|
|
135
|
-
series,
|
|
136
|
-
edges
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
scales(ctx) {
|
|
140
|
-
const { buckets, edges } = this.buckets();
|
|
141
|
-
const { width, height } = ctx.plot;
|
|
142
|
-
const top = max(buckets, (bucket) => bucket.end) || 1;
|
|
143
|
-
const along = scaleLinear([edges[0], edges[edges.length - 1]], this.vertical ? [0, width] : [height, 0]);
|
|
144
|
-
const count = scaleLinear([0, top], this.vertical ? [height, 0] : [0, width]).nice();
|
|
145
|
-
return this.vertical ? {
|
|
146
|
-
x: along,
|
|
147
|
-
y: count
|
|
148
|
-
} : {
|
|
149
|
-
x: count,
|
|
150
|
-
y: along
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
plotMarks(ctx, axes) {
|
|
154
|
-
const along = this.vertical ? axes.x : axes.y;
|
|
155
|
-
const count = this.vertical ? axes.y : axes.x;
|
|
156
|
-
const frame = new BarFrame(this.vertical, count, scaleBand());
|
|
157
|
-
const { buckets, series } = this.buckets();
|
|
158
|
-
const { layout, density } = this.options;
|
|
159
|
-
const single = layout === "single";
|
|
160
|
-
if (!this.vertical) this.countGrid(ctx, count);
|
|
161
|
-
const overlaid = layout === "overlaid";
|
|
162
|
-
const edge = (d) => Math.min(along(d.x0), along(d.x1)) + 1;
|
|
163
|
-
const size = (d) => Math.max(1, Math.abs(along(d.x1) - along(d.x0)) - 2);
|
|
164
|
-
const name = (d) => single ? this.options.y : d.series;
|
|
165
|
-
const shown = overlaid ? [] : buckets;
|
|
166
|
-
const bars = ctx.marks("bars", "path", shown, (d) => `${d.x0}/${d.series}`).attr("fill", (d) => ctx.palette.color(name(d)));
|
|
167
|
-
const outer = (d) => d.series === series[series.length - 1];
|
|
168
|
-
ctx.set(bars, { d: (d) => frame.bar(edge(d), size(d), d.start, d.end, outer(d) ? 3 : 0, d.start ? 2 : 0) }, { d: (d) => frame.bar(edge(d), size(d), d.start, d.start, 0) }, 6);
|
|
169
|
-
const tip = (d) => ({
|
|
170
|
-
title: `${d.x0}–${d.x1}`,
|
|
171
|
-
color: ctx.palette.color(name(d)),
|
|
172
|
-
rows: [[single ? "Count" : d.series, d.count]]
|
|
173
|
-
});
|
|
174
|
-
ctx.hover(bars, tip);
|
|
175
|
-
const steps = series.map((key) => ({
|
|
176
|
-
key,
|
|
177
|
-
path: this.stepPath(buckets.filter((d) => d.series === key), along, count)
|
|
178
|
-
}));
|
|
179
|
-
const areas = ctx.marks("outlines", "path", overlaid ? steps : [], (d) => d.key).attr("fill", (d) => this.options.cumulative ? "none" : ctx.palette.color(d.key)).attr("fill-opacity", .16).attr("stroke", (d) => ctx.palette.color(d.key)).attr("stroke-width", 2).attr("stroke-linejoin", "round");
|
|
180
|
-
ctx.set(areas, { d: (d) => d.path });
|
|
181
|
-
const zones = ctx.marks("zones", "rect", overlaid ? buckets : [], (d) => `${d.x0}/${d.series}`).attr("fill", "transparent").attr("x", (d) => this.vertical ? edge(d) : 0).attr("y", (d) => this.vertical ? count(d.end) : edge(d)).attr("width", (d) => this.vertical ? size(d) : count(d.end)).attr("height", (d) => this.vertical ? Math.abs(count(0) - count(d.end)) : size(d));
|
|
182
|
-
ctx.hover(zones, tip);
|
|
183
|
-
this.drawDensity(ctx, density ? this.kde(buckets) : [], along, count);
|
|
184
|
-
}
|
|
185
|
-
stepPath(rows, along, count) {
|
|
186
|
-
const point = (x, n) => this.vertical ? `${along(x).toFixed(2)},${count(n).toFixed(2)}` : `${count(n).toFixed(2)},${along(x).toFixed(2)}`;
|
|
187
|
-
if (!rows.length) return "";
|
|
188
|
-
const close = this.options.cumulative ? [] : [point(rows[rows.length - 1].x1, 0)];
|
|
189
|
-
return `M${[
|
|
190
|
-
point(rows[0].x0, 0),
|
|
191
|
-
...rows.flatMap((row) => [point(row.x0, row.count), point(row.x1, row.count)]),
|
|
192
|
-
...close
|
|
193
|
-
].join("L")}`;
|
|
194
|
-
}
|
|
195
|
-
countGrid(ctx, count) {
|
|
196
|
-
const ticks = this.options.grid === false ? [] : count.ticks(Math.min(this.xTicks(), Math.floor(ctx.plot.width / 80)));
|
|
197
|
-
ctx.group("count-grid").lower().selectAll("line").data(ticks).join("line").attr("x1", (tick) => count(tick)).attr("x2", (tick) => count(tick)).attr("y1", 0).attr("y2", ctx.plot.height).attr("stroke", ctx.theme.grid);
|
|
198
|
-
}
|
|
199
|
-
/** Gaussian kernel density with Silverman's bandwidth, scaled to bin counts. */
|
|
200
|
-
kde(buckets) {
|
|
201
|
-
const values = this.values.map((item) => item.value).sort(ascending);
|
|
202
|
-
if (values.length < 2 || !buckets.length) return [];
|
|
203
|
-
const h = .9 * (Math.min(deviation(values) ?? 1, ((quantile(values, .75) ?? 0) - (quantile(values, .25) ?? 0)) / 1.34) || 1) * values.length ** -.2;
|
|
204
|
-
const width = buckets[0].x1 - buckets[0].x0;
|
|
205
|
-
const low = buckets[0].x0, high = buckets[buckets.length - 1].x1;
|
|
206
|
-
return Array.from({ length: 64 }, (_, i) => {
|
|
207
|
-
const at = low + (high - low) * i / 63;
|
|
208
|
-
return [at, sum(values, (value) => Math.exp(-.5 * ((at - value) / h) ** 2)) / (h * Math.sqrt(2 * Math.PI)) * width];
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
drawDensity(ctx, points, along, count) {
|
|
212
|
-
const curve = line().curve(Scales.curve(CurveKind.Monotone)).x((d) => this.vertical ? along(d[0]) : count(d[1])).y((d) => this.vertical ? count(d[1]) : along(d[0]));
|
|
213
|
-
const paths = ctx.marks("density", "path", points.length ? [points] : []).attr("fill", "none").attr("stroke", ctx.theme.ink).attr("stroke-width", 2).attr("stroke-linecap", "round").attr("d", (d) => curve(d));
|
|
214
|
-
ctx.drawOn(paths);
|
|
215
|
-
}
|
|
216
|
-
};
|
|
217
|
-
export { HistogramBar, HistogramBarBinning, HistogramBarLayout };
|