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

Unify [max|min]ValueScale and consider range as the base #55

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
41 changes: 20 additions & 21 deletions smoothie.js
Expand Up @@ -490,33 +490,33 @@
SmoothieChart.prototype.updateValueRange = function() {
// Calculate the current scale of the chart, from all time series.
var chartOptions = this.options,
chartMaxValue = Number.NaN,
chartMinValue = Number.NaN;

for (var d = 0; d < this.seriesSet.length; d++) {
// TODO(ndunn): We could calculate / track these values as they stream in.
var timeSeries = this.seriesSet[d].timeSeries;
if (!isNaN(timeSeries.maxValue)) {
chartMaxValue = !isNaN(chartMaxValue) ? Math.max(chartMaxValue, timeSeries.maxValue) : timeSeries.maxValue;
}
chartMaxValue = chartOptions.maxValue,
chartMinValue = chartOptions.minValue;

if (isNaN(chartMinValue + chartMaxValue)) {
for (var d = 0; d < this.seriesSet.length; d++) {
// TODO(ndunn): We could calculate / track these values as they stream in.
var timeSeries = this.seriesSet[d].timeSeries;
if (chartOptions.maxValue == null && !isNaN(timeSeries.maxValue)) {
chartMaxValue = chartMaxValue > timeSeries.maxValue ? chartMaxValue : timeSeries.maxValue;
}

if (!isNaN(timeSeries.minValue)) {
chartMinValue = !isNaN(chartMinValue) ? Math.min(chartMinValue, timeSeries.minValue) : timeSeries.minValue;
if (chartOptions.minValue == null && !isNaN(timeSeries.minValue)) {
chartMinValue = chartMinValue > timeSeries.minValue ? chartMinValue : timeSeries.minValue;
}
}
}

var range = chartMaxValue - chartMinValue;

// Scale the chartMaxValue to add padding at the top if required
if (chartOptions.maxValue != null) {
chartMaxValue = chartOptions.maxValue;
} else {
chartMaxValue *= chartOptions.maxValueScale;
if (chartOptions.maxValue == null) {
chartMaxValue += range * chartOptions.maxValueScale - range;
}

// Set the minimum if we've specified one
if (chartOptions.minValue != null) {
chartMinValue = chartOptions.minValue;
} else {
chartMinValue -= Math.abs(chartMinValue * chartOptions.minValueScale - chartMinValue);
if (chartOptions.minValue == null) {
chartMinValue -= range * chartOptions.minValueScale - range;
}

// If a custom range function is set, call it
Expand All @@ -527,8 +527,7 @@
}

if (!isNaN(chartMaxValue) && !isNaN(chartMinValue)) {
var targetValueRange = chartMaxValue - chartMinValue;
var valueRangeDiff = (targetValueRange - this.currentValueRange);
var valueRangeDiff = (chartMaxValue - chartMinValue) - this.currentValueRange;
var minValueDiff = (chartMinValue - this.currentVisMinValue);
this.isAnimatingScale = Math.abs(valueRangeDiff) > 0.1 || Math.abs(minValueDiff) > 0.1;
this.currentValueRange += chartOptions.scaleSmoothing * valueRangeDiff;
Expand Down