columbus3 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (199) hide show
  1. checksums.yaml +4 -4
  2. data/README.textile +62 -0
  3. data/bower_components/flot/.bower.json +19 -0
  4. data/bower_components/flot/.gitignore +3 -0
  5. data/bower_components/flot/.travis.yml +3 -0
  6. data/bower_components/flot/API.md +1498 -0
  7. data/bower_components/flot/CONTRIBUTING.md +98 -0
  8. data/bower_components/flot/FAQ.md +75 -0
  9. data/bower_components/flot/LICENSE.txt +22 -0
  10. data/bower_components/flot/Makefile +12 -0
  11. data/bower_components/flot/NEWS.md +1026 -0
  12. data/bower_components/flot/PLUGINS.md +143 -0
  13. data/bower_components/flot/README.md +110 -0
  14. data/bower_components/flot/component.json +8 -0
  15. data/bower_components/flot/examples/ajax/data-eu-gdp-growth-1.json +4 -0
  16. data/bower_components/flot/examples/ajax/data-eu-gdp-growth-2.json +4 -0
  17. data/bower_components/flot/examples/ajax/data-eu-gdp-growth-3.json +4 -0
  18. data/bower_components/flot/examples/ajax/data-eu-gdp-growth-4.json +4 -0
  19. data/bower_components/flot/examples/ajax/data-eu-gdp-growth-5.json +4 -0
  20. data/bower_components/flot/examples/ajax/data-eu-gdp-growth.json +4 -0
  21. data/bower_components/flot/examples/ajax/data-japan-gdp-growth.json +4 -0
  22. data/bower_components/flot/examples/ajax/data-usa-gdp-growth.json +4 -0
  23. data/bower_components/flot/examples/ajax/index.html +173 -0
  24. data/bower_components/flot/examples/annotating/index.html +87 -0
  25. data/bower_components/flot/examples/axes-interacting/index.html +97 -0
  26. data/bower_components/flot/examples/axes-multiple/index.html +77 -0
  27. data/bower_components/flot/examples/axes-time-zones/date.js +893 -0
  28. data/bower_components/flot/examples/axes-time-zones/index.html +114 -0
  29. data/bower_components/flot/examples/axes-time-zones/tz/africa +1181 -0
  30. data/bower_components/flot/examples/axes-time-zones/tz/antarctica +413 -0
  31. data/bower_components/flot/examples/axes-time-zones/tz/asia +2717 -0
  32. data/bower_components/flot/examples/axes-time-zones/tz/australasia +1719 -0
  33. data/bower_components/flot/examples/axes-time-zones/tz/backward +117 -0
  34. data/bower_components/flot/examples/axes-time-zones/tz/etcetera +81 -0
  35. data/bower_components/flot/examples/axes-time-zones/tz/europe +2856 -0
  36. data/bower_components/flot/examples/axes-time-zones/tz/factory +10 -0
  37. data/bower_components/flot/examples/axes-time-zones/tz/iso3166.tab +276 -0
  38. data/bower_components/flot/examples/axes-time-zones/tz/leapseconds +100 -0
  39. data/bower_components/flot/examples/axes-time-zones/tz/northamerica +3235 -0
  40. data/bower_components/flot/examples/axes-time-zones/tz/pacificnew +28 -0
  41. data/bower_components/flot/examples/axes-time-zones/tz/solar87 +390 -0
  42. data/bower_components/flot/examples/axes-time-zones/tz/solar88 +390 -0
  43. data/bower_components/flot/examples/axes-time-zones/tz/solar89 +395 -0
  44. data/bower_components/flot/examples/axes-time-zones/tz/southamerica +1711 -0
  45. data/bower_components/flot/examples/axes-time-zones/tz/systemv +38 -0
  46. data/bower_components/flot/examples/axes-time-zones/tz/yearistype.sh +38 -0
  47. data/bower_components/flot/examples/axes-time-zones/tz/zone.tab +441 -0
  48. data/bower_components/flot/examples/axes-time/index.html +137 -0
  49. data/bower_components/flot/examples/background.png +0 -0
  50. data/bower_components/flot/examples/basic-options/index.html +91 -0
  51. data/bower_components/flot/examples/basic-usage/index.html +57 -0
  52. data/bower_components/flot/examples/canvas/index.html +75 -0
  53. data/bower_components/flot/examples/categories/index.html +64 -0
  54. data/bower_components/flot/examples/examples.css +97 -0
  55. data/bower_components/flot/examples/image/hs-2004-27-a-large-web.jpg +0 -0
  56. data/bower_components/flot/examples/image/index.html +69 -0
  57. data/bower_components/flot/examples/index.html +80 -0
  58. data/bower_components/flot/examples/interacting/index.html +118 -0
  59. data/bower_components/flot/examples/navigate/arrow-down.gif +0 -0
  60. data/bower_components/flot/examples/navigate/arrow-left.gif +0 -0
  61. data/bower_components/flot/examples/navigate/arrow-right.gif +0 -0
  62. data/bower_components/flot/examples/navigate/arrow-up.gif +0 -0
  63. data/bower_components/flot/examples/navigate/index.html +153 -0
  64. data/bower_components/flot/examples/percentiles/index.html +79 -0
  65. data/bower_components/flot/examples/realtime/index.html +122 -0
  66. data/bower_components/flot/examples/resize/index.html +76 -0
  67. data/bower_components/flot/examples/selection/index.html +152 -0
  68. data/bower_components/flot/examples/series-errorbars/index.html +150 -0
  69. data/bower_components/flot/examples/series-pie/index.html +818 -0
  70. data/bower_components/flot/examples/series-toggle/index.html +121 -0
  71. data/bower_components/flot/examples/series-types/index.html +90 -0
  72. data/bower_components/flot/examples/shared/jquery-ui/jquery-ui.min.css +6 -0
  73. data/bower_components/flot/examples/stacking/index.html +107 -0
  74. data/bower_components/flot/examples/symbols/index.html +76 -0
  75. data/bower_components/flot/examples/threshold/index.html +76 -0
  76. data/bower_components/flot/examples/tracking/index.html +135 -0
  77. data/bower_components/flot/examples/visitors/index.html +147 -0
  78. data/bower_components/flot/examples/zooming/index.html +144 -0
  79. data/bower_components/flot/excanvas.js +1428 -0
  80. data/bower_components/flot/excanvas.min.js +1 -0
  81. data/bower_components/flot/flot.jquery.json +27 -0
  82. data/bower_components/flot/jquery.colorhelpers.js +180 -0
  83. data/bower_components/flot/jquery.flot.canvas.js +345 -0
  84. data/bower_components/flot/jquery.flot.categories.js +190 -0
  85. data/bower_components/flot/jquery.flot.crosshair.js +176 -0
  86. data/bower_components/flot/jquery.flot.errorbars.js +353 -0
  87. data/bower_components/flot/jquery.flot.fillbetween.js +226 -0
  88. data/bower_components/flot/jquery.flot.image.js +241 -0
  89. data/bower_components/flot/jquery.flot.js +3168 -0
  90. data/bower_components/flot/jquery.flot.navigate.js +346 -0
  91. data/bower_components/flot/jquery.flot.pie.js +820 -0
  92. data/bower_components/flot/jquery.flot.resize.js +59 -0
  93. data/bower_components/flot/jquery.flot.selection.js +360 -0
  94. data/bower_components/flot/jquery.flot.stack.js +188 -0
  95. data/bower_components/flot/jquery.flot.symbol.js +71 -0
  96. data/bower_components/flot/jquery.flot.threshold.js +142 -0
  97. data/bower_components/flot/jquery.flot.time.js +432 -0
  98. data/bower_components/flot/jquery.js +9472 -0
  99. data/bower_components/flot/package.json +11 -0
  100. data/bower_components/jquery/.bower.json +38 -0
  101. data/bower_components/jquery/MIT-LICENSE.txt +21 -0
  102. data/bower_components/jquery/bower.json +28 -0
  103. data/bower_components/jquery/dist/jquery.js +9210 -0
  104. data/bower_components/jquery/dist/jquery.min.js +5 -0
  105. data/bower_components/jquery/dist/jquery.min.map +1 -0
  106. data/bower_components/jquery/src/ajax.js +786 -0
  107. data/bower_components/jquery/src/ajax/jsonp.js +89 -0
  108. data/bower_components/jquery/src/ajax/load.js +75 -0
  109. data/bower_components/jquery/src/ajax/parseJSON.js +13 -0
  110. data/bower_components/jquery/src/ajax/parseXML.js +28 -0
  111. data/bower_components/jquery/src/ajax/script.js +64 -0
  112. data/bower_components/jquery/src/ajax/var/nonce.js +5 -0
  113. data/bower_components/jquery/src/ajax/var/rquery.js +3 -0
  114. data/bower_components/jquery/src/ajax/xhr.js +136 -0
  115. data/bower_components/jquery/src/attributes.js +11 -0
  116. data/bower_components/jquery/src/attributes/attr.js +141 -0
  117. data/bower_components/jquery/src/attributes/classes.js +158 -0
  118. data/bower_components/jquery/src/attributes/prop.js +94 -0
  119. data/bower_components/jquery/src/attributes/support.js +35 -0
  120. data/bower_components/jquery/src/attributes/val.js +161 -0
  121. data/bower_components/jquery/src/callbacks.js +205 -0
  122. data/bower_components/jquery/src/core.js +502 -0
  123. data/bower_components/jquery/src/core/access.js +60 -0
  124. data/bower_components/jquery/src/core/init.js +123 -0
  125. data/bower_components/jquery/src/core/parseHTML.js +39 -0
  126. data/bower_components/jquery/src/core/ready.js +97 -0
  127. data/bower_components/jquery/src/core/var/rsingleTag.js +4 -0
  128. data/bower_components/jquery/src/css.js +450 -0
  129. data/bower_components/jquery/src/css/addGetHookIf.js +22 -0
  130. data/bower_components/jquery/src/css/curCSS.js +57 -0
  131. data/bower_components/jquery/src/css/defaultDisplay.js +70 -0
  132. data/bower_components/jquery/src/css/hiddenVisibleSelectors.js +15 -0
  133. data/bower_components/jquery/src/css/support.js +96 -0
  134. data/bower_components/jquery/src/css/swap.js +28 -0
  135. data/bower_components/jquery/src/css/var/cssExpand.js +3 -0
  136. data/bower_components/jquery/src/css/var/getStyles.js +12 -0
  137. data/bower_components/jquery/src/css/var/isHidden.js +13 -0
  138. data/bower_components/jquery/src/css/var/rmargin.js +3 -0
  139. data/bower_components/jquery/src/css/var/rnumnonpx.js +5 -0
  140. data/bower_components/jquery/src/data.js +178 -0
  141. data/bower_components/jquery/src/data/Data.js +181 -0
  142. data/bower_components/jquery/src/data/accepts.js +20 -0
  143. data/bower_components/jquery/src/data/var/data_priv.js +5 -0
  144. data/bower_components/jquery/src/data/var/data_user.js +5 -0
  145. data/bower_components/jquery/src/deferred.js +149 -0
  146. data/bower_components/jquery/src/deprecated.js +13 -0
  147. data/bower_components/jquery/src/dimensions.js +50 -0
  148. data/bower_components/jquery/src/effects.js +648 -0
  149. data/bower_components/jquery/src/effects/Tween.js +114 -0
  150. data/bower_components/jquery/src/effects/animatedSelector.js +13 -0
  151. data/bower_components/jquery/src/event.js +868 -0
  152. data/bower_components/jquery/src/event/ajax.js +13 -0
  153. data/bower_components/jquery/src/event/alias.js +39 -0
  154. data/bower_components/jquery/src/event/support.js +9 -0
  155. data/bower_components/jquery/src/exports/amd.js +24 -0
  156. data/bower_components/jquery/src/exports/global.js +32 -0
  157. data/bower_components/jquery/src/intro.js +44 -0
  158. data/bower_components/jquery/src/jquery.js +37 -0
  159. data/bower_components/jquery/src/manipulation.js +580 -0
  160. data/bower_components/jquery/src/manipulation/_evalUrl.js +18 -0
  161. data/bower_components/jquery/src/manipulation/support.js +32 -0
  162. data/bower_components/jquery/src/manipulation/var/rcheckableType.js +3 -0
  163. data/bower_components/jquery/src/offset.js +207 -0
  164. data/bower_components/jquery/src/outro.js +1 -0
  165. data/bower_components/jquery/src/queue.js +142 -0
  166. data/bower_components/jquery/src/queue/delay.js +22 -0
  167. data/bower_components/jquery/src/selector-native.js +172 -0
  168. data/bower_components/jquery/src/selector-sizzle.js +14 -0
  169. data/bower_components/jquery/src/selector.js +1 -0
  170. data/bower_components/jquery/src/serialize.js +111 -0
  171. data/bower_components/jquery/src/sizzle/dist/sizzle.js +2067 -0
  172. data/bower_components/jquery/src/sizzle/dist/sizzle.min.js +3 -0
  173. data/bower_components/jquery/src/sizzle/dist/sizzle.min.map +1 -0
  174. data/bower_components/jquery/src/traversing.js +199 -0
  175. data/bower_components/jquery/src/traversing/findFilter.js +100 -0
  176. data/bower_components/jquery/src/traversing/var/rneedsContext.js +6 -0
  177. data/bower_components/jquery/src/var/arr.js +3 -0
  178. data/bower_components/jquery/src/var/class2type.js +4 -0
  179. data/bower_components/jquery/src/var/concat.js +5 -0
  180. data/bower_components/jquery/src/var/hasOwn.js +5 -0
  181. data/bower_components/jquery/src/var/indexOf.js +5 -0
  182. data/bower_components/jquery/src/var/pnum.js +3 -0
  183. data/bower_components/jquery/src/var/push.js +5 -0
  184. data/bower_components/jquery/src/var/rnotwhite.js +3 -0
  185. data/bower_components/jquery/src/var/slice.js +5 -0
  186. data/bower_components/jquery/src/var/strundefined.js +3 -0
  187. data/bower_components/jquery/src/var/support.js +4 -0
  188. data/bower_components/jquery/src/var/toString.js +5 -0
  189. data/bower_components/jquery/src/wrap.js +79 -0
  190. data/columbus3.gemspec +1 -1
  191. data/exe/columbus3 +72 -7
  192. data/lib/columbus3.rb +2 -1
  193. data/lib/columbus3/metadata/sidecar.rb +10 -1
  194. data/lib/columbus3/renderer/flot_renderer.rb +66 -0
  195. data/lib/columbus3/renderer/{renderer.rb → leaflet_renderer.rb} +0 -0
  196. data/lib/columbus3/version.rb +1 -1
  197. data/lib/html/flot.html.erb +106 -0
  198. metadata +194 -5
  199. data/README.md +0 -41
