From 7ec2fdb27863ba6dc3941a1b03eb33bbffec0b18 Mon Sep 17 00:00:00 2001 From: Rufus Pollock Date: Fri, 8 Mar 2013 10:30:02 +0000 Subject: [PATCH] [#334,flot,bugfix][s]: find and resolve issue with no ticks on x-axis if values are floats - fixes #334. * Change to explicitly signal the Labels / Dates case (where x values are indices into records array) * No longer always set xticks - let flot do this except in indices case --- src/view.flot.js | 57 +++++++++++++++++++++--------------------------- 1 file changed, 25 insertions(+), 32 deletions(-) diff --git a/src/view.flot.js b/src/view.flot.js index 5506c4f3..f23abc87 100644 --- a/src/view.flot.js +++ b/src/view.flot.js @@ -159,14 +159,19 @@ my.Flot = Backbone.View.extend({ var xtype = xfield.get('type'); var isDateTime = (xtype === 'date' || xtype === 'date-time' || xtype === 'time'); - if (this.model.records.models[parseInt(x, 10)]) { - x = this.model.records.models[parseInt(x, 10)].get(this.state.attributes.group); - if (isDateTime) { - x = new Date(x).toLocaleDateString(); - } - } else if (isDateTime) { - x = new Date(parseInt(x, 10)).toLocaleDateString(); + if (this.xvaluesAreIndex) { + x = parseInt(x, 10); + // HACK: deal with bar graph style cases where x-axis items were strings + // In this case x at this point is the index of the item in the list of + // records not its actual x-axis value + x = this.model.records.models[x].get(this.state.attributes.group); } + if (isDateTime) { + x = new Date(x).toLocaleDateString(); + } + // } else if (isDateTime) { + // x = new Date(parseInt(x, 10)).toLocaleDateString(); + // } return x; }, @@ -201,31 +206,16 @@ my.Flot = Backbone.View.extend({ var xaxis = {}; xaxis.tickFormatter = tickFormatter; - // calculate the x-axis ticks - // - // the number of ticks should be a multiple of the number of points so that - // each tick lines up with a point - if (numPoints) { - var ticks = [], - maxTicks = 10, - x = 1, - i = 0; - - // show all ticks in bar graphs - // for other graphs only show up to maxTicks ticks - if (self.state.attributes.graphType !== 'bars') { - while (x <= maxTicks) { - if ((numPoints / x) <= maxTicks) { - break; - } - x = x + 1; - } + // for labels case we only want ticks at the label intervals + // HACK: however we also get this case with Date fields. In that case we + // could have a lot of values and so we limit to max 30 (we assume) + if (this.xvaluesAreIndex) { + var numTicks = Math.min(this.model.records.length, 15); + var increment = this.model.records.length / numTicks; + var ticks = []; + for (i=0; i