From 2e5f3e2db48a41a1578c15c2685dba7b5c424978 Mon Sep 17 00:00:00 2001 From: Matt Gibbs Date: Thu, 14 Jan 2016 15:10:55 -0500 Subject: [PATCH] Added Interpolation definitions and tests --- chartist/chartist-tests.ts | 39 ++++++++++++++++++++++++++++++++++++++ chartist/chartist.d.ts | 27 +++++++++++++++++++++++++- 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/chartist/chartist-tests.ts b/chartist/chartist-tests.ts index 5c76754f2..36e5a38e1 100644 --- a/chartist/chartist-tests.ts +++ b/chartist/chartist-tests.ts @@ -318,3 +318,42 @@ new Chartist.Bar('.ct-chart', { position: 'end' } }); + +new Chartist.Line('.ct-chart', { + labels: [1, 2, 3, 4, 5], + series: [[1, 2, 8, 1, 7]] +}, { + lineSmooth: Chartist.Interpolation.none({ + fillHoles: false + }) + }); + +new Chartist.Line('.ct-chart', { + labels: [1, 2, 3, 4, 5], + series: [[1, 2, 8, 1, 7]] +}, { + lineSmooth: Chartist.Interpolation.simple({ + divisor: 2, + fillHoles: false + }) + }); + +new Chartist.Line('.ct-chart', { + labels: [1, 2, 3, 4, 5], + series: [[1, 2, 8, 1, 7]] +}, { + lineSmooth: Chartist.Interpolation.cardinal({ + tension: 1, + fillHoles: false + }) + }); + +new Chartist.Line('.ct-chart', { + labels: [1, 2, 3, 4, 5], + series: [[1, 2, 8, 1, 7]] +}, { + lineSmooth: Chartist.Interpolation.step({ + postpone: true, + fillHoles: false + }) + }); diff --git a/chartist/chartist.d.ts b/chartist/chartist.d.ts index a510032c2..6c18e9c96 100644 --- a/chartist/chartist.d.ts +++ b/chartist/chartist.d.ts @@ -26,6 +26,8 @@ declare module Chartist { StepAxis: IStepAxisStatic; Svg: ChartistSvgStatic; + Interpolation: ChartistInterpolationStatic; + noop: Function; alphaNumerate(n: number): string; @@ -281,7 +283,7 @@ declare module Chartist { showPoint?: boolean; showArea?: boolean; areaBase?: number; - lineSmooth?: boolean; + lineSmooth?: Function | boolean; low?: number; high?: number; ticks?: Array; @@ -504,6 +506,29 @@ declare module Chartist { easeOutBack: IChartistEasingDefinition; easeInOutBack: IChartistEasingDefinition; } + + interface ChartistInterpolationStatic { + + /** + * This interpolation function does not smooth the path and the result is only containing lines and no curves. + */ + none(options?: Object): Function; + + /** + * Simple smoothing creates horizontal handles that are positioned with a fraction of the length between two data points. You can use the divisor option to specify the amount of smoothing. + */ + simple(options?: Object): Function; + + /** + * Cardinal / Catmull-Rome spline interpolation is the default smoothing function in Chartist. It produces nice results where the splines will always meet the points. It produces some artifacts though when data values are increased or decreased rapidly. The line may not follow a very accurate path and if the line should be accurate this smoothing function does not produce the best results. + */ + cardinal(options?: Object): Function; + + /** + * Step interpolation will cause the line chart to move in steps rather than diagonal or smoothed lines. This interpolation will create additional points that will also be drawn when the showPoint option is enabled. + */ + step(options?: Object): Function; + } } declare var Chartist: Chartist.ChartistStatic;