Skip to content
This repository has been archived by the owner on Mar 15, 2018. It is now read-only.

Commit

Permalink
fix duplicate yAxis tick values on small-valued graphs (bug 759099)
Browse files Browse the repository at this point in the history
  • Loading branch information
ngokevin committed May 30, 2012
1 parent d220b40 commit d88dbc5
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions media/js/mkt/stats/chart.js
Expand Up @@ -26,7 +26,8 @@
title: {
text: null
},
tickmarkPlacement: 'on'
tickmarkPlacement: 'on',
startOfWeek: 0
},
yAxis: {
title: {
Expand Down Expand Up @@ -174,14 +175,14 @@
}
}

// highCharts seems to dislike 0 and null data when determining a yAxis range
// highCharts seems to dislike 0 and null data when determining a yAxis range.
if (dataSum === 0) {
baseConfig.yAxis.max = 10;
} else {
baseConfig.yAxis.max = null;
}

// Transform xAxis based on time grouping (day, week, month) and range
// Transform xAxis based on time grouping (day, week, month) and range.
var pointInterval = dayMsecs = 1 * 24 * 3600 * 1000;
baseConfig.xAxis.tickInterval = (end - start) / 7;
baseConfig.xAxis.min = start - dayMsecs; // Fix chart truncation.
Expand All @@ -194,6 +195,18 @@
baseConfig.xAxis.tickInterval = pointInterval;
}

// Set minimum max value for yAxis to prevent duplicate yAxis values.
var max = 0;
for (var key in data) {
if (data[key].count > max) {
max = data[key].count;
}
}
// Chart has minimum 5 ticks so set max to 5 to avoid pigeonholing.
if (max < 5) {
baseConfig.yAxis.max = 5;
}

// Populate the chart config object.
var chartData = [], id;
for (i = 0; i < fields.length; i++) {
Expand All @@ -205,7 +218,6 @@
'id' : id,
'pointInterval' : pointInterval,
// Compensate for timezone offsets from UTC.
// + dayMsecs to line up points with X-axis on week grouping
'pointStart' : start.getTime() - start.getTimezoneOffset() * 60000,
'data' : series[field],
'visible' : !(metric == 'contributions' && id !='total')
Expand Down

0 comments on commit d88dbc5

Please sign in to comment.