[chart.js] Updated type of borderWidth in ChartDataSets. (#38176)

This commit is contained in:
Ignat Ignatov 2019-09-09 15:25:18 +03:00 committed by Mine Starks
parent 84b802ed6d
commit 2c1824785a
3 changed files with 22 additions and 7 deletions

View File

@ -1,4 +1,4 @@
import { Chart, ChartData, Point, ChartColor } from 'chart.js';
import { BorderWidth, Chart, ChartData, Point, ChartColor } from 'chart.js';
// alternative:
// import chartjs = require('chart.js');
@ -14,7 +14,7 @@ const chart: Chart = new Chart(ctx, {
type: 'bar',
plugins: [plugin, plugin],
data: {
labels: ['group 1'],
labels: ['group 1', 'group 2'],
datasets: [
{
backgroundColor: '#000000',
@ -24,6 +24,12 @@ const chart: Chart = new Chart(ctx, {
label: 'test',
data: [1, null, 3],
},
{
backgroundColor: '#ff0000',
borderWidth: { top: 1, right: 1, bottom: 0, left: 1 },
label: 'test',
data: [1, 3, 5],
}
],
},
options: {
@ -197,6 +203,12 @@ const chartWithScriptedOptions = new Chart(new CanvasRenderingContext2D(), {
return "black";
}
return value > 3 ? "red" : "green";
},
borderWidth: ({ dataset, dataIndex }): BorderWidth => {
if (dataset === undefined || dataset.data === undefined || dataIndex === undefined) {
return 1;
}
return { top: 1, right: 1, bottom: 0, left: 1 };
}
}],
}

View File

@ -138,6 +138,8 @@ declare namespace Chart {
type BorderAlignment = 'center' | 'inner';
type BorderWidth = number | { [key in PositionType]?: number };
interface ChartArea {
top: number;
right: number;
@ -218,9 +220,9 @@ declare namespace Chart {
datasets?: ChartDataSets[];
}
interface RadialChartOptions extends ChartOptions {
scale?: RadialLinearScale;
}
interface RadialChartOptions extends ChartOptions {
scale?: RadialLinearScale;
}
interface ChartSize {
height: number;
@ -537,7 +539,7 @@ declare namespace Chart {
cubicInterpolationMode?: 'default' | 'monotone';
backgroundColor?: ChartColor | ChartColor[] | Scriptable<ChartColor>;
borderAlign?: BorderAlignment | BorderAlignment[] | Scriptable<BorderAlignment>;
borderWidth?: number | number[] | Scriptable<number>;
borderWidth?: BorderWidth | BorderWidth[] | Scriptable<BorderWidth>;
borderColor?: ChartColor | ChartColor[] | Scriptable<ChartColor>;
borderCapStyle?: 'butt' | 'round' | 'square';
borderDash?: number[];

View File

@ -1,6 +1,7 @@
{
"extends": "dtslint/dt.json",
"rules": {
"ban-types": false
"ban-types": false,
"indent": [true, "spaces", 4]
}
}