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

Added support for a ticks function and moved labelMargin to .grid

git-svn-id: https://flot.googlecode.com/svn/trunk@13 1e0a6537-2640-0410-bfb7-f154510ff394
parent 19eb7612
/* Javascript plotting library for jQuery, v. 0.1 */ /* Javascript plotting library for jQuery, v. 0.2 */
(function($) { (function($) {
function Plot(target_, data_, options_) { function Plot(target_, data_, options_) {
...@@ -7,10 +7,6 @@ ...@@ -7,10 +7,6 @@
// where series is either just the data as [ [x1, y1], [x2, y2], ... ] // where series is either just the data as [ [x1, y1], [x2, y2], ... ]
// or { data: [ [x1, y1], [x2, y2], ... ], label: "some label" } // or { data: [ [x1, y1], [x2, y2], ... ], label: "some label" }
function defaultTickFormatter(val) {
return "" + val;
}
var series = []; var series = [];
var options = { var options = {
// the color theme used for graphs // the color theme used for graphs
...@@ -33,7 +29,6 @@ ...@@ -33,7 +29,6 @@
noTicks: 5, // approximate number of ticks for auto-ticks noTicks: 5, // approximate number of ticks for auto-ticks
tickFormatter: defaultTickFormatter, // fn: number -> string tickFormatter: defaultTickFormatter, // fn: number -> string
tickDecimals: null, // no. of decimals, null means auto tickDecimals: null, // no. of decimals, null means auto
labelMargin: 3, // in pixels
min: null, // min. value to show, null means set automatically min: null, // min. value to show, null means set automatically
max: null, // max. value to show, null means set automatically max: null, // max. value to show, null means set automatically
autoscaleMargin: 0 // margin in % to add if auto-setting min/max autoscaleMargin: 0 // margin in % to add if auto-setting min/max
...@@ -42,7 +37,6 @@ ...@@ -42,7 +37,6 @@
noTicks: 5, noTicks: 5,
ticks: null, ticks: null,
tickFormatter: defaultTickFormatter, tickFormatter: defaultTickFormatter,
labelMargin: 3,
min: null, min: null,
max: null, max: null,
autoscaleMargin: 0.02 autoscaleMargin: 0.02
...@@ -70,7 +64,8 @@ ...@@ -70,7 +64,8 @@
grid: { grid: {
color: "#545454", // primary color used for outline and labels color: "#545454", // primary color used for outline and labels
backgroundColor: null, // null for transparent, else color backgroundColor: null, // null for transparent, else color
tickColor: "#dddddd" // color used for the ticks tickColor: "#dddddd", // color used for the ticks
labelMargin: 3 // in pixels
}, },
selection: { selection: {
mode: null, // one of null, "x", "y" or "xy" mode: null, // one of null, "x", "y" or "xy"
...@@ -294,15 +289,25 @@ ...@@ -294,15 +289,25 @@
} }
} }
function defaultTickFormatter(val) {
return "" + val;
}
function calculateTicks(axis, axisOptions) { function calculateTicks(axis, axisOptions) {
var i; var i;
axis.ticks = []; axis.ticks = [];
if (axisOptions.ticks) { if (axisOptions.ticks) {
// user-supplied ticks, just copy them var ticks = axisOptions.ticks;
for (i = 0; i < axisOptions.ticks.length; ++i) {
if ($.isFunction(ticks))
// generate the ticks
ticks = ticks({ min: axis.min, max: axis.max });
// clean up the user-supplied ticks, copy them over
for (i = 0; i < ticks.length; ++i) {
var v, label; var v, label;
var t = axisOptions.ticks[i]; var t = ticks[i];
if (typeof(t) == "object") { if (typeof(t) == "object") {
v = t[0]; v = t[0];
if (t.length > 1) if (t.length > 1)
...@@ -364,8 +369,8 @@ ...@@ -364,8 +369,8 @@
plotOffset.left = plotOffset.right = plotOffset.top = plotOffset.bottom = maxOutset; plotOffset.left = plotOffset.right = plotOffset.top = plotOffset.bottom = maxOutset;
plotOffset.left += labelMaxWidth + options.yaxis.labelMargin; plotOffset.left += labelMaxWidth + options.grid.labelMargin;
plotOffset.bottom += labelMaxHeight + options.xaxis.labelMargin; plotOffset.bottom += labelMaxHeight + options.grid.labelMargin;
plotWidth = canvasWidth - plotOffset.left - plotOffset.right; plotWidth = canvasWidth - plotOffset.left - plotOffset.right;
plotHeight = canvasHeight - plotOffset.bottom - plotOffset.top; plotHeight = canvasHeight - plotOffset.bottom - plotOffset.top;
...@@ -452,7 +457,7 @@ ...@@ -452,7 +457,7 @@
tick = xaxis.ticks[i]; tick = xaxis.ticks[i];
if (!tick.label) if (!tick.label)
continue; continue;
html += '<div style="position:absolute;top:' + (plotOffset.top + plotHeight + options.xaxis.labelMargin) + 'px;left:' + (plotOffset.left + translateHoz(tick.v) - xBoxWidth/2) + 'px;width:' + xBoxWidth + 'px;text-align:center" class="gridLabel">' + tick.label + "</div>"; html += '<div style="position:absolute;top:' + (plotOffset.top + plotHeight + options.grid.labelMargin) + 'px;left:' + (plotOffset.left + translateHoz(tick.v) - xBoxWidth/2) + 'px;width:' + xBoxWidth + 'px;text-align:center" class="gridLabel">' + tick.label + "</div>";
} }
// do the y-axis // do the y-axis
......
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