Commit 5587862a authored by olau@iola.dk's avatar olau@iola.dk

Added support for disabling interactivity for specific plots

git-svn-id: https://flot.googlecode.com/svn/trunk@107 1e0a6537-2640-0410-bfb7-f154510ff394
parent 39faf24b
...@@ -59,6 +59,8 @@ The format of a single series object is as follows: ...@@ -59,6 +59,8 @@ The format of a single series object is as follows:
points: specific points options, points: specific points options,
xaxis: 1 or 2, xaxis: 1 or 2,
yaxis: 1 or 2, yaxis: 1 or 2,
clickable: boolean
hoverable: boolean
shadowSize: number shadowSize: number
} }
...@@ -88,6 +90,10 @@ to get the secondary axis (x axis at top or y axis to the right). ...@@ -88,6 +90,10 @@ to get the secondary axis (x axis at top or y axis to the right).
E.g., you can use this to make a dual axis plot by specifying E.g., you can use this to make a dual axis plot by specifying
{ yaxis: 2 } for one data series. { yaxis: 2 } for one data series.
"clickable" and "hoverable" can be set to false to disable
interactivity for specific series if interactivity is turned on in
plot, see below.
The rest of the options are all documented below as they are the same The rest of the options are all documented below as they are the same
as the default options passed in via the options parameter in the plot as the default options passed in via the options parameter in the plot
commmand. When you specify them for a specific data series, they will commmand. When you specify them for a specific data series, they will
...@@ -571,6 +577,10 @@ and still activate it. If there are two or more points within this ...@@ -571,6 +577,10 @@ and still activate it. If there are two or more points within this
radius, Flot chooses the closest item. For bars, the top-most bar radius, Flot chooses the closest item. For bars, the top-most bar
(from the latest specified data series) is chosen. (from the latest specified data series) is chosen.
If you want to disable interactivity for a specific data series, you
can set "hoverable" and "clickable" to false in the options for that
series, like this { data: [...], label: "Foo", clickable: false }.
Customizing the selection Customizing the selection
========================= =========================
......
Flot 0.x Flot 0.x
-------- --------
New features:
- Added support for disabling interactivity for specific data series
(request from Ronald Schouten and Steve Upton).
Bug fixes: Bug fixes:
- Fixed two corner-case bugs when drawing filled curves (report and - Fixed two corner-case bugs when drawing filled curves (report and
......
...@@ -1565,7 +1565,7 @@ ...@@ -1565,7 +1565,7 @@
hoverTimeout = null; hoverTimeout = null;
// Returns the data item the mouse is over, or null if none is found // Returns the data item the mouse is over, or null if none is found
function findNearbyItem(mouseX, mouseY) { function findNearbyItem(mouseX, mouseY, seriesFilter) {
var maxDistance = options.grid.mouseActiveRadius, var maxDistance = options.grid.mouseActiveRadius,
lowestDistance = maxDistance * maxDistance + 1, lowestDistance = maxDistance * maxDistance + 1,
item = null, foundPoint = false; item = null, foundPoint = false;
...@@ -1578,6 +1578,9 @@ ...@@ -1578,6 +1578,9 @@
} }
for (var i = 0; i < series.length; ++i) { for (var i = 0; i < series.length; ++i) {
if (!seriesFilter(series[i]))
continue;
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,
...@@ -1682,17 +1685,19 @@ ...@@ -1682,17 +1685,19 @@
return; return;
} }
triggerClickHoverEvent("plotclick", e); triggerClickHoverEvent("plotclick", e,
function (s) { return s["clickable"] != false; });
} }
function onHover() { function onHover() {
triggerClickHoverEvent("plothover", lastMousePos); triggerClickHoverEvent("plothover", lastMousePos,
function (s) { return s["hoverable"] != false; });
hoverTimeout = null; hoverTimeout = null;
} }
// trigger click or hover event (they send the same parameters // trigger click or hover event (they send the same parameters
// so we share their code) // so we share their code)
function triggerClickHoverEvent(eventname, event) { function triggerClickHoverEvent(eventname, event, seriesFilter) {
var offset = eventHolder.offset(), var offset = eventHolder.offset(),
pos = { pageX: event.pageX, pageY: event.pageY }, pos = { pageX: event.pageX, pageY: event.pageY },
canvasX = event.pageX - offset.left - plotOffset.left, canvasX = event.pageX - offset.left - plotOffset.left,
...@@ -1707,7 +1712,7 @@ ...@@ -1707,7 +1712,7 @@
if (axes.y2axis.used) if (axes.y2axis.used)
pos.y2 = axes.y2axis.c2p(canvasY); pos.y2 = axes.y2axis.c2p(canvasY);
var item = findNearbyItem(canvasX, canvasY); var item = findNearbyItem(canvasX, canvasY, seriesFilter);
if (item) { if (item) {
// fill in mouse pos for any listeners out there // fill in mouse pos for any listeners out there
...@@ -1718,15 +1723,17 @@ ...@@ -1718,15 +1723,17 @@
} }
if (options.grid.autoHighlight) { if (options.grid.autoHighlight) {
// clear auto-highlights
for (var i = 0; i < highlights.length; ++i) { for (var i = 0; i < highlights.length; ++i) {
var h = highlights[i]; var h = highlights[i];
if (h.auto && console.log(h.auto, eventname)
if (h.auto == eventname &&
!(item && h.series == item.series && h.point == item.datapoint)) !(item && h.series == item.series && h.point == item.datapoint))
unhighlight(h.series, h.point); unhighlight(h.series, h.point);
} }
if (item) if (item)
highlight(item.series, item.datapoint, true); highlight(item.series, item.datapoint, eventname);
} }
target.trigger(eventname, [ pos, item ]); target.trigger(eventname, [ pos, item ]);
......
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