Commit de724cf7 authored by olau@iola.dk's avatar olau@iola.dk

Refactored the axis adjustment code for bars

git-svn-id: https://flot.googlecode.com/svn/trunk@82 1e0a6537-2640-0410-bfb7-f154510ff394
parent f8594bd2
...@@ -30,7 +30,7 @@ $(function () { ...@@ -30,7 +30,7 @@ $(function () {
d3.push([i, Math.cos(i)]); d3.push([i, Math.cos(i)]);
var d4 = []; var d4 = [];
for (var i = 0; i < 14; i += 0.5) for (var i = 0; i < 14; i += 0.1)
d4.push([i, Math.sqrt(i * 10)]); d4.push([i, Math.sqrt(i * 10)]);
var d5 = []; var d5 = [];
......
...@@ -251,7 +251,12 @@ ...@@ -251,7 +251,12 @@
for (var i = 0; i < series.length; ++i) { for (var i = 0; i < series.length; ++i) {
var data = series[i].data, var data = series[i].data,
axisx = series[i].xaxis, axisx = series[i].xaxis,
axisy = series[i].yaxis; axisy = series[i].yaxis,
mindelta = 0, maxdelta = 0;
// make sure we got room for the bar
if (series[i].bars.show)
maxdelta = series[i].bars.barWidth;
axisx.used = axisy.used = true; axisx.used = axisy.used = true;
for (var j = 0; j < data.length; ++j) { for (var j = 0; j < data.length; ++j) {
...@@ -262,10 +267,10 @@ ...@@ -262,10 +267,10 @@
// convert to number // convert to number
if (x != null && !isNaN(x = +x)) { if (x != null && !isNaN(x = +x)) {
if (x < axisx.datamin) if (x - mindelta < axisx.datamin)
axisx.datamin = x; axisx.datamin = x - mindelta;
if (x > axisx.datamax) if (x + maxdelta > axisx.datamax)
axisx.datamax = x; axisx.datamax = x + maxdelta;
} }
if (y != null && !isNaN(y = +y)) { if (y != null && !isNaN(y = +y)) {
...@@ -351,24 +356,9 @@ ...@@ -351,24 +356,9 @@
} }
} }
function extendXRangeIfNeededByBar(axis, options) {
// extend x range so end bar graph won't be drawn on the chart border
if (options.max == null) {
// great, we're autoscaling, check if we might need a bump
var newmax = axis.max;
for (var i = 0; i < series.length; ++i)
if (series[i].bars.show && series[i].bars.barWidth + axis.datamax > newmax)
newmax = axis.datamax + series[i].bars.barWidth;
axis.max = newmax;
}
}
setupAxis(xaxis, options.xaxis); setupAxis(xaxis, options.xaxis);
extendXRangeIfNeededByBar(xaxis,options.xaxis);
setupAxis(yaxis, options.yaxis); setupAxis(yaxis, options.yaxis);
setupAxis(x2axis, options.x2axis); setupAxis(x2axis, options.x2axis);
extendXRangeIfNeededByBar(x2axis, options.x2axis);
setupAxis(y2axis, options.y2axis); setupAxis(y2axis, options.y2axis);
setSpacing(); setSpacing();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment