Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different bar width per data point #25

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 14 additions & 4 deletions jquery.flot.js
Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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) &&
Expand Down Expand Up @@ -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);
}

Expand Down