Commit 51485c03 authored by rlinehan's avatar rlinehan

Add option to always show selection rectangle

Previously, if the selected area was very small, the selection
rectangle would not be displayed. This commit adds an "alwaysShow"
option so that, when true, the selection rectangle will always be
displayed. When the selected area is very small, the selection
rectangle will become a line.
parent 0a3db845
...@@ -8,7 +8,8 @@ The plugin supports these options: ...@@ -8,7 +8,8 @@ The plugin supports these options:
selection: { selection: {
mode: null or "x" or "y" or "xy", mode: null or "x" or "y" or "xy",
color: color, color: color,
shape: "round" or "miter" or "bevel" shape: "round" or "miter" or "bevel",
alwaysShow: boolean
} }
Selection support is enabled by setting the mode to one of "x", "y" or "xy". Selection support is enabled by setting the mode to one of "x", "y" or "xy".
...@@ -16,7 +17,9 @@ In "x" mode, the user will only be able to specify the x range, similarly for ...@@ -16,7 +17,9 @@ In "x" mode, the user will only be able to specify the x range, similarly for
"y" mode. For "xy", the selection becomes a rectangle where both ranges can be "y" mode. For "xy", the selection becomes a rectangle where both ranges can be
specified. "color" is color of the selection (if you need to change the color specified. "color" is color of the selection (if you need to change the color
later on, you can get to it with plot.getOptions().selection.color). "shape" later on, you can get to it with plot.getOptions().selection.color). "shape"
is the shape of the corners of the selection. is the shape of the corners of the selection. When "alwaysShow" is true,
the selection rectangle will always be displayed (as a line), even when the
selection is very small.
When selection support is enabled, a "plotselected" event will be emitted on When selection support is enabled, a "plotselected" event will be emitted on
the DOM element you passed into the plot function. The event handler gets a the DOM element you passed into the plot function. The event handler gets a
...@@ -296,9 +299,9 @@ The plugin allso adds the following methods to the plot object: ...@@ -296,9 +299,9 @@ The plugin allso adds the following methods to the plot object:
plot.hooks.drawOverlay.push(function (plot, ctx) { plot.hooks.drawOverlay.push(function (plot, ctx) {
// draw selection // draw selection
if (selection.show && selectionIsSane()) { var o = plot.getOptions();
if (selection.show && (selectionIsSane() || o.selection.alwaysShow)) {
var plotOffset = plot.getPlotOffset(); var plotOffset = plot.getPlotOffset();
var o = plot.getOptions();
ctx.save(); ctx.save();
ctx.translate(plotOffset.left, plotOffset.top); ctx.translate(plotOffset.left, plotOffset.top);
...@@ -338,7 +341,8 @@ The plugin allso adds the following methods to the plot object: ...@@ -338,7 +341,8 @@ The plugin allso adds the following methods to the plot object:
selection: { selection: {
mode: null, // one of null, "x", "y" or "xy" mode: null, // one of null, "x", "y" or "xy"
color: "#e8cfac", color: "#e8cfac",
shape: "round" // one of "round", "miter", or "bevel" shape: "round", // one of "round", "miter", or "bevel"
alwaysShow: false // boolean
} }
}, },
name: 'selection', name: 'selection',
......
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