Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Different bar width per data point #25

Open
wants to merge 2 commits into from

6 participants

pedrofaustino Thomas Grainger s-d-p arjan0307 jee7 David Schnur
pedrofaustino

This may be somehow related with google code issue 275.

In any case, let me know if you're interested into merging this and in that case if there's something else that needs to be done (e.g. code is not correct, an example is required).

Thomas Grainger

presumably this is accepts data formatted:

data: [
   [x, y],
   [x, y, width],
   [x, y],
   [x, y, width]
]
Thomas Grainger

This would be really handy as I want to implement a time based histogram, and some months have the gall to have more milliseconds that others!

s-d-p

Wow, this is exactly what I'm looking for. How should the third parameter be formated? Just an integer or an object?

This was referenced
jee7

It seems to be the fourth parameter. Why isn't this merged to flot:master?

David Schnur
Owner

This pull request was opened before I took over as maintainer, and I hadn't really looked at it. Quickly reviewing it now, there are a few problems:

  • It assumes that the new point will be the last, which isn't true if the user or plugins have added additional values.
  • Bars can already have an optional third coordinate
  • It doesn't use pointformat to add the new value

I don't have time, but if anyone would like to fix this up, add docs, and submit a pull request against the 0.9-work branch, I'd be happy to merge it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 6, 2011
  1. pedrofaustino
Commits on Nov 13, 2011
  1. pedrofaustino
This page is out of date. Refresh to see the latest.
Showing with 14 additions and 4 deletions.
  1. +14 −4 jquery.flot.js
18 jquery.flot.js
View
@@ -666,13 +666,15 @@
if (s.bars.show) {
// make sure we got room for the bar on the dancing floor
var delta = s.bars.align == "left" ? 0 : -s.bars.barWidth/2;
+ var barWidth = format.length === 4 ? points[points.length-1] : s.bars.barWidth;
+
if (s.bars.horizontal) {
ymin += delta;
- ymax += delta + s.bars.barWidth;
+ ymax += delta + barWidth;
}
else {
xmin += delta;
- xmax += delta + s.bars.barWidth;
+ xmax += delta + barWidth;
}
}
@@ -2185,6 +2187,10 @@
for (var i = 0; i < points.length; i += ps) {
if (points[i] == null)
continue;
+
+ if (datapoints.format.length === 4) // 4th element is the width
+ barRight = barLeft + points[i + 3];
+
drawBar(points[i], points[i + 1], points[i + 2], barLeft, barRight, offset, fillStyleCallback, axisx, axisy, ctx, series.bars.horizontal, series.bars.lineWidth);
}
}
@@ -2355,7 +2361,10 @@
var x = points[j], y = points[j + 1], b = points[j + 2];
if (x == null)
continue;
-
+
+ if (s.datapoints.length === 4) // 4th element is the width
+ barRight = barLeft + points[j + 3];
+
// for a bar graph, the cursor must be inside the bar
if (series[i].bars.horizontal ?
(mx <= Math.max(b, x) && mx >= Math.min(b, x) &&
@@ -2545,7 +2554,8 @@
octx.strokeStyle = $.color.parse(series.color).scale('a', 0.5).toString();
var fillStyle = $.color.parse(series.color).scale('a', 0.5).toString();
var barLeft = series.bars.align == "left" ? 0 : -series.bars.barWidth/2;
- drawBar(point[0], point[1], point[2] || 0, barLeft, barLeft + series.bars.barWidth,
+ var barRight = series.datapoints.format.length === 4 ? (barLeft + point[3]) : (barLeft + series.bars.barWidth);
+ drawBar(point[0], point[1], point[2] || 0, barLeft, barRight,
0, function () { return fillStyle; }, series.xaxis, series.yaxis, octx, series.bars.horizontal, series.bars.lineWidth);
}
Something went wrong with that request. Please try again.