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

Commit 5b1084d

Browse files
committed
scriptable options
1 parent 5f06974 commit 5b1084d

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
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
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
}

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) {

0 commit comments

Comments
 (0)