Skip to content

Commit

Permalink
Improve validation of options
Browse files Browse the repository at this point in the history
  • Loading branch information
Makanz committed Jun 23, 2024
1 parent 08c5832 commit e25772f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion dist/chartjs-plugin-trendline.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 5 additions & 7 deletions src/chartjs-plugin-trendline.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,14 @@ const addFitter = (datasetMeta, ctx, dataset, xScale, yScale) => {
let defaultColor = dataset.borderColor || 'rgba(169,169,169, .6)';
let colorMin = dataset.trendlineLinear.colorMin || defaultColor;
let colorMax = dataset.trendlineLinear.colorMax || defaultColor;
let lineWidth = dataset.trendlineLinear.width || dataset.borderWidth;
let lineWidth = dataset.trendlineLinear.width ?? dataset.borderWidth ?? 3;
let lineStyle = dataset.trendlineLinear.lineStyle || 'solid';
let fillColor = dataset.trendlineLinear.fillColor;

const parsing = typeof datasetMeta.controller.chart.options.parsing === "object" ?
datasetMeta.controller.chart.options.parsing : undefined;
const xAxisKey = dataset.trendlineLinear.xAxisKey || parsing ? parsing.xAxisKey : "x";
const yAxisKey = dataset.trendlineLinear.yAxisKey || parsing ? parsing.yAxisKey : "y";

lineWidth = lineWidth !== undefined ? lineWidth : 3;
const chartOptions = datasetMeta.controller.chart.options;
const parsingOptions = typeof chartOptions.parsing === 'object' ? chartOptions.parsing : undefined;
const xAxisKey = dataset.trendlineLinear.xAxisKey || parsingOptions?.xAxisKey || 'x';
const yAxisKey = dataset.trendlineLinear.yAxisKey || parsingOptions?.yAxisKey || 'y';

let fitter = new LineFitter();
let firstIndex = dataset.data.findIndex((d) => {
Expand Down

0 comments on commit e25772f

Please sign in to comment.