Skip to content

Commit

Permalink
Support dashed series lines.
Browse files Browse the repository at this point in the history
This follows on from #68. Unfortunately the dashes jump back and forth
during rendering, which is quite visually annoying. Fixing this would be
quite difficult I suspect.
  • Loading branch information
drewnoakes committed Aug 25, 2017
1 parent 21fc647 commit 631bab8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
14 changes: 13 additions & 1 deletion builder/index.html
Expand Up @@ -119,7 +119,8 @@

if (typeof(a[key]) === 'object') {
if (a[key] instanceof Array) {
// ignore arrays
if (!(b[key] instanceof Array) || a[key].length !== b.length && a[key].length)
result[key] = a[key];
} else {
var sub = difference(a[key], b[key]);
if (Object.keys(sub).length)
Expand Down Expand Up @@ -411,6 +412,17 @@
propertyName: 'interpolation',
values: ['bezier', 'linear', 'step']
});
bindCheckBox({
target: chart.seriesSet[0].options,
name: 'Use dashed line',
propertyName: 'lineDash',
convert: function (checked) {
return checked ? [5,5] : [];
},
convertBack: function (value) {
return value && value.length ? true : false;
}
});

// Grid lines
startControlSection('Grid Lines');
Expand Down
1 change: 1 addition & 0 deletions smoothie.d.ts
Expand Up @@ -13,6 +13,7 @@ export interface ITimeSeriesPresentationOptions {
strokeStyle?: string;
fillStyle?: string;
lineWidth?: number;
lineDash?: number[];
}

export declare class TimeSeries {
Expand Down
7 changes: 5 additions & 2 deletions smoothie.js
Expand Up @@ -346,7 +346,8 @@

SmoothieChart.defaultSeriesPresentationOptions = {
lineWidth: 1,
strokeStyle: '#ffffff'
strokeStyle: '#ffffff',
lineDash: []
};

/**
Expand All @@ -358,7 +359,8 @@
* {
* lineWidth: 1,
* strokeStyle: '#ffffff',
* fillStyle: undefined
* fillStyle: undefined,
* lineDash: []
* }
* </pre>
*/
Expand Down Expand Up @@ -698,6 +700,7 @@
// Set style for this dataSet.
context.lineWidth = seriesOptions.lineWidth;
context.strokeStyle = seriesOptions.strokeStyle;
context.setLineDash(seriesOptions.lineDash || []);
// Draw the line...
context.beginPath();
// Retain lastX, lastY for calculating the control points of bezier curves.
Expand Down

0 comments on commit 631bab8

Please sign in to comment.