Commit f5efa0d4 authored by Ole Laursen's avatar Ole Laursen

Rework interacting example slightly to make DOM text update optional

parent d60f0d47
...@@ -16,13 +16,16 @@ ...@@ -16,13 +16,16 @@
<p>One of the goals of Flot is to support user interactions. Try <p>One of the goals of Flot is to support user interactions. Try
pointing and clicking on the points.</p> pointing and clicking on the points.</p>
<p id="hoverdata">Mouse hovers at <p>
(<span id="x">0</span>, <span id="y">0</span>). <span id="clickdata"></span></p> <label><input id="enablePosition" type="checkbox">Show mouse position</label>
<span id="hoverdata"></span>
<span id="clickdata"></span>
</p>
<p>A tooltip is easy to build with a bit of jQuery code and the <p>A tooltip is easy to build with a bit of jQuery code and the
data returned from the plot.</p> data returned from the plot.</p>
<p><input id="enableTooltip" type="checkbox">Enable tooltip</p> <p><label><input id="enableTooltip" type="checkbox">Enable tooltip</label></p>
<script type="text/javascript"> <script type="text/javascript">
$(function () { $(function () {
...@@ -57,8 +60,10 @@ $(function () { ...@@ -57,8 +60,10 @@ $(function () {
var previousPoint = null; var previousPoint = null;
$("#placeholder").bind("plothover", function (event, pos, item) { $("#placeholder").bind("plothover", function (event, pos, item) {
$("#x").text(pos.x.toFixed(2)); if ($("#enablePosition:checked").length > 0) {
$("#y").text(pos.y.toFixed(2)); var str = "(" + pos.x.toFixed(2) + ", " + pos.y.toFixed(2) + ")";
$("#hoverdata").text(str);
}
if ($("#enableTooltip:checked").length > 0) { if ($("#enableTooltip:checked").length > 0) {
if (item) { if (item) {
...@@ -82,7 +87,7 @@ $(function () { ...@@ -82,7 +87,7 @@ $(function () {
$("#placeholder").bind("plotclick", function (event, pos, item) { $("#placeholder").bind("plotclick", function (event, pos, item) {
if (item) { if (item) {
$("#clickdata").text("You clicked point " + item.dataIndex + " in " + item.series.label + "."); $("#clickdata").text(" - click point " + item.dataIndex + " in " + item.series.label);
plot.highlight(item.series, item.datapoint); plot.highlight(item.series, item.datapoint);
} }
}); });
......
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