Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow setting interpolation per time series #123

Merged
merged 2 commits into from Aug 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion builder/index.html
Expand Up @@ -419,7 +419,7 @@
bindColor({target: chart.seriesSet[0].options, name: 'Series fill color', propertyName: 'fillStyle', optional: true, enabled: false, opacity: 0.3});
bindRange({target: chart.seriesSet[0].options, name: 'Series line width', propertyName: 'lineWidth', min: 0.5, max: 5, scale: 10});
bindDropDown({
target: chart.options,
target: chart.seriesSet[0].options,
name: 'Interpolation',
propertyName: 'interpolation',
values: ['bezier', 'linear', 'step']
Expand Down
9 changes: 7 additions & 2 deletions smoothie.d.ts
Expand Up @@ -12,6 +12,11 @@ export interface ITimeSeriesPresentationOptions {
strokeStyle?: string;
fillStyle?: string;
lineWidth?: number;
/**
* Controls how lines are drawn between data points.
* Default value is controlled by <code>SmoothieChart</code>'s <code>interpolation</code> option.
*/
interpolation?: "linear" | "step" | "bezier";
tooltipLabel?: string;
}

Expand Down Expand Up @@ -144,8 +149,8 @@ export interface IChartOptions {
/** Callback function that formats the intermediate y value labels */
yIntermediateFormatter?: (intermediate: number, precision: number) => string;
maxDataSetLength?: number;
/** Controls how lines are drawn between data points. Defaults to "bezier". */
interpolation?: "linear" | "step" | "bezier";
/** Default value for time series presentation options' <code>interpolation</code>. Defaults to "bezier". */
interpolation?: ITimeSeriesPresentationOptions['interpolation'];
/** Optional function to format time stamps for bottom of chart. You may use <code>SmoothieChart.timeFormatter</code>, or your own/ */
timestampFormatter?: (date: Date) => string;
horizontalLines?: IHorizontalLine[];
Expand Down
4 changes: 3 additions & 1 deletion smoothie.js
Expand Up @@ -94,6 +94,7 @@
* Fix bug rendering issue in series fill when using scroll backwards, by @olssonfredrik
* Add title option, by @mesca
* Fix data drop stoppage by rejecting NaNs in append(), by @timdrysdale
* Allow setting interpolation per time series, by @WofWca (#123)
*/

;(function(exports) {
Expand Down Expand Up @@ -465,6 +466,7 @@
* lineWidth: 1,
* strokeStyle: '#ffffff',
* fillStyle: undefined,
* interpolation: undefined;
* tooltipLabel: undefined
* }
* </pre>
Expand Down Expand Up @@ -936,7 +938,7 @@
firstY = y;
context.moveTo(x, y);
} else {
switch (chartOptions.interpolation) {
switch (seriesOptions.interpolation || chartOptions.interpolation) {
case "linear":
case "line": {
context.lineTo(x,y);
Expand Down