@hpcc-js/chart 2.86.2 → 2.86.3

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 (78) hide show
  1. package/LICENSE +43 -43
  2. package/README.md +93 -93
  3. package/dist/index.es6.js.map +1 -1
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.min.js.map +1 -1
  6. package/package.json +6 -6
  7. package/src/Area.md +176 -176
  8. package/src/Area.ts +12 -12
  9. package/src/Axis.css +34 -34
  10. package/src/Axis.ts +733 -733
  11. package/src/Bar.md +90 -90
  12. package/src/Bar.ts +9 -9
  13. package/src/Bubble.css +16 -16
  14. package/src/Bubble.md +69 -69
  15. package/src/Bubble.ts +191 -191
  16. package/src/BubbleXY.ts +14 -14
  17. package/src/Bullet.css +60 -60
  18. package/src/Bullet.md +104 -104
  19. package/src/Bullet.ts +167 -167
  20. package/src/Column.css +17 -17
  21. package/src/Column.md +90 -90
  22. package/src/Column.ts +659 -659
  23. package/src/Contour.md +88 -88
  24. package/src/Contour.ts +97 -97
  25. package/src/D3Cloud.ts +400 -400
  26. package/src/Gantt.md +119 -119
  27. package/src/Gantt.ts +14 -14
  28. package/src/Gauge.md +148 -148
  29. package/src/Gauge.ts +358 -358
  30. package/src/HalfPie.md +62 -62
  31. package/src/HalfPie.ts +26 -26
  32. package/src/Heat.md +42 -42
  33. package/src/Heat.ts +283 -283
  34. package/src/HexBin.css +9 -9
  35. package/src/HexBin.md +88 -88
  36. package/src/HexBin.ts +139 -139
  37. package/src/Line.css +6 -6
  38. package/src/Line.md +170 -170
  39. package/src/Line.ts +14 -14
  40. package/src/Pie.css +23 -23
  41. package/src/Pie.md +88 -88
  42. package/src/Pie.ts +503 -503
  43. package/src/QuarterPie.md +61 -61
  44. package/src/QuarterPie.ts +35 -35
  45. package/src/QuartileCandlestick.md +129 -129
  46. package/src/QuartileCandlestick.ts +349 -349
  47. package/src/Radar.css +15 -15
  48. package/src/Radar.md +104 -104
  49. package/src/Radar.ts +336 -336
  50. package/src/RadialBar.css +25 -25
  51. package/src/RadialBar.md +91 -91
  52. package/src/RadialBar.ts +212 -212
  53. package/src/Scatter.css +16 -16
  54. package/src/Scatter.md +163 -163
  55. package/src/Scatter.ts +376 -376
  56. package/src/StatChart.md +117 -117
  57. package/src/StatChart.ts +253 -253
  58. package/src/Step.md +163 -163
  59. package/src/Step.ts +12 -12
  60. package/src/Summary.css +56 -56
  61. package/src/Summary.md +219 -219
  62. package/src/Summary.ts +322 -322
  63. package/src/SummaryC.md +154 -154
  64. package/src/SummaryC.ts +240 -240
  65. package/src/WordCloud.css +3 -3
  66. package/src/WordCloud.md +144 -144
  67. package/src/WordCloud.ts +263 -263
  68. package/src/XYAxis.css +41 -41
  69. package/src/XYAxis.md +149 -149
  70. package/src/XYAxis.ts +803 -803
  71. package/src/__package__.ts +3 -3
  72. package/src/__tests__/heat.ts +71 -71
  73. package/src/__tests__/index.ts +3 -3
  74. package/src/__tests__/pie.ts +20 -20
  75. package/src/__tests__/stat.ts +16 -16
  76. package/src/__tests__/test3.ts +69 -69
  77. package/src/index.ts +27 -27
  78. package/src/test.ts +71 -71
