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

update to Intermediate labels #99

Merged
merged 3 commits into from
Dec 29, 2017
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions builder/index.html
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,16 @@
return !value;
}
});
bindCheckBox({
target: chart.options.labels,
name: 'Show intermediate labels',
propertyName: 'showIntermediateLabels',
});
bindCheckBox({
target: chart.options.labels,
name: 'Show intermediate labels on same axis',
propertyName: 'intermediateLabelSameAxis',
});
bindRange({target: chart.options.labels, name: 'Font size', propertyName: 'fontSize', min: 1, max: 20});
bindRange({target: chart.options.labels, name: 'Label precision', propertyName: 'precision', min: 0, max: 6});
bindCheckBox({
Expand Down
21 changes: 17 additions & 4 deletions smoothie.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,9 @@
* yMaxFormatter: function(max, precision) { // callback function that formats the max y value label
* return parseFloat(max).toFixed(precision);
* },
* yIntermediateFormatter: function(intermediate, precision) { // callback function that formats the intermediate y value labels
* return parseFloat(intermediate).toFixed(precision);
* },
* maxDataSetLength: 2,
* interpolation: 'bezier' // one of 'bezier', 'linear', or 'step'
* timestampFormatter: null, // optional function to format time stamps for bottom of chart
Expand All @@ -285,6 +288,7 @@
* fontFamily: 'sans-serif',
* precision: 2,
* showIntermediateLabels: false, // shows intermediate labels between min and max values along y axis
* intermediateLabelSameAxis: true,
* },
* tooltip: false // show tooltip when mouse is over the chart
* tooltipLine: { // properties for a vertical line at the cursor position
Expand Down Expand Up @@ -337,6 +341,9 @@
yMaxFormatter: function(max, precision) {
return parseFloat(max).toFixed(precision);
},
yIntermediateFormatter: function(intermediate, precision) {
return parseFloat(intermediate).toFixed(precision);
},
maxValueScale: 1,
minValueScale: 1,
interpolation: 'bezier',
Expand All @@ -360,6 +367,7 @@
fontFamily: 'monospace',
precision: 2,
showIntermediateLabels: false,
intermediateLabelSameAxis: true,
},
horizontalLines: [],
tooltip: false,
Expand Down Expand Up @@ -968,14 +976,19 @@
// show a label above every vertical section divider
var step = (this.valueRange.max - this.valueRange.min) / chartOptions.grid.verticalSections;
var stepPixels = dimensions.height / chartOptions.grid.verticalSections;
for (var v = 0; v < chartOptions.grid.verticalSections; v++) {
for (var v = 1; v < chartOptions.grid.verticalSections; v++) {
var gy = dimensions.height - Math.round(v * stepPixels);
if (chartOptions.grid.sharpLines) {
gy -= 0.5;
}
var yValue = (this.valueRange.min + (v * step)).toPrecision(chartOptions.labels.precision);
context.fillStyle = chartOptions.labels.fillStyle;
context.fillText(yValue, 0, gy - chartOptions.grid.lineWidth);
var yValue = chartOptions.yIntermediateFormatter(this.valueRange.min + (v * step), chartOptions.labels.precision);
//left of right axis?
intermediateLabelPos =
chartOptions.labels.intermediateLabelSameAxis
? (chartOptions.scrollBackwards ? 0 : dimensions.width - context.measureText(yValue).width - 2)
: (chartOptions.scrollBackwards ? dimensions.width - context.measureText(yValue).width - 2 : 0);

context.fillText(yValue, intermediateLabelPos, gy - chartOptions.grid.lineWidth);
}
}

Expand Down