@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.
Files changed (238) hide show
  1. package/README.md +111 -14
  2. package/dist/ExcelWriter-3ZSYUH4T.cjs +154 -0
  3. package/dist/GraphType.js +24 -38
  4. package/dist/PdfWriter-6HJFYMCO.cjs +205 -0
  5. package/dist/catalog-YWX6FHRM.cjs +8 -0
  6. package/dist/catalog.js +5 -1
  7. package/dist/charts/bars/index.js +2 -12
  8. package/dist/charts/comparison/EffectForestPlot.js +1 -1
  9. package/dist/charts/comparison/index.js +1 -8
  10. package/dist/charts/demography/Nomogram.js +3 -3
  11. package/dist/charts/density/HexbinChart.js +6 -4
  12. package/dist/charts/diagrams/ArchitectureCanvas.js +68 -0
  13. package/dist/charts/diagrams/ArchitectureDiagram.js +331 -0
  14. package/dist/charts/diagrams/ArchitectureLayout.js +106 -0
  15. package/dist/charts/diagrams/ArchitectureLinkLabels.js +78 -0
  16. package/dist/charts/diagrams/ArchitectureModel.js +108 -0
  17. package/dist/charts/diagrams/ArchitectureRouter.js +348 -0
  18. package/dist/charts/diagrams/ArchitectureSamples.js +312 -0
  19. package/dist/charts/diagrams/ArchitectureShapes.js +130 -0
  20. package/dist/charts/diagrams/ArchitectureText.js +25 -0
  21. package/dist/charts/diagrams/DiagramText.js +38 -0
  22. package/dist/charts/diagrams/EntityRelationshipDiagram.js +465 -0
  23. package/dist/charts/diagrams/ErCrowsFoot.js +33 -0
  24. package/dist/charts/diagrams/ErSamples.js +205 -0
  25. package/dist/charts/diagrams/ErSchema.js +122 -0
  26. package/dist/charts/diagrams/LogicCircuit.js +154 -0
  27. package/dist/charts/diagrams/LogicCircuitLayout.js +600 -0
  28. package/dist/charts/diagrams/LogicCircuitSamples.js +66 -0
  29. package/dist/charts/diagrams/LogicGateDiagram.js +216 -0
  30. package/dist/charts/diagrams/LogicGateSymbol.js +113 -0
  31. package/dist/charts/diagrams/NetworkTopologyDiagram.js +247 -0
  32. package/dist/charts/diagrams/SequenceDiagram.js +351 -0
  33. package/dist/charts/diagrams/SequenceLayout.js +422 -0
  34. package/dist/charts/diagrams/SequenceModel.js +221 -0
  35. package/dist/charts/diagrams/TopologyLayout.js +143 -0
  36. package/dist/charts/diagrams/architectureEnums.js +50 -0
  37. package/dist/charts/diagrams/index.js +26 -0
  38. package/dist/charts/diagrams/logicEnums.js +42 -0
  39. package/dist/charts/diagrams/sequenceEnums.js +40 -0
  40. package/dist/charts/distribution/HistogramChart.js +25 -3
  41. package/dist/charts/distribution/index.js +1 -3
  42. package/dist/charts/earthscience/HovmollerDiagram.js +477 -0
  43. package/dist/charts/earthscience/HovmollerEnums.js +42 -0
  44. package/dist/charts/earthscience/HovmollerField.js +180 -0
  45. package/dist/charts/earthscience/HovmollerSample.js +40 -0
  46. package/dist/charts/earthscience/HovmollerSpeed.js +71 -0
  47. package/dist/charts/earthscience/index.js +10 -2
  48. package/dist/charts/engineering/ConstellationDiagram.js +26 -6
  49. package/dist/charts/engineering/EyeDiagram.js +2 -1
  50. package/dist/charts/engineering/PoleZeroPlot.js +32 -8
  51. package/dist/charts/financial/RelativeStrengthRotation.js +434 -0
  52. package/dist/charts/financial/RelativeStrengthRotationMath.js +71 -0
  53. package/dist/charts/financial/RelativeStrengthRotationSamples.js +27 -0
  54. package/dist/charts/financial/index.js +5 -3
  55. package/dist/charts/flow/index.js +1 -5
  56. package/dist/charts/frameworks/AnsoffMatrix.js +523 -0
  57. package/dist/charts/frameworks/FrameworkText.js +98 -0
  58. package/dist/charts/frameworks/NpsGauge.js +279 -0
  59. package/dist/charts/frameworks/NpsSurvey.js +58 -0
  60. package/dist/charts/frameworks/PerceptualMap.js +419 -0
  61. package/dist/charts/frameworks/PerceptualProjection.js +142 -0
  62. package/dist/charts/frameworks/PositioningSamples.js +191 -0
  63. package/dist/charts/frameworks/RaciMatrix.js +458 -0
  64. package/dist/charts/frameworks/RaciPlan.js +81 -0
  65. package/dist/charts/frameworks/RaciSamples.js +76 -0
  66. package/dist/charts/frameworks/SwotMatrix.js +358 -0
  67. package/dist/charts/frameworks/SwotSamples.js +85 -0
  68. package/dist/charts/frameworks/VanWestendorpChart.js +187 -0
  69. package/dist/charts/frameworks/VanWestendorpSurvey.js +197 -0
  70. package/dist/charts/frameworks/index.js +26 -0
  71. package/dist/charts/frameworks/raciEnums.js +30 -0
  72. package/dist/charts/frameworks/swotEnums.js +34 -0
  73. package/dist/charts/genomics/CircosPlot.js +1 -1
  74. package/dist/charts/geoflows/GeoFlowChart.js +2 -2
  75. package/dist/charts/geoflows/GeoFlowSample.js +2 -1
  76. package/dist/charts/geomaps/FloorPlanMap.js +324 -0
  77. package/dist/charts/geomaps/FloorPlanModel.js +179 -0
  78. package/dist/charts/geomaps/FloorPlanSamples.js +416 -0
  79. package/dist/charts/geomaps/GeoLand.js +2 -2
  80. package/dist/charts/geomaps/GeoSamples.js +2 -1
  81. package/dist/charts/geomaps/GraticuleMap.js +2 -2
  82. package/dist/charts/geomaps/RoomLabelFit.js +200 -0
  83. package/dist/charts/geomaps/TissotMap.js +2 -2
  84. package/dist/charts/geomaps/index.js +8 -4
  85. package/dist/charts/hierarchy/SunburstChart.js +17 -10
  86. package/dist/charts/hierarchy/index.js +2 -11
  87. package/dist/charts/indicators/BulletChart.js +8 -2
  88. package/dist/charts/indicators/SpeedometerChart.js +1 -1
  89. package/dist/charts/indicators/ThermometerChart.js +1 -1
  90. package/dist/charts/lifescience/LoessFit.js +113 -0
  91. package/dist/charts/lifescience/MaPlot.js +337 -0
  92. package/dist/charts/lifescience/MaPlotSamples.js +35 -0
  93. package/dist/charts/lifescience/OncoGlyph.js +137 -0
  94. package/dist/charts/lifescience/OncoPrint.js +373 -0
  95. package/dist/charts/lifescience/OncoPrintMatrix.js +107 -0
  96. package/dist/charts/lifescience/OncoPrintSamples.js +142 -0
  97. package/dist/charts/lifescience/PedigreeChart.js +306 -0
  98. package/dist/charts/lifescience/PedigreeLayout.js +261 -0
  99. package/dist/charts/lifescience/PedigreeRows.js +70 -0
  100. package/dist/charts/lifescience/PedigreeSamples.js +161 -0
  101. package/dist/charts/lifescience/PedigreeSymbol.js +47 -0
  102. package/dist/charts/lifescience/RamachandranPlot.js +364 -0
  103. package/dist/charts/lifescience/RamachandranRegions.js +2712 -0
  104. package/dist/charts/lifescience/RamachandranSamples.js +235 -0
  105. package/dist/charts/lifescience/index.js +25 -0
  106. package/dist/charts/lifescience/pedigreeEnums.js +21 -0
  107. package/dist/charts/lifescience/ramachandranEnums.js +34 -0
  108. package/dist/charts/linesareas/DualAxisChart.js +1 -1
  109. package/dist/charts/linesareas/LineEnums.js +1 -15
  110. package/dist/charts/linesareas/MultiLineChart.js +1 -1
  111. package/dist/charts/linesareas/TrendChart.js +15 -5
  112. package/dist/charts/linesareas/index.js +2 -6
  113. package/dist/charts/massive/MassiveChart.js +3 -2
  114. package/dist/charts/mathematical/FourierSeriesChart.js +7 -1
  115. package/dist/charts/mathematical/index.js +2 -6
  116. package/dist/charts/matrix/GridPlot.js +27 -2
  117. package/dist/charts/matrix/TilegramChart.js +2 -2
  118. package/dist/charts/mlcharts/AttentionGrid.js +79 -0
  119. package/dist/charts/mlcharts/AttentionHeatmap.js +329 -0
  120. package/dist/charts/mlcharts/AttentionModel.js +132 -0
  121. package/dist/charts/mlcharts/AttentionSamples.js +82 -0
  122. package/dist/charts/mlcharts/CellNumber.js +8 -0
  123. package/dist/charts/mlcharts/CurveDiagnosticSamples.js +95 -0
  124. package/dist/charts/mlcharts/CurvePickMark.js +31 -0
  125. package/dist/charts/mlcharts/DecisionBoundaryChart.js +316 -0
  126. package/dist/charts/mlcharts/DecisionSamples.js +60 -0
  127. package/dist/charts/mlcharts/DecisionSurface.js +130 -0
  128. package/dist/charts/mlcharts/DistinctTicks.js +13 -0
  129. package/dist/charts/mlcharts/ElbowMath.js +153 -0
  130. package/dist/charts/mlcharts/ElbowPlot.js +273 -0
  131. package/dist/charts/mlcharts/ExplainabilitySamples.js +70 -0
  132. package/dist/charts/mlcharts/FeatureImportanceChart.js +150 -0
  133. package/dist/charts/mlcharts/ImportanceRanking.js +98 -0
  134. package/dist/charts/mlcharts/LearningCurveChart.js +276 -0
  135. package/dist/charts/mlcharts/LearningCurveMath.js +92 -0
  136. package/dist/charts/mlcharts/PartialDependence.js +92 -0
  137. package/dist/charts/mlcharts/PartialDependencePlot.js +225 -0
  138. package/dist/charts/mlcharts/WideLabel.js +28 -0
  139. package/dist/charts/mlcharts/curveDiagnosticEnums.js +37 -0
  140. package/dist/charts/mlcharts/index.js +32 -0
  141. package/dist/charts/proportion/index.js +5 -9
  142. package/dist/charts/scatter/CategoryScatterBase.js +1 -4
  143. package/dist/charts/scatter/ConnectedScatter.js +7 -4
  144. package/dist/charts/scatter/MarginalScatter.js +13 -8
  145. package/dist/charts/scatter/index.js +4 -17
  146. package/dist/charts/scientific/SpectrogramChart.js +9 -3
  147. package/dist/charts/scientific/index.js +2 -2
  148. package/dist/charts/signals/index.js +3 -13
  149. package/dist/charts/statistics/LorenzCurve.js +7 -4
  150. package/dist/charts/threebars/Candlestick3DChart.js +18 -2
  151. package/dist/charts/threeglobe/GlobeChart.js +2 -2
  152. package/dist/charts/threeglobe/GlobeSamples.js +2 -1
  153. package/dist/charts/threeglobe/RingGlobe.js +1 -1
  154. package/dist/charts/threenetwork/ConeTreeChart.js +2 -1
  155. package/dist/charts/threenetwork/Gantt3DChart.js +3 -2
  156. package/dist/charts/threesurfaces/Ridgeline3DChart.js +22 -4
  157. package/dist/charts/threevolume/LorenzAttractor.js +19 -0
  158. package/dist/charts/threevolume/VolumeRaycastChart.js +4 -3
  159. package/dist/charts/threevolume/volumeEnums.js +1 -0
  160. package/dist/charts/timeline/index.js +2 -10
  161. package/dist/chunk-753UBLV2.cjs +33 -0
  162. package/dist/chunk-VX54A7KA.cjs +17 -0
  163. package/dist/{chunk-W5GAAAZY.cjs → chunk-WAODDPYX.cjs} +24874 -17620
  164. package/dist/chunk-Z3JPIJSC.cjs +338 -0
  165. package/dist/core/CartesianChart.js +87 -11
  166. package/dist/core/Chart.js +63 -15
  167. package/dist/core/Chart2D.js +54 -17
  168. package/dist/core/Chart3D.js +56 -20
  169. package/dist/core/ChartExportError.js +2 -0
  170. package/dist/core/ChartExporter.js +50 -8
  171. package/dist/core/ColumnCheck.js +53 -0
  172. package/dist/core/Context2D.js +29 -15
  173. package/dist/core/Context3D.js +7 -2
  174. package/dist/core/ExcelWriter.js +152 -0
  175. package/dist/core/ExportText.js +28 -0
  176. package/dist/core/MarkOrigin.js +88 -0
  177. package/dist/core/MarkStyle.js +294 -0
  178. package/dist/core/Palette.js +27 -7
  179. package/dist/core/PdfPage.js +13 -0
  180. package/dist/core/PdfWriter.js +245 -0
  181. package/dist/core/Scales.js +52 -2
  182. package/dist/core/SceneOverlay.js +4 -4
  183. package/dist/core/TextFit.js +37 -0
  184. package/dist/core/Theme.js +28 -1
  185. package/dist/core/enums.js +33 -1
  186. package/dist/core/pathMorph.js +15 -0
  187. package/dist/data/SampleData.js +1 -17
  188. package/dist/data/WorldSample.js +23 -0
  189. package/dist/index.cjs +810 -691
  190. package/dist/index.d.cts +8390 -2925
  191. package/dist/index.d.ts +8392 -2927
  192. package/dist/index.js +106 -56
  193. package/dist/react/ChartView.js +18 -8
  194. package/dist/react/GraphHandle.js +2 -0
  195. package/dist/react/components.js +74 -116
  196. package/package.json +13 -3
  197. package/dist/catalog-4UP2YFNR.cjs +0 -7
  198. package/dist/charts/bars/BulletBar.js +0 -184
  199. package/dist/charts/bars/ErrorBarColumn.js +0 -147
  200. package/dist/charts/bars/HistogramBar.js +0 -217
  201. package/dist/charts/bars/MarimekkoBar.js +0 -191
  202. package/dist/charts/bars/ParetoBar.js +0 -143
  203. package/dist/charts/comparison/PanelChart.js +0 -70
  204. package/dist/charts/comparison/SmallMultipleBars.js +0 -134
  205. package/dist/charts/comparison/SpanChart.js +0 -118
  206. package/dist/charts/comparison/TrellisChart.js +0 -158
  207. package/dist/charts/distribution/RidgeSlabs3DChart.js +0 -169
  208. package/dist/charts/financial/Candlestick3D.js +0 -157
  209. package/dist/charts/flow/BumpFlow.js +0 -212
  210. package/dist/charts/flow/StreamFlow.js +0 -174
  211. package/dist/charts/geomaps/ThiessenMap.js +0 -106
  212. package/dist/charts/hierarchy/ConeTree3D.js +0 -135
  213. package/dist/charts/hierarchy/Hierarchy3DChart.js +0 -27
  214. package/dist/charts/hierarchy/SpherePack3D.js +0 -81
  215. package/dist/charts/hierarchy/SunburstTower3D.js +0 -93
  216. package/dist/charts/hierarchy/TreemapSkyline3D.js +0 -98
  217. package/dist/charts/linesareas/ConnectedScatterTime.js +0 -206
  218. package/dist/charts/linesareas/SmallMultipleLines.js +0 -153
  219. package/dist/charts/mathematical/ParametricSurface3D.js +0 -234
  220. package/dist/charts/mathematical/StrangeAttractor3D.js +0 -251
  221. package/dist/charts/proportion/ConeFunnel.js +0 -126
  222. package/dist/charts/proportion/ExtrudedPieChart.js +0 -123
  223. package/dist/charts/scatter/BeeswarmScatter.js +0 -151
  224. package/dist/charts/scatter/BinnedScatterBase.js +0 -51
  225. package/dist/charts/scatter/ContourScatter.js +0 -116
  226. package/dist/charts/scatter/GridBinScatter.js +0 -98
  227. package/dist/charts/scatter/HexbinScatter.js +0 -74
  228. package/dist/charts/scatter/StripScatter.js +0 -107
  229. package/dist/charts/scatter/SunflowerScatter.js +0 -109
  230. package/dist/charts/signals/ConstellationChart.js +0 -153
  231. package/dist/charts/signals/CorrelogramChart.js +0 -171
  232. package/dist/charts/signals/EyeDiagramChart.js +0 -155
  233. package/dist/charts/signals/PoleZeroChart.js +0 -164
  234. package/dist/charts/signals/SpectrogramChart.js +0 -79
  235. package/dist/charts/timeline/CalendarSkylineChart.js +0 -128
  236. package/dist/charts/timeline/ScheduleBlocksChart.js +0 -119
  237. package/dist/charts/timeline/SpiralTimeline.js +0 -154
  238. package/dist/charts/timeline/StreamTimeline.js +0 -141
