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

Added getPlaceholder and renamed internal target to placeholder


git-svn-id: https://flot.googlecode.com/svn/trunk@183 1e0a6537-2640-0410-bfb7-f154510ff394
parent a4e60e84
......@@ -822,7 +822,6 @@ Flot to keep track of its state, so be careful.
flat array (the field "pointsize" is the increment in the flat
array to get to the next point so for a dataset consisting only of
(x,y) pairs it would be 2).
- getAxes()
......@@ -835,12 +834,15 @@ Flot to keep track of its state, so be careful.
transforming from data point space to the canvas plot space and
back. Both returns values that are offset with the plot offset.
- getPlaceholder()
Returns placeholder that the plot was put into. This can be useful
for plugins for adding DOM elements or firing events.
- getCanvas()
Returns the canvas used for drawing in case you need to hack on it
yourself. You'll probably need to get the plot offset too.
- getPlotOffset()
......
......@@ -3,7 +3,7 @@ Flot 0.x
API changes:
In the global options specified in the $.plot command,
1. In the global options specified in the $.plot command,
"lines", "points", "bars" and "shadowSize" have been moved to a
sub-object called "series", i.e.
......@@ -13,14 +13,14 @@ becomes
$.plot(placeholder, data, { series: { lines: { show: true }}})
All future series-specific options will go into this sub-object (to
simplify plugin writing). Backward-compatibility hooks are in place,
All future series-specific options will go into this sub-object to
simplify plugin writing. Backward-compatibility hooks are in place,
so old code should not break.
"plothover" no longer provides the original data point, but instead a
normalized one, since there may be no corresponding original point.
2. "plothover" no longer provides the original data point, but instead
a normalized one, since there may be no corresponding original point.
Due to a bug in previous versions of jQuery, you now need at least
3. Due to a bug in previous versions of jQuery, you now need at least
jQuery 1.2.6. But if you can, try jQuery 1.3.2 as it got some
improvements in event handling speed.
......@@ -86,6 +86,8 @@ Changes:
- Plugin system: register an init method in the $.flot.plugins array
to get started, see PLUGINS.txt for details on how to write plugins.
There are also some extra methods to enable access to internal
state.
- Hooks: you can register functions that are called while Flot is
crunching the data and doing the plot. This can be used to modify
......
......@@ -5,7 +5,7 @@
*/
(function($) {
function Plot(target, data_, options_, plugins) {
function Plot(placeholder, data_, options_, plugins) {
// data is on the form:
// [ series1, series2 ... ]
// where series is either just the data as [ [x1, y1], [x2, y2], ... ]
......@@ -128,6 +128,7 @@
plot.clearSelection = clearSelection;
plot.setSelection = setSelection;
plot.getSelection = getSelection;
plot.getPlaceholder = function() { return placeholder; };
plot.getCanvas = function() { return canvas; };
plot.getPlotOffset = function() { return plotOffset; };
plot.width = function () { return plotWidth; }
......@@ -515,11 +516,11 @@
return c;
}
canvasWidth = target.width();
canvasHeight = target.height();
target.html(""); // clear target
if (target.css("position") == 'static')
target.css("position", "relative"); // for positioning labels and overlay
canvasWidth = placeholder.width();
canvasHeight = placeholder.height();
placeholder.html(""); // clear placeholder
if (placeholder.css("position") == 'static')
placeholder.css("position", "relative"); // for positioning labels and overlay
if (canvasWidth <= 0 || canvasHeight <= 0)
throw "Invalid dimensions for plot, width = " + canvasWidth + ", height = " + canvasHeight;
......@@ -528,11 +529,11 @@
window.G_vmlCanvasManager.init_(document); // make sure everything is setup
// the canvas
canvas = $(makeCanvas(canvasWidth, canvasHeight)).appendTo(target).get(0);
canvas = $(makeCanvas(canvasWidth, canvasHeight)).appendTo(placeholder).get(0);
ctx = canvas.getContext("2d");
// overlay canvas for interactive features
overlay = $(makeCanvas(canvasWidth, canvasHeight)).css({ position: 'absolute', left: 0, top: 0 }).appendTo(target).get(0);
overlay = $(makeCanvas(canvasWidth, canvasHeight)).css({ position: 'absolute', left: 0, top: 0 }).appendTo(placeholder).get(0);
octx = overlay.getContext("2d");
octx.stroke();
}
......@@ -606,7 +607,7 @@
if (labels.length > 0) {
var dummyDiv = $('<div style="position:absolute;top:-10000px;width:10000px;font-size:smaller">'
+ labels.join("") + '<div style="clear:left"></div></div>').appendTo(target);
+ labels.join("") + '<div style="clear:left"></div></div>').appendTo(placeholder);
axis.labelHeight = dummyDiv.height();
dummyDiv.remove();
}
......@@ -622,7 +623,7 @@
if (labels.length > 0) {
var dummyDiv = $('<div style="position:absolute;top:-10000px;font-size:smaller">'
+ labels.join("") + '</div>').appendTo(target);
+ labels.join("") + '</div>').appendTo(placeholder);
if (axis.labelWidth == null)
axis.labelWidth = dummyDiv.width();
if (axis.labelHeight == null)
......@@ -1184,7 +1185,7 @@
}
function insertLabels() {
target.find(".tickLabels").remove();
placeholder.find(".tickLabels").remove();
var html = ['<div class="tickLabels" style="font-size:smaller;color:' + options.grid.color + '">'];
......@@ -1218,7 +1219,7 @@
html.push('</div>');
target.append(html.join(""));
placeholder.append(html.join(""));
}
function drawSeries(series) {
......@@ -1669,7 +1670,7 @@
}
function insertLegend() {
target.find(".legend").remove();
placeholder.find(".legend").remove();
if (!options.legend.show)
return;
......@@ -1719,7 +1720,7 @@
pos += 'right:' + (m[0] + plotOffset.right) + 'px;';
else if (p.charAt(1) == "w")
pos += 'left:' + (m[0] + plotOffset.left) + 'px;';
var legend = $('<div class="legend">' + table.replace('style="', 'style="position:absolute;' + pos +';') + '</div>').appendTo(target);
var legend = $('<div class="legend">' + table.replace('style="', 'style="position:absolute;' + pos +';') + '</div>').appendTo(placeholder);
if (options.legend.backgroundOpacity != 0.0) {
// put in the transparent background
// separately to avoid blended labels and
......@@ -1839,7 +1840,7 @@
function (s) { return s["hoverable"] != false; });
if (selection.active) {
target.trigger("plotselecting", [ getSelection() ]);
placeholder.trigger("plotselecting", [ getSelection() ]);
updateSelection(lastMousePos);
}
......@@ -1917,7 +1918,7 @@
highlight(item.series, item.datapoint, eventname);
}
target.trigger(eventname, [ pos, item ]);
placeholder.trigger(eventname, [ pos, item ]);
}
function triggerRedrawOverlay() {
......@@ -2059,11 +2060,11 @@
function triggerSelectedEvent() {
var r = getSelection();
target.trigger("plotselected", [ r ]);
placeholder.trigger("plotselected", [ r ]);
// backwards-compat stuff, to be removed in future
if (axes.xaxis.used && axes.yaxis.used)
target.trigger("selected", [ { x1: r.xaxis.from, y1: r.yaxis.from, x2: r.xaxis.to, y2: r.yaxis.to } ]);
placeholder.trigger("selected", [ { x1: r.xaxis.from, y1: r.yaxis.from, x2: r.xaxis.to, y2: r.yaxis.to } ]);
}
function onSelectionMouseUp(e) {
......@@ -2083,8 +2084,8 @@
}
else {
// this counts as a clear
target.trigger("plotunselected", [ ]);
target.trigger("plotselecting", [ null ]);
placeholder.trigger("plotunselected", [ ]);
placeholder.trigger("plotselecting", [ null ]);
}
return false;
......@@ -2128,7 +2129,7 @@
selection.show = false;
triggerRedrawOverlay();
if (!preventEvent)
target.trigger("plotunselected", [ ]);
placeholder.trigger("plotunselected", [ ]);
}
}
......@@ -2188,8 +2189,8 @@
}
}
$.plot = function(target, data, options) {
var plot = new Plot($(target), data, options, $.plot.plugins);
$.plot = function(placeholder, data, options) {
var plot = new Plot($(placeholder), data, options, $.plot.plugins);
/*var t0 = new Date();
var t1 = new Date();
var tstr = "time used (msecs): " + (t1.getTime() - t0.getTime())
......
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