@@ -0,0 +1,346 @@
1
+ /* Flot plugin for adding the ability to pan and zoom the plot.
2
+
3
+ Copyright (c) 2007-2014 IOLA and Ole Laursen.
4
+ Licensed under the MIT license.
5
+
6
+ The default behaviour is double click and scrollwheel up/down to zoom in, drag
7
+ to pan. The plugin defines plot.zoom({ center }), plot.zoomOut() and
8
+ plot.pan( offset ) so you easily can add custom controls. It also fires
9
+ "plotpan" and "plotzoom" events, useful for synchronizing plots.
10
+
11
+ The plugin supports these options:
12
+
13
+ zoom: {
14
+ interactive: false
15
+ trigger: "dblclick" // or "click" for single click
16
+ amount: 1.5 // 2 = 200% (zoom in), 0.5 = 50% (zoom out)
17
+ }
18
+
19
+ pan: {
20
+ interactive: false
21
+ cursor: "move" // CSS mouse cursor value used when dragging, e.g. "pointer"
22
+ frameRate: 20
23
+ }
24
+
25
+ xaxis, yaxis, x2axis, y2axis: {
26
+ zoomRange: null // or [ number, number ] (min range, max range) or false
27
+ panRange: null // or [ number, number ] (min, max) or false
28
+ }
29
+
30
+ "interactive" enables the built-in drag/click behaviour. If you enable
31
+ interactive for pan, then you'll have a basic plot that supports moving
32
+ around; the same for zoom.
33
+
34
+ "amount" specifies the default amount to zoom in (so 1.5 = 150%) relative to
35
+ the current viewport.
36
+
37
+ "cursor" is a standard CSS mouse cursor string used for visual feedback to the
38
+ user when dragging.
39
+
40
+ "frameRate" specifies the maximum number of times per second the plot will
41
+ update itself while the user is panning around on it (set to null to disable
42
+ intermediate pans, the plot will then not update until the mouse button is
43
+ released).
44
+
45
+ "zoomRange" is the interval in which zooming can happen, e.g. with zoomRange:
46
+ [1, 100] the zoom will never scale the axis so that the difference between min
47
+ and max is smaller than 1 or larger than 100. You can set either end to null
48
+ to ignore, e.g. [1, null]. If you set zoomRange to false, zooming on that axis
49
+ will be disabled.
50
+
51
+ "panRange" confines the panning to stay within a range, e.g. with panRange:
52
+ [-10, 20] panning stops at -10 in one end and at 20 in the other. Either can
53
+ be null, e.g. [-10, null]. If you set panRange to false, panning on that axis
54
+ will be disabled.
55
+
56
+ Example API usage:
57
+
58
+ plot = $.plot(...);
59
+
60
+ // zoom default amount in on the pixel ( 10, 20 )
61
+ plot.zoom({ center: { left: 10, top: 20 } });
62
+
63
+ // zoom out again
64
+ plot.zoomOut({ center: { left: 10, top: 20 } });
65
+
66
+ // zoom 200% in on the pixel (10, 20)
67
+ plot.zoom({ amount: 2, center: { left: 10, top: 20 } });
68
+
69
+ // pan 100 pixels to the left and 20 down
70
+ plot.pan({ left: -100, top: 20 })
71
+
72
+ Here, "center" specifies where the center of the zooming should happen. Note
73
+ that this is defined in pixel space, not the space of the data points (you can
74
+ use the p2c helpers on the axes in Flot to help you convert between these).
75
+
76
+ "amount" is the amount to zoom the viewport relative to the current range, so
77
+ 1 is 100% (i.e. no change), 1.5 is 150% (zoom in), 0.7 is 70% (zoom out). You
78
+ can set the default in the options.
79
+
80
+ */
81
+
82
+ // First two dependencies, jquery.event.drag.js and
83
+ // jquery.mousewheel.js, we put them inline here to save people the
84
+ // effort of downloading them.
85
+
86
+ /*
87
+ jquery.event.drag.js ~ v1.5 ~ Copyright (c) 2008, Three Dub Media (http://threedubmedia.com)
88
+ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-LICENSE.txt
89
+ */
90
+ (function(a){function e(h){var k,j=this,l=h.data||{};if(l.elem)j=h.dragTarget=l.elem,h.dragProxy=d.proxy||j,h.cursorOffsetX=l.pageX-l.left,h.cursorOffsetY=l.pageY-l.top,h.offsetX=h.pageX-h.cursorOffsetX,h.offsetY=h.pageY-h.cursorOffsetY;else if(d.dragging||l.which>0&&h.which!=l.which||a(h.target).is(l.not))return;switch(h.type){case"mousedown":return a.extend(l,a(j).offset(),{elem:j,target:h.target,pageX:h.pageX,pageY:h.pageY}),b.add(document,"mousemove mouseup",e,l),i(j,!1),d.dragging=null,!1;case!d.dragging&&"mousemove":if(g(h.pageX-l.pageX)+g(h.pageY-l.pageY)<l.distance)break;h.target=l.target,k=f(h,"dragstart",j),k!==!1&&(d.dragging=j,d.proxy=h.dragProxy=a(k||j)[0]);case"mousemove":if(d.dragging){if(k=f(h,"drag",j),c.drop&&(c.drop.allowed=k!==!1,c.drop.handler(h)),k!==!1)break;h.type="mouseup"}case"mouseup":b.remove(document,"mousemove mouseup",e),d.dragging&&(c.drop&&c.drop.handler(h),f(h,"dragend",j)),i(j,!0),d.dragging=d.proxy=l.elem=!1}return!0}function f(b,c,d){b.type=c;var e=a.event.dispatch.call(d,b);return e===!1?!1:e||b.result}function g(a){return Math.pow(a,2)}function h(){return d.dragging===!1}function i(a,b){a&&(a.unselectable=b?"off":"on",a.onselectstart=function(){return b},a.style&&(a.style.MozUserSelect=b?"":"none"))}a.fn.drag=function(a,b,c){return b&&this.bind("dragstart",a),c&&this.bind("dragend",c),a?this.bind("drag",b?b:a):this.trigger("drag")};var b=a.event,c=b.special,d=c.drag={not:":input",distance:0,which:1,dragging:!1,setup:function(c){c=a.extend({distance:d.distance,which:d.which,not:d.not},c||{}),c.distance=g(c.distance),b.add(this,"mousedown",e,c),this.attachEvent&&this.attachEvent("ondragstart",h)},teardown:function(){b.remove(this,"mousedown",e),this===d.dragging&&(d.dragging=d.proxy=!1),i(this,!0),this.detachEvent&&this.detachEvent("ondragstart",h)}};c.dragstart=c.dragend={setup:function(){},teardown:function(){}}})(jQuery);
91
+
92
+ /* jquery.mousewheel.min.js
93
+ * Copyright (c) 2011 Brandon Aaron (http://brandonaaron.net)
94
+ * Licensed under the MIT License (LICENSE.txt).
95
+ * Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers.
96
+ * Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix.
97
+ * Thanks to: Seamus Leahy for adding deltaX and deltaY
98
+ *
99
+ * Version: 3.0.6
100
+ *
101
+ * Requires: 1.2.2+
102
+ */
103
+ (function(d){function e(a){var b=a||window.event,c=[].slice.call(arguments,1),f=0,e=0,g=0,a=d.event.fix(b);a.type="mousewheel";b.wheelDelta&&(f=b.wheelDelta/120);b.detail&&(f=-b.detail/3);g=f;void 0!==b.axis&&b.axis===b.HORIZONTAL_AXIS&&(g=0,e=-1*f);void 0!==b.wheelDeltaY&&(g=b.wheelDeltaY/120);void 0!==b.wheelDeltaX&&(e=-1*b.wheelDeltaX/120);c.unshift(a,f,e,g);return(d.event.dispatch||d.event.handle).apply(this,c)}var c=["DOMMouseScroll","mousewheel"];if(d.event.fixHooks)for(var h=c.length;h;)d.event.fixHooks[c[--h]]=d.event.mouseHooks;d.event.special.mousewheel={setup:function(){if(this.addEventListener)for(var a=c.length;a;)this.addEventListener(c[--a],e,!1);else this.onmousewheel=e},teardown:function(){if(this.removeEventListener)for(var a=c.length;a;)this.removeEventListener(c[--a],e,!1);else this.onmousewheel=null}};d.fn.extend({mousewheel:function(a){return a?this.bind("mousewheel",a):this.trigger("mousewheel")},unmousewheel:function(a){return this.unbind("mousewheel",a)}})})(jQuery);
104
+
105
+
106
+
107
+
108
+ (function ($) {
109
+ var options = {
110
+ xaxis: {
111
+ zoomRange: null, // or [number, number] (min range, max range)
112
+ panRange: null // or [number, number] (min, max)
113
+ },
114
+ zoom: {
115
+ interactive: false,
116
+ trigger: "dblclick", // or "click" for single click
117
+ amount: 1.5 // how much to zoom relative to current position, 2 = 200% (zoom in), 0.5 = 50% (zoom out)
118
+ },
119
+ pan: {
120
+ interactive: false,
121
+ cursor: "move",
122
+ frameRate: 20
123
+ }
124
+ };
125
+
126
+ function init(plot) {
127
+ function onZoomClick(e, zoomOut) {
128
+ var c = plot.offset();
129
+ c.left = e.pageX - c.left;
130
+ c.top = e.pageY - c.top;
131
+ if (zoomOut)
132
+ plot.zoomOut({ center: c });
133
+ else
134
+ plot.zoom({ center: c });
135
+ }
136
+
137
+ function onMouseWheel(e, delta) {
138
+ e.preventDefault();
139
+ onZoomClick(e, delta < 0);
140
+ return false;
141
+ }
142
+
143
+ var prevCursor = 'default', prevPageX = 0, prevPageY = 0,
144
+ panTimeout = null;
145
+
146
+ function onDragStart(e) {
147
+ if (e.which != 1) // only accept left-click
148
+ return false;
149
+ var c = plot.getPlaceholder().css('cursor');
150
+ if (c)
151
+ prevCursor = c;
152
+ plot.getPlaceholder().css('cursor', plot.getOptions().pan.cursor);
153
+ prevPageX = e.pageX;
154
+ prevPageY = e.pageY;
155
+ }
156
+
157
+ function onDrag(e) {
158
+ var frameRate = plot.getOptions().pan.frameRate;
159
+ if (panTimeout || !frameRate)
160
+ return;
161
+
162
+ panTimeout = setTimeout(function () {
163
+ plot.pan({ left: prevPageX - e.pageX,
164
+ top: prevPageY - e.pageY });
165
+ prevPageX = e.pageX;
166
+ prevPageY = e.pageY;
167
+
168
+ panTimeout = null;
169
+ }, 1 / frameRate * 1000);
170
+ }
171
+
172
+ function onDragEnd(e) {
173
+ if (panTimeout) {
174
+ clearTimeout(panTimeout);
175
+ panTimeout = null;
176
+ }
177
+
178
+ plot.getPlaceholder().css('cursor', prevCursor);
179
+ plot.pan({ left: prevPageX - e.pageX,
180
+ top: prevPageY - e.pageY });
181
+ }
182
+
183
+ function bindEvents(plot, eventHolder) {
184
+ var o = plot.getOptions();
185
+ if (o.zoom.interactive) {
186
+ eventHolder[o.zoom.trigger](onZoomClick);
187
+ eventHolder.mousewheel(onMouseWheel);
188
+ }
189
+
190
+ if (o.pan.interactive) {
191
+ eventHolder.bind("dragstart", { distance: 10 }, onDragStart);
192
+ eventHolder.bind("drag", onDrag);
193
+ eventHolder.bind("dragend", onDragEnd);
194
+ }
195
+ }
196
+
197
+ plot.zoomOut = function (args) {
198
+ if (!args)
199
+ args = {};
200
+
201
+ if (!args.amount)
202
+ args.amount = plot.getOptions().zoom.amount;
203
+
204
+ args.amount = 1 / args.amount;
205
+ plot.zoom(args);
206
+ };
207
+
208
+ plot.zoom = function (args) {
209
+ if (!args)
210
+ args = {};
211
+
212
+ var c = args.center,
213
+ amount = args.amount || plot.getOptions().zoom.amount,
214
+ w = plot.width(), h = plot.height();
215
+
216
+ if (!c)
217
+ c = { left: w / 2, top: h / 2 };
218
+
219
+ var xf = c.left / w,
220
+ yf = c.top / h,
221
+ minmax = {
222
+ x: {
223
+ min: c.left - xf * w / amount,
224
+ max: c.left + (1 - xf) * w / amount
225
+ },
226
+ y: {
227
+ min: c.top - yf * h / amount,
228
+ max: c.top + (1 - yf) * h / amount
229
+ }
230
+ };
231
+
232
+ $.each(plot.getAxes(), function(_, axis) {
233
+ var opts = axis.options,
234
+ min = minmax[axis.direction].min,
235
+ max = minmax[axis.direction].max,
236
+ zr = opts.zoomRange,
237
+ pr = opts.panRange;
238
+
239
+ if (zr === false) // no zooming on this axis
240
+ return;
241
+
242
+ min = axis.c2p(min);
243
+ max = axis.c2p(max);
244
+ if (min > max) {
245
+ // make sure min < max
246
+ var tmp = min;
247
+ min = max;
248
+ max = tmp;
249
+ }
250
+
251
+ //Check that we are in panRange
252
+ if (pr) {
253
+ if (pr[0] != null && min < pr[0]) {
254
+ min = pr[0];
255
+ }
256
+ if (pr[1] != null && max > pr[1]) {
257
+ max = pr[1];
258
+ }
259
+ }
260
+
261
+ var range = max - min;
262
+ if (zr &&
263
+ ((zr[0] != null && range < zr[0] && amount >1) ||
264
+ (zr[1] != null && range > zr[1] && amount <1)))
265
+ return;
266
+
267
+ opts.min = min;
268
+ opts.max = max;
269
+ });
270
+
271
+ plot.setupGrid();
272
+ plot.draw();
273
+
274
+ if (!args.preventEvent)
275
+ plot.getPlaceholder().trigger("plotzoom", [ plot, args ]);
276
+ };
277
+
278
+ plot.pan = function (args) {
279
+ var delta = {
280
+ x: +args.left,
281
+ y: +args.top
282
+ };
283
+
284
+ if (isNaN(delta.x))
285
+ delta.x = 0;
286
+ if (isNaN(delta.y))
287
+ delta.y = 0;
288
+
289
+ $.each(plot.getAxes(), function (_, axis) {
290
+ var opts = axis.options,
291
+ min, max, d = delta[axis.direction];
292
+
293
+ min = axis.c2p(axis.p2c(axis.min) + d),
294
+ max = axis.c2p(axis.p2c(axis.max) + d);
295
+
296
+ var pr = opts.panRange;
297
+ if (pr === false) // no panning on this axis
298
+ return;
299
+
300
+ if (pr) {
301
+ // check whether we hit the wall
302
+ if (pr[0] != null && pr[0] > min) {
303
+ d = pr[0] - min;
304
+ min += d;
305
+ max += d;
306
+ }
307
+
308
+ if (pr[1] != null && pr[1] < max) {
309
+ d = pr[1] - max;
310
+ min += d;
311
+ max += d;
312
+ }
313
+ }
314
+
315
+ opts.min = min;
316
+ opts.max = max;
317
+ });
318
+
319
+ plot.setupGrid();
320
+ plot.draw();
321
+
322
+ if (!args.preventEvent)
323
+ plot.getPlaceholder().trigger("plotpan", [ plot, args ]);
324
+ };
325
+
326
+ function shutdown(plot, eventHolder) {
327
+ eventHolder.unbind(plot.getOptions().zoom.trigger, onZoomClick);
328
+ eventHolder.unbind("mousewheel", onMouseWheel);
329
+ eventHolder.unbind("dragstart", onDragStart);
330
+ eventHolder.unbind("drag", onDrag);
331
+ eventHolder.unbind("dragend", onDragEnd);
332
+ if (panTimeout)
333
+ clearTimeout(panTimeout);
334
+ }
335
+
336
+ plot.hooks.bindEvents.push(bindEvents);
337
+ plot.hooks.shutdown.push(shutdown);
338
+ }
339
+
340
+ $.plot.plugins.push({
341
+ init: init,
342
+ options: options,
343
+ name: 'navigate',
344
+ version: '1.3'
345
+ });
346
+ })(jQuery);
@@ -0,0 +1,820 @@
1
+ /* Flot plugin for rendering pie charts.
2
+
3
+ Copyright (c) 2007-2014 IOLA and Ole Laursen.
4
+ Licensed under the MIT license.
5
+
6
+ The plugin assumes that each series has a single data value, and that each
7
+ value is a positive integer or zero. Negative numbers don't make sense for a
8
+ pie chart, and have unpredictable results. The values do NOT need to be
9
+ passed in as percentages; the plugin will calculate the total and per-slice
10
+ percentages internally.
11
+
12
+ * Created by Brian Medendorp
13
+
14
+ * Updated with contributions from btburnett3, Anthony Aragues and Xavi Ivars
15
+
16
+ The plugin supports these options:
17
+
18
+ series: {
19
+ pie: {
20
+ show: true/false
21
+ radius: 0-1 for percentage of fullsize, or a specified pixel length, or 'auto'
22
+ innerRadius: 0-1 for percentage of fullsize or a specified pixel length, for creating a donut effect
23
+ startAngle: 0-2 factor of PI used for starting angle (in radians) i.e 3/2 starts at the top, 0 and 2 have the same result
24
+ tilt: 0-1 for percentage to tilt the pie, where 1 is no tilt, and 0 is completely flat (nothing will show)
25
+ offset: {
26
+ top: integer value to move the pie up or down
27
+ left: integer value to move the pie left or right, or 'auto'
28
+ },
29
+ stroke: {
30
+ color: any hexidecimal color value (other formats may or may not work, so best to stick with something like '#FFF')
31
+ width: integer pixel width of the stroke
32
+ },
33
+ label: {
34
+ show: true/false, or 'auto'
35
+ formatter: a user-defined function that modifies the text/style of the label text
36
+ radius: 0-1 for percentage of fullsize, or a specified pixel length
37
+ background: {
38
+ color: any hexidecimal color value (other formats may or may not work, so best to stick with something like '#000')
39
+ opacity: 0-1
40
+ },
41
+ threshold: 0-1 for the percentage value at which to hide labels (if they're too small)
42
+ },
43
+ combine: {
44
+ threshold: 0-1 for the percentage value at which to combine slices (if they're too small)
45
+ color: any hexidecimal color value (other formats may or may not work, so best to stick with something like '#CCC'), if null, the plugin will automatically use the color of the first slice to be combined
46
+ label: any text value of what the combined slice should be labeled
47
+ }
48
+ highlight: {
49
+ opacity: 0-1
50
+ }
51
+ }
52
+ }
53
+
54
+ More detail and specific examples can be found in the included HTML file.
55
+
56
+ */
57
+
58
+ (function($) {
59
+
60
+ // Maximum redraw attempts when fitting labels within the plot
61
+
62
+ var REDRAW_ATTEMPTS = 10;
63
+
64
+ // Factor by which to shrink the pie when fitting labels within the plot
65
+
66
+ var REDRAW_SHRINK = 0.95;
67
+
68
+ function init(plot) {
69
+
70
+ var canvas = null,
71
+ target = null,
72
+ options = null,
73
+ maxRadius = null,
74
+ centerLeft = null,
75
+ centerTop = null,
76
+ processed = false,
77
+ ctx = null;
78
+
79
+ // interactive variables
80
+
81
+ var highlights = [];
82
+
83
+ // add hook to determine if pie plugin in enabled, and then perform necessary operations
84
+
85
+ plot.hooks.processOptions.push(function(plot, options) {
86
+ if (options.series.pie.show) {
87
+
88
+ options.grid.show = false;
89
+
90
+ // set labels.show
91
+
92
+ if (options.series.pie.label.show == "auto") {
93
+ if (options.legend.show) {
94
+ options.series.pie.label.show = false;
95
+ } else {
96
+ options.series.pie.label.show = true;
97
+ }
98
+ }
99
+
100
+ // set radius
101
+
102
+ if (options.series.pie.radius == "auto") {
103
+ if (options.series.pie.label.show) {
104
+ options.series.pie.radius = 3/4;
105
+ } else {
106
+ options.series.pie.radius = 1;
107
+ }
108
+ }
109
+
110
+ // ensure sane tilt
111
+
112
+ if (options.series.pie.tilt > 1) {
113
+ options.series.pie.tilt = 1;
114
+ } else if (options.series.pie.tilt < 0) {
115
+ options.series.pie.tilt = 0;
116
+ }
117
+ }
118
+ });
119
+
120
+ plot.hooks.bindEvents.push(function(plot, eventHolder) {
121
+ var options = plot.getOptions();
122
+ if (options.series.pie.show) {
123
+ if (options.grid.hoverable) {
124
+ eventHolder.unbind("mousemove").mousemove(onMouseMove);
125
+ }
126
+ if (options.grid.clickable) {
127
+ eventHolder.unbind("click").click(onClick);
128
+ }
129
+ }
130
+ });
131
+
132
+ plot.hooks.processDatapoints.push(function(plot, series, data, datapoints) {
133
+ var options = plot.getOptions();
134
+ if (options.series.pie.show) {
135
+ processDatapoints(plot, series, data, datapoints);
136
+ }
137
+ });
138
+
139
+ plot.hooks.drawOverlay.push(function(plot, octx) {
140
+ var options = plot.getOptions();
141
+ if (options.series.pie.show) {
142
+ drawOverlay(plot, octx);
143
+ }
144
+ });
145
+
146
+ plot.hooks.draw.push(function(plot, newCtx) {
147
+ var options = plot.getOptions();
148
+ if (options.series.pie.show) {
149
+ draw(plot, newCtx);
150
+ }
151
+ });
152
+
153
+ function processDatapoints(plot, series, datapoints) {
154
+ if (!processed) {
155
+ processed = true;
156
+ canvas = plot.getCanvas();
157
+ target = $(canvas).parent();
158
+ options = plot.getOptions();
159
+ plot.setData(combine(plot.getData()));
160
+ }
161
+ }
162
+
163
+ function combine(data) {
164
+
165
+ var total = 0,
166
+ combined = 0,
167
+ numCombined = 0,
168
+ color = options.series.pie.combine.color,
169
+ newdata = [];
170
+
171
+ // Fix up the raw data from Flot, ensuring the data is numeric
172
+
173
+ for (var i = 0; i < data.length; ++i) {
174
+
175
+ var value = data[i].data;
176
+
177
+ // If the data is an array, we'll assume that it's a standard
178
+ // Flot x-y pair, and are concerned only with the second value.
179
+
180
+ // Note how we use the original array, rather than creating a
181
+ // new one; this is more efficient and preserves any extra data
182
+ // that the user may have stored in higher indexes.
183
+
184
+ if ($.isArray(value) && value.length == 1) {
185
+ value = value[0];
186
+ }
187
+
188
+ if ($.isArray(value)) {
189
+ // Equivalent to $.isNumeric() but compatible with jQuery < 1.7
190
+ if (!isNaN(parseFloat(value[1])) && isFinite(value[1])) {
191
+ value[1] = +value[1];
192
+ } else {
193
+ value[1] = 0;
194
+ }
195
+ } else if (!isNaN(parseFloat(value)) && isFinite(value)) {
196
+ value = [1, +value];
197
+ } else {
198
+ value = [1, 0];
199
+ }
200
+
201
+ data[i].data = [value];
202
+ }
203
+
204
+ // Sum up all the slices, so we can calculate percentages for each
205
+
206
+ for (var i = 0; i < data.length; ++i) {
207
+ total += data[i].data[0][1];
208
+ }
209
+
210
+ // Count the number of slices with percentages below the combine
211
+ // threshold; if it turns out to be just one, we won't combine.
212
+
213
+ for (var i = 0; i < data.length; ++i) {
214
+ var value = data[i].data[0][1];
215
+ if (value / total <= options.series.pie.combine.threshold) {
216
+ combined += value;
217
+ numCombined++;
218
+ if (!color) {
219
+ color = data[i].color;
220
+ }
221
+ }
222
+ }
223
+
224
+ for (var i = 0; i < data.length; ++i) {
225
+ var value = data[i].data[0][1];
226
+ if (numCombined < 2 || value / total > options.series.pie.combine.threshold) {
227
+ newdata.push(
228
+ $.extend(data[i], { /* extend to allow keeping all other original data values
229
+ and using them e.g. in labelFormatter. */
230
+ data: [[1, value]],
231
+ color: data[i].color,
232
+ label: data[i].label,
233
+ angle: value * Math.PI * 2 / total,
234
+ percent: value / (total / 100)
235
+ })
236
+ );
237
+ }
238
+ }
239
+
240
+ if (numCombined > 1) {
241
+ newdata.push({
242
+ data: [[1, combined]],
243
+ color: color,
244
+ label: options.series.pie.combine.label,
245
+ angle: combined * Math.PI * 2 / total,
246
+ percent: combined / (total / 100)
247
+ });
248
+ }
249
+
250
+ return newdata;
251
+ }
252
+
253
+ function draw(plot, newCtx) {
254
+
255
+ if (!target) {
256
+ return; // if no series were passed
257
+ }
258
+
259
+ var canvasWidth = plot.getPlaceholder().width(),
260
+ canvasHeight = plot.getPlaceholder().height(),
261
+ legendWidth = target.children().filter(".legend").children().width() || 0;
262
+
263
+ ctx = newCtx;
264
+
265
+ // WARNING: HACK! REWRITE THIS CODE AS SOON AS POSSIBLE!
266
+
267
+ // When combining smaller slices into an 'other' slice, we need to
268
+ // add a new series. Since Flot gives plugins no way to modify the
269
+ // list of series, the pie plugin uses a hack where the first call
270
+ // to processDatapoints results in a call to setData with the new
271
+ // list of series, then subsequent processDatapoints do nothing.
272
+
273
+ // The plugin-global 'processed' flag is used to control this hack;
274
+ // it starts out false, and is set to true after the first call to
275
+ // processDatapoints.
276
+
277
+ // Unfortunately this turns future setData calls into no-ops; they
278
+ // call processDatapoints, the flag is true, and nothing happens.
279
+
280
+ // To fix this we'll set the flag back to false here in draw, when
281
+ // all series have been processed, so the next sequence of calls to
282
+ // processDatapoints once again starts out with a slice-combine.
283
+ // This is really a hack; in 0.9 we need to give plugins a proper
284
+ // way to modify series before any processing begins.
285
+
286
+ processed = false;
287
+
288
+ // calculate maximum radius and center point
289
+
290
+ maxRadius = Math.min(canvasWidth, canvasHeight / options.series.pie.tilt) / 2;
291
+ centerTop = canvasHeight / 2 + options.series.pie.offset.top;
292
+ centerLeft = canvasWidth / 2;
293
+
294
+ if (options.series.pie.offset.left == "auto") {
295
+ if (options.legend.position.match("w")) {
296
+ centerLeft += legendWidth / 2;
297
+ } else {
298
+ centerLeft -= legendWidth / 2;
299
+ }
300
+ if (centerLeft < maxRadius) {
301
+ centerLeft = maxRadius;
302
+ } else if (centerLeft > canvasWidth - maxRadius) {
303
+ centerLeft = canvasWidth - maxRadius;
304
+ }
305
+ } else {
306
+ centerLeft += options.series.pie.offset.left;
307
+ }
308
+
309
+ var slices = plot.getData(),
310
+ attempts = 0;
311
+
312
+ // Keep shrinking the pie's radius until drawPie returns true,
313
+ // indicating that all the labels fit, or we try too many times.
314
+
315
+ do {
316
+ if (attempts > 0) {
317
+ maxRadius *= REDRAW_SHRINK;
318
+ }
319
+ attempts += 1;
320
+ clear();
321
+ if (options.series.pie.tilt <= 0.8) {
322
+ drawShadow();
323
+ }
324
+ } while (!drawPie() && attempts < REDRAW_ATTEMPTS)
325
+
326
+ if (attempts >= REDRAW_ATTEMPTS) {
327
+ clear();
328
+ target.prepend("<div class='error'>Could not draw pie with labels contained inside canvas</div>");
329
+ }
330
+
331
+ if (plot.setSeries && plot.insertLegend) {
332
+ plot.setSeries(slices);
333
+ plot.insertLegend();
334
+ }
335
+
336
+ // we're actually done at this point, just defining internal functions at this point
337
+
338
+ function clear() {
339
+ ctx.clearRect(0, 0, canvasWidth, canvasHeight);
340
+ target.children().filter(".pieLabel, .pieLabelBackground").remove();
341
+ }
342
+
343
+ function drawShadow() {
344
+
345
+ var shadowLeft = options.series.pie.shadow.left;
346
+ var shadowTop = options.series.pie.shadow.top;
347
+ var edge = 10;
348
+ var alpha = options.series.pie.shadow.alpha;
349
+ var radius = options.series.pie.radius > 1 ? options.series.pie.radius : maxRadius * options.series.pie.radius;
350
+
351
+ if (radius >= canvasWidth / 2 - shadowLeft || radius * options.series.pie.tilt >= canvasHeight / 2 - shadowTop || radius <= edge) {
352
+ return; // shadow would be outside canvas, so don't draw it
353
+ }
354
+
355
+ ctx.save();
356
+ ctx.translate(shadowLeft,shadowTop);
357
+ ctx.globalAlpha = alpha;
358
+ ctx.fillStyle = "#000";
359
+
360
+ // center and rotate to starting position
361
+
362
+ ctx.translate(centerLeft,centerTop);
363
+ ctx.scale(1, options.series.pie.tilt);
364
+
365
+ //radius -= edge;
366
+
367
+ for (var i = 1; i <= edge; i++) {
368
+ ctx.beginPath();
369
+ ctx.arc(0, 0, radius, 0, Math.PI * 2, false);
370
+ ctx.fill();
371
+ radius -= i;
372
+ }
373
+
374
+ ctx.restore();
375
+ }
376
+
377
+ function drawPie() {
378
+
379
+ var startAngle = Math.PI * options.series.pie.startAngle;
380
+ var radius = options.series.pie.radius > 1 ? options.series.pie.radius : maxRadius * options.series.pie.radius;
381
+
382
+ // center and rotate to starting position
383
+
384
+ ctx.save();
385
+ ctx.translate(centerLeft,centerTop);
386
+ ctx.scale(1, options.series.pie.tilt);
387
+ //ctx.rotate(startAngle); // start at top; -- This doesn't work properly in Opera
388
+
389
+ // draw slices
390
+
391
+ ctx.save();
392
+ var currentAngle = startAngle;
393
+ for (var i = 0; i < slices.length; ++i) {
394
+ slices[i].startAngle = currentAngle;
395
+ drawSlice(slices[i].angle, slices[i].color, true);
396
+ }
397
+ ctx.restore();
398
+
399
+ // draw slice outlines
400
+
401
+ if (options.series.pie.stroke.width > 0) {
402
+ ctx.save();
403
+ ctx.lineWidth = options.series.pie.stroke.width;
404
+ currentAngle = startAngle;
405
+ for (var i = 0; i < slices.length; ++i) {
406
+ drawSlice(slices[i].angle, options.series.pie.stroke.color, false);
407
+ }
408
+ ctx.restore();
409
+ }
410
+
411
+ // draw donut hole
412
+
413
+ drawDonutHole(ctx);
414
+
415
+ ctx.restore();
416
+
417
+ // Draw the labels, returning true if they fit within the plot
418
+
419
+ if (options.series.pie.label.show) {
420
+ return drawLabels();
421
+ } else return true;
422
+
423
+ function drawSlice(angle, color, fill) {
424
+
425
+ if (angle <= 0 || isNaN(angle)) {
426
+ return;
427
+ }
428
+
429
+ if (fill) {
430
+ ctx.fillStyle = color;
431
+ } else {
432
+ ctx.strokeStyle = color;
433
+ ctx.lineJoin = "round";
434
+ }
435
+
436
+ ctx.beginPath();
437
+ if (Math.abs(angle - Math.PI * 2) > 0.000000001) {
438
+ ctx.moveTo(0, 0); // Center of the pie
439
+ }
440
+
441
+ //ctx.arc(0, 0, radius, 0, angle, false); // This doesn't work properly in Opera
442
+ ctx.arc(0, 0, radius,currentAngle, currentAngle + angle / 2, false);
443
+ ctx.arc(0, 0, radius,currentAngle + angle / 2, currentAngle + angle, false);
444
+ ctx.closePath();
445
+ //ctx.rotate(angle); // This doesn't work properly in Opera
446
+ currentAngle += angle;
447
+
448
+ if (fill) {
449
+ ctx.fill();
450
+ } else {
451
+ ctx.stroke();
452
+ }
453
+ }
454
+
455
+ function drawLabels() {
456
+
457
+ var currentAngle = startAngle;
458
+ var radius = options.series.pie.label.radius > 1 ? options.series.pie.label.radius : maxRadius * options.series.pie.label.radius;
459
+
460
+ for (var i = 0; i < slices.length; ++i) {
461
+ if (slices[i].percent >= options.series.pie.label.threshold * 100) {
462
+ if (!drawLabel(slices[i], currentAngle, i)) {
463
+ return false;
464
+ }
465
+ }
466
+ currentAngle += slices[i].angle;
467
+ }
468
+
469
+ return true;
470
+
471
+ function drawLabel(slice, startAngle, index) {
472
+
473
+ if (slice.data[0][1] == 0) {
474
+ return true;
475
+ }
476
+
477
+ // format label text
478
+
479
+ var lf = options.legend.labelFormatter, text, plf = options.series.pie.label.formatter;
480
+
481
+ if (lf) {
482
+ text = lf(slice.label, slice);
483
+ } else {
484
+ text = slice.label;
485
+ }
486
+
487
+ if (plf) {
488
+ text = plf(text, slice);
489
+ }
490
+
491
+ var halfAngle = ((startAngle + slice.angle) + startAngle) / 2;
492
+ var x = centerLeft + Math.round(Math.cos(halfAngle) * radius);
493
+ var y = centerTop + Math.round(Math.sin(halfAngle) * radius) * options.series.pie.tilt;
494
+
495
+ var html = "<span class='pieLabel' id='pieLabel" + index + "' style='position:absolute;top:" + y + "px;left:" + x + "px;'>" + text + "</span>";
496
+ target.append(html);
497
+
498
+ var label = target.children("#pieLabel" + index);
499
+ var labelTop = (y - label.height() / 2);
500
+ var labelLeft = (x - label.width() / 2);
501
+
502
+ label.css("top", labelTop);
503
+ label.css("left", labelLeft);
504
+
505
+ // check to make sure that the label is not outside the canvas
506
+
507
+ if (0 - labelTop > 0 || 0 - labelLeft > 0 || canvasHeight - (labelTop + label.height()) < 0 || canvasWidth - (labelLeft + label.width()) < 0) {
508
+ return false;
509
+ }
510
+
511
+ if (options.series.pie.label.background.opacity != 0) {
512
+
513
+ // put in the transparent background separately to avoid blended labels and label boxes
514
+
515
+ var c = options.series.pie.label.background.color;
516
+
517
+ if (c == null) {
518
+ c = slice.color;
519
+ }
520
+
521
+ var pos = "top:" + labelTop + "px;left:" + labelLeft + "px;";
522
+ $("<div class='pieLabelBackground' style='position:absolute;width:" + label.width() + "px;height:" + label.height() + "px;" + pos + "background-color:" + c + ";'></div>")
523
+ .css("opacity", options.series.pie.label.background.opacity)
524
+ .insertBefore(label);
525
+ }
526
+
527
+ return true;
528
+ } // end individual label function
529
+ } // end drawLabels function
530
+ } // end drawPie function
531
+ } // end draw function
532
+
533
+ // Placed here because it needs to be accessed from multiple locations
534
+
535
+ function drawDonutHole(layer) {
536
+ if (options.series.pie.innerRadius > 0) {
537
+
538
+ // subtract the center
539
+
540
+ layer.save();
541
+ var innerRadius = options.series.pie.innerRadius > 1 ? options.series.pie.innerRadius : maxRadius * options.series.pie.innerRadius;
542
+ layer.globalCompositeOperation = "destination-out"; // this does not work with excanvas, but it will fall back to using the stroke color
543
+ layer.beginPath();
544
+ layer.fillStyle = options.series.pie.stroke.color;
545
+ layer.arc(0, 0, innerRadius, 0, Math.PI * 2, false);
546
+ layer.fill();
547
+ layer.closePath();
548
+ layer.restore();
549
+
550
+ // add inner stroke
551
+
552
+ layer.save();
553
+ layer.beginPath();
554
+ layer.strokeStyle = options.series.pie.stroke.color;
555
+ layer.arc(0, 0, innerRadius, 0, Math.PI * 2, false);
556
+ layer.stroke();
557
+ layer.closePath();
558
+ layer.restore();
559
+
560
+ // TODO: add extra shadow inside hole (with a mask) if the pie is tilted.
561
+ }
562
+ }
563
+
564
+ //-- Additional Interactive related functions --
565
+
566
+ function isPointInPoly(poly, pt) {
567
+ for(var c = false, i = -1, l = poly.length, j = l - 1; ++i < l; j = i)
568
+ ((poly[i][1] <= pt[1] && pt[1] < poly[j][1]) || (poly[j][1] <= pt[1] && pt[1]< poly[i][1]))
569
+ && (pt[0] < (poly[j][0] - poly[i][0]) * (pt[1] - poly[i][1]) / (poly[j][1] - poly[i][1]) + poly[i][0])
570
+ && (c = !c);
571
+ return c;
572
+ }
573
+
574
+ function findNearbySlice(mouseX, mouseY) {
575
+
576
+ var slices = plot.getData(),
577
+ options = plot.getOptions(),
578
+ radius = options.series.pie.radius > 1 ? options.series.pie.radius : maxRadius * options.series.pie.radius,
579
+ x, y;
580
+
581
+ for (var i = 0; i < slices.length; ++i) {
582
+
583
+ var s = slices[i];
584
+
585
+ if (s.pie.show) {
586
+
587
+ ctx.save();
588
+ ctx.beginPath();
589
+ ctx.moveTo(0, 0); // Center of the pie
590
+ //ctx.scale(1, options.series.pie.tilt); // this actually seems to break everything when here.
591
+ ctx.arc(0, 0, radius, s.startAngle, s.startAngle + s.angle / 2, false);
592
+ ctx.arc(0, 0, radius, s.startAngle + s.angle / 2, s.startAngle + s.angle, false);
593
+ ctx.closePath();
594
+ x = mouseX - centerLeft;
595
+ y = mouseY - centerTop;
596
+
597
+ if (ctx.isPointInPath) {
598
+ if (ctx.isPointInPath(mouseX - centerLeft, mouseY - centerTop)) {
599
+ ctx.restore();
600
+ return {
601
+ datapoint: [s.percent, s.data],
602
+ dataIndex: 0,
603
+ series: s,
604
+ seriesIndex: i
605
+ };
606
+ }
607
+ } else {
608
+
609
+ // excanvas for IE doesn;t support isPointInPath, this is a workaround.
610
+
611
+ var p1X = radius * Math.cos(s.startAngle),
612
+ p1Y = radius * Math.sin(s.startAngle),
613
+ p2X = radius * Math.cos(s.startAngle + s.angle / 4),
614
+ p2Y = radius * Math.sin(s.startAngle + s.angle / 4),
615
+ p3X = radius * Math.cos(s.startAngle + s.angle / 2),
616
+ p3Y = radius * Math.sin(s.startAngle + s.angle / 2),
617
+ p4X = radius * Math.cos(s.startAngle + s.angle / 1.5),
618
+ p4Y = radius * Math.sin(s.startAngle + s.angle / 1.5),
619
+ p5X = radius * Math.cos(s.startAngle + s.angle),
620
+ p5Y = radius * Math.sin(s.startAngle + s.angle),
621
+ arrPoly = [[0, 0], [p1X, p1Y], [p2X, p2Y], [p3X, p3Y], [p4X, p4Y], [p5X, p5Y]],
622
+ arrPoint = [x, y];
623
+
624
+ // TODO: perhaps do some mathmatical trickery here with the Y-coordinate to compensate for pie tilt?
625
+
626
+ if (isPointInPoly(arrPoly, arrPoint)) {
627
+ ctx.restore();
628
+ return {
629
+ datapoint: [s.percent, s.data],
630
+ dataIndex: 0,
631
+ series: s,
632
+ seriesIndex: i
633
+ };
634
+ }
635
+ }
636
+
637
+ ctx.restore();
638
+ }
639
+ }
640
+
641
+ return null;
642
+ }
643
+
644
+ function onMouseMove(e) {
645
+ triggerClickHoverEvent("plothover", e);
646
+ }
647
+
648
+ function onClick(e) {
649
+ triggerClickHoverEvent("plotclick", e);
650
+ }
651
+
652
+ // trigger click or hover event (they send the same parameters so we share their code)
653
+
654
+ function triggerClickHoverEvent(eventname, e) {
655
+
656
+ var offset = plot.offset();
657
+ var canvasX = parseInt(e.pageX - offset.left);
658
+ var canvasY = parseInt(e.pageY - offset.top);
659
+ var item = findNearbySlice(canvasX, canvasY);
660
+
661
+ if (options.grid.autoHighlight) {
662
+
663
+ // clear auto-highlights
664
+
665
+ for (var i = 0; i < highlights.length; ++i) {
666
+ var h = highlights[i];
667
+ if (h.auto == eventname && !(item && h.series == item.series)) {
668
+ unhighlight(h.series);
669
+ }
670
+ }
671
+ }
672
+
673
+ // highlight the slice
674
+
675
+ if (item) {
676
+ highlight(item.series, eventname);
677
+ }
678
+
679
+ // trigger any hover bind events
680
+
681
+ var pos = { pageX: e.pageX, pageY: e.pageY };
682
+ target.trigger(eventname, [pos, item]);
683
+ }
684
+
685
+ function highlight(s, auto) {
686
+ //if (typeof s == "number") {
687
+ // s = series[s];
688
+ //}
689
+
690
+ var i = indexOfHighlight(s);
691
+
692
+ if (i == -1) {
693
+ highlights.push({ series: s, auto: auto });
694
+ plot.triggerRedrawOverlay();
695
+ } else if (!auto) {
696
+ highlights[i].auto = false;
697
+ }
698
+ }
699
+
700
+ function unhighlight(s) {
701
+ if (s == null) {
702
+ highlights = [];
703
+ plot.triggerRedrawOverlay();
704
+ }
705
+
706
+ //if (typeof s == "number") {
707
+ // s = series[s];
708
+ //}
709
+
710
+ var i = indexOfHighlight(s);
711
+
712
+ if (i != -1) {
713
+ highlights.splice(i, 1);
714
+ plot.triggerRedrawOverlay();
715
+ }
716
+ }
717
+
718
+ function indexOfHighlight(s) {
719
+ for (var i = 0; i < highlights.length; ++i) {
720
+ var h = highlights[i];
721
+ if (h.series == s)
722
+ return i;
723
+ }
724
+ return -1;
725
+ }
726
+
727
+ function drawOverlay(plot, octx) {
728
+
729
+ var options = plot.getOptions();
730
+
731
+ var radius = options.series.pie.radius > 1 ? options.series.pie.radius : maxRadius * options.series.pie.radius;
732
+
733
+ octx.save();
734
+ octx.translate(centerLeft, centerTop);
735
+ octx.scale(1, options.series.pie.tilt);
736
+
737
+ for (var i = 0; i < highlights.length; ++i) {
738
+ drawHighlight(highlights[i].series);
739
+ }
740
+
741
+ drawDonutHole(octx);
742
+
743
+ octx.restore();
744
+
745
+ function drawHighlight(series) {
746
+
747
+ if (series.angle <= 0 || isNaN(series.angle)) {
748
+ return;
749
+ }
750
+
751
+ //octx.fillStyle = parseColor(options.series.pie.highlight.color).scale(null, null, null, options.series.pie.highlight.opacity).toString();
752
+ octx.fillStyle = "rgba(255, 255, 255, " + options.series.pie.highlight.opacity + ")"; // this is temporary until we have access to parseColor
753
+ octx.beginPath();
754
+ if (Math.abs(series.angle - Math.PI * 2) > 0.000000001) {
755
+ octx.moveTo(0, 0); // Center of the pie
756
+ }
757
+ octx.arc(0, 0, radius, series.startAngle, series.startAngle + series.angle / 2, false);
758
+ octx.arc(0, 0, radius, series.startAngle + series.angle / 2, series.startAngle + series.angle, false);
759
+ octx.closePath();
760
+ octx.fill();
761
+ }
762
+ }
763
+ } // end init (plugin body)
764
+
765
+ // define pie specific options and their default values
766
+
767
+ var options = {
768
+ series: {
769
+ pie: {
770
+ show: false,
771
+ radius: "auto", // actual radius of the visible pie (based on full calculated radius if <=1, or hard pixel value)
772
+ innerRadius: 0, /* for donut */
773
+ startAngle: 3/2,
774
+ tilt: 1,
775
+ shadow: {
776
+ left: 5, // shadow left offset
777
+ top: 15, // shadow top offset
778
+ alpha: 0.02 // shadow alpha
779
+ },
780
+ offset: {
781
+ top: 0,
782
+ left: "auto"
783
+ },
784
+ stroke: {
785
+ color: "#fff",
786
+ width: 1
787
+ },
788
+ label: {
789
+ show: "auto",
790
+ formatter: function(label, slice) {
791
+ return "<div style='font-size:x-small;text-align:center;padding:2px;color:" + slice.color + ";'>" + label + "<br/>" + Math.round(slice.percent) + "%</div>";
792
+ }, // formatter function
793
+ radius: 1, // radius at which to place the labels (based on full calculated radius if <=1, or hard pixel value)
794
+ background: {
795
+ color: null,
796
+ opacity: 0
797
+ },
798
+ threshold: 0 // percentage at which to hide the label (i.e. the slice is too narrow)
799
+ },
800
+ combine: {
801
+ threshold: -1, // percentage at which to combine little slices into one larger slice
802
+ color: null, // color to give the new slice (auto-generated if null)
803
+ label: "Other" // label to give the new slice
804
+ },
805
+ highlight: {
806
+ //color: "#fff", // will add this functionality once parseColor is available
807
+ opacity: 0.5
808
+ }
809
+ }
810
+ }
811
+ };
812
+
813
+ $.plot.plugins.push({
814
+ init: init,
815
+ options: options,
816
+ name: "pie",
817
+ version: "1.1"
818
+ });
819
+
820
+ })(jQuery);