@@ -1,191 +0,0 @@
1
- import { CartesianChart } from "../../core/CartesianChart.js";
2
- import { ChartFamily, DataShape, Dimension, Orientation } from "../../core/enums.js";
3
- import { SampleData } from "../../data/SampleData.js";
4
- import { BarRows, BarSort } from "./BarRows.js";
5
- import { ascending, descending, scaleLinear, sum } from "d3";
6
- // src/charts/bars/MarimekkoBar.ts
7
- var MekkoMode = /* @__PURE__ */ function(MekkoMode) {
8
- MekkoMode["Mosaic"] = "mosaic";
9
- MekkoMode["Spine"] = "spine";
10
- return MekkoMode;
11
- }({});
12
- /** Band positions at custom offsets, so tick labels can sit under columns of unequal width. */
13
- var placed = (bands, centers, span) => {
14
- const scale = ((band) => centers.get(band));
15
- return Object.assign(scale, {
16
- domain: () => bands,
17
- range: () => [0, span],
18
- copy: () => scale
19
- });
20
- };
21
- /** Two-way composition: column width is a category's size, segment height its internal mix. */
22
- var MarimekkoBar = class extends CartesianChart {
23
- static meta = {
24
- id: "bar-marimekko",
25
- name: "Marimekko bar",
26
- family: ChartFamily.Composition,
27
- dimension: Dimension.Two,
28
- shape: DataShape.Table,
29
- description: "Sizes columns by total and splits them by share, so each cell area is that combination of a market.",
30
- tags: [
31
- "mekko",
32
- "mosaic",
33
- "spine",
34
- "variable width"
35
- ],
36
- sample: (seed) => SampleData.categories(seed, 6, 4),
37
- variants: {
38
- orientation: [Orientation.Vertical, Orientation.Horizontal],
39
- mode: ["mosaic", "spine"],
40
- sort: [
41
- BarSort.Descending,
42
- BarSort.Data,
43
- BarSort.Ascending
44
- ],
45
- ranked: [false, true],
46
- labels: [false, true]
47
- },
48
- valid: (values) => !(values.mode === "spine" && values.ranked)
49
- };
50
- zoomAxes() {
51
- return null;
52
- }
53
- defaults() {
54
- return {
55
- x: "category",
56
- y: "value",
57
- series: "series",
58
- orientation: Orientation.Vertical,
59
- mode: "mosaic",
60
- sort: BarSort.Descending,
61
- ranked: false,
62
- labels: false
63
- };
64
- }
65
- get vertical() {
66
- return this.options.orientation === Orientation.Vertical;
67
- }
68
- layout() {
69
- const { data, x, y, series, sort, ranked, mode, focus } = this.options;
70
- const positive = (data ?? []).filter((row) => (BarRows.number(row[y]) ?? 0) > 0);
71
- const pivot = BarRows.pivot(positive, x, series, y);
72
- const grand = sum(pivot.bands, pivot.total) || 1;
73
- const bands = BarRows.order(pivot.bands, sort, pivot.total, (band) => band);
74
- const spine = mode === "spine";
75
- const key = focus ?? pivot.series[0] ?? "";
76
- const names = spine ? [key, "Other"] : pivot.series;
77
- let along = 0;
78
- const columns = [], cells = [];
79
- for (const band of bands) {
80
- const total = pivot.total(band), span = total / grand;
81
- columns.push({
82
- band,
83
- total,
84
- start: along,
85
- end: along + span
86
- });
87
- const value = (name) => spine && name === "Other" ? total - pivot.cell(band, key) : pivot.cell(band, name);
88
- const parts = names.map((name) => ({
89
- name,
90
- size: value(name)
91
- })).filter((part) => part.size > 0);
92
- if (ranked) parts.sort((a, b) => descending(a.size, b.size) || ascending(a.name, b.name));
93
- let up = 0;
94
- for (const { name, size } of parts) {
95
- const share = size / total;
96
- cells.push({
97
- band,
98
- series: name,
99
- value: size,
100
- share,
101
- x0: along,
102
- x1: along + span,
103
- y0: up,
104
- y1: up + share
105
- });
106
- up += share;
107
- }
108
- along += span;
109
- }
110
- return {
111
- columns,
112
- cells,
113
- series: names
114
- };
115
- }
116
- scales(ctx) {
117
- const { width, height } = ctx.plot;
118
- const { columns } = this.layout();
119
- const across = this.vertical ? width : height;
120
- const band = placed(columns.map((column) => column.band), new Map(columns.map((column) => [column.band, (column.start + column.end) / 2 * across])), across);
121
- const share = scaleLinear([0, 100], this.vertical ? [height, 0] : [0, width]);
122
- return this.vertical ? {
123
- x: band,
124
- y: share
125
- } : {
126
- x: share,
127
- y: band
128
- };
129
- }
130
- tickFormat(scale) {
131
- if (typeof (scale.domain?.() ?? [])[0] === "number") return (value) => `${value}%`;
132
- const { columns } = this.layout();
133
- const [, span = 0] = scale.range();
134
- const width = new Map(columns.map((column) => [column.band, (column.end - column.start) * span]));
135
- return (value) => {
136
- const name = String(value), room = this.vertical ? Math.floor(((width.get(name) ?? 0) - 6) / 6.2) : 14;
137
- return room < 3 ? "" : BarRows.clip(name, room);
138
- };
139
- }
140
- plotMarks(ctx) {
141
- const { cells, series } = this.layout();
142
- const { width, height } = ctx.plot;
143
- if (this.options.mode === "mosaic") series.forEach(ctx.palette.color);
144
- const across = this.vertical ? width : height, along = this.vertical ? height : width;
145
- const box = (d) => {
146
- const a = d.x0 * across + 1, b = d.x1 * across - 1;
147
- const c = (1 - d.y1) * along + (d.y1 < 1 ? 1 : 0), e = (1 - d.y0) * along - (d.y0 > 0 ? 1 : 0);
148
- return this.vertical ? {
149
- x: a,
150
- y: c,
151
- width: Math.max(0, b - a),
152
- height: Math.max(0, e - c)
153
- } : {
154
- x: along - e,
155
- y: a,
156
- width: Math.max(0, e - c),
157
- height: Math.max(0, b - a)
158
- };
159
- };
160
- const fill = (d) => d.series === "Other" && this.options.mode === "spine" ? ctx.theme.grid : ctx.palette.color(d.series);
161
- const rects = ctx.marks("cells", "rect", cells, (d) => `${d.band}/${d.series}`).attr("fill", fill).attr("rx", 2);
162
- ctx.set(rects, {
163
- x: (d) => box(d).x,
164
- y: (d) => box(d).y,
165
- width: (d) => box(d).width,
166
- height: (d) => box(d).height
167
- }, this.vertical ? {
168
- x: (d) => box(d).x,
169
- width: (d) => box(d).width,
170
- y: height,
171
- height: 0
172
- } : {
173
- y: (d) => box(d).y,
174
- height: (d) => box(d).height,
175
- x: 0,
176
- width: 0
177
- }, 10);
178
- ctx.hover(rects, (d) => ({
179
- title: d.band,
180
- color: fill(d),
181
- rows: [[d.series, d.value], ["Share of column", `${(d.share * 100).toFixed(1)}%`]]
182
- }));
183
- const fits = (d) => box(d).width >= 28 && box(d).height >= 16;
184
- const text = ctx.marks("cell-labels", "text", this.options.labels ? cells.filter(fits) : [], (d) => `${d.band}/${d.series}`).text((d) => `${Math.round(d.share * 100)}%`).attr("text-anchor", "middle").attr("font-size", 10.5).attr("font-family", ctx.theme.fontFamily).attr("fill", (d) => d.series === "Other" ? ctx.theme.inkSecondary : ctx.palette.inkOn(fill(d))).style("pointer-events", "none");
185
- ctx.set(text, {
186
- x: (d) => box(d).x + box(d).width / 2,
187
- y: (d) => box(d).y + box(d).height / 2 + 3.5
188
- });
189
- }
190
- };
191
- export { MarimekkoBar, MekkoMode };
@@ -1,143 +0,0 @@
1
- import { ChartFamily, DataShape, Dimension, LegendPosition, Orientation } from "../../core/enums.js";
2
- import { ZoomAxis } from "../../core/ChartViewport.js";
3
- import { SampleData } from "../../data/SampleData.js";
4
- import { BandChart } from "./BandChart.js";
5
- import { BarRows } from "./BarRows.js";
6
- import { axisRight, curveLinear, curveStepAfter, descending, line, scaleLinear, sum } from "d3";
7
- // src/charts/bars/ParetoBar.ts
8
- var ParetoBarLine = /* @__PURE__ */ function(ParetoBarLine) {
9
- ParetoBarLine["Linear"] = "linear";
10
- ParetoBarLine["Step"] = "step";
11
- return ParetoBarLine;
12
- }({});
13
- /** The vital few: sorted bars with a cumulative line, to find which causes account for most of an effect. */
14
- var ParetoBar = class extends BandChart {
15
- static meta = {
16
- id: "bar-pareto",
17
- name: "Pareto chart",
18
- family: ChartFamily.Statistical,
19
- dimension: Dimension.Two,
20
- shape: DataShape.Table,
21
- description: "Sorts causes by size against a running total, to show how few of them account for most of the effect.",
22
- tags: [
23
- "80 20",
24
- "cumulative",
25
- "quality"
26
- ],
27
- sample: (seed) => SampleData.categories(seed, 10, 1),
28
- variants: {
29
- lineShape: ["linear", "step"],
30
- groupTail: [false, true],
31
- threshold: [80, 0],
32
- points: [true, false],
33
- padding: [.15, .04]
34
- }
35
- };
36
- zoomAxes() {
37
- return ZoomAxis.X;
38
- }
39
- defaults() {
40
- return {
41
- x: "category",
42
- y: "value",
43
- orientation: Orientation.Vertical,
44
- lineShape: "linear",
45
- groupTail: false,
46
- threshold: 80,
47
- points: true,
48
- padding: .15
49
- };
50
- }
51
- get items() {
52
- const { data, x, y, groupTail, threshold } = this.options;
53
- const rows = BarRows.rollup(data, x, y).filter((row) => row.value > 0).sort((a, b) => descending(a.value, b.value));
54
- const total = sum(rows, (row) => row.value) || 1;
55
- const items = [];
56
- let running = 0;
57
- for (const row of rows) {
58
- running += row.value;
59
- items.push({
60
- ...row,
61
- running: running / total * 100
62
- });
63
- }
64
- const cut = threshold || 80;
65
- const keep = items.findIndex((item) => item.running >= cut) + 1;
66
- if (!groupTail || !keep || keep >= items.length - 1) return items;
67
- const tail = items.slice(keep);
68
- return [...items.slice(0, keep), {
69
- band: `Other (${tail.length})`,
70
- value: sum(tail, (item) => item.value),
71
- running: 100
72
- }];
73
- }
74
- get vertical() {
75
- return true;
76
- }
77
- get legendPosition() {
78
- return LegendPosition.None;
79
- }
80
- bandNames() {
81
- return this.items.map((item) => item.band);
82
- }
83
- bandPadding() {
84
- return this.options.padding;
85
- }
86
- valueExtent() {
87
- return [0, sum(this.items, (item) => item.value) || 1];
88
- }
89
- valueScale(domain) {
90
- return scaleLinear().domain(domain);
91
- }
92
- baseline() {
93
- return null;
94
- }
95
- plotMargin() {
96
- return {
97
- ...super.plotMargin(),
98
- right: 40
99
- };
100
- }
101
- drawBands(ctx, frame) {
102
- const { items } = this;
103
- const { y, points, threshold, lineShape } = this.options;
104
- const { width, height } = ctx.plot;
105
- const color = ctx.palette.color(y);
106
- const percent = scaleLinear([0, 100], [height, 0]);
107
- this.percentAxis(ctx, percent, width);
108
- const bars = ctx.marks("bars", "path", items, (d) => d.band).attr("fill", color);
109
- const at = (d) => frame.band(d.band) ?? 0;
110
- ctx.set(bars, { d: (d) => frame.bar(at(d), frame.thick, 0, d.value) }, { d: (d) => frame.bar(at(d), frame.thick, 0, 0) }, 25);
111
- ctx.hover(bars, (d) => ({
112
- title: d.band,
113
- color,
114
- rows: [[y, d.value], ["Cumulative", `${d.running.toFixed(1)}%`]]
115
- }));
116
- const rule = ctx.marks("threshold", "line", threshold ? [threshold] : []).attr("stroke", ctx.theme.inkMuted).attr("stroke-width", 1).attr("stroke-dasharray", "4 3");
117
- ctx.set(rule, {
118
- x1: 0,
119
- x2: width,
120
- y1: (d) => percent(d),
121
- y2: (d) => percent(d)
122
- });
123
- const trend = line().curve(lineShape === "step" ? curveStepAfter : curveLinear).x((d) => frame.center(d.band)).y((d) => percent(d.running));
124
- const stroke = ctx.theme.ink;
125
- const path = ctx.marks("cumulative", "path", items.length ? [items] : []).attr("fill", "none").attr("stroke", stroke).attr("stroke-width", 2).attr("stroke-linejoin", "round").attr("d", (d) => trend(d));
126
- ctx.drawOn(path);
127
- const dots = ctx.marks("points", "circle", points ? items : [], (d) => d.band).attr("r", 4).attr("fill", stroke).attr("stroke", ctx.theme.surface).attr("stroke-width", 2);
128
- ctx.set(dots, {
129
- cx: (d) => frame.center(d.band),
130
- cy: (d) => percent(d.running)
131
- });
132
- ctx.hover(dots, (d) => ({
133
- title: d.band,
134
- rows: [["Cumulative", `${d.running.toFixed(1)}%`]]
135
- }));
136
- }
137
- percentAxis(ctx, percent, width) {
138
- const axis = ctx.group("axis-percent").attr("transform", `translate(${width},0)`).call(axisRight(percent).ticks(5).tickSize(0).tickFormat((value) => `${value}%`));
139
- axis.select(".domain").attr("stroke", "none");
140
- axis.selectAll("text").attr("fill", ctx.theme.inkSecondary).attr("font-size", 11).attr("font-family", ctx.theme.fontFamily);
141
- }
142
- };
143
- export { ParetoBar, ParetoBarLine };
@@ -1,70 +0,0 @@
1
- import { Chart2D } from "../../core/Chart2D.js";
2
- import { Tally } from "./Tally.js";
3
- import { max, select } from "d3";
4
- // src/charts/comparison/PanelChart.ts
5
- /** How panels wrap across the plot. */
6
- var PanelFlow = /* @__PURE__ */ function(PanelFlow) {
7
- PanelFlow["Auto"] = "auto";
8
- PanelFlow["Row"] = "row";
9
- PanelFlow["Column"] = "column";
10
- return PanelFlow;
11
- }({});
12
- var TITLE = 18;
13
- var GAP_Y = 8;
14
- /** A wrapped grid of small panels sharing one reading: each subclass fills a panel with its marks. */
15
- var PanelChart = class extends Chart2D {
16
- panels(ctx, keys, gutter) {
17
- const { width, height } = ctx.plot;
18
- const n = keys.length, gapY = gutter.gapY ?? GAP_Y;
19
- const flow = this.options.flow ?? "auto";
20
- const columns = Math.max(1, flow === "row" ? n : flow === "column" ? 1 : Math.min(n, Math.ceil(Math.sqrt(n * width / height / 1.6))));
21
- const rows = Math.max(1, Math.ceil(n / columns));
22
- const side = (height - gutter.bottom) / rows < 58;
23
- const titleWidth = side ? Math.min(84, (max(keys, (key) => Tally.width(key)) ?? 0) + 8) : 0;
24
- const left = gutter.left + titleWidth;
25
- const cellWidth = (width - left - (columns - 1) * gutter.gapX) / columns;
26
- const cellHeight = (height - gutter.bottom - (rows - 1) * gapY) / rows;
27
- return keys.map((key, index) => {
28
- const column = index % columns, row = Math.floor(index / columns);
29
- const title = side ? 0 : TITLE;
30
- return {
31
- key,
32
- index,
33
- side,
34
- room: side ? titleWidth - 8 : Math.max(4, cellWidth) + gutter.gapX - 4,
35
- x: left + column * (cellWidth + gutter.gapX),
36
- y: row * (cellHeight + gapY) + title,
37
- width: Math.max(4, cellWidth),
38
- height: Math.max(4, cellHeight - title),
39
- left: column === 0,
40
- bottom: index + columns >= n
41
- };
42
- });
43
- }
44
- /** One `<g>` per panel, with its title, ready for `fill`. */
45
- eachPanel(ctx, panels, fill) {
46
- ctx.marks("panels", "g", panels, (panel) => panel.key).attr("transform", (panel) => `translate(${panel.x},${panel.y})`).each(function(panel) {
47
- const group = select(this);
48
- ctx.text(ctx.marks("title", "text", [panel], (d) => d.key, group), 11, "ink").attr("font-weight", 600).attr("x", panel.side ? -panel.x : 0).attr("y", panel.side ? panel.height / 2 + 4 : -6).text(Tally.clip(panel.key, panel.room));
49
- fill(panel, group);
50
- });
51
- }
52
- /** Recessive grid across a panel, labelled when `labelled`. */
53
- panelGrid(ctx, group, panel, scale, axis, labelled) {
54
- const ticks = scale.ticks(axis === "y" ? Math.max(2, Math.floor(panel.height / 32)) : Math.max(2, Math.floor(panel.width / 56)));
55
- const reach = max(scale.domain(), (value) => Math.abs(value)) ?? 0;
56
- const rules = ctx.marks("rules", "line", ticks, (tick) => tick, group).attr("stroke", ctx.theme.grid);
57
- if (axis === "y") rules.attr("x1", 0).attr("x2", panel.width).attr("y1", (tick) => scale(tick)).attr("y2", (tick) => scale(tick));
58
- else rules.attr("y1", 0).attr("y2", panel.height).attr("x1", (tick) => scale(tick)).attr("x2", (tick) => scale(tick));
59
- const room = axis === "y" ? 12 : 34;
60
- const stacked = axis === "y" && panel.y > TITLE;
61
- const spaced = ticks.filter((tick, i) => i === 0 || Math.abs(scale(tick) - scale(ticks[0])) / i >= room).filter((tick) => !stacked || scale(tick) >= 5);
62
- const labels = ctx.text(ctx.marks("ticks", "text", labelled ? spaced : [], (tick) => tick, group), 10, "muted").text((tick) => tick.toLocaleString("en", {
63
- notation: reach >= 1e4 ? "compact" : "standard",
64
- maximumFractionDigits: reach < 10 ? 1 : 0
65
- }));
66
- if (axis === "y") labels.attr("text-anchor", "end").attr("x", -5).attr("y", (tick) => scale(tick) + 3);
67
- else labels.attr("text-anchor", "middle").attr("y", panel.height + 12).attr("x", (tick) => scale(tick));
68
- }
69
- };
70
- export { PanelChart, PanelFlow };
@@ -1,134 +0,0 @@
1
- import { ChartFamily, DataShape, Dimension, LegendPosition, Orientation } from "../../core/enums.js";
2
- import { SampleData } from "../../data/SampleData.js";
3
- import { PanelChart, PanelFlow } from "./PanelChart.js";
4
- import { ComparisonSort, Tally } from "./Tally.js";
5
- import { settleMarks } from "./settleMarks.js";
6
- import { max, mean, min, rollup, scaleBand, scaleLinear } from "d3";
7
- // src/charts/comparison/SmallMultipleBars.ts
8
- /** Which field makes the panels. */
9
- var BarFacet = /* @__PURE__ */ function(BarFacet) {
10
- BarFacet["Series"] = "series";
11
- BarFacet["Category"] = "category";
12
- return BarFacet;
13
- }({});
14
- /** One small bar chart per group, sharing scales, for comparing shapes that overlap when stacked in one plot. */
15
- var SmallMultipleBars = class extends PanelChart {
16
- static meta = {
17
- id: "comparison-small-multiple-bars",
18
- name: "Small multiple bars",
19
- family: ChartFamily.Comparison,
20
- dimension: Dimension.Two,
21
- shape: DataShape.Table,
22
- description: "Repeats a bar chart across panels of a grouping field so each group shows its own shape on shared axes.",
23
- tags: [
24
- "facet",
25
- "small multiples",
26
- "panel chart"
27
- ],
28
- sample: (seed) => SampleData.categories(seed, 7, 4),
29
- variants: {
30
- facet: ["series", "category"],
31
- orientation: [Orientation.Vertical, Orientation.Horizontal],
32
- flow: [
33
- PanelFlow.Auto,
34
- PanelFlow.Row,
35
- PanelFlow.Column
36
- ],
37
- freeScale: [false, true],
38
- sort: [ComparisonSort.Input, ComparisonSort.Descending]
39
- },
40
- valid: (values) => !(values.freeScale && values.flow === PanelFlow.Column && values.orientation === Orientation.Horizontal)
41
- };
42
- defaults() {
43
- return {
44
- legend: LegendPosition.None,
45
- category: "category",
46
- series: "series",
47
- value: "value",
48
- facet: "series",
49
- orientation: Orientation.Vertical,
50
- flow: PanelFlow.Auto,
51
- freeScale: false,
52
- sort: ComparisonSort.Input
53
- };
54
- }
55
- plotMargin() {
56
- return {
57
- top: 6,
58
- right: 16,
59
- bottom: 8,
60
- left: 16
61
- };
62
- }
63
- draw(ctx) {
64
- const { data, category, series, value, facet, orientation, freeScale, sort } = this.options;
65
- const panelField = facet === "series" ? series : category, barField = facet === "series" ? category : series;
66
- const clean = data.filter((row) => Tally.num(row[value]) !== null);
67
- const cells = rollup(clean, (rows) => mean(rows, (row) => Tally.num(row[value])) ?? 0, (row) => String(row[panelField] ?? ""), (row) => String(row[barField] ?? ""));
68
- const keys = [...cells.keys()];
69
- const names = [...new Set(clean.map((row) => String(row[barField] ?? "")))];
70
- const every = [...cells.values()].flatMap((line) => [...line.values()]);
71
- const vertical = orientation === Orientation.Vertical;
72
- const longest = Math.min(64, (max(names, (name) => Tally.width(name)) ?? 0) + 6);
73
- const widest = Tally.width(Tally.format(Math.round(max(every, Math.abs) ?? 0))) + 8;
74
- const axisLeft = vertical ? widest : longest;
75
- const panels = this.panels(ctx, keys, {
76
- left: axisLeft,
77
- bottom: 16,
78
- gapX: freeScale ? vertical ? widest + 6 : 18 : 12,
79
- gapY: freeScale && !vertical ? 20 : void 0
80
- });
81
- this.eachPanel(ctx, panels, (panel, group) => {
82
- const line = cells.get(panel.key);
83
- const bars = Tally.sorted([...line].map(([band, v]) => ({
84
- panel: panel.key,
85
- band,
86
- value: v
87
- })), sort, (d) => d.value, (d) => d.band);
88
- const order = sort === ComparisonSort.Input ? names.filter((name) => line.has(name)) : bars.map((d) => d.band);
89
- const span = freeScale ? [...line.values()] : every;
90
- const low = Math.min(0, min(span) ?? 0), high = Math.max(0, max(span) ?? 1);
91
- const scale = scaleLinear([low, high > low ? high : 1], vertical ? [panel.height, 0] : [0, panel.width]).nice();
92
- const band = scaleBand(order, vertical ? [0, panel.width] : [0, panel.height]).padding(.16);
93
- this.panelGrid(ctx, group, panel, scale, vertical ? "y" : "x", freeScale || (vertical ? panel.left : panel.bottom));
94
- const color = ctx.palette.color(panel.key);
95
- const zero = scale(0), thick = band.bandwidth();
96
- const rx = Math.min(3, thick / 2);
97
- const marks = ctx.marks("bars", "rect", bars, (d) => d.band, group).attr("fill", color).attr("rx", rx);
98
- settleMarks(ctx, marks, vertical ? {
99
- x: (d) => band(d.band),
100
- width: thick,
101
- y: (d) => Math.min(scale(d.value), zero),
102
- height: (d) => Math.abs(scale(d.value) - zero)
103
- } : {
104
- y: (d) => band(d.band),
105
- height: thick,
106
- x: (d) => Math.min(scale(d.value), zero),
107
- width: (d) => Math.abs(scale(d.value) - zero)
108
- }, vertical ? {
109
- y: zero,
110
- height: 0
111
- } : {
112
- x: zero,
113
- width: 0
114
- }, 10);
115
- ctx.hover(marks, (d) => ({
116
- title: d.panel,
117
- color,
118
- rows: [[d.band, Tally.format(d.value)]]
119
- }));
120
- this.bandNames(ctx, group, panel, order, band, vertical, longest);
121
- });
122
- }
123
- bandNames(ctx, group, panel, order, band, vertical, room) {
124
- const step = band.step() || 1;
125
- const labelled = vertical ? panel.bottom : panel.left && !panel.side;
126
- const widest = max(order, (name) => Tally.width(name)) ?? 0;
127
- const every = Math.max(1, Math.ceil((vertical ? Math.min(widest, 40) + 6 : 12) / step));
128
- const shown = labelled ? order.filter((_, i) => i % every === 0) : [];
129
- const texts = ctx.text(ctx.marks("names", "text", shown, (d) => d, group), 10, "secondary").text((d) => Tally.clip(d, vertical ? step * every - 2 : room - 6)).attr("text-anchor", vertical ? "middle" : "end");
130
- if (vertical) texts.attr("x", (d) => band(d) + band.bandwidth() / 2).attr("y", panel.height + 12);
131
- else texts.attr("x", -5).attr("y", (d) => band(d) + band.bandwidth() / 2 + 3);
132
- }
133
- };
134
- export { BarFacet, SmallMultipleBars };
@@ -1,118 +0,0 @@
1
- import { ChartFamily, DataShape, Dimension, LegendPosition, Orientation } from "../../core/enums.js";
2
- import { SampleData } from "../../data/SampleData.js";
3
- import { BandValueChart } from "./BandValueChart.js";
4
- import { ComparisonSort, ComparisonSpread, Tally } from "./Tally.js";
5
- import { settleMarks } from "./settleMarks.js";
6
- // src/charts/comparison/SpanChart.ts
7
- /** What marks the centre of a span. */
8
- var SpanMarker = /* @__PURE__ */ function(SpanMarker) {
9
- SpanMarker["None"] = "none";
10
- SpanMarker["Median"] = "median";
11
- SpanMarker["Mean"] = "mean";
12
- return SpanMarker;
13
- }({});
14
- /** How far each group reaches: a bar from low to high, derived from raw observations. */
15
- var SpanChart = class extends BandValueChart {
16
- static meta = {
17
- id: "comparison-span",
18
- name: "Span chart",
19
- family: ChartFamily.Comparison,
20
- dimension: Dimension.Two,
21
- shape: DataShape.Table,
22
- description: "Shows the low-to-high reach of each group as a floating bar, for comparing ranges rather than totals.",
23
- tags: [
24
- "range bar",
25
- "difference chart",
26
- "min max"
27
- ],
28
- sample: (seed) => SampleData.distribution(seed, 60, 6),
29
- variants: {
30
- statistic: [
31
- ComparisonSpread.Range,
32
- ComparisonSpread.Iqr,
33
- ComparisonSpread.Decile
34
- ],
35
- orientation: [Orientation.Horizontal, Orientation.Vertical],
36
- sort: [ComparisonSort.Input, ComparisonSort.Descending],
37
- marker: [
38
- "median",
39
- "mean",
40
- "none"
41
- ],
42
- ends: [false, true]
43
- }
44
- };
45
- defaults() {
46
- return {
47
- legend: LegendPosition.None,
48
- group: "group",
49
- value: "value",
50
- orientation: Orientation.Horizontal,
51
- statistic: ComparisonSpread.Range,
52
- sort: ComparisonSort.Input,
53
- marker: "median",
54
- ends: false
55
- };
56
- }
57
- bandLayout() {
58
- const { data, group, value, statistic, sort, ends } = this.options;
59
- const all = Tally.group(data, group, value).map((tally) => {
60
- const [low, high] = Tally.interval(tally, statistic);
61
- return {
62
- tally,
63
- low,
64
- high
65
- };
66
- });
67
- const items = Tally.sorted(all, sort, (d) => d.high - d.low, (d) => d.tally.key);
68
- const reach = items.flatMap((d) => [d.low, d.high]);
69
- const lo = Math.min(...reach), hi = Math.max(...reach), pad = ends && items.length ? (hi - lo) * .09 : 0;
70
- return {
71
- bands: items.map((d) => d.tally.key),
72
- items,
73
- values: items.length ? [lo - pad, hi + pad] : []
74
- };
75
- }
76
- plotBands(ctx, { items, band, mid, value }) {
77
- const { marker, ends } = this.options;
78
- const fill = ctx.palette.color(this.options.value);
79
- const width = band.bandwidth();
80
- const along = (d) => mid(d.tally.key);
81
- const centre = (d) => marker === "mean" ? d.tally.mean : d.tally.median;
82
- const tip = (d) => ({
83
- title: d.tally.key,
84
- color: fill,
85
- rows: [
86
- ["Low", Tally.format(d.low)],
87
- ["High", Tally.format(d.high)],
88
- ["Span", Tally.format(d.high - d.low)]
89
- ]
90
- });
91
- const bars = ctx.marks("bars", "rect", items, (d) => d.tally.key).attr("fill", fill).attr("rx", Math.min(4, width / 2));
92
- settleMarks(ctx, bars, this.span(along, width, (d) => value(d.low), (d) => value(d.high)), this.span(along, width, (d) => value(centre(d)), (d) => value(centre(d))), 30);
93
- ctx.hover(bars, tip);
94
- const ticks = ctx.marks("centres", "line", marker === "none" ? [] : items, (d) => d.tally.key).attr("stroke", ctx.palette.inkOn(fill)).attr("stroke-width", 2);
95
- settleMarks(ctx, ticks, this.cross(along, (d) => value(centre(d)), width / 2 - 1));
96
- const labels = ends ? items.flatMap((d) => [{
97
- key: `${d.tally.key}/low`,
98
- d,
99
- at: d.low,
100
- sign: this.vertical ? 1 : -1
101
- }, {
102
- key: `${d.tally.key}/high`,
103
- d,
104
- at: d.high,
105
- sign: this.vertical ? -1 : 1
106
- }]) : [];
107
- const shift = (d) => d.sign * (this.vertical ? d.sign > 0 ? 13 : 5 : 5);
108
- const texts = ctx.text(ctx.marks("ends", "text", labels, (d) => d.key)).text((d) => Tally.format(Math.round(d.at))).attr("text-anchor", (d) => this.vertical ? "middle" : d.sign > 0 ? "start" : "end");
109
- settleMarks(ctx, texts, this.vertical ? {
110
- x: (d) => along(d.d),
111
- y: (d) => value(d.at) + shift(d)
112
- } : {
113
- y: (d) => along(d.d) + 4,
114
- x: (d) => value(d.at) + shift(d)
115
- });
116
- }
117
- };
118
- export { SpanChart, SpanMarker };