Permalink
Browse files

Code cleanup in line chart layouting

I removed the condition 'if (this.style != "area")' because the "area"
chart type does not exist anywhere else. I'm not sure if this was
accidentally left in the code after some refactoring in the past, or if
it was the beginnings of a new feature. In any case, I think that it
makes sense that the points in a dataset should be sorted before
connecting them up with a line, whether or not this creates an area
graph. Unless you want to be able to create graphs which wrap back on
themselves on the x axis... but that should probably be a completely
different layout type anyway.
  • Loading branch information...
Martin Kleppmann
Martin Kleppmann committed May 6, 2009
1 parent 45b474e commit 9b12932df29503c684226fed26105f469ed3bcf6
Showing with 11 additions and 11 deletions.
  1. +11 −11 PlotKit/Layout.js
View
@@ -436,25 +436,25 @@ PlotKit.Layout.prototype._evaluateHorizBarCharts = function() {
PlotKit.Layout.prototype._evaluateLineCharts = function() {
var setCount = this.datasetNames.length;
- // add all the rects
+ // add all the points
this.points = new Array();
for (var i = 0; i < this.datasetNames.length; i++) {
var setName = this.datasetNames[i];
var dataset = this.datasets[setName];
if (PlotKit.Base.isFuncLike(dataset)) continue;
- if (this.style != "area") {
- dataset.sort(function(a, b) {
- return MochiKit.Base.compare(parseFloat(a[0]), parseFloat(b[0]));
- });
- }
+
+ dataset.sort(function(a, b) {
+ return MochiKit.Base.compare(parseFloat(a[0]), parseFloat(b[0]));
+ });
+
for (var j = 0; j < dataset.length; j++) {
var item = dataset[j];
+ var xval = parseFloat(item[0]);
+ var yval = parseFloat(item[1]);
var point = {
- x: ((parseFloat(item[0]) - this.minxval) * this.xscale),
- y: 1.0 - ((parseFloat(item[1]) - this.minyval) * this.yscale),
- xval: parseFloat(item[0]),
- yval: parseFloat(item[1]),
- name: setName
+ x: ((xval - this.minxval) * this.xscale),
+ y: 1.0 - ((yval - this.minyval) * this.yscale),
+ xval: xval, yval: yval, name: setName
};
// limit the x, y values so they do not overdraw

0 comments on commit 9b12932

Please sign in to comment.