Skip to content

Commit e343651

Browse files
committed
simple boxplots
1 parent bc83a4f commit e343651

17 files changed

+461
-442
lines changed

samples/animation.html

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,6 @@
5151
display: true,
5252
text: 'Chart.js Box Plot Chart',
5353
},
54-
scales: {
55-
x: {
56-
// Specific to Bar Controller
57-
categoryPercentage: 0.9,
58-
barPercentage: 0.8,
59-
},
60-
},
6154
},
6255
});
6356
};

samples/datalimits.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
display: true,
5757
text: 'Chart.js Box Plot Chart',
5858
},
59-
boxplot: {
59+
datasets: {
6060
minStats: 'min',
6161
maxStats: 'max',
6262
},

samples/vertical.html renamed to samples/default.html

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
borderWidth: 1,
4040
data: samples.boxplots({ count: 7, random: random }),
4141
outlierColor: '#999999',
42-
lowerColor: '#461e7d',
42+
// lowerColor: '#461e7d',
4343
},
4444
{
4545
label: 'Dataset 2',
@@ -67,13 +67,6 @@
6767
display: true,
6868
text: 'Chart.js Box Plot Chart',
6969
},
70-
scales: {
71-
x: {
72-
// Specific to Bar Controller
73-
categoryPercentage: 0.9,
74-
barPercentage: 0.8,
75-
},
76-
},
7770
},
7871
});
7972
};

samples/empty.html

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,6 @@
5151
display: true,
5252
text: 'Chart.js Box Plot Chart',
5353
},
54-
scales: {
55-
x: {
56-
// Specific to Bar Controller
57-
categoryPercentage: 0.9,
58-
barPercentage: 0.8,
59-
},
60-
},
6154
},
6255
});
6356
};

samples/fivenum.html

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
display: true,
5353
text: 'Quantiles type 7',
5454
},
55-
boxplot: {
55+
datasets: {
5656
quantiles: 'quantiles',
5757
},
5858
},
@@ -70,14 +70,8 @@
7070
display: true,
7171
text: 'Quantiles Fivenum',
7272
},
73-
scales: {
74-
yAxes: [
75-
{
76-
ticks: {
77-
quantiles: 'fivenum',
78-
},
79-
},
80-
],
73+
datasets: {
74+
quantiles: 'fivenum',
8175
},
8276
},
8377
});

samples/mediancolor.html

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,6 @@
5252
display: true,
5353
text: 'Chart.js Box Plot Chart',
5454
},
55-
scales: {
56-
x: {
57-
// Specific to Bar Controller
58-
categoryPercentage: 0.9,
59-
barPercentage: 0.8,
60-
},
61-
},
6255
},
6356
});
6457
};

samples/minmax.html

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,6 @@
4747
display: true,
4848
text: 'Chart.js Box Plot Chart',
4949
},
50-
scales: {
51-
x: {
52-
// Specific to Bar Controller
53-
categoryPercentage: 0.9,
54-
barPercentage: 0.8,
55-
},
56-
},
5750
},
5851
});
5952
};

src/animation.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const interpolators = {
2+
number(from, to, factor) {
3+
if (from === to) {
4+
return to;
5+
}
6+
return from + (to - from) * factor;
7+
},
8+
};
9+
10+
export function interpolateNumberArray(from, to, factor) {
11+
if (typeof from === 'number' && typeof to === 'number') {
12+
return interpolators.number(from, to, factor);
13+
}
14+
if (Array.isArray(from) && Array.isArray(to)) {
15+
return from.map((f, i) => interpolators.number(f, to[i], factor));
16+
}
17+
return to;
18+
}

src/bundle.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
export * from '.';
22

3-
// import {} from './controllers';
3+
import { BoxPlot } from './controllers';
4+
5+
BoxPlot.register();

src/controllers/base.js

Lines changed: 15 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,25 @@
1-
import * as Chart from 'chart.js';
2-
3-
export const verticalDefaults = {
4-
scales: {
5-
yAxes: [
6-
{
7-
type: 'arrayLinear',
8-
},
9-
],
10-
},
11-
};
12-
export const horizontalDefaults = {
13-
scales: {
14-
xAxes: [
15-
{
16-
type: 'arrayLinear',
17-
},
18-
],
19-
},
20-
};
1+
import {} from 'chart.js';
2+
import { interpolateNumberArray } from '../animation';
213

224
export function toFixed(value) {
235
const decimals = this._chart.config.options.tooltipDecimals; // inject number of decimals from config
246
if (decimals == null || typeof decimals !== 'number' || decimals < 0) {
257
return value;
268
}
27-
return Number.parseFloat(value).toFixed(decimals);
9+
return value.toFixed(decimals);
2810
}
2911

12+
export const baseDefaults = {
13+
datasets: {
14+
animation: {
15+
numberArray: {
16+
fn: interpolateNumberArray,
17+
properties: ['outliers', 'items'],
18+
},
19+
},
20+
},
21+
};
22+
3023
const configKeys = [
3124
'outlierRadius',
3225
'itemRadius',
@@ -39,12 +32,9 @@ const configKeys = [
3932
'outlierHitRadius',
4033
'lowerColor',
4134
];
42-
const configKeyIsColor = [false, false, false, true, true, true, true, false, false, true];
35+
// const configKeyIsColor = [false, false, false, true, true, true, true, false, false, true];
4336

4437
const array = {
45-
_elementOptions() {
46-
return {};
47-
},
4838
updateElement(elem, index, reset) {
4939
const dataset = this.getDataset();
5040
const custom = elem.custom || {};
@@ -76,23 +66,4 @@ const array = {
7666
r.items = container.items.map((d) => scale.getPixelForValue(Number(d)));
7767
}
7868
},
79-
setHoverStyle(element) {
80-
Chart.controllers.bar.prototype.setHoverStyle.call(this, element);
81-
82-
const dataset = this.chart.data.datasets[element._datasetIndex];
83-
const index = element._index;
84-
const custom = element.custom || {};
85-
const model = element._model;
86-
const getHoverColor = Chart.helpers.getHoverColor;
87-
const resolve = Chart.helpers.options.resolve;
88-
89-
configKeys.forEach((item, i) => {
90-
element.$previousStyle[item] = model[item];
91-
const hoverKey = `hover${item.charAt(0).toUpperCase()}${item.slice(1)}`;
92-
const modelValue = configKeyIsColor[i] && model[item] != null ? getHoverColor(model[item]) : model[item];
93-
element._model[item] = resolve([custom[hoverKey], dataset[hoverKey], modelValue], undefined, index);
94-
});
95-
},
9669
};
97-
98-
export default array;

0 commit comments

Comments
 (0)