package/src/StatChart.ts CHANGED
@@ -1,253 +1,253 @@
1
- import { format as d3Format, HTMLWidget, Palette } from "@hpcc-js/common";
2
- import { QuartileCandlestick } from "./QuartileCandlestick";
3
- import { Scatter } from "./Scatter";
4
-
5
- const rainbow = Palette.rainbow("Blues");
6
- const palette = Palette.ordinal("Quartile", [rainbow(100, 0, 100), rainbow(50, 0, 100), rainbow(50, 0, 100), rainbow(75, 0, 100)]);
7
- palette("Std. Dev.");
8
- palette("MinMax");
9
- palette("25%");
10
- palette("50%");
11
-
12
- type View = "min_max" | "25_75" | "normal";
13
- type Tick = { label: string, value: number };
14
- type Ticks = Tick[];
15
- type AxisTick = { label: string, value: string };
16
- type AxisTicks = AxisTick[];
17
-
18
- function myFormatter(format: string): (num: number) => string {
19
- const formatter = d3Format(format);
20
- return function (num: number) {
21
- const strVal = (Math.round(num * 100) / 100).toString();
22
- if (strVal.length <= 4) return strVal;
23
- return formatter(num);
24
- };
25
- }
26
-
27
- export type StatChartView = "min_max" | "25_75" | "normal";
28
- export type Quartiles = [number, number, number, number, number];
29
- export type Data = [[number, number, number, number, number, number, number]];
30
-
31
- export class StatChart extends HTMLWidget {
32
-
33
- protected _selectElement: any;
34
- protected _tickFormatter: (_: number) => string;
35
-
36
- protected _bellCurve: Scatter = new Scatter()
37
- .columns(["", "Std. Dev."])
38
- .paletteID("Quartile")
39
- .interpolate_default("basis")
40
- .pointSize(0)
41
- .xAxisType("linear")
42
- .xAxisOverlapMode("none")
43
- .xAxisTickFormat(",")
44
- .yAxisHidden(true)
45
- .yAxisDomainLow(0)
46
- .yAxisDomainHigh(110)
47
- .yAxisGuideLines(false) as Scatter
48
- ;
49
-
50
- protected _candle = new QuartileCandlestick()
51
- .columns(["Min", "25%", "50%", "75%", "Max"])
52
- .edgePadding(0)
53
- .roundedCorners(1)
54
- .lineWidth(1)
55
- .upperTextRotation(-90)
56
- .lowerTextRotation(-90)
57
- .labelFontSize(0)
58
- .valueFontSize(0)
59
- .lineColor(rainbow(90, 0, 100))
60
- .innerRectColor(rainbow(10, 0, 100))
61
- ;
62
-
63
- constructor() {
64
- super();
65
- this
66
- .columns(["Min", "25%", "50%", "75%", "Max", "Mean", "Std. Dev."])
67
- ;
68
- }
69
-
70
- protected stdDev(degrees: number): number {
71
- return this.mean() + degrees * this.standardDeviation();
72
- }
73
-
74
- protected formatStdDev(degrees: number): string {
75
- return this._tickFormatter(this.stdDev(degrees));
76
- }
77
-
78
- protected quartile(q: 0 | 1 | 2 | 3 | 4): number {
79
- return this.quartiles()[q];
80
- }
81
-
82
- protected formatQ(q: 0 | 1 | 2 | 3 | 4): string {
83
- return this._tickFormatter(this.quartile(q));
84
- }
85
-
86
- protected domain(mode: View): [number, number] {
87
- switch (mode) {
88
- case "25_75":
89
- return [this.quartile(1), this.quartile(3)];
90
- case "normal":
91
- return [this.stdDev(-4), this.stdDev(4)];
92
- case "min_max":
93
- default:
94
- return [this.quartile(0), this.quartile(4)];
95
- }
96
- }
97
-
98
- protected min(): number {
99
- return this.quartile(0);
100
- }
101
-
102
- protected max(): number {
103
- return this.quartile(4);
104
- }
105
-
106
- data(): Data;
107
- data(_: Data): this;
108
- data(_?: Data): Data | this {
109
- if (!arguments.length) return [[...this.quartiles(), this.mean(), this.standardDeviation()]];
110
- const row = _[0];
111
- this.quartiles([row[0], row[1], row[2], row[3], row[4]]);
112
- this.mean(row[5]);
113
- this.standardDeviation(row[6]);
114
- return this;
115
- }
116
-
117
- enter(domNode, element) {
118
- super.enter(domNode, element);
119
-
120
- this._bellCurve.target(element.append("div").node());
121
-
122
- this._candle.target(element.append("div").node());
123
-
124
- this._selectElement = element.append("div")
125
- .style("position", "absolute")
126
- .style("top", "0px")
127
- .style("right", "0px").append("select")
128
- .on("change", () => {
129
- this.view(this._selectElement.node().value);
130
- this.lazyRender();
131
- })
132
- ;
133
- this._selectElement.append("option").attr("value", "min_max").text("Min / Max");
134
- this._selectElement.append("option").attr("value", "25_75").text("25% / 75%");
135
- this._selectElement.append("option").attr("value", "normal").text("Normal");
136
- }
137
-
138
- protected bellTicks(mode: View): AxisTicks {
139
- let ticks: Ticks;
140
- switch (mode) {
141
- case "25_75":
142
- ticks = [
143
- { label: this.formatQ(1), value: this.quartile(1) },
144
- { label: this.formatQ(2), value: this.quartile(2) },
145
- { label: this.formatQ(3), value: this.quartile(3) }
146
- ];
147
- break;
148
- case "normal":
149
- ticks = [
150
- { label: this.formatStdDev(-4), value: this.stdDev(-4) },
151
- { label: "-3σ", value: this.stdDev(-3) },
152
- { label: "-2σ", value: this.stdDev(-2) },
153
- { label: "-1σ", value: this.stdDev(-1) },
154
- { label: this.formatStdDev(0), value: this.stdDev(0) },
155
- { label: "+1σ", value: this.stdDev(1) },
156
- { label: "+2σ", value: this.stdDev(2) },
157
- { label: "+3σ", value: this.stdDev(3) },
158
- { label: this.formatStdDev(4), value: this.stdDev(4) }
159
- ];
160
- break;
161
- case "min_max":
162
- default:
163
- ticks = [
164
- { label: this.formatQ(0), value: this.quartile(0) },
165
- { label: this.formatQ(1), value: this.quartile(1) },
166
- { label: this.formatQ(2), value: this.quartile(2) },
167
- { label: this.formatQ(3), value: this.quartile(3) },
168
- { label: this.formatQ(4), value: this.quartile(4) }
169
- ];
170
- }
171
-
172
- const [domainLow, domainHigh] = this.domain(this._selectElement.node().value);
173
- return ticks
174
- .filter(sd => sd.value >= domainLow && sd.value <= domainHigh)
175
- .map(sd => ({ label: sd.label, value: sd.value.toString() }))
176
- ;
177
- }
178
-
179
- updateScatter() {
180
- const mode = this._selectElement.node().value;
181
- const [domainLow, domainHigh] = this.domain(mode);
182
- const padding = (domainHigh - domainLow) * (this.domainPadding() / 100);
183
-
184
- this._bellCurve
185
- .xAxisDomainLow(domainLow - padding)
186
- .xAxisDomainHigh(domainHigh + padding)
187
- .xAxisTicks(this.bellTicks(mode))
188
- .data([
189
- [this.stdDev(-4), 0],
190
- [this.stdDev(-3), 0.3],
191
- [this.stdDev(-2), 5],
192
- [this.stdDev(-1), 68],
193
- [this.stdDev(0), 100],
194
- [this.stdDev(1), 68],
195
- [this.stdDev(2), 5],
196
- [this.stdDev(3), 0.3],
197
- [this.stdDev(4), 0]
198
- ])
199
- .resize({ width: this.width(), height: this.height() - this.candleHeight() })
200
- .render()
201
- ;
202
- }
203
-
204
- updateCandle() {
205
- const candleX = this._bellCurve.dataPos(this.quartile(0));
206
- const candleW = this._bellCurve.dataPos(this.quartile(4)) - candleX;
207
- this._candle
208
- .resize({ width: this.width(), height: this.candleHeight() })
209
- .pos({ x: (candleX + candleW / 2) + 2, y: this.candleHeight() / 2 })
210
- .width(candleW)
211
- .candleWidth(this.candleHeight())
212
- .data(this.quartiles())
213
- .render()
214
- ;
215
- }
216
-
217
- update(domNode, element) {
218
- super.update(domNode, element);
219
- this._tickFormatter = myFormatter(this.tickFormat());
220
- this._selectElement.node().value = this.view();
221
- this.updateScatter();
222
- this.updateCandle();
223
- }
224
- }
225
- StatChart.prototype._class += " chart_Stat";
226
-
227
- export interface StatChart {
228
- view(): StatChartView;
229
- view(_: StatChartView): this;
230
-
231
- tickFormat(): string;
232
- tickFormat(_: string): this;
233
- candleHeight(): number;
234
- candleHeight(_: number): this;
235
- domainPadding(): number;
236
- domainPadding(_: number): this;
237
-
238
- mean(): number;
239
- mean(_: number): this;
240
- standardDeviation(): number;
241
- standardDeviation(_: number): this;
242
- quartiles(): Quartiles;
243
- quartiles(_: Quartiles): this;
244
- }
245
- StatChart.prototype.publish("view", "min_max", "set", "View", ["min_max", "25_75", "normal"]);
246
-
247
- StatChart.prototype.publish("tickFormat", ".2e", "string", "X-Axis Tick Format");
248
- StatChart.prototype.publish("candleHeight", 20, "number", "Height of candle widget (pixels)");
249
- StatChart.prototype.publish("domainPadding", 10, "number", "Domain value padding");
250
-
251
- StatChart.prototype.publish("mean", .5, "number", "Mean");
252
- StatChart.prototype.publish("standardDeviation", .125, "number", "Standard Deviation (σ)");
253
- StatChart.prototype.publish("quartiles", [0, .25, .5, .75, 1], "object", "Quartiles (Min, 25%, 50%, 75%, Max)");
1
+ import { format as d3Format, HTMLWidget, Palette } from "@hpcc-js/common";
2
+ import { QuartileCandlestick } from "./QuartileCandlestick";
3
+ import { Scatter } from "./Scatter";
4
+
5
+ const rainbow = Palette.rainbow("Blues");
6
+ const palette = Palette.ordinal("Quartile", [rainbow(100, 0, 100), rainbow(50, 0, 100), rainbow(50, 0, 100), rainbow(75, 0, 100)]);
7
+ palette("Std. Dev.");
8
+ palette("MinMax");
9
+ palette("25%");
10
+ palette("50%");
11
+
12
+ type View = "min_max" | "25_75" | "normal";
13
+ type Tick = { label: string, value: number };
14
+ type Ticks = Tick[];
15
+ type AxisTick = { label: string, value: string };
16
+ type AxisTicks = AxisTick[];
17
+
18
+ function myFormatter(format: string): (num: number) => string {
19
+ const formatter = d3Format(format);
20
+ return function (num: number) {
21
+ const strVal = (Math.round(num * 100) / 100).toString();
22
+ if (strVal.length <= 4) return strVal;
23
+ return formatter(num);
24
+ };
25
+ }
26
+
27
+ export type StatChartView = "min_max" | "25_75" | "normal";
28
+ export type Quartiles = [number, number, number, number, number];
29
+ export type Data = [[number, number, number, number, number, number, number]];
30
+
31
+ export class StatChart extends HTMLWidget {
32
+
33
+ protected _selectElement: any;
34
+ protected _tickFormatter: (_: number) => string;
35
+
36
+ protected _bellCurve: Scatter = new Scatter()
37
+ .columns(["", "Std. Dev."])
38
+ .paletteID("Quartile")
39
+ .interpolate_default("basis")
40
+ .pointSize(0)
41
+ .xAxisType("linear")
42
+ .xAxisOverlapMode("none")
43
+ .xAxisTickFormat(",")
44
+ .yAxisHidden(true)
45
+ .yAxisDomainLow(0)
46
+ .yAxisDomainHigh(110)
47
+ .yAxisGuideLines(false) as Scatter
48
+ ;
49
+
50
+ protected _candle = new QuartileCandlestick()
51
+ .columns(["Min", "25%", "50%", "75%", "Max"])
52
+ .edgePadding(0)
53
+ .roundedCorners(1)
54
+ .lineWidth(1)
55
+ .upperTextRotation(-90)
56
+ .lowerTextRotation(-90)
57
+ .labelFontSize(0)
58
+ .valueFontSize(0)
59
+ .lineColor(rainbow(90, 0, 100))
60
+ .innerRectColor(rainbow(10, 0, 100))
61
+ ;
62
+
63
+ constructor() {
64
+ super();
65
+ this
66
+ .columns(["Min", "25%", "50%", "75%", "Max", "Mean", "Std. Dev."])
67
+ ;
68
+ }
69
+
70
+ protected stdDev(degrees: number): number {
71
+ return this.mean() + degrees * this.standardDeviation();
72
+ }
73
+
74
+ protected formatStdDev(degrees: number): string {
75
+ return this._tickFormatter(this.stdDev(degrees));
76
+ }
77
+
78
+ protected quartile(q: 0 | 1 | 2 | 3 | 4): number {
79
+ return this.quartiles()[q];
80
+ }
81
+
82
+ protected formatQ(q: 0 | 1 | 2 | 3 | 4): string {
83
+ return this._tickFormatter(this.quartile(q));
84
+ }
85
+
86
+ protected domain(mode: View): [number, number] {
87
+ switch (mode) {
88
+ case "25_75":
89
+ return [this.quartile(1), this.quartile(3)];
90
+ case "normal":
91
+ return [this.stdDev(-4), this.stdDev(4)];
92
+ case "min_max":
93
+ default:
94
+ return [this.quartile(0), this.quartile(4)];
95
+ }
96
+ }
97
+
98
+ protected min(): number {
99
+ return this.quartile(0);
100
+ }
101
+
102
+ protected max(): number {
103
+ return this.quartile(4);
104
+ }
105
+
106
+ data(): Data;
107
+ data(_: Data): this;
108
+ data(_?: Data): Data | this {
109
+ if (!arguments.length) return [[...this.quartiles(), this.mean(), this.standardDeviation()]];
110
+ const row = _[0];
111
+ this.quartiles([row[0], row[1], row[2], row[3], row[4]]);
112
+ this.mean(row[5]);
113
+ this.standardDeviation(row[6]);
114
+ return this;
115
+ }
116
+
117
+ enter(domNode, element) {
118
+ super.enter(domNode, element);
119
+
120
+ this._bellCurve.target(element.append("div").node());
121
+
122
+ this._candle.target(element.append("div").node());
123
+
124
+ this._selectElement = element.append("div")
125
+ .style("position", "absolute")
126
+ .style("top", "0px")
127
+ .style("right", "0px").append("select")
128
+ .on("change", () => {
129
+ this.view(this._selectElement.node().value);
130
+ this.lazyRender();
131
+ })
132
+ ;
133
+ this._selectElement.append("option").attr("value", "min_max").text("Min / Max");
134
+ this._selectElement.append("option").attr("value", "25_75").text("25% / 75%");
135
+ this._selectElement.append("option").attr("value", "normal").text("Normal");
136
+ }
137
+
138
+ protected bellTicks(mode: View): AxisTicks {
139
+ let ticks: Ticks;
140
+ switch (mode) {
141
+ case "25_75":
142
+ ticks = [
143
+ { label: this.formatQ(1), value: this.quartile(1) },
144
+ { label: this.formatQ(2), value: this.quartile(2) },
145
+ { label: this.formatQ(3), value: this.quartile(3) }
146
+ ];
147
+ break;
148
+ case "normal":
149
+ ticks = [
150
+ { label: this.formatStdDev(-4), value: this.stdDev(-4) },
151
+ { label: "-3σ", value: this.stdDev(-3) },
152
+ { label: "-2σ", value: this.stdDev(-2) },
153
+ { label: "-1σ", value: this.stdDev(-1) },
154
+ { label: this.formatStdDev(0), value: this.stdDev(0) },
155
+ { label: "+1σ", value: this.stdDev(1) },
156
+ { label: "+2σ", value: this.stdDev(2) },
157
+ { label: "+3σ", value: this.stdDev(3) },
158
+ { label: this.formatStdDev(4), value: this.stdDev(4) }
159
+ ];
160
+ break;
161
+ case "min_max":
162
+ default:
163
+ ticks = [
164
+ { label: this.formatQ(0), value: this.quartile(0) },
165
+ { label: this.formatQ(1), value: this.quartile(1) },
166
+ { label: this.formatQ(2), value: this.quartile(2) },
167
+ { label: this.formatQ(3), value: this.quartile(3) },
168
+ { label: this.formatQ(4), value: this.quartile(4) }
169
+ ];
170
+ }
171
+
172
+ const [domainLow, domainHigh] = this.domain(this._selectElement.node().value);
173
+ return ticks
174
+ .filter(sd => sd.value >= domainLow && sd.value <= domainHigh)
175
+ .map(sd => ({ label: sd.label, value: sd.value.toString() }))
176
+ ;
177
+ }
178
+
179
+ updateScatter() {
180
+ const mode = this._selectElement.node().value;
181
+ const [domainLow, domainHigh] = this.domain(mode);
182
+ const padding = (domainHigh - domainLow) * (this.domainPadding() / 100);
183
+
184
+ this._bellCurve
185
+ .xAxisDomainLow(domainLow - padding)
186
+ .xAxisDomainHigh(domainHigh + padding)
187
+ .xAxisTicks(this.bellTicks(mode))
188
+ .data([
189
+ [this.stdDev(-4), 0],
190
+ [this.stdDev(-3), 0.3],
191
+ [this.stdDev(-2), 5],
192
+ [this.stdDev(-1), 68],
193
+ [this.stdDev(0), 100],
194
+ [this.stdDev(1), 68],
195
+ [this.stdDev(2), 5],
196
+ [this.stdDev(3), 0.3],
197
+ [this.stdDev(4), 0]
198
+ ])
199
+ .resize({ width: this.width(), height: this.height() - this.candleHeight() })
200
+ .render()
201
+ ;
202
+ }
203
+
204
+ updateCandle() {
205
+ const candleX = this._bellCurve.dataPos(this.quartile(0));
206
+ const candleW = this._bellCurve.dataPos(this.quartile(4)) - candleX;
207
+ this._candle
208
+ .resize({ width: this.width(), height: this.candleHeight() })
209
+ .pos({ x: (candleX + candleW / 2) + 2, y: this.candleHeight() / 2 })
210
+ .width(candleW)
211
+ .candleWidth(this.candleHeight())
212
+ .data(this.quartiles())
213
+ .render()
214
+ ;
215
+ }
216
+
217
+ update(domNode, element) {
218
+ super.update(domNode, element);
219
+ this._tickFormatter = myFormatter(this.tickFormat());
220
+ this._selectElement.node().value = this.view();
221
+ this.updateScatter();
222
+ this.updateCandle();
223
+ }
224
+ }
225
+ StatChart.prototype._class += " chart_Stat";
226
+
227
+ export interface StatChart {
228
+ view(): StatChartView;
229
+ view(_: StatChartView): this;
230
+
231
+ tickFormat(): string;
232
+ tickFormat(_: string): this;
233
+ candleHeight(): number;
234
+ candleHeight(_: number): this;
235
+ domainPadding(): number;
236
+ domainPadding(_: number): this;
237
+
238
+ mean(): number;
239
+ mean(_: number): this;
240
+ standardDeviation(): number;
241
+ standardDeviation(_: number): this;
242
+ quartiles(): Quartiles;
243
+ quartiles(_: Quartiles): this;
244
+ }
245
+ StatChart.prototype.publish("view", "min_max", "set", "View", ["min_max", "25_75", "normal"]);
246
+
247
+ StatChart.prototype.publish("tickFormat", ".2e", "string", "X-Axis Tick Format");
248
+ StatChart.prototype.publish("candleHeight", 20, "number", "Height of candle widget (pixels)");
249
+ StatChart.prototype.publish("domainPadding", 10, "number", "Domain value padding");
250
+
251
+ StatChart.prototype.publish("mean", .5, "number", "Mean");
252
+ StatChart.prototype.publish("standardDeviation", .125, "number", "Standard Deviation (σ)");
253
+ StatChart.prototype.publish("quartiles", [0, .25, .5, .75, 1], "object", "Quartiles (Min, 25%, 50%, 75%, Max)");