UNPKG

@progress/kendo-charts

Version:

Kendo UI platform-independent Charts library

47 lines (35 loc) 1.29 kB
import calculateSlope from './calculate-slope'; import getTrendlineData from './get-trendline-data'; function linearTrendline(context) { var options = context.options; var categoryAxis = context.categoryAxis; var seriesValues = context.seriesValues; var data = getData({ seriesValues: seriesValues, categoryAxis: categoryAxis, options: options }); if (data) { return Object.assign({}, options, {type: 'line', data: data, categoryField: 'category', field: 'value'}); } return null; } var valueGetter = function (fieldName) { return function (ref) { var categoryIx = ref.categoryIx; var valueFields = ref.valueFields; return ({ xValue: categoryIx + 1, yValue: valueFields[fieldName] }); ; } }; function getData(ref) { var seriesValues = ref.seriesValues; var categoryAxis = ref.categoryAxis; var options = ref.options; var ref$1 = calculateSlope(seriesValues(), valueGetter(options.field)); var slope = ref$1.slope; var intercept = ref$1.intercept; var count = ref$1.count; if (count > 0) { return getTrendlineData(function (x) { return slope * x + intercept; }, categoryAxis); } return null; } export default linearTrendline;