123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- (function($) {
-
-
- $.jqplot.Dragable = function(options) {
-
- this.markerRenderer = new $.jqplot.MarkerRenderer({shadow:false});
- this.shapeRenderer = new $.jqplot.ShapeRenderer();
- this.isDragging = false;
- this.isOver = false;
- this._ctx;
- this._elem;
- this._point;
- this._gridData;
-
-
- this.color;
-
-
-
- this.constrainTo = 'none';
- $.extend(true, this, options);
- };
-
- function DragCanvas() {
- $.jqplot.GenericCanvas.call(this);
- this.isDragging = false;
- this.isOver = false;
- this._neighbor;
- this._cursors = [];
- }
-
- DragCanvas.prototype = new $.jqplot.GenericCanvas();
- DragCanvas.prototype.constructor = DragCanvas;
-
-
-
- $.jqplot.Dragable.parseOptions = function (defaults, opts) {
- var options = opts || {};
- this.plugins.dragable = new $.jqplot.Dragable(options.dragable);
-
-
- this.isDragable = $.jqplot.config.enablePlugins;
- };
-
-
-
-
-
- $.jqplot.Dragable.postPlotDraw = function() {
-
- if (this.plugins.dragable && this.plugins.dragable.highlightCanvas) {
- this.plugins.dragable.highlightCanvas.resetCanvas();
- this.plugins.dragable.highlightCanvas = null;
- }
- this.plugins.dragable = {previousCursor:'auto', isOver:false};
- this.plugins.dragable.dragCanvas = new DragCanvas();
-
- this.eventCanvas._elem.before(this.plugins.dragable.dragCanvas.createElement(this._gridPadding, 'jqplot-dragable-canvas', this._plotDimensions, this));
- var dctx = this.plugins.dragable.dragCanvas.setContext();
- };
-
-
- $.jqplot.preParseSeriesOptionsHooks.push($.jqplot.Dragable.parseOptions);
- $.jqplot.postDrawHooks.push($.jqplot.Dragable.postPlotDraw);
- $.jqplot.eventListenerHooks.push(['jqplotMouseMove', handleMove]);
- $.jqplot.eventListenerHooks.push(['jqplotMouseDown', handleDown]);
- $.jqplot.eventListenerHooks.push(['jqplotMouseUp', handleUp]);
-
- function initDragPoint(plot, neighbor) {
- var s = plot.series[neighbor.seriesIndex];
- var drag = s.plugins.dragable;
-
-
- var smr = s.markerRenderer;
- var mr = drag.markerRenderer;
- mr.style = smr.style;
- mr.lineWidth = smr.lineWidth + 2.5;
- mr.size = smr.size + 5;
- if (!drag.color) {
- var rgba = $.jqplot.getColorComponents(smr.color);
- var newrgb = [rgba[0], rgba[1], rgba[2]];
- var alpha = (rgba[3] >= 0.6) ? rgba[3]*0.6 : rgba[3]*(2-rgba[3]);
- drag.color = 'rgba('+newrgb[0]+','+newrgb[1]+','+newrgb[2]+','+alpha+')';
- }
- mr.color = drag.color;
- mr.init();
- var start = (neighbor.pointIndex > 0) ? neighbor.pointIndex - 1 : 0;
- var end = neighbor.pointIndex+2;
- drag._gridData = s.gridData.slice(start, end);
- }
-
- function handleMove(ev, gridpos, datapos, neighbor, plot) {
- if (plot.plugins.dragable.dragCanvas.isDragging) {
- var dc = plot.plugins.dragable.dragCanvas;
- var dp = dc._neighbor;
- var s = plot.series[dp.seriesIndex];
- var drag = s.plugins.dragable;
- var gd = s.gridData;
-
-
- var x = (drag.constrainTo == 'y') ? dp.gridData[0] : gridpos.x;
- var y = (drag.constrainTo == 'x') ? dp.gridData[1] : gridpos.y;
-
-
- var xu = s._xaxis.series_p2u(x);
- var yu = s._yaxis.series_p2u(y);
-
-
- var ctx = dc._ctx;
- ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
-
-
- if (dp.pointIndex > 0) {
- drag._gridData[1] = [x, y];
- }
- else {
- drag._gridData[0] = [x, y];
- }
- plot.series[dp.seriesIndex].draw(dc._ctx, {gridData:drag._gridData, shadow:false, preventJqPlotSeriesDrawTrigger:true, color:drag.color, markerOptions:{color:drag.color, shadow:false}, trendline:{show:false}});
- plot.target.trigger('jqplotSeriesPointChange', [dp.seriesIndex, dp.pointIndex, [xu,yu], [x,y]]);
- }
- else if (neighbor != null) {
- var series = plot.series[neighbor.seriesIndex];
- if (series.isDragable) {
- var dc = plot.plugins.dragable.dragCanvas;
- if (!dc.isOver) {
- dc._cursors.push(ev.target.style.cursor);
- ev.target.style.cursor = "pointer";
- }
- dc.isOver = true;
- }
- }
- else if (neighbor == null) {
- var dc = plot.plugins.dragable.dragCanvas;
- if (dc.isOver) {
- ev.target.style.cursor = dc._cursors.pop();
- dc.isOver = false;
- }
- }
- }
-
- function handleDown(ev, gridpos, datapos, neighbor, plot) {
- var dc = plot.plugins.dragable.dragCanvas;
- dc._cursors.push(ev.target.style.cursor);
- if (neighbor != null) {
- var s = plot.series[neighbor.seriesIndex];
- var drag = s.plugins.dragable;
- if (s.isDragable && !dc.isDragging) {
- dc._neighbor = neighbor;
- dc.isDragging = true;
- initDragPoint(plot, neighbor);
- drag.markerRenderer.draw(s.gridData[neighbor.pointIndex][0], s.gridData[neighbor.pointIndex][1], dc._ctx);
- ev.target.style.cursor = "move";
- plot.target.trigger('jqplotDragStart', [neighbor.seriesIndex, neighbor.pointIndex, gridpos, datapos]);
- }
- }
-
- else {
- var ctx = dc._ctx;
- ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
- dc.isDragging = false;
- }
- }
-
- function handleUp(ev, gridpos, datapos, neighbor, plot) {
- if (plot.plugins.dragable.dragCanvas.isDragging) {
- var dc = plot.plugins.dragable.dragCanvas;
-
- var ctx = dc._ctx;
- ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
- dc.isDragging = false;
-
- var dp = dc._neighbor;
- var s = plot.series[dp.seriesIndex];
- var drag = s.plugins.dragable;
-
- var x = (drag.constrainTo == 'y') ? dp.data[0] : datapos[s.xaxis];
- var y = (drag.constrainTo == 'x') ? dp.data[1] : datapos[s.yaxis];
-
-
- s.data[dp.pointIndex][0] = x;
- s.data[dp.pointIndex][1] = y;
- plot.drawSeries({preventJqPlotSeriesDrawTrigger:true}, dp.seriesIndex);
- dc._neighbor = null;
- ev.target.style.cursor = dc._cursors.pop();
- plot.target.trigger('jqplotDragStop', [gridpos, datapos]);
- }
- }
- })(jQuery);
|