2
* Selection Handles Plugin
4
* Depends upon options.selection.mode
7
* show - True enables the handles plugin.
8
* drag - Left and Right drag handles
9
* scroll - Scrolling handle
15
Flotr.addPlugin('handles', {
24
'flotr:afterinit': init,
25
'flotr:select': handleSelect,
26
'flotr:mousedown': reset,
27
'flotr:mousemove': mouseMoveHandler
36
options = this.options,
37
handles = this.handles,
39
scroll, left, right, container;
41
if (!options.selection.mode || !options.handles.show || 'ontouchstart' in el) return;
43
handles.initialized = true;
45
container = D.node('<div class="flotr-handles"></div>');
46
options = options.handles;
50
right = D.node('<div class="flotr-handles-handle flotr-handles-drag flotr-handles-right"></div>');
51
left = D.node('<div class="flotr-handles-handle flotr-handles-drag flotr-handles-left"></div>');
52
D.insert(container, right);
53
D.insert(container, left);
57
handles.right = right;
59
this.observe(left, 'mousedown', function () {
60
handles.moveHandler = leftMoveHandler;
62
this.observe(right, 'mousedown', function () {
63
handles.moveHandler = rightMoveHandler;
69
scroll = D.node('<div class="flotr-handles-handle flotr-handles-scroll"></div>');
70
D.insert(container, scroll);
72
handles.scroll = scroll;
73
this.observe(scroll, 'mousedown', function () {
74
handles.moveHandler = scrollMoveHandler;
78
this.observe(document, 'mouseup', function() {
79
handles.moveHandler = null;
82
D.insert(el, container);
86
function handleSelect(selection) {
88
if (!this.handles.initialized) return;
91
handles = this.handles,
92
options = this.options.handles,
94
right = handles.right,
95
scroll = handles.scroll;
99
positionDrag(this, left, selection.x1);
100
positionDrag(this, right, selection.x2);
103
if (options.scroll) {
114
function positionDrag(graph, handle, x) {
118
var size = D.size(handle),
119
l = Math.round(graph.axes.x.d2p(x) - size.width / 2),
120
t = (graph.plotHeight - size.height) / 2;
122
D.setStyles(handle, {
128
function positionScroll(graph, handle, x1, x2) {
132
var size = D.size(handle),
133
l = Math.round(graph.axes.x.d2p(x1)),
134
t = (graph.plotHeight) - size.height / 2,
135
w = (graph.axes.x.d2p(x2) - graph.axes.x.d2p(x1));
137
D.setStyles(handle, {
146
if (!this.handles.initialized) return;
149
handles = this.handles;
151
D.hide(handles.left);
152
D.hide(handles.right);
153
D.hide(handles.scroll);
157
function mouseMoveHandler(e, position) {
159
if (!this.handles.initialized) return;
160
if (!this.handles.moveHandler) return;
164
selection = this.selection.selection,
165
area = this.selection.getArea(),
166
handles = this.handles;
168
handles.moveHandler(area, delta);
169
checkSwap(area, handles);
171
this.selection.setSelection(area);
174
function checkSwap (area, handles) {
175
var moveHandler = handles.moveHandler;
176
if (area.x1 > area.x2) {
177
if (moveHandler == leftMoveHandler) {
178
moveHandler = rightMoveHandler;
179
} else if (moveHandler == rightMoveHandler) {
180
moveHandler = leftMoveHandler;
182
handles.moveHandler = moveHandler;
186
function leftMoveHandler(area, delta) {
190
function rightMoveHandler(area, delta) {
194
function scrollMoveHandler(area, delta) {