acts_as_dashboard 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +54 -0
- data/Rakefile +23 -0
- data/VERSION +1 -0
- data/acts_as_dashboard.gemspec +166 -0
- data/generators/dashboard/USAGE +23 -0
- data/generators/dashboard/dashboard_generator.rb +105 -0
- data/generators/dashboard/templates/controller.erb +39 -0
- data/generators/dashboard/templates/dashboard.css +66 -0
- data/generators/dashboard/templates/dashboard.js +305 -0
- data/generators/dashboard/templates/jqplot-0.9.7/jquery.jqplot.min.js +14 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.barRenderer.js +404 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.barRenderer.min.js +14 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.canvasAxisLabelRenderer.js +200 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.canvasAxisLabelRenderer.min.js +14 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.canvasAxisTickRenderer.js +232 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.canvasAxisTickRenderer.min.js +14 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.canvasTextRenderer.js +408 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.canvasTextRenderer.min.js +14 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.categoryAxisRenderer.js +238 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.categoryAxisRenderer.min.js +14 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.cursor.js +812 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.cursor.min.js +14 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.dateAxisRenderer.js +313 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.dateAxisRenderer.min.js +14 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.dragable.js +203 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.dragable.min.js +14 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.highlighter.js +359 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.highlighter.min.js +14 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.logAxisRenderer.js +434 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.logAxisRenderer.min.js +14 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.mekkoAxisRenderer.js +595 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.mekkoAxisRenderer.min.js +14 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.mekkoRenderer.js +308 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.mekkoRenderer.min.js +14 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.ohlcRenderer.js +343 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.ohlcRenderer.min.js +14 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.pieRenderer.js +333 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.pieRenderer.min.js +14 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.pointLabels.js +307 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.pointLabels.js.orig +273 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.pointLabels.min.js +14 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.trendline.js +208 -0
- data/generators/dashboard/templates/jqplot-0.9.7/plugins/jqplot.trendline.min.js +14 -0
- data/generators/dashboard/templates/jquery.jqplot.min.css +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/CHANGELOG +269 -0
- data/generators/dashboard/templates/js.class-2.1.4/MIT-LICENSE +30 -0
- data/generators/dashboard/templates/js.class-2.1.4/README +30 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/command.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/comparable.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/constant_scope.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/core.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/decorator.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/enumerable.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/forwardable.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/hash.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/linked_list.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/loader.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/method_chain.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/observable.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/package.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/proxy.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/ruby.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/set.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/stack_trace.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/state.js +1 -0
- data/generators/dashboard/templates/js.class-2.1.4/min/stdlib.js +16 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/command.js +93 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/comparable.js +37 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/constant_scope.js +48 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/core.js +1060 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/decorator.js +50 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/enumerable.js +505 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/forwardable.js +22 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/hash.js +334 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/linked_list.js +114 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/loader.js +458 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/method_chain.js +172 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/observable.js +55 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/package.js +377 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/proxy.js +58 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/ruby.js +44 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/set.js +332 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/stack_trace.js +151 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/state.js +95 -0
- data/generators/dashboard/templates/js.class-2.1.4/src/stdlib.js +2517 -0
- data/generators/dashboard/templates/show.html.erb +67 -0
- data/lib/acts_as_dashboard/app/views/dashboards/show.html.erb +67 -0
- data/lib/acts_as_dashboard/class_methods.rb +58 -0
- data/lib/acts_as_dashboard/config.rb +25 -0
- data/lib/acts_as_dashboard/instance_methods.rb +32 -0
- data/lib/acts_as_dashboard/line_graph_widget.rb +68 -0
- data/lib/acts_as_dashboard/public/javascripts/dashboard.js +305 -0
- data/lib/acts_as_dashboard/public/stylesheets/dashboard.css +66 -0
- data/lib/acts_as_dashboard/short_messages_widget.rb +25 -0
- data/lib/acts_as_dashboard/widget.rb +55 -0
- data/lib/acts_as_dashboard.rb +17 -0
- data/spec/acts_as_dashboard/class_method_specs.rb +188 -0
- data/spec/acts_as_dashboard/config_spec.rb +57 -0
- data/spec/acts_as_dashboard/instance_methods_spec.rb +134 -0
- data/spec/acts_as_dashboard/line_graph_widget_spec.rb +165 -0
- data/spec/acts_as_dashboard/short_messages_widget_spec.rb +69 -0
- data/spec/acts_as_dashboard/widget_spec.rb +6 -0
- data/spec/acts_as_dashboard_spec.rb +15 -0
- data/spec/shared/widget_behaviours.rb +171 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +10 -0
- data/tasks/install.rake +8 -0
- data/tasks/install_javascript.rake +7 -0
- data/tasks/install_stylesheets.rake +7 -0
- metadata +209 -0
@@ -0,0 +1,14 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) 2009 Chris Leonello
|
3
|
+
* jqPlot is currently available for use in all personal or commercial projects
|
4
|
+
* under both the MIT and GPL version 2.0 licenses. This means that you can
|
5
|
+
* choose the license that best suits your project and use it accordingly.
|
6
|
+
*
|
7
|
+
* Although not required, the author would appreciate an email letting him
|
8
|
+
* know of any substantial use of jqPlot. You can reach the author at:
|
9
|
+
* chris dot leonello at gmail dot com or see http://www.jqplot.com/info.php .
|
10
|
+
*
|
11
|
+
* If you are feeling kind and generous, consider supporting the project by
|
12
|
+
* making a donation at: http://www.jqplot.com/donate.php .
|
13
|
+
*/
|
14
|
+
(function(i){i.jqplot.Cursor=function(o){this.style="crosshair";this.previousCursor="auto";this.show=i.jqplot.config.enablePlugins;this.showTooltip=true;this.followMouse=false;this.tooltipLocation="se";this.tooltipOffset=6;this.showTooltipGridPosition=false;this.showTooltipUnitPosition=true;this.showTooltipDataPosition=false;this.tooltipFormatString="%.4P, %.4P";this.useAxesFormatters=true;this.tooltipAxisGroups=[];this.zoom=false;this.zoomProxy=false;this.zoomTarget=false;this.clickReset=false;this.dblClickReset=true;this.showVerticalLine=false;this.showHorizontalLine=false;this.constrainZoomTo="none";this.shapeRenderer=new i.jqplot.ShapeRenderer();this._zoom={start:[],end:[],started:false,zooming:false,isZoomed:false,axes:{start:{},end:{}}};this._tooltipElem;this.zoomCanvas;this.cursorCanvas;this.intersectionThreshold=2;this.showCursorLegend=false;this.cursorLegendFormatString=i.jqplot.Cursor.cursorLegendFormatString;i.extend(true,this,o)};i.jqplot.Cursor.cursorLegendFormatString="%s x:%s, y:%s";i.jqplot.Cursor.init=function(t,r,q){var o=q||{};this.plugins.cursor=new i.jqplot.Cursor(o.cursor);var u=this.plugins.cursor;if(u.show){i.jqplot.eventListenerHooks.push(["jqplotMouseEnter",b]);i.jqplot.eventListenerHooks.push(["jqplotMouseLeave",f]);i.jqplot.eventListenerHooks.push(["jqplotMouseMove",h]);if(u.showCursorLegend){q.legend=q.legend||{};q.legend.renderer=i.jqplot.CursorLegendRenderer;q.legend.formatString=this.plugins.cursor.cursorLegendFormatString;q.legend.show=true}if(u.zoom){i.jqplot.eventListenerHooks.push(["jqplotMouseDown",a]);i.jqplot.eventListenerHooks.push(["jqplotMouseUp",n]);if(u.clickReset){i.jqplot.eventListenerHooks.push(["jqplotClick",j])}if(u.dblClickReset){i.jqplot.eventListenerHooks.push(["jqplotDblClick",c])}}this.resetZoom=function(){var x=this.axes;if(!u.zoomProxy){for(var w in x){x[w].reset()}this.redraw()}else{var v=this.plugins.cursor.zoomCanvas._ctx;v.clearRect(0,0,v.canvas.width,v.canvas.height)}this.plugins.cursor._zoom.isZoomed=false;this.target.trigger("jqplotResetZoom",[this,this.plugins.cursor])};if(u.showTooltipDataPosition){u.showTooltipUnitPosition=false;u.showTooltipGridPosition=false;if(o.cursor.tooltipFormatString==undefined){u.tooltipFormatString=i.jqplot.Cursor.cursorLegendFormatString}}}};i.jqplot.Cursor.postDraw=function(){var w=this.plugins.cursor;w.zoomCanvas=new i.jqplot.GenericCanvas();this.eventCanvas._elem.before(w.zoomCanvas.createElement(this._gridPadding,"jqplot-zoom-canvas",this._plotDimensions));var v=w.zoomCanvas.setContext();w._tooltipElem=i('<div class="jqplot-cursor-tooltip" style="position:absolute;display:none"></div>');w.zoomCanvas._elem.before(w._tooltipElem);if(w.showVerticalLine||w.showHorizontalLine){w.cursorCanvas=new i.jqplot.GenericCanvas();this.eventCanvas._elem.before(w.cursorCanvas.createElement(this._gridPadding,"jqplot-cursor-canvas",this._plotDimensions));var v=w.cursorCanvas.setContext()}if(w.showTooltipUnitPosition){if(w.tooltipAxisGroups.length===0){var r=this.series;var t;var o=[];for(var q=0;q<r.length;q++){t=r[q];var u=t.xaxis+","+t.yaxis;if(i.inArray(u,o)==-1){o.push(u)}}for(var q=0;q<o.length;q++){w.tooltipAxisGroups.push(o[q].split(","))}}}};i.jqplot.Cursor.zoomProxy=function(v,q){var o=v.plugins.cursor;var u=q.plugins.cursor;o.zoomTarget=true;o.zoom=true;o.style="auto";o.dblClickReset=false;u.zoom=true;u.zoomProxy=true;q.target.bind("jqplotZoom",t);q.target.bind("jqplotResetZoom",r);function t(x,w,z,y,A){o.doZoom(w,z,v,A)}function r(w,x,y){v.resetZoom()}};i.jqplot.Cursor.prototype.resetZoom=function(u,v){var t=u.axes;var r=v._zoom.axes;if(!u.plugins.cursor.zoomProxy&&v._zoom.isZoomed){for(var q in t){t[q]._ticks=[];t[q].min=r[q].min;t[q].max=r[q].max;t[q].numberTicks=r[q].numberTicks;t[q].tickInterval=r[q].tickInterval;t[q].daTickInterval=r[q].daTickInterval}u.redraw();v._zoom.isZoomed=false}else{var o=v.zoomCanvas._ctx;o.clearRect(0,0,o.canvas.width,o.canvas.height)}u.target.trigger("jqplotResetZoom",[u,v])};i.jqplot.Cursor.resetZoom=function(o){o.resetZoom()};i.jqplot.Cursor.prototype.doZoom=function(w,t,x,B){var z=B;var y=x.axes;var q=z._zoom.axes;var r=q.start;var u=q.end;var v,A;var C=x.plugins.cursor.zoomCanvas._ctx;if((z.constrainZoomTo=="none"&&Math.abs(w.x-z._zoom.start[0])>6&&Math.abs(w.y-z._zoom.start[1])>6)||(z.constrainZoomTo=="x"&&Math.abs(w.x-z._zoom.start[0])>6)||(z.constrainZoomTo=="y"&&Math.abs(w.y-z._zoom.start[1])>6)){if(!x.plugins.cursor.zoomProxy){for(var o in t){if(z._zoom.axes[o]==undefined){z._zoom.axes[o]={};z._zoom.axes[o].numberTicks=y[o].numberTicks;z._zoom.axes[o].tickInterval=y[o].tickInterval;z._zoom.axes[o].daTickInterval=y[o].daTickInterval;z._zoom.axes[o].min=y[o].min;z._zoom.axes[o].max=y[o].max}if((z.constrainZoomTo=="none")||(z.constrainZoomTo=="x"&&o.charAt(0)=="x")||(z.constrainZoomTo=="y"&&o.charAt(0)=="y")){dp=t[o];if(dp!=null){if(dp>r[o]){y[o].min=r[o];y[o].max=dp}else{span=r[o]-dp;y[o].max=r[o];y[o].min=dp}y[o].tickInterval=null;y[o].daTickInterval=null;y[o]._ticks=[]}}}C.clearRect(0,0,C.canvas.width,C.canvas.height);x.redraw();z._zoom.isZoomed=true}x.target.trigger("jqplotZoom",[w,t,x,B])}};i.jqplot.preInitHooks.push(i.jqplot.Cursor.init);i.jqplot.postDrawHooks.push(i.jqplot.Cursor.postDraw);function e(D,q,A){var F=A.plugins.cursor;var v="";var J=false;if(F.showTooltipGridPosition){v=D.x+", "+D.y;J=true}if(F.showTooltipUnitPosition){var C;for(var B=0;B<F.tooltipAxisGroups.length;B++){C=F.tooltipAxisGroups[B];if(J){v+="<br />"}if(F.useAxesFormatters){var z=A.axes[C[0]]._ticks[0].formatter;var o=A.axes[C[1]]._ticks[0].formatter;var G=A.axes[C[0]]._ticks[0].formatString;var u=A.axes[C[1]]._ticks[0].formatString;v+=z(G,q[C[0]])+", "+o(u,q[C[1]])}else{v+=i.jqplot.sprintf(F.tooltipFormatString,q[C[0]],q[C[1]])}J=true}}if(F.showTooltipDataPosition){var t=A.series;var I=d(A,D.x,D.y);var J=false;for(var B=0;B<t.length;B++){if(t[B].show){var x=t[B].index;var r=t[B].label.toString();var E=i.inArray(x,I.indices);var y=undefined;var w=undefined;if(E!=-1){var H=I.data[E].data;if(F.useAxesFormatters){var z=t[B]._xaxis._ticks[0].formatter;var o=t[B]._yaxis._ticks[0].formatter;var G=t[B]._xaxis._ticks[0].formatString;var u=t[B]._yaxis._ticks[0].formatString;y=z(G,H[0]);w=o(u,H[1])}else{y=H[0];w=H[1]}if(J){v+="<br />"}v+=i.jqplot.sprintf(F.tooltipFormatString,r,y,w);J=true}}}}F._tooltipElem.html(v)}function g(C,A){var E=A.plugins.cursor;var z=E.cursorCanvas._ctx;z.clearRect(0,0,z.canvas.width,z.canvas.height);if(E.showVerticalLine){E.shapeRenderer.draw(z,[[C.x,0],[C.x,z.canvas.height]])}if(E.showHorizontalLine){E.shapeRenderer.draw(z,[[0,C.y],[z.canvas.width,C.y]])}var G=d(A,C.x,C.y);if(E.showCursorLegend){var q=i(A.targetId+" td.jqplot-cursor-legend-label");for(var B=0;B<q.length;B++){var v=i(q[B]).data("seriesIndex");var t=A.series[v];var r=t.label.toString();var D=i.inArray(v,G.indices);var x=undefined;var w=undefined;if(D!=-1){var H=G.data[D].data;if(E.useAxesFormatters){var y=t._xaxis._ticks[0].formatter;var o=t._yaxis._ticks[0].formatter;var F=t._xaxis._ticks[0].formatString;var u=t._yaxis._ticks[0].formatString;x=y(F,H[0]);w=o(u,H[1])}else{x=H[0];w=H[1]}}if(A.legend.escapeHtml){i(q[B]).text(i.jqplot.sprintf(E.cursorLegendFormatString,r,x,w))}else{i(q[B]).html(i.jqplot.sprintf(E.cursorLegendFormatString,r,x,w))}}}}function d(w,D,C){var z={indices:[],data:[]};var E,u,q,A,t,o;var v;var B=w.plugins.cursor;for(var u=0;u<w.series.length;u++){E=w.series[u];o=E.renderer;if(E.show){v=B.intersectionThreshold;if(E.showMarker){v+=E.markerRenderer.size/2}for(var t=0;t<E.gridData.length;t++){p=E.gridData[t];if(B.showVerticalLine){if(Math.abs(D-p[0])<=v){z.indices.push(u);z.data.push({seriesIndex:u,pointIndex:t,gridData:p,data:E.data[t]})}}}}}return z}function m(q,t){var v=t.plugins.cursor;var r=v._tooltipElem;switch(v.tooltipLocation){case"nw":var o=q.x+t._gridPadding.left-r.outerWidth(true)-v.tooltipOffset;var u=q.y+t._gridPadding.top-v.tooltipOffset-r.outerHeight(true);break;case"n":var o=q.x+t._gridPadding.left-r.outerWidth(true)/2;var u=q.y+t._gridPadding.top-v.tooltipOffset-r.outerHeight(true);break;case"ne":var o=q.x+t._gridPadding.left+v.tooltipOffset;var u=q.y+t._gridPadding.top-v.tooltipOffset-r.outerHeight(true);break;case"e":var o=q.x+t._gridPadding.left+v.tooltipOffset;var u=q.y+t._gridPadding.top-r.outerHeight(true)/2;break;case"se":var o=q.x+t._gridPadding.left+v.tooltipOffset;var u=q.y+t._gridPadding.top+v.tooltipOffset;break;case"s":var o=q.x+t._gridPadding.left-r.outerWidth(true)/2;var u=q.y+t._gridPadding.top+v.tooltipOffset;break;case"sw":var o=q.x+t._gridPadding.left-r.outerWidth(true)-v.tooltipOffset;var u=q.y+t._gridPadding.top+v.tooltipOffset;break;case"w":var o=q.x+t._gridPadding.left-r.outerWidth(true)-v.tooltipOffset;var u=q.y+t._gridPadding.top-r.outerHeight(true)/2;break;default:var o=q.x+t._gridPadding.left+v.tooltipOffset;var u=q.y+t._gridPadding.top+v.tooltipOffset;break}v._tooltipElem.css("left",o);v._tooltipElem.css("top",u)}function l(u){var r=u._gridPadding;var v=u.plugins.cursor;var t=v._tooltipElem;switch(v.tooltipLocation){case"nw":var q=r.left+v.tooltipOffset;var o=r.top+v.tooltipOffset;t.css("left",q);t.css("top",o);break;case"n":var q=(r.left+(u._plotDimensions.width-r.right))/2-t.outerWidth(true)/2;var o=r.top+v.tooltipOffset;t.css("left",q);t.css("top",o);break;case"ne":var q=r.right+v.tooltipOffset;var o=r.top+v.tooltipOffset;t.css({right:q,top:o});break;case"e":var q=r.right+v.tooltipOffset;var o=(r.top+(u._plotDimensions.height-r.bottom))/2-t.outerHeight(true)/2;t.css({right:q,top:o});break;case"se":var q=r.right+v.tooltipOffset;var o=r.bottom+v.tooltipOffset;t.css({right:q,bottom:o});break;case"s":var q=(r.left+(u._plotDimensions.width-r.right))/2-t.outerWidth(true)/2;var o=r.bottom+v.tooltipOffset;t.css({left:q,bottom:o});break;case"sw":var q=r.left+v.tooltipOffset;var o=r.bottom+v.tooltipOffset;t.css({left:q,bottom:o});break;case"w":var q=r.left+v.tooltipOffset;var o=(r.top+(u._plotDimensions.height-r.bottom))/2-t.outerHeight(true)/2;t.css({left:q,top:o});break;default:var q=r.right-v.tooltipOffset;var o=r.bottom+v.tooltipOffset;t.css({right:q,bottom:o});break}}function j(q,o,u,t,r){q.stopPropagation();q.preventDefault();var v=r.plugins.cursor;if(v.clickReset){v.resetZoom(r,v)}return false}function c(q,o,u,t,r){q.stopPropagation();q.preventDefault();var v=r.plugins.cursor;if(v.dblClickReset){v.resetZoom(r,v)}return false}function f(w,t,o,z,u){var v=u.plugins.cursor;if(v.show){i(w.target).css("cursor",v.previousCursor);if(v.showTooltip){v._tooltipElem.hide()}if(v.zoom){v._zoom.started=false;v._zoom.zooming=false;if(!v.zoomProxy){var B=v.zoomCanvas._ctx;B.clearRect(0,0,B.canvas.width,B.canvas.height)}}if(v.showVerticalLine||v.showHorizontalLine){var B=v.cursorCanvas._ctx;B.clearRect(0,0,B.canvas.width,B.canvas.height)}if(v.showCursorLegend){var A=i(u.targetId+" td.jqplot-cursor-legend-label");for(var r=0;r<A.length;r++){var y=i(A[r]).data("seriesIndex");var q=u.series[y];var x=q.label.toString();if(u.legend.escapeHtml){i(A[r]).text(i.jqplot.sprintf(v.cursorLegendFormatString,x,undefined,undefined))}else{i(A[r]).html(i.jqplot.sprintf(v.cursorLegendFormatString,x,undefined,undefined))}}}}}function b(q,o,u,t,r){var v=r.plugins.cursor;if(v.show){v.previousCursor=q.target.style.cursor;q.target.style.cursor=v.style;if(v.showTooltip){e(o,u,r);if(v.followMouse){m(o,r)}else{l(r)}v._tooltipElem.show()}if(v.showVerticalLine||v.showHorizontalLine){g(o,r)}}}function h(r,q,v,u,t){var w=t.plugins.cursor;var o=w.zoomCanvas._ctx;if(w.show){if(w.showTooltip){e(q,v,t);if(w.followMouse){m(q,t)}}if(w.zoom&&w._zoom.started&&!w.zoomTarget){w._zoom.zooming=true;if(w.constrainZoomTo=="x"){w._zoom.end=[q.x,o.canvas.height]}else{if(w.constrainZoomTo=="y"){w._zoom.end=[o.canvas.width,q.y]}else{w._zoom.end=[q.x,q.y]}}k.call(w)}if(w.showVerticalLine||w.showHorizontalLine){g(q,t)}}}function a(w,r,q,x,t){var v=t.plugins.cursor;var u=t.axes;if(v.zoom){if(!v.zoomProxy){var y=v.zoomCanvas._ctx;y.clearRect(0,0,y.canvas.width,y.canvas.height)}if(v.constrainZoomTo=="x"){v._zoom.start=[r.x,0]}else{if(v.constrainZoomTo=="y"){v._zoom.start=[0,r.y]}else{v._zoom.start=[r.x,r.y]}}v._zoom.started=true;for(var o in q){v._zoom.axes.start[o]=q[o]}}}function n(q,o,u,t,r){var v=r.plugins.cursor;if(v.zoom&&v._zoom.zooming&&!v.zoomTarget){v.doZoom(o,u,r,v)}v._zoom.started=false;v._zoom.zooming=false}function k(){var y=this._zoom.start;var u=this._zoom.end;var r=this.zoomCanvas._ctx;var q,v,x,o;if(u[0]>y[0]){q=y[0];o=u[0]-y[0]}else{q=u[0];o=y[0]-u[0]}if(u[1]>y[1]){v=y[1];x=u[1]-y[1]}else{v=u[1];x=y[1]-u[1]}r.fillStyle="rgba(0,0,0,0.2)";r.strokeStyle="#999999";r.lineWidth=1;r.clearRect(0,0,r.canvas.width,r.canvas.height);r.fillRect(0,0,r.canvas.width,r.canvas.height);r.clearRect(q,v,o,x);r.strokeRect(q,v,o,x)}i.jqplot.CursorLegendRenderer=function(o){i.jqplot.TableLegendRenderer.call(this,o);this.formatString="%s"};i.jqplot.CursorLegendRenderer.prototype=new i.jqplot.TableLegendRenderer();i.jqplot.CursorLegendRenderer.prototype.constructor=i.jqplot.CursorLegendRenderer;i.jqplot.CursorLegendRenderer.prototype.draw=function(){if(this.show){var u=this._series;this._elem=i('<table class="jqplot-legend jqplot-cursor-legend" style="position:absolute"></table>');var x=false;for(var t=0;t<u.length;t++){s=u[t];if(s.show){var o=i.jqplot.sprintf(this.formatString,s.label.toString());if(o){var q=s.color;if(s._stack&&!s.fill){q=""}v.call(this,o,q,x,t);x=true}for(var r=0;r<i.jqplot.addLegendRowHooks.length;r++){var w=i.jqplot.addLegendRowHooks[r].call(this,s);if(w){v.call(this,w.label,w.color,x);x=true}}}}}function v(B,A,D,y){var z=(D)?this.rowSpacing:"0";var C=i('<tr class="jqplot-legend jqplot-cursor-legend"></tr>').appendTo(this._elem);C.data("seriesIndex",y);i('<td class="jqplot-legend jqplot-cursor-legend-swatch" style="padding-top:'+z+';"><div style="border:1px solid #cccccc;padding:0.2em;"><div class="jqplot-cursor-legend-swatch" style="background-color:'+A+';"></div></div></td>').appendTo(C);var E=i('<td class="jqplot-legend jqplot-cursor-legend-label" style="vertical-align:middle;padding-top:'+z+';"></td>');E.appendTo(C);E.data("seriesIndex",y);if(this.escapeHtml){E.text(B)}else{E.html(B)}}return this._elem}})(jQuery);
|
@@ -0,0 +1,313 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) 2009 Chris Leonello
|
3
|
+
* jqPlot is currently available for use in all personal or commercial projects
|
4
|
+
* under both the MIT and GPL version 2.0 licenses. This means that you can
|
5
|
+
* choose the license that best suits your project and use it accordingly.
|
6
|
+
*
|
7
|
+
* The author would appreciate an email letting him know of any substantial
|
8
|
+
* use of jqPlot. You can reach the author at: chris dot leonello at gmail
|
9
|
+
* dot com or see http://www.jqplot.com/info.php . This is, of course,
|
10
|
+
* not required.
|
11
|
+
*
|
12
|
+
* If you are feeling kind and generous, consider supporting the project by
|
13
|
+
* making a donation at: http://www.jqplot.com/donate.php .
|
14
|
+
*
|
15
|
+
* Thanks for using jqPlot!
|
16
|
+
*
|
17
|
+
*/
|
18
|
+
(function($) {
|
19
|
+
/**
|
20
|
+
* Class: $.jqplot.DateAxisRenderer
|
21
|
+
* A plugin for a jqPlot to render an axis as a series of date values.
|
22
|
+
* This renderer has no options beyond those supplied by the <Axis> class.
|
23
|
+
* It supplies it's own tick formatter, so the tickOptions.formatter option
|
24
|
+
* should not be overridden.
|
25
|
+
*
|
26
|
+
* Thanks to Ken Synder for his enhanced Date instance methods which are
|
27
|
+
* included with this code <http://kendsnyder.com/sandbox/date/>.
|
28
|
+
*
|
29
|
+
* To use this renderer, include the plugin in your source
|
30
|
+
* > <script type="text/javascript" language="javascript" src="plugins/jqplot.dateAxisRenderer.js"></script>
|
31
|
+
*
|
32
|
+
* and supply the appropriate options to your plot
|
33
|
+
*
|
34
|
+
* > {axes:{xaxis:{renderer:$.jqplot.DateAxisRenderer}}}
|
35
|
+
*
|
36
|
+
* Dates can be passed into the axis in almost any recognizable value and
|
37
|
+
* will be parsed. They will be rendered on the axis in the format
|
38
|
+
* specified by tickOptions.formatString. e.g. tickOptions.formatString = '%Y-%m-%d'.
|
39
|
+
*
|
40
|
+
* Accecptable format codes
|
41
|
+
* are:
|
42
|
+
*
|
43
|
+
* > Code Result Description
|
44
|
+
* > == Years ==
|
45
|
+
* > %Y 2008 Four-digit year
|
46
|
+
* > %y 08 Two-digit year
|
47
|
+
* > == Months ==
|
48
|
+
* > %m 09 Two-digit month
|
49
|
+
* > %#m 9 One or two-digit month
|
50
|
+
* > %B September Full month name
|
51
|
+
* > %b Sep Abbreviated month name
|
52
|
+
* > == Days ==
|
53
|
+
* > %d 05 Two-digit day of month
|
54
|
+
* > %#d 5 One or two-digit day of month
|
55
|
+
* > %e 5 One or two-digit day of month
|
56
|
+
* > %A Sunday Full name of the day of the week
|
57
|
+
* > %a Sun Abbreviated name of the day of the week
|
58
|
+
* > %w 0 Number of the day of the week (0 = Sunday, 6 = Saturday)
|
59
|
+
* > %o th The ordinal suffix string following the day of the month
|
60
|
+
* > == Hours ==
|
61
|
+
* > %H 23 Hours in 24-hour format (two digits)
|
62
|
+
* > %#H 3 Hours in 24-hour integer format (one or two digits)
|
63
|
+
* > %I 11 Hours in 12-hour format (two digits)
|
64
|
+
* > %#I 3 Hours in 12-hour integer format (one or two digits)
|
65
|
+
* > %p PM AM or PM
|
66
|
+
* > == Minutes ==
|
67
|
+
* > %M 09 Minutes (two digits)
|
68
|
+
* > %#M 9 Minutes (one or two digits)
|
69
|
+
* > == Seconds ==
|
70
|
+
* > %S 02 Seconds (two digits)
|
71
|
+
* > %#S 2 Seconds (one or two digits)
|
72
|
+
* > %s 1206567625723 Unix timestamp (Seconds past 1970-01-01 00:00:00)
|
73
|
+
* > == Milliseconds ==
|
74
|
+
* > %N 008 Milliseconds (three digits)
|
75
|
+
* > %#N 8 Milliseconds (one to three digits)
|
76
|
+
* > == Timezone ==
|
77
|
+
* > %O 360 difference in minutes between local time and GMT
|
78
|
+
* > %Z Mountain Standard Time Name of timezone as reported by browser
|
79
|
+
* > %G -06:00 Hours and minutes between GMT
|
80
|
+
* > == Shortcuts ==
|
81
|
+
* > %F 2008-03-26 %Y-%m-%d
|
82
|
+
* > %T 05:06:30 %H:%M:%S
|
83
|
+
* > %X 05:06:30 %H:%M:%S
|
84
|
+
* > %x 03/26/08 %m/%d/%y
|
85
|
+
* > %D 03/26/08 %m/%d/%y
|
86
|
+
* > %#c Wed Mar 26 15:31:00 2008 %a %b %e %H:%M:%S %Y
|
87
|
+
* > %v 3-Sep-2008 %e-%b-%Y
|
88
|
+
* > %R 15:31 %H:%M
|
89
|
+
* > %r 3:31:00 PM %I:%M:%S %p
|
90
|
+
* > == Characters ==
|
91
|
+
* > %n \n Newline
|
92
|
+
* > %t \t Tab
|
93
|
+
* > %% % Percent Symbol
|
94
|
+
*/
|
95
|
+
$.jqplot.DateAxisRenderer = function() {
|
96
|
+
$.jqplot.LinearAxisRenderer.call(this);
|
97
|
+
};
|
98
|
+
|
99
|
+
$.jqplot.DateAxisRenderer.prototype = new $.jqplot.LinearAxisRenderer();
|
100
|
+
$.jqplot.DateAxisRenderer.prototype.constructor = $.jqplot.DateAxisRenderer;
|
101
|
+
|
102
|
+
$.jqplot.DateTickFormatter = function(format, val) {
|
103
|
+
if (!format) {
|
104
|
+
format = '%Y/%m/%d';
|
105
|
+
}
|
106
|
+
return Date.create(val).strftime(format);
|
107
|
+
};
|
108
|
+
|
109
|
+
$.jqplot.DateAxisRenderer.prototype.init = function(options){
|
110
|
+
// prop: tickRenderer
|
111
|
+
// A class of a rendering engine for creating the ticks labels displayed on the plot,
|
112
|
+
// See <$.jqplot.AxisTickRenderer>.
|
113
|
+
// this.tickRenderer = $.jqplot.AxisTickRenderer;
|
114
|
+
// this.labelRenderer = $.jqplot.AxisLabelRenderer;
|
115
|
+
this.tickOptions.formatter = $.jqplot.DateTickFormatter;
|
116
|
+
this.daTickInterval = null;
|
117
|
+
this._daTickInterval = null;
|
118
|
+
$.extend(true, this, options);
|
119
|
+
var db = this._dataBounds;
|
120
|
+
// Go through all the series attached to this axis and find
|
121
|
+
// the min/max bounds for this axis.
|
122
|
+
for (var i=0; i<this._series.length; i++) {
|
123
|
+
var s = this._series[i];
|
124
|
+
var d = s.data;
|
125
|
+
var pd = s._plotData;
|
126
|
+
var sd = s._stackData;
|
127
|
+
|
128
|
+
for (var j=0; j<d.length; j++) {
|
129
|
+
if (this.name == 'xaxis' || this.name == 'x2axis') {
|
130
|
+
d[j][0] = Date.create(d[j][0]).getTime();
|
131
|
+
pd[j][0] = Date.create(d[j][0]).getTime();
|
132
|
+
sd[j][0] = Date.create(d[j][0]).getTime();
|
133
|
+
if (d[j][0] < db.min || db.min == null) {
|
134
|
+
db.min = d[j][0];
|
135
|
+
}
|
136
|
+
if (d[j][0] > db.max || db.max == null) {
|
137
|
+
db.max = d[j][0];
|
138
|
+
}
|
139
|
+
}
|
140
|
+
else {
|
141
|
+
d[j][1] = Date.create(d[j][1]).getTime();
|
142
|
+
pd[j][1] = Date.create(d[j][1]).getTime();
|
143
|
+
sd[j][1] = Date.create(d[j][1]).getTime();
|
144
|
+
if (d[j][1] < db.min || db.min == null) {
|
145
|
+
db.min = d[j][1];
|
146
|
+
}
|
147
|
+
if (d[j][1] > db.max || db.max == null) {
|
148
|
+
db.max = d[j][1];
|
149
|
+
}
|
150
|
+
}
|
151
|
+
}
|
152
|
+
}
|
153
|
+
};
|
154
|
+
|
155
|
+
// called with scope of an axis
|
156
|
+
$.jqplot.DateAxisRenderer.prototype.reset = function() {
|
157
|
+
this.min = this._min;
|
158
|
+
this.max = this._max;
|
159
|
+
this.tickInterval = this._tickInterval;
|
160
|
+
this.numberTicks = this._numberTicks;
|
161
|
+
this.daTickInterval = this._daTickInterval;
|
162
|
+
// this._ticks = this.__ticks;
|
163
|
+
};
|
164
|
+
|
165
|
+
$.jqplot.DateAxisRenderer.prototype.createTicks = function() {
|
166
|
+
// we're are operating on an axis here
|
167
|
+
var ticks = this._ticks;
|
168
|
+
var userTicks = this.ticks;
|
169
|
+
var name = this.name;
|
170
|
+
// databounds were set on axis initialization.
|
171
|
+
var db = this._dataBounds;
|
172
|
+
var dim, interval;
|
173
|
+
var min, max;
|
174
|
+
var pos1, pos2;
|
175
|
+
var tt, i;
|
176
|
+
|
177
|
+
// if we already have ticks, use them.
|
178
|
+
// ticks must be in order of increasing value.
|
179
|
+
|
180
|
+
if (userTicks.length) {
|
181
|
+
// ticks could be 1D or 2D array of [val, val, ,,,] or [[val, label], [val, label], ...] or mixed
|
182
|
+
for (i=0; i<userTicks.length; i++){
|
183
|
+
var ut = userTicks[i];
|
184
|
+
var t = new this.tickRenderer(this.tickOptions);
|
185
|
+
if (ut.constructor == Array) {
|
186
|
+
t.value = Date.create(ut[0]).getTime();
|
187
|
+
t.label = ut[1];
|
188
|
+
if (!this.showTicks) {
|
189
|
+
t.showLabel = false;
|
190
|
+
t.showMark = false;
|
191
|
+
}
|
192
|
+
else if (!this.showTickMarks) {
|
193
|
+
t.showMark = false;
|
194
|
+
}
|
195
|
+
t.setTick(t.value, this.name);
|
196
|
+
this._ticks.push(t);
|
197
|
+
}
|
198
|
+
|
199
|
+
else {
|
200
|
+
t.value = Date.create(ut).getTime();
|
201
|
+
if (!this.showTicks) {
|
202
|
+
t.showLabel = false;
|
203
|
+
t.showMark = false;
|
204
|
+
}
|
205
|
+
else if (!this.showTickMarks) {
|
206
|
+
t.showMark = false;
|
207
|
+
}
|
208
|
+
t.setTick(t.value, this.name);
|
209
|
+
this._ticks.push(t);
|
210
|
+
}
|
211
|
+
}
|
212
|
+
this.numberTicks = userTicks.length;
|
213
|
+
this.min = this._ticks[0].value;
|
214
|
+
this.max = this._ticks[this.numberTicks-1].value;
|
215
|
+
this.daTickInterval = [(this.max - this.min) / (this.numberTicks - 1)/1000, 'seconds'];
|
216
|
+
}
|
217
|
+
|
218
|
+
// we don't have any ticks yet, let's make some!
|
219
|
+
else {
|
220
|
+
if (name == 'xaxis' || name == 'x2axis') {
|
221
|
+
dim = this._plotDimensions.width;
|
222
|
+
}
|
223
|
+
else {
|
224
|
+
dim = this._plotDimensions.height;
|
225
|
+
}
|
226
|
+
|
227
|
+
// if min, max and number of ticks specified, user can't specify interval.
|
228
|
+
if (this.min != null && this.max != null && this.numberTicks != null) {
|
229
|
+
this.tickInterval = null;
|
230
|
+
}
|
231
|
+
|
232
|
+
// if user specified a tick interval, convert to usable.
|
233
|
+
if (this.tickInterval != null)
|
234
|
+
{
|
235
|
+
// if interval is a number or can be converted to one, use it.
|
236
|
+
// Assume it is in SECONDS!!!
|
237
|
+
if (Number(this.tickInterval)) {
|
238
|
+
this.daTickInterval = [Number(this.tickInterval), 'seconds'];
|
239
|
+
}
|
240
|
+
// else, parse out something we can build from.
|
241
|
+
else if (typeof this.tickInterval == "string") {
|
242
|
+
var parts = this.tickInterval.split(' ');
|
243
|
+
if (parts.length == 1) {
|
244
|
+
this.daTickInterval = [1, parts[0]];
|
245
|
+
}
|
246
|
+
else if (parts.length == 2) {
|
247
|
+
this.daTickInterval = [parts[0], parts[1]];
|
248
|
+
}
|
249
|
+
}
|
250
|
+
}
|
251
|
+
|
252
|
+
min = ((this.min != null) ? Date.create(this.min).getTime() : db.min);
|
253
|
+
max = ((this.max != null) ? Date.create(this.max).getTime() : db.max);
|
254
|
+
|
255
|
+
// if min and max are same, space them out a bit
|
256
|
+
if (min == max) {
|
257
|
+
var adj = 24*60*60*500; // 1/2 day
|
258
|
+
min -= adj;
|
259
|
+
max += adj;
|
260
|
+
}
|
261
|
+
|
262
|
+
var range = max - min;
|
263
|
+
var rmin, rmax;
|
264
|
+
|
265
|
+
rmin = (this.min != null) ? Date.create(this.min).getTime() : min - range/2*(this.padMin - 1);
|
266
|
+
rmax = (this.max != null) ? Date.create(this.max).getTime() : max + range/2*(this.padMax - 1);
|
267
|
+
this.min = rmin;
|
268
|
+
this.max = rmax;
|
269
|
+
range = this.max - this.min;
|
270
|
+
|
271
|
+
if (this.numberTicks == null){
|
272
|
+
// if tickInterval is specified by user, we will ignore computed maximum.
|
273
|
+
// max will be equal or greater to fit even # of ticks.
|
274
|
+
if (this.daTickInterval != null) {
|
275
|
+
var nc = Date.create(this.max).diff(this.min, this.daTickInterval[1], true);
|
276
|
+
this.numberTicks = Math.ceil(nc/this.daTickInterval[0]) +1;
|
277
|
+
// this.max = Date.create(this.min).add(this.numberTicks-1, this.daTickInterval[1]).getTime();
|
278
|
+
this.max = Date.create(this.min).add((this.numberTicks-1) * this.daTickInterval[0], this.daTickInterval[1]).getTime();
|
279
|
+
}
|
280
|
+
else if (dim > 200) {
|
281
|
+
this.numberTicks = parseInt(3+(dim-200)/100, 10);
|
282
|
+
}
|
283
|
+
else {
|
284
|
+
this.numberTicks = 2;
|
285
|
+
}
|
286
|
+
}
|
287
|
+
|
288
|
+
if (this.daTickInterval == null) {
|
289
|
+
this.daTickInterval = [range / (this.numberTicks-1)/1000, 'seconds'];
|
290
|
+
}
|
291
|
+
for (var i=0; i<this.numberTicks; i++){
|
292
|
+
var min = Date.create(this.min);
|
293
|
+
tt = min.add(i*this.daTickInterval[0], this.daTickInterval[1]).getTime();
|
294
|
+
var t = new this.tickRenderer(this.tickOptions);
|
295
|
+
// var t = new $.jqplot.AxisTickRenderer(this.tickOptions);
|
296
|
+
if (!this.showTicks) {
|
297
|
+
t.showLabel = false;
|
298
|
+
t.showMark = false;
|
299
|
+
}
|
300
|
+
else if (!this.showTickMarks) {
|
301
|
+
t.showMark = false;
|
302
|
+
}
|
303
|
+
t.setTick(tt, this.name);
|
304
|
+
this._ticks.push(t);
|
305
|
+
}
|
306
|
+
}
|
307
|
+
if (this._daTickInterval == null) {
|
308
|
+
this._daTickInterval = this.daTickInterval;
|
309
|
+
}
|
310
|
+
};
|
311
|
+
|
312
|
+
})(jQuery);
|
313
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) 2009 Chris Leonello
|
3
|
+
* jqPlot is currently available for use in all personal or commercial projects
|
4
|
+
* under both the MIT and GPL version 2.0 licenses. This means that you can
|
5
|
+
* choose the license that best suits your project and use it accordingly.
|
6
|
+
*
|
7
|
+
* Although not required, the author would appreciate an email letting him
|
8
|
+
* know of any substantial use of jqPlot. You can reach the author at:
|
9
|
+
* chris dot leonello at gmail dot com or see http://www.jqplot.com/info.php .
|
10
|
+
*
|
11
|
+
* If you are feeling kind and generous, consider supporting the project by
|
12
|
+
* making a donation at: http://www.jqplot.com/donate.php .
|
13
|
+
*/
|
14
|
+
(function(a){a.jqplot.DateAxisRenderer=function(){a.jqplot.LinearAxisRenderer.call(this)};a.jqplot.DateAxisRenderer.prototype=new a.jqplot.LinearAxisRenderer();a.jqplot.DateAxisRenderer.prototype.constructor=a.jqplot.DateAxisRenderer;a.jqplot.DateTickFormatter=function(b,c){if(!b){b="%Y/%m/%d"}return Date.create(c).strftime(b)};a.jqplot.DateAxisRenderer.prototype.init=function(f){this.tickOptions.formatter=a.jqplot.DateTickFormatter;this.daTickInterval=null;this._daTickInterval=null;a.extend(true,this,f);var c=this._dataBounds;for(var g=0;g<this._series.length;g++){var h=this._series[g];var l=h.data;var b=h._plotData;var k=h._stackData;for(var e=0;e<l.length;e++){if(this.name=="xaxis"||this.name=="x2axis"){l[e][0]=Date.create(l[e][0]).getTime();b[e][0]=Date.create(l[e][0]).getTime();k[e][0]=Date.create(l[e][0]).getTime();if(l[e][0]<c.min||c.min==null){c.min=l[e][0]}if(l[e][0]>c.max||c.max==null){c.max=l[e][0]}}else{l[e][1]=Date.create(l[e][1]).getTime();b[e][1]=Date.create(l[e][1]).getTime();k[e][1]=Date.create(l[e][1]).getTime();if(l[e][1]<c.min||c.min==null){c.min=l[e][1]}if(l[e][1]>c.max||c.max==null){c.max=l[e][1]}}}}};a.jqplot.DateAxisRenderer.prototype.reset=function(){this.min=this._min;this.max=this._max;this.tickInterval=this._tickInterval;this.numberTicks=this._numberTicks;this.daTickInterval=this._daTickInterval};a.jqplot.DateAxisRenderer.prototype.createTicks=function(){var v=this._ticks;var r=this.ticks;var w=this.name;var u=this._dataBounds;var o,s;var m,p;var d,c;var b,q;if(r.length){for(q=0;q<r.length;q++){var f=r[q];var h=new this.tickRenderer(this.tickOptions);if(f.constructor==Array){h.value=Date.create(f[0]).getTime();h.label=f[1];if(!this.showTicks){h.showLabel=false;h.showMark=false}else{if(!this.showTickMarks){h.showMark=false}}h.setTick(h.value,this.name);this._ticks.push(h)}else{h.value=Date.create(f).getTime();if(!this.showTicks){h.showLabel=false;h.showMark=false}else{if(!this.showTickMarks){h.showMark=false}}h.setTick(h.value,this.name);this._ticks.push(h)}}this.numberTicks=r.length;this.min=this._ticks[0].value;this.max=this._ticks[this.numberTicks-1].value;this.daTickInterval=[(this.max-this.min)/(this.numberTicks-1)/1000,"seconds"]}else{if(w=="xaxis"||w=="x2axis"){o=this._plotDimensions.width}else{o=this._plotDimensions.height}if(this.min!=null&&this.max!=null&&this.numberTicks!=null){this.tickInterval=null}if(this.tickInterval!=null){if(Number(this.tickInterval)){this.daTickInterval=[Number(this.tickInterval),"seconds"]}else{if(typeof this.tickInterval=="string"){var k=this.tickInterval.split(" ");if(k.length==1){this.daTickInterval=[1,k[0]]}else{if(k.length==2){this.daTickInterval=[k[0],k[1]]}}}}}m=((this.min!=null)?Date.create(this.min).getTime():u.min);p=((this.max!=null)?Date.create(this.max).getTime():u.max);if(m==p){var g=24*60*60*500;m-=g;p+=g}var j=p-m;var l,n;l=(this.min!=null)?Date.create(this.min).getTime():m-j/2*(this.padMin-1);n=(this.max!=null)?Date.create(this.max).getTime():p+j/2*(this.padMax-1);this.min=l;this.max=n;j=this.max-this.min;if(this.numberTicks==null){if(this.daTickInterval!=null){var e=Date.create(this.max).diff(this.min,this.daTickInterval[1],true);this.numberTicks=Math.ceil(e/this.daTickInterval[0])+1;this.max=Date.create(this.min).add((this.numberTicks-1)*this.daTickInterval[0],this.daTickInterval[1]).getTime()}else{if(o>200){this.numberTicks=parseInt(3+(o-200)/100,10)}else{this.numberTicks=2}}}if(this.daTickInterval==null){this.daTickInterval=[j/(this.numberTicks-1)/1000,"seconds"]}for(var q=0;q<this.numberTicks;q++){var m=Date.create(this.min);b=m.add(q*this.daTickInterval[0],this.daTickInterval[1]).getTime();var h=new this.tickRenderer(this.tickOptions);if(!this.showTicks){h.showLabel=false;h.showMark=false}else{if(!this.showTickMarks){h.showMark=false}}h.setTick(b,this.name);this._ticks.push(h)}}if(this._daTickInterval==null){this._daTickInterval=this.daTickInterval}}})(jQuery);
|
@@ -0,0 +1,203 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) 2009 Chris Leonello
|
3
|
+
* jqPlot is currently available for use in all personal or commercial projects
|
4
|
+
* under both the MIT and GPL version 2.0 licenses. This means that you can
|
5
|
+
* choose the license that best suits your project and use it accordingly.
|
6
|
+
*
|
7
|
+
* The author would appreciate an email letting him know of any substantial
|
8
|
+
* use of jqPlot. You can reach the author at: chris dot leonello at gmail
|
9
|
+
* dot com or see http://www.jqplot.com/info.php . This is, of course,
|
10
|
+
* not required.
|
11
|
+
*
|
12
|
+
* If you are feeling kind and generous, consider supporting the project by
|
13
|
+
* making a donation at: http://www.jqplot.com/donate.php .
|
14
|
+
*
|
15
|
+
* Thanks for using jqPlot!
|
16
|
+
*
|
17
|
+
*/
|
18
|
+
(function($) {
|
19
|
+
|
20
|
+
/**
|
21
|
+
* Class: $.jqplot.Dragable
|
22
|
+
* Plugin to make plotted points dragable by the user.
|
23
|
+
*/
|
24
|
+
$.jqplot.Dragable = function(options) {
|
25
|
+
// Group: Properties
|
26
|
+
this.markerRenderer = new $.jqplot.MarkerRenderer({shadow:false});
|
27
|
+
this.shapeRenderer = new $.jqplot.ShapeRenderer();
|
28
|
+
this.isDragging = false;
|
29
|
+
this.isOver = false;
|
30
|
+
this._ctx;
|
31
|
+
this._elem;
|
32
|
+
this._point;
|
33
|
+
this._gridData;
|
34
|
+
// prop: color
|
35
|
+
// CSS color spec for the dragged point (and adjacent line segment or bar).
|
36
|
+
this.color;
|
37
|
+
// prop: constrainTo
|
38
|
+
// Constrain dragging motion to an axis or to none.
|
39
|
+
// Allowable values are 'none', 'x', 'y'
|
40
|
+
this.constrainTo = 'none'; // 'x', 'y', or 'none';
|
41
|
+
$.extend(true, this, options);
|
42
|
+
};
|
43
|
+
|
44
|
+
function DragCanvas() {
|
45
|
+
$.jqplot.GenericCanvas.call(this);
|
46
|
+
this.isDragging = false;
|
47
|
+
this.isOver = false;
|
48
|
+
this._neighbor;
|
49
|
+
this._cursors = [];
|
50
|
+
}
|
51
|
+
|
52
|
+
DragCanvas.prototype = new $.jqplot.GenericCanvas();
|
53
|
+
DragCanvas.prototype.constructor = DragCanvas;
|
54
|
+
|
55
|
+
|
56
|
+
// called within scope of series
|
57
|
+
$.jqplot.Dragable.parseOptions = function (defaults, opts) {
|
58
|
+
var options = opts || {};
|
59
|
+
this.plugins.dragable = new $.jqplot.Dragable(options.dragable);
|
60
|
+
// since this function is called before series options are parsed,
|
61
|
+
// we can set this here and it will be overridden if needed.
|
62
|
+
this.isDragable = $.jqplot.config.enablePlugins;
|
63
|
+
};
|
64
|
+
|
65
|
+
// called within context of plot
|
66
|
+
// create a canvas which we can draw on.
|
67
|
+
// insert it before the eventCanvas, so eventCanvas will still capture events.
|
68
|
+
// add a new DragCanvas object to the plot plugins to handle drawing on this new canvas.
|
69
|
+
$.jqplot.Dragable.postPlotDraw = function() {
|
70
|
+
this.plugins.dragable = {previousCursor:'auto', isOver:false};
|
71
|
+
this.plugins.dragable.dragCanvas = new DragCanvas();
|
72
|
+
|
73
|
+
this.eventCanvas._elem.before(this.plugins.dragable.dragCanvas.createElement(this._gridPadding, 'jqplot-dragable-canvas', this._plotDimensions));
|
74
|
+
var dctx = this.plugins.dragable.dragCanvas.setContext();
|
75
|
+
};
|
76
|
+
|
77
|
+
//$.jqplot.preInitHooks.push($.jqplot.Dragable.init);
|
78
|
+
$.jqplot.preParseSeriesOptionsHooks.push($.jqplot.Dragable.parseOptions);
|
79
|
+
$.jqplot.postDrawHooks.push($.jqplot.Dragable.postPlotDraw);
|
80
|
+
$.jqplot.eventListenerHooks.push(['jqplotMouseMove', handleMove]);
|
81
|
+
$.jqplot.eventListenerHooks.push(['jqplotMouseDown', handleDown]);
|
82
|
+
$.jqplot.eventListenerHooks.push(['jqplotMouseUp', handleUp]);
|
83
|
+
|
84
|
+
|
85
|
+
function initDragPoint(plot, neighbor) {
|
86
|
+
var s = plot.series[neighbor.seriesIndex];
|
87
|
+
var drag = s.plugins.dragable;
|
88
|
+
|
89
|
+
// first, init the mark renderer for the dragged point
|
90
|
+
var smr = s.markerRenderer;
|
91
|
+
var mr = drag.markerRenderer;
|
92
|
+
mr.style = smr.style;
|
93
|
+
mr.lineWidth = smr.lineWidth + 2.5;
|
94
|
+
mr.size = smr.size + 5;
|
95
|
+
if (!drag.color) {
|
96
|
+
var rgba = $.jqplot.getColorComponents(smr.color);
|
97
|
+
var newrgb = [rgba[0], rgba[1], rgba[2]];
|
98
|
+
var alpha = (rgba[3] >= 0.6) ? rgba[3]*0.6 : rgba[3]*(2-rgba[3]);
|
99
|
+
drag.color = 'rgba('+newrgb[0]+','+newrgb[1]+','+newrgb[2]+','+alpha+')';
|
100
|
+
}
|
101
|
+
mr.color = drag.color;
|
102
|
+
mr.init();
|
103
|
+
|
104
|
+
var start = (neighbor.pointIndex > 0) ? neighbor.pointIndex - 1 : 0;
|
105
|
+
var end = neighbor.pointIndex+2;
|
106
|
+
drag._gridData = s.gridData.slice(start, end);
|
107
|
+
}
|
108
|
+
|
109
|
+
function handleMove(ev, gridpos, datapos, neighbor, plot) {
|
110
|
+
if (plot.plugins.dragable.dragCanvas.isDragging) {
|
111
|
+
var dc = plot.plugins.dragable.dragCanvas;
|
112
|
+
var dp = dc._neighbor;
|
113
|
+
var s = plot.series[dp.seriesIndex];
|
114
|
+
var drag = s.plugins.dragable;
|
115
|
+
var gd = s.gridData;
|
116
|
+
|
117
|
+
// compute the new grid position with any constraints.
|
118
|
+
var x = (drag.constrainTo == 'y') ? dp.gridData[0] : gridpos.x;
|
119
|
+
var y = (drag.constrainTo == 'x') ? dp.gridData[1] : gridpos.y;
|
120
|
+
|
121
|
+
// compute data values for any listeners.
|
122
|
+
var xu = s._xaxis.series_p2u(x);
|
123
|
+
var yu = s._yaxis.series_p2u(y);
|
124
|
+
|
125
|
+
// clear the canvas then redraw effect at new position.
|
126
|
+
var ctx = dc._ctx;
|
127
|
+
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
|
128
|
+
|
129
|
+
// adjust our gridData for the new mouse position
|
130
|
+
if (dp.pointIndex > 0) {
|
131
|
+
drag._gridData[1] = [x, y];
|
132
|
+
}
|
133
|
+
else {
|
134
|
+
drag._gridData[0] = [x, y];
|
135
|
+
}
|
136
|
+
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}});
|
137
|
+
plot.target.trigger('jqplotSeriesPointChange', [dp.seriesIndex, dp.pointIndex, [xu,yu], [x,y]]);
|
138
|
+
}
|
139
|
+
else if (neighbor != null) {
|
140
|
+
var series = plot.series[neighbor.seriesIndex];
|
141
|
+
if (series.isDragable) {
|
142
|
+
var dc = plot.plugins.dragable.dragCanvas;
|
143
|
+
if (!dc.isOver) {
|
144
|
+
dc._cursors.push(ev.target.style.cursor);
|
145
|
+
ev.target.style.cursor = "pointer";
|
146
|
+
}
|
147
|
+
dc.isOver = true;
|
148
|
+
}
|
149
|
+
}
|
150
|
+
else if (neighbor == null) {
|
151
|
+
var dc = plot.plugins.dragable.dragCanvas;
|
152
|
+
if (dc.isOver) {
|
153
|
+
ev.target.style.cursor = dc._cursors.pop();
|
154
|
+
dc.isOver = false;
|
155
|
+
}
|
156
|
+
}
|
157
|
+
}
|
158
|
+
|
159
|
+
function handleDown(ev, gridpos, datapos, neighbor, plot) {
|
160
|
+
var dc = plot.plugins.dragable.dragCanvas;
|
161
|
+
dc._cursors.push(ev.target.style.cursor);
|
162
|
+
if (neighbor != null) {
|
163
|
+
var s = plot.series[neighbor.seriesIndex];
|
164
|
+
var drag = s.plugins.dragable;
|
165
|
+
if (s.isDragable && !dc.isDragging) {
|
166
|
+
dc._neighbor = neighbor;
|
167
|
+
dc.isDragging = true;
|
168
|
+
initDragPoint(plot, neighbor);
|
169
|
+
drag.markerRenderer.draw(s.gridData[neighbor.pointIndex][0], s.gridData[neighbor.pointIndex][1], dc._ctx);
|
170
|
+
ev.target.style.cursor = "move";
|
171
|
+
}
|
172
|
+
}
|
173
|
+
// Just in case of a hickup, we'll clear the drag canvas and reset.
|
174
|
+
else {
|
175
|
+
var ctx = dc._ctx;
|
176
|
+
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
|
177
|
+
dc.isDragging = false;
|
178
|
+
}
|
179
|
+
}
|
180
|
+
|
181
|
+
function handleUp(ev, gridpos, datapos, neighbor, plot) {
|
182
|
+
if (plot.plugins.dragable.dragCanvas.isDragging) {
|
183
|
+
var dc = plot.plugins.dragable.dragCanvas;
|
184
|
+
// clear the canvas
|
185
|
+
var ctx = dc._ctx;
|
186
|
+
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
|
187
|
+
dc.isDragging = false;
|
188
|
+
// redraw the series canvas at the new point.
|
189
|
+
var dp = dc._neighbor;
|
190
|
+
var s = plot.series[dp.seriesIndex];
|
191
|
+
var drag = s.plugins.dragable;
|
192
|
+
// compute the new grid position with any constraints.
|
193
|
+
var x = (drag.constrainTo == 'y') ? dp.data[0] : datapos[s.xaxis];
|
194
|
+
var y = (drag.constrainTo == 'x') ? dp.data[1] : datapos[s.yaxis];
|
195
|
+
// var x = datapos[s.xaxis];
|
196
|
+
// var y = datapos[s.yaxis];
|
197
|
+
s.data[dp.pointIndex] = [x,y];
|
198
|
+
plot.drawSeries({preventJqPlotSeriesDrawTrigger:true}, dp.seriesIndex);
|
199
|
+
dc._neighbor = null;
|
200
|
+
ev.target.style.cursor = dc._cursors.pop();
|
201
|
+
}
|
202
|
+
}
|
203
|
+
})(jQuery);
|
@@ -0,0 +1,14 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) 2009 Chris Leonello
|
3
|
+
* jqPlot is currently available for use in all personal or commercial projects
|
4
|
+
* under both the MIT and GPL version 2.0 licenses. This means that you can
|
5
|
+
* choose the license that best suits your project and use it accordingly.
|
6
|
+
*
|
7
|
+
* Although not required, the author would appreciate an email letting him
|
8
|
+
* know of any substantial use of jqPlot. You can reach the author at:
|
9
|
+
* chris dot leonello at gmail dot com or see http://www.jqplot.com/info.php .
|
10
|
+
*
|
11
|
+
* If you are feeling kind and generous, consider supporting the project by
|
12
|
+
* making a donation at: http://www.jqplot.com/donate.php .
|
13
|
+
*/
|
14
|
+
(function(d){d.jqplot.Dragable=function(g){this.markerRenderer=new d.jqplot.MarkerRenderer({shadow:false});this.shapeRenderer=new d.jqplot.ShapeRenderer();this.isDragging=false;this.isOver=false;this._ctx;this._elem;this._point;this._gridData;this.color;this.constrainTo="none";d.extend(true,this,g)};function b(){d.jqplot.GenericCanvas.call(this);this.isDragging=false;this.isOver=false;this._neighbor;this._cursors=[]}b.prototype=new d.jqplot.GenericCanvas();b.prototype.constructor=b;d.jqplot.Dragable.parseOptions=function(i,h){var g=h||{};this.plugins.dragable=new d.jqplot.Dragable(g.dragable);this.isDragable=d.jqplot.config.enablePlugins};d.jqplot.Dragable.postPlotDraw=function(){this.plugins.dragable={previousCursor:"auto",isOver:false};this.plugins.dragable.dragCanvas=new b();this.eventCanvas._elem.before(this.plugins.dragable.dragCanvas.createElement(this._gridPadding,"jqplot-dragable-canvas",this._plotDimensions));var g=this.plugins.dragable.dragCanvas.setContext()};d.jqplot.preParseSeriesOptionsHooks.push(d.jqplot.Dragable.parseOptions);d.jqplot.postDrawHooks.push(d.jqplot.Dragable.postPlotDraw);d.jqplot.eventListenerHooks.push(["jqplotMouseMove",e]);d.jqplot.eventListenerHooks.push(["jqplotMouseDown",c]);d.jqplot.eventListenerHooks.push(["jqplotMouseUp",a]);function f(n,p){var q=n.series[p.seriesIndex];var m=q.plugins.dragable;var h=q.markerRenderer;var i=m.markerRenderer;i.style=h.style;i.lineWidth=h.lineWidth+2.5;i.size=h.size+5;if(!m.color){var l=d.jqplot.getColorComponents(h.color);var o=[l[0],l[1],l[2]];var k=(l[3]>=0.6)?l[3]*0.6:l[3]*(2-l[3]);m.color="rgba("+o[0]+","+o[1]+","+o[2]+","+k+")"}i.color=m.color;i.init();var g=(p.pointIndex>0)?p.pointIndex-1:0;var j=p.pointIndex+2;m._gridData=q.gridData.slice(g,j)}function e(o,l,h,t,m){if(m.plugins.dragable.dragCanvas.isDragging){var u=m.plugins.dragable.dragCanvas;var i=u._neighbor;var w=m.series[i.seriesIndex];var k=w.plugins.dragable;var r=w.gridData;var p=(k.constrainTo=="y")?i.gridData[0]:l.x;var n=(k.constrainTo=="x")?i.gridData[1]:l.y;var g=w._xaxis.series_p2u(p);var q=w._yaxis.series_p2u(n);var v=u._ctx;v.clearRect(0,0,v.canvas.width,v.canvas.height);if(i.pointIndex>0){k._gridData[1]=[p,n]}else{k._gridData[0]=[p,n]}m.series[i.seriesIndex].draw(u._ctx,{gridData:k._gridData,shadow:false,preventJqPlotSeriesDrawTrigger:true,color:k.color,markerOptions:{color:k.color,shadow:false},trendline:{show:false}});m.target.trigger("jqplotSeriesPointChange",[i.seriesIndex,i.pointIndex,[g,q],[p,n]])}else{if(t!=null){var j=m.series[t.seriesIndex];if(j.isDragable){var u=m.plugins.dragable.dragCanvas;if(!u.isOver){u._cursors.push(o.target.style.cursor);o.target.style.cursor="pointer"}u.isOver=true}}else{if(t==null){var u=m.plugins.dragable.dragCanvas;if(u.isOver){o.target.style.cursor=u._cursors.pop();u.isOver=false}}}}}function c(k,i,g,l,j){var m=j.plugins.dragable.dragCanvas;m._cursors.push(k.target.style.cursor);if(l!=null){var o=j.series[l.seriesIndex];var h=o.plugins.dragable;if(o.isDragable&&!m.isDragging){m._neighbor=l;m.isDragging=true;f(j,l);h.markerRenderer.draw(o.gridData[l.pointIndex][0],o.gridData[l.pointIndex][1],m._ctx);k.target.style.cursor="move"}}else{var n=m._ctx;n.clearRect(0,0,n.canvas.width,n.canvas.height);m.isDragging=false}}function a(m,j,g,o,k){if(k.plugins.dragable.dragCanvas.isDragging){var p=k.plugins.dragable.dragCanvas;var q=p._ctx;q.clearRect(0,0,q.canvas.width,q.canvas.height);p.isDragging=false;var h=p._neighbor;var r=k.series[h.seriesIndex];var i=r.plugins.dragable;var n=(i.constrainTo=="y")?h.data[0]:g[r.xaxis];var l=(i.constrainTo=="x")?h.data[1]:g[r.yaxis];r.data[h.pointIndex]=[n,l];k.drawSeries({preventJqPlotSeriesDrawTrigger:true},h.seriesIndex);p._neighbor=null;m.target.style.cursor=p._cursors.pop()}}})(jQuery);
|