UNPKG

@progress/kendo-charts

Version:

Kendo UI platform-independent Charts library

57 lines (44 loc) 1.61 kB
import calculateSlope from './calculate-slope'; import checkAllPositive from './check-all-positive'; import getTrendlineData from './get-trendline-data'; function powerTrendline(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: Math.log(categoryIx + 1), yValue: Math.log(valueFields[fieldName]) }); ; } }; function getData(ref) { var seriesValues = ref.seriesValues; var categoryAxis = ref.categoryAxis; var options = ref.options; var sourceValues = seriesValues(); if (!checkAllPositive(sourceValues, options.field)) { return null; } var ref$1 = calculateSlope(sourceValues, valueGetter(options.field)); var slope = ref$1.slope; var intercept = ref$1.intercept; var count = ref$1.count; if (count > 0) { // Power trendline equation: // y = a * x ^ b var a = Math.exp(intercept); var b = slope; return getTrendlineData(function (x) { return a * Math.pow(x, b); }, categoryAxis); } return null; } export default powerTrendline;