Skip to content
This repository

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?

arjan0307

+1

jee7
jee7 commented March 12, 2014

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
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 14 additions and 4 deletions. Show diff stats Hide diff stats

  1. 18  jquery.flot.js
18  jquery.flot.js
@@ -666,13 +666,15 @@
666 666
                 if (s.bars.show) {
667 667
                     // make sure we got room for the bar on the dancing floor
668 668
                     var delta = s.bars.align == "left" ? 0 : -s.bars.barWidth/2;
  669
+                    var barWidth = format.length === 4 ? points[points.length-1] : s.bars.barWidth;
  670
+                    
669 671
                     if (s.bars.horizontal) {
670 672
                         ymin += delta;
671  
-                        ymax += delta + s.bars.barWidth;
  673
+                        ymax += delta + barWidth;
672 674
                     }
673 675
                     else {
674 676
                         xmin += delta;
675  
-                        xmax += delta + s.bars.barWidth;
  677
+                        xmax += delta + barWidth;
676 678
                     }
677 679
                 }
678 680
                 
@@ -2185,6 +2187,10 @@
2185 2187
                 for (var i = 0; i < points.length; i += ps) {
2186 2188
                     if (points[i] == null)
2187 2189
                         continue;
  2190
+                    
  2191
+                    if (datapoints.format.length === 4) // 4th element is the width
  2192
+                        barRight = barLeft + points[i + 3];
  2193
+                    
2188 2194
                     drawBar(points[i], points[i + 1], points[i + 2], barLeft, barRight, offset, fillStyleCallback, axisx, axisy, ctx, series.bars.horizontal, series.bars.lineWidth);
2189 2195
                 }
2190 2196
             }
@@ -2355,7 +2361,10 @@
2355 2361
                         var x = points[j], y = points[j + 1], b = points[j + 2];
2356 2362
                         if (x == null)
2357 2363
                             continue;
2358  
-  
  2364
+                        
  2365
+                        if (s.datapoints.length === 4) // 4th element is the width
  2366
+                            barRight = barLeft + points[j + 3];
  2367
+                        
2359 2368
                         // for a bar graph, the cursor must be inside the bar
2360 2369
                         if (series[i].bars.horizontal ? 
2361 2370
                             (mx <= Math.max(b, x) && mx >= Math.min(b, x) && 
@@ -2545,7 +2554,8 @@
2545 2554
             octx.strokeStyle = $.color.parse(series.color).scale('a', 0.5).toString();
2546 2555
             var fillStyle = $.color.parse(series.color).scale('a', 0.5).toString();
2547 2556
             var barLeft = series.bars.align == "left" ? 0 : -series.bars.barWidth/2;
2548  
-            drawBar(point[0], point[1], point[2] || 0, barLeft, barLeft + series.bars.barWidth,
  2557
+            var barRight = series.datapoints.format.length === 4 ? (barLeft + point[3]) : (barLeft + series.bars.barWidth);
  2558
+            drawBar(point[0], point[1], point[2] || 0, barLeft, barRight,
2549 2559
                     0, function () { return fillStyle; }, series.xaxis, series.yaxis, octx, series.bars.horizontal, series.bars.lineWidth);
2550 2560
         }
2551 2561
 
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.