Skip to content
This repository was archived by the owner on Nov 25, 2021. It is now read-only.

Commit 346315a

Browse files
committed
bugfix items are not properly handled
1 parent 3ac0215 commit 346315a

File tree

3 files changed

+87
-1
lines changed

3 files changed

+87
-1
lines changed

samples/datastructures.html

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<!doctype html>
2+
<html>
3+
4+
<head>
5+
<title>Box Plot Chart</title>
6+
<script src="../node_modules/chart.js/dist/Chart.bundle.js"></script>
7+
<script src="../build/Chart.BoxPlot.js" type="text/javascript"></script>
8+
<script src="https://unpkg.com/d3-random@latest/dist/d3-random.js"></script>
9+
<script src="./utils.js"></script>
10+
<style>
11+
canvas {
12+
-moz-user-select: none;
13+
-webkit-user-select: none;
14+
-ms-user-select: none;
15+
}
16+
</style>
17+
</head>
18+
19+
<body>
20+
<div id="container" style="width: 75%;">
21+
<canvas id="canvas"></canvas>
22+
</div>
23+
<script>
24+
25+
const boxplotData = {
26+
// define label tree
27+
labels: ['array', '{boxplot values}', 'with items', 'as outliers'],
28+
datasets: [{
29+
label: 'Dataset 1',
30+
backgroundColor: 'rgba(255,0,0,0.2)',
31+
borderColor: 'red',
32+
borderWidth: 1,
33+
outlierColor: '#999999',
34+
padding: 10,
35+
itemRadius: 2,
36+
itemStyle: 'circle',
37+
itemBackgroundColor: '#000',
38+
outlierColor: '#000',
39+
data: [
40+
[1, 2, 3, 4, 5], {
41+
min: 1,
42+
q1: 2,
43+
median: 3,
44+
q3: 4,
45+
max: 5
46+
}, {
47+
min: 1,
48+
q1: 2,
49+
median: 3,
50+
q3: 4,
51+
max: 5,
52+
items: [1, 2, 3, 4, 5]
53+
},
54+
{
55+
min: 1,
56+
q1: 2,
57+
median: 3,
58+
q3: 4,
59+
max: 5,
60+
outliers: [1, 2, 3, 4, 5]
61+
},
62+
]
63+
}]
64+
};
65+
66+
window.onload = function() {
67+
var ctx = document.getElementById("canvas").getContext("2d");
68+
window.myBar = new Chart(ctx, {
69+
type: 'boxplot',
70+
data: boxplotData,
71+
options: {
72+
responsive: true,
73+
title: {
74+
display: true,
75+
text: 'Chart.js Box Plot Chart'
76+
}
77+
}
78+
});
79+
80+
};
81+
</script>
82+
</body>
83+
84+
</html>

src/controllers/base.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ const array = {
5757

5858
if (Array.isArray(data)) {
5959
r.items = data.map((d) => scale.getPixelForValue(Number(d)));
60+
} else if (container.items) {
61+
r.items = container.items.map((d) => scale.getPixelForValue(Number(d)));
6062
}
6163
}
6264
};

src/controllers/boxplot.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const boxplot = {
5353

5454
const r = {};
5555
Object.keys(v).forEach((key) => {
56-
if (key !== 'outliers') {
56+
if (key !== 'outliers' && key !== 'items') {
5757
r[key] = scale.getPixelForValue(Number(v[key]));
5858
}
5959
});

0 commit comments

Comments
 (0)