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

Commit 49742c1

Browse files
committed
merge develop
2 parents 5aa8db0 + 5b1084d commit 49742c1

File tree

6 files changed

+59
-27
lines changed

6 files changed

+59
-27
lines changed

README.md

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# Chart.js Box and Violin Plot
22
[![datavisyn][datavisyn-image]][datavisyn-url] [![NPM Package][npm-image]][npm-url] [![CircleCI][circleci-image]][circleci-url]
33

4-
Chart.js module for charting box and violin plots. **Works only with Chart.js ~2.7.x**
4+
Chart.js module for charting box and violin plots. **Works only with Chart.js >= 2.8.0**
55

66
![Box Plot](https://user-images.githubusercontent.com/4129778/42724341-9a6ec554-8770-11e8-99b5-626e34dafdb3.png)
77
![Violin Plot](https://user-images.githubusercontent.com/4129778/42724342-9a8dbb58-8770-11e8-9a30-3e69d07d3b79.png)
88

99

1010
## Install
11+
1112
```bash
1213
npm install --save chart.js chartjs-chart-box-and-violin-plot
1314
```
@@ -28,38 +29,52 @@ The boxplot element is called `boxandwhiskers`. The basic options are from the `
2829
interface IBaseStyling {
2930
/**
3031
* @default see rectangle
32+
* @scriptable
33+
* @indexable
3134
*/
3235
backgroundColor: string;
3336

3437
/**
3538
* @default see rectangle
39+
* @scriptable
40+
* @indexable
3641
*/
3742
borderColor: string;
3843

3944
/**
40-
* @default null takes the current borderColor
41-
*/
45+
* @default null takes the current borderColor
46+
* @scriptable
47+
* @indexable
48+
*/
4249
medianColor: string;
4350

4451
/**
4552
* @default 1
53+
* @scriptable
54+
* @indexable
4655
*/
4756
borderWidth: number;
4857

4958
/**
5059
* radius used to render outliers
5160
* @default 2
61+
* @scriptable
62+
* @indexable
5263
*/
5364
outlierRadius: number;
5465

5566
/**
5667
* @default see rectangle.backgroundColor
68+
* @scriptable
69+
* @indexable
5770
*/
5871
outlierColor: string;
5972

6073
/**
6174
* radius used to render items
6275
* @default 0 so disabled
76+
* @scriptable
77+
* @indexable
6378
*/
6479
itemRadius: number;
6580

@@ -69,21 +84,27 @@ interface IBaseStyling {
6984
*/
7085
itemStyle: 'circle'|'triangle'|'rect'|'rectRounded'|'rectRot'|'cross'|'crossRot'|'star'|'line'|'dash';
7186

72-
/*
87+
/**
7388
* background color for items
7489
* @default see rectangle backgroundColor
90+
* @scriptable
91+
* @indexable
7592
*/
7693
itemBackgroundColor: string;
7794

78-
/*
95+
/**
7996
* border color for items
8097
* @default see rectangle backgroundColor
98+
* @scriptable
99+
* @indexable
81100
*/
82101
itemBorderColor: string;
83102

84103
/**
85104
* padding thst is added around the bounding box when computing a mouse hit
86105
* @default 1
106+
* @scriptable
107+
* @indexable
87108
*/
88109
hitPadding: number;
89110
}

package-lock.json

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"src/**/*.js"
2121
],
2222
"dependencies": {
23-
"chart.js": "~2.7.3",
23+
"chart.js": "^2.8.0",
2424
"@sgratzl/science": "^2.0.0"
2525
},
2626
"devDependencies": {

src/controllers/base.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,19 @@ const array = {
2727
const options = this._elementOptions();
2828

2929
Chart.controllers.bar.prototype.updateElement.call(this, elem, index, reset);
30-
['outlierRadius', 'itemRadius', 'itemStyle', 'itemBackgroundColor', 'itemBorderColor', 'outlierColor', 'medianColor', 'hitPadding'].forEach((item) => {
31-
elem._model[item] = custom[item] !== undefined ? custom[item] : Chart.helpers.valueAtIndexOrDefault(dataset[item], index, options[item]);
30+
const resolve = Chart.helpers.options.resolve;
31+
32+
const keys = ['outlierRadius', 'itemRadius', 'itemStyle', 'itemBackgroundColor', 'itemBorderColor', 'outlierColor', 'medianColor', 'hitPadding'];
33+
// Scriptable options
34+
const context = {
35+
chart: this.chart,
36+
dataIndex: index,
37+
dataset,
38+
datasetIndex: this.index
39+
};
40+
41+
keys.forEach((item) => {
42+
elem._model[item] = resolve([custom[item], dataset[item], options[item]], context, index);
3243
});
3344
},
3445
_calculateCommonModel(r, data, container, scale) {

src/controllers/boxplot.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ const boxplot = {
3434
/**
3535
* @private
3636
*/
37-
updateElementGeometry(elem, index, reset) {
38-
Chart.controllers.bar.prototype.updateElementGeometry.call(this, elem, index, reset);
37+
_updateElementGeometry(elem, index, reset) {
38+
Chart.controllers.bar.prototype._updateElementGeometry.call(this, elem, index, reset);
3939
elem._model.boxplot = this._calculateBoxPlotValuesPixels(this.index, index);
4040
},
4141

@@ -44,7 +44,7 @@ const boxplot = {
4444
*/
4545

4646
_calculateBoxPlotValuesPixels(datasetIndex, index) {
47-
const scale = this.getValueScale();
47+
const scale = this._getValueScale();
4848
const data = this.chart.data.datasets[datasetIndex].data[index];
4949
if (!data) {
5050
return null;

src/controllers/violin.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ const controller = {
1919
/**
2020
* @private
2121
*/
22-
updateElementGeometry(elem, index, reset) {
23-
Chart.controllers.bar.prototype.updateElementGeometry.call(this, elem, index, reset);
22+
_updateElementGeometry(elem, index, reset) {
23+
Chart.controllers.bar.prototype._updateElementGeometry.call(this, elem, index, reset);
2424
const custom = elem.custom || {};
2525
const options = this._elementOptions();
2626
elem._model.violin = this._calculateViolinValuesPixels(this.index, index, custom.points !== undefined ? custom.points : options.points);
@@ -31,7 +31,7 @@ const controller = {
3131
*/
3232

3333
_calculateViolinValuesPixels(datasetIndex, index, points) {
34-
const scale = this.getValueScale();
34+
const scale = this._getValueScale();
3535
const data = this.chart.data.datasets[datasetIndex].data[index];
3636
const violin = asViolinStats(data);
3737

0 commit comments

Comments
 (0)