Skip to content

Commit 4a8a171

Browse files
authored
Merge pull request #64 from sgratzl/sgratzl/float64
fix: parse to float64 to support large numbers
2 parents 6f7bb5b + 2012180 commit 4a8a171

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

samples/largenumber.html

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Box Plot Chart</title>
5+
<script src=" https://cdn.jsdelivr.net/npm/chart.js@~4.2.0"></script>
6+
<script src="../build/index.umd.js"></script>
7+
<script src=" https://cdn.jsdelivr.net/npm/d3-random@latest/dist/d3-random.min.js"></script>
8+
<script src="./utils.js"></script>
9+
</head>
10+
11+
<body>
12+
<div id="container" style="width: 75%">
13+
<canvas id="canvas"></canvas>
14+
</div>
15+
<script>
16+
const boxplotData = {
17+
labels: ['A'],
18+
datasets: [
19+
{
20+
label: 'Dataset 1',
21+
data: [[57297214, 57297216, 117540924, 117540928]],
22+
},
23+
],
24+
};
25+
const options = {
26+
responsive: true,
27+
legend: {
28+
position: 'top',
29+
},
30+
title: {
31+
display: true,
32+
text: 'Chart.js Box Plot Chart',
33+
},
34+
minStats: 'min',
35+
maxStats: 'max',
36+
};
37+
38+
window.onload = () => {
39+
const ctx = document.getElementById('canvas').getContext('2d');
40+
let myBar = new Chart(ctx, {
41+
type: 'boxplot',
42+
data: boxplotData,
43+
options: options,
44+
});
45+
};
46+
</script>
47+
</body>
48+
</html>

src/data.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,11 @@ function determineStatsOptions(options?: IBaseOptions) {
181181
}
182182

183183
export function boxplotStats(arr: readonly number[] | Float32Array | Float64Array, options: IBaseOptions): IBoxPlot {
184-
const r = boxplots(arr, determineStatsOptions(options));
184+
const vs =
185+
window.Float64Array != null && !(arr instanceof Float32Array || arr instanceof Float64Array)
186+
? Float64Array.from(arr)
187+
: arr;
188+
const r = boxplots(vs, determineStatsOptions(options));
185189
return {
186190
items: Array.from(r.items),
187191
outliers: r.outlier,
@@ -215,7 +219,11 @@ export function violinStats(arr: readonly number[], options: IViolinOptions): IV
215219
if (arr.length === 0) {
216220
return undefined;
217221
}
218-
const stats = boxplots(arr, determineStatsOptions(options));
222+
const vs =
223+
window.Float64Array != null && !(arr instanceof Float32Array || arr instanceof Float64Array)
224+
? Float64Array.from(arr)
225+
: arr;
226+
const stats = boxplots(vs, determineStatsOptions(options));
219227

220228
// generate coordinates
221229
const samples = computeSamples(stats.min, stats.max, options.points);

0 commit comments

Comments
 (0)