ruby-trade 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. data/.gitignore +5 -0
  2. data/README.md +99 -0
  3. data/examples/market_maker.rb +42 -0
  4. data/lib/Gemfile +6 -0
  5. data/lib/Gemfile.lock +23 -0
  6. data/lib/client.rb +203 -0
  7. data/lib/order.rb +49 -0
  8. data/lib/ruby-trade.rb +1 -0
  9. data/rubytrade.gemspec +12 -0
  10. data/server/Gemfile +12 -0
  11. data/server/Gemfile.lock +57 -0
  12. data/server/account.rb +39 -0
  13. data/server/app.rb +20 -0
  14. data/server/exchange.rb +59 -0
  15. data/server/order-book.rb +113 -0
  16. data/server/order.rb +60 -0
  17. data/server/public/app.js +51 -0
  18. data/server/public/dist/css/bootstrap-theme.css +459 -0
  19. data/server/public/dist/css/bootstrap-theme.min.css +9 -0
  20. data/server/public/dist/css/bootstrap.css +7098 -0
  21. data/server/public/dist/css/bootstrap.min.css +9 -0
  22. data/server/public/dist/fonts/glyphicons-halflings-regular.eot +0 -0
  23. data/server/public/dist/fonts/glyphicons-halflings-regular.svg +229 -0
  24. data/server/public/dist/fonts/glyphicons-halflings-regular.ttf +0 -0
  25. data/server/public/dist/fonts/glyphicons-halflings-regular.woff +0 -0
  26. data/server/public/dist/js/bootstrap.js +2002 -0
  27. data/server/public/dist/js/bootstrap.min.js +9 -0
  28. data/server/public/flot/API.md +1464 -0
  29. data/server/public/flot/CONTRIBUTING.md +99 -0
  30. data/server/public/flot/FAQ.md +75 -0
  31. data/server/public/flot/LICENSE.txt +22 -0
  32. data/server/public/flot/Makefile +12 -0
  33. data/server/public/flot/NEWS.md +893 -0
  34. data/server/public/flot/PLUGINS.md +143 -0
  35. data/server/public/flot/README.md +110 -0
  36. data/server/public/flot/build.log +0 -0
  37. data/server/public/flot/examples/ajax/data-eu-gdp-growth-1.json +4 -0
  38. data/server/public/flot/examples/ajax/data-eu-gdp-growth-2.json +4 -0
  39. data/server/public/flot/examples/ajax/data-eu-gdp-growth-3.json +4 -0
  40. data/server/public/flot/examples/ajax/data-eu-gdp-growth-4.json +4 -0
  41. data/server/public/flot/examples/ajax/data-eu-gdp-growth-5.json +4 -0
  42. data/server/public/flot/examples/ajax/data-eu-gdp-growth.json +4 -0
  43. data/server/public/flot/examples/ajax/data-japan-gdp-growth.json +4 -0
  44. data/server/public/flot/examples/ajax/data-usa-gdp-growth.json +4 -0
  45. data/server/public/flot/examples/ajax/index.html +173 -0
  46. data/server/public/flot/examples/annotating/index.html +87 -0
  47. data/server/public/flot/examples/axes-interacting/index.html +97 -0
  48. data/server/public/flot/examples/axes-multiple/index.html +77 -0
  49. data/server/public/flot/examples/axes-time-zones/date.js +893 -0
  50. data/server/public/flot/examples/axes-time-zones/index.html +114 -0
  51. data/server/public/flot/examples/axes-time-zones/tz/africa +1181 -0
  52. data/server/public/flot/examples/axes-time-zones/tz/antarctica +413 -0
  53. data/server/public/flot/examples/axes-time-zones/tz/asia +2717 -0
  54. data/server/public/flot/examples/axes-time-zones/tz/australasia +1719 -0
  55. data/server/public/flot/examples/axes-time-zones/tz/backward +117 -0
  56. data/server/public/flot/examples/axes-time-zones/tz/etcetera +81 -0
  57. data/server/public/flot/examples/axes-time-zones/tz/europe +2856 -0
  58. data/server/public/flot/examples/axes-time-zones/tz/factory +10 -0
  59. data/server/public/flot/examples/axes-time-zones/tz/iso3166.tab +276 -0
  60. data/server/public/flot/examples/axes-time-zones/tz/leapseconds +100 -0
  61. data/server/public/flot/examples/axes-time-zones/tz/northamerica +3235 -0
  62. data/server/public/flot/examples/axes-time-zones/tz/pacificnew +28 -0
  63. data/server/public/flot/examples/axes-time-zones/tz/solar87 +390 -0
  64. data/server/public/flot/examples/axes-time-zones/tz/solar88 +390 -0
  65. data/server/public/flot/examples/axes-time-zones/tz/solar89 +395 -0
  66. data/server/public/flot/examples/axes-time-zones/tz/southamerica +1711 -0
  67. data/server/public/flot/examples/axes-time-zones/tz/systemv +38 -0
  68. data/server/public/flot/examples/axes-time-zones/tz/yearistype.sh +38 -0
  69. data/server/public/flot/examples/axes-time-zones/tz/zone.tab +441 -0
  70. data/server/public/flot/examples/axes-time/index.html +137 -0
  71. data/server/public/flot/examples/background.png +0 -0
  72. data/server/public/flot/examples/basic-options/index.html +91 -0
  73. data/server/public/flot/examples/basic-usage/index.html +57 -0
  74. data/server/public/flot/examples/canvas/index.html +75 -0
  75. data/server/public/flot/examples/categories/index.html +64 -0
  76. data/server/public/flot/examples/examples.css +97 -0
  77. data/server/public/flot/examples/image/hs-2004-27-a-large-web.jpg +0 -0
  78. data/server/public/flot/examples/image/index.html +69 -0
  79. data/server/public/flot/examples/index.html +80 -0
  80. data/server/public/flot/examples/interacting/index.html +130 -0
  81. data/server/public/flot/examples/navigate/arrow-down.gif +0 -0
  82. data/server/public/flot/examples/navigate/arrow-left.gif +0 -0
  83. data/server/public/flot/examples/navigate/arrow-right.gif +0 -0
  84. data/server/public/flot/examples/navigate/arrow-up.gif +0 -0
  85. data/server/public/flot/examples/navigate/index.html +153 -0
  86. data/server/public/flot/examples/percentiles/index.html +79 -0
  87. data/server/public/flot/examples/realtime/index.html +122 -0
  88. data/server/public/flot/examples/resize/index.html +76 -0
  89. data/server/public/flot/examples/selection/index.html +141 -0
  90. data/server/public/flot/examples/series-errorbars/index.html +150 -0
  91. data/server/public/flot/examples/series-pie/index.html +818 -0
  92. data/server/public/flot/examples/series-toggle/index.html +121 -0
  93. data/server/public/flot/examples/series-types/index.html +90 -0
  94. data/server/public/flot/examples/shared/jquery-ui/jquery-ui.min.css +6 -0
  95. data/server/public/flot/examples/shared/jquery-ui/jquery-ui.min.js +6 -0
  96. data/server/public/flot/examples/stacking/index.html +107 -0
  97. data/server/public/flot/examples/symbols/index.html +76 -0
  98. data/server/public/flot/examples/threshold/index.html +76 -0
  99. data/server/public/flot/examples/tracking/index.html +135 -0
  100. data/server/public/flot/examples/visitors/index.html +146 -0
  101. data/server/public/flot/examples/zooming/index.html +144 -0
  102. data/server/public/flot/excanvas.js +1428 -0
  103. data/server/public/flot/excanvas.min.js +1 -0
  104. data/server/public/flot/jquery.colorhelpers.js +179 -0
  105. data/server/public/flot/jquery.colorhelpers.min.js +21 -0
  106. data/server/public/flot/jquery.flot.canvas.js +345 -0
  107. data/server/public/flot/jquery.flot.canvas.min.js +28 -0
  108. data/server/public/flot/jquery.flot.categories.js +190 -0
  109. data/server/public/flot/jquery.flot.categories.min.js +44 -0
  110. data/server/public/flot/jquery.flot.crosshair.js +176 -0
  111. data/server/public/flot/jquery.flot.crosshair.min.js +59 -0
  112. data/server/public/flot/jquery.flot.errorbars.js +353 -0
  113. data/server/public/flot/jquery.flot.errorbars.min.js +63 -0
  114. data/server/public/flot/jquery.flot.fillbetween.js +226 -0
  115. data/server/public/flot/jquery.flot.fillbetween.min.js +30 -0
  116. data/server/public/flot/jquery.flot.image.js +241 -0
  117. data/server/public/flot/jquery.flot.image.min.js +53 -0
  118. data/server/public/flot/jquery.flot.js +3061 -0
  119. data/server/public/flot/jquery.flot.min.js +29 -0
  120. data/server/public/flot/jquery.flot.navigate.js +346 -0
  121. data/server/public/flot/jquery.flot.navigate.min.js +86 -0
  122. data/server/public/flot/jquery.flot.pie.js +817 -0
  123. data/server/public/flot/jquery.flot.pie.min.js +56 -0
  124. data/server/public/flot/jquery.flot.resize.js +60 -0
  125. data/server/public/flot/jquery.flot.resize.min.js +19 -0
  126. data/server/public/flot/jquery.flot.selection.js +360 -0
  127. data/server/public/flot/jquery.flot.selection.min.js +79 -0
  128. data/server/public/flot/jquery.flot.stack.js +188 -0
  129. data/server/public/flot/jquery.flot.stack.min.js +36 -0
  130. data/server/public/flot/jquery.flot.symbol.js +71 -0
  131. data/server/public/flot/jquery.flot.symbol.min.js +14 -0
  132. data/server/public/flot/jquery.flot.threshold.js +142 -0
  133. data/server/public/flot/jquery.flot.threshold.min.js +43 -0
  134. data/server/public/flot/jquery.flot.time.js +431 -0
  135. data/server/public/flot/jquery.flot.time.min.js +9 -0
  136. data/server/public/flot/jquery.js +9472 -0
  137. data/server/public/flot/jquery.min.js +2 -0
  138. data/server/public/index.html +53 -0
  139. data/server/public/jquery-2.0.3.min.js +6 -0
  140. data/server/public/sockjs-0.2.1.min.js +27 -0
  141. data/server/server.rb +156 -0
  142. data/server/test/test_order_book.rb +118 -0
  143. data/server/web_server.rb +110 -0
  144. metadata +188 -0
@@ -0,0 +1,79 @@
1
+ /* Flot plugin for selecting regions of a plot.
2
+
3
+ Copyright (c) 2007-2013 IOLA and Ole Laursen.
4
+ Licensed under the MIT license.
5
+
6
+ The plugin supports these options:
7
+
8
+ selection: {
9
+ mode: null or "x" or "y" or "xy",
10
+ color: color,
11
+ shape: "round" or "miter" or "bevel",
12
+ minSize: number of pixels
13
+ }
14
+
15
+ Selection support is enabled by setting the mode to one of "x", "y" or "xy".
16
+ In "x" mode, the user will only be able to specify the x range, similarly for
17
+ "y" mode. For "xy", the selection becomes a rectangle where both ranges can be
18
+ specified. "color" is color of the selection (if you need to change the color
19
+ later on, you can get to it with plot.getOptions().selection.color). "shape"
20
+ is the shape of the corners of the selection.
21
+
22
+ "minSize" is the minimum size a selection can be in pixels. This value can
23
+ be customized to determine the smallest size a selection can be and still
24
+ have the selection rectangle be displayed. When customizing this value, the
25
+ fact that it refers to pixels, not axis units must be taken into account.
26
+ Thus, for example, if there is a bar graph in time mode with BarWidth set to 1
27
+ minute, setting "minSize" to 1 will not make the minimum selection size 1
28
+ minute, but rather 1 pixel. Note also that setting "minSize" to 0 will prevent
29
+ "plotunselected" events from being fired when the user clicks the mouse without
30
+ dragging.
31
+
32
+ When selection support is enabled, a "plotselected" event will be emitted on
33
+ the DOM element you passed into the plot function. The event handler gets a
34
+ parameter with the ranges selected on the axes, like this:
35
+
36
+ placeholder.bind( "plotselected", function( event, ranges ) {
37
+ alert("You selected " + ranges.xaxis.from + " to " + ranges.xaxis.to)
38
+ // similar for yaxis - with multiple axes, the extra ones are in
39
+ // x2axis, x3axis, ...
40
+ });
41
+
42
+ The "plotselected" event is only fired when the user has finished making the
43
+ selection. A "plotselecting" event is fired during the process with the same
44
+ parameters as the "plotselected" event, in case you want to know what's
45
+ happening while it's happening,
46
+
47
+ A "plotunselected" event with no arguments is emitted when the user clicks the
48
+ mouse to remove the selection. As stated above, setting "minSize" to 0 will
49
+ destroy this behavior.
50
+
51
+ The plugin allso adds the following methods to the plot object:
52
+
53
+ - setSelection( ranges, preventEvent )
54
+
55
+ Set the selection rectangle. The passed in ranges is on the same form as
56
+ returned in the "plotselected" event. If the selection mode is "x", you
57
+ should put in either an xaxis range, if the mode is "y" you need to put in
58
+ an yaxis range and both xaxis and yaxis if the selection mode is "xy", like
59
+ this:
60
+
61
+ setSelection({ xaxis: { from: 0, to: 10 }, yaxis: { from: 40, to: 60 } });
62
+
63
+ setSelection will trigger the "plotselected" event when called. If you don't
64
+ want that to happen, e.g. if you're inside a "plotselected" handler, pass
65
+ true as the second parameter. If you are using multiple axes, you can
66
+ specify the ranges on any of those, e.g. as x2axis/x3axis/... instead of
67
+ xaxis, the plugin picks the first one it sees.
68
+
69
+ - clearSelection( preventEvent )
70
+
71
+ Clear the selection rectangle. Pass in true to avoid getting a
72
+ "plotunselected" event.
73
+
74
+ - getSelection()
75
+
76
+ Returns the current selection in the same format as the "plotselected"
77
+ event. If there's currently no selection, the function returns null.
78
+
79
+ */(function(e){function t(t){function s(e){n.active&&(h(e),t.getPlaceholder().trigger("plotselecting",[a()]))}function o(t){if(t.which!=1)return;document.body.focus(),document.onselectstart!==undefined&&r.onselectstart==null&&(r.onselectstart=document.onselectstart,document.onselectstart=function(){return!1}),document.ondrag!==undefined&&r.ondrag==null&&(r.ondrag=document.ondrag,document.ondrag=function(){return!1}),c(n.first,t),n.active=!0,i=function(e){u(e)},e(document).one("mouseup",i)}function u(e){return i=null,document.onselectstart!==undefined&&(document.onselectstart=r.onselectstart),document.ondrag!==undefined&&(document.ondrag=r.ondrag),n.active=!1,h(e),m()?f():(t.getPlaceholder().trigger("plotunselected",[]),t.getPlaceholder().trigger("plotselecting",[null])),!1}function a(){if(!m())return null;if(!n.show)return null;var r={},i=n.first,s=n.second;return e.each(t.getAxes(),function(e,t){if(t.used){var n=t.c2p(i[t.direction]),o=t.c2p(s[t.direction]);r[e]={from:Math.min(n,o),to:Math.max(n,o)}}}),r}function f(){var e=a();t.getPlaceholder().trigger("plotselected",[e]),e.xaxis&&e.yaxis&&t.getPlaceholder().trigger("selected",[{x1:e.xaxis.from,y1:e.yaxis.from,x2:e.xaxis.to,y2:e.yaxis.to}])}function l(e,t,n){return t<e?e:t>n?n:t}function c(e,r){var i=t.getOptions(),s=t.getPlaceholder().offset(),o=t.getPlotOffset();e.x=l(0,r.pageX-s.left-o.left,t.width()),e.y=l(0,r.pageY-s.top-o.top,t.height()),i.selection.mode=="y"&&(e.x=e==n.first?0:t.width()),i.selection.mode=="x"&&(e.y=e==n.first?0:t.height())}function h(e){if(e.pageX==null)return;c(n.second,e),m()?(n.show=!0,t.triggerRedrawOverlay()):p(!0)}function p(e){n.show&&(n.show=!1,t.triggerRedrawOverlay(),e||t.getPlaceholder().trigger("plotunselected",[]))}function d(e,n){var r,i,s,o,u=t.getAxes();for(var a in u){r=u[a];if(r.direction==n){o=n+r.n+"axis",!e[o]&&r.n==1&&(o=n+"axis");if(e[o]){i=e[o].from,s=e[o].to;break}}}e[o]||(r=n=="x"?t.getXAxes()[0]:t.getYAxes()[0],i=e[n+"1"],s=e[n+"2"]);if(i!=null&&s!=null&&i>s){var f=i;i=s,s=f}return{from:i,to:s,axis:r}}function v(e,r){var i,s,o=t.getOptions();o.selection.mode=="y"?(n.first.x=0,n.second.x=t.width()):(s=d(e,"x"),n.first.x=s.axis.p2c(s.from),n.second.x=s.axis.p2c(s.to)),o.selection.mode=="x"?(n.first.y=0,n.second.y=t.height()):(s=d(e,"y"),n.first.y=s.axis.p2c(s.from),n.second.y=s.axis.p2c(s.to)),n.show=!0,t.triggerRedrawOverlay(),!r&&m()&&f()}function m(){var e=t.getOptions().selection.minSize;return Math.abs(n.second.x-n.first.x)>=e&&Math.abs(n.second.y-n.first.y)>=e}var n={first:{x:-1,y:-1},second:{x:-1,y:-1},show:!1,active:!1},r={},i=null;t.clearSelection=p,t.setSelection=v,t.getSelection=a,t.hooks.bindEvents.push(function(e,t){var n=e.getOptions();n.selection.mode!=null&&(t.mousemove(s),t.mousedown(o))}),t.hooks.drawOverlay.push(function(t,r){if(n.show&&m()){var i=t.getPlotOffset(),s=t.getOptions();r.save(),r.translate(i.left,i.top);var o=e.color.parse(s.selection.color);r.strokeStyle=o.scale("a",.8).toString(),r.lineWidth=1,r.lineJoin=s.selection.shape,r.fillStyle=o.scale("a",.4).toString();var u=Math.min(n.first.x,n.second.x)+.5,a=Math.min(n.first.y,n.second.y)+.5,f=Math.abs(n.second.x-n.first.x)-1,l=Math.abs(n.second.y-n.first.y)-1;r.fillRect(u,a,f,l),r.strokeRect(u,a,f,l),r.restore()}}),t.hooks.shutdown.push(function(t,n){n.unbind("mousemove",s),n.unbind("mousedown",o),i&&e(document).unbind("mouseup",i)})}e.plot.plugins.push({init:t,options:{selection:{mode:null,color:"#e8cfac",shape:"round",minSize:5}},name:"selection",version:"1.1"})})(jQuery);
@@ -0,0 +1,188 @@
1
+ /* Flot plugin for stacking data sets rather than overlyaing them.
2
+
3
+ Copyright (c) 2007-2013 IOLA and Ole Laursen.
4
+ Licensed under the MIT license.
5
+
6
+ The plugin assumes the data is sorted on x (or y if stacking horizontally).
7
+ For line charts, it is assumed that if a line has an undefined gap (from a
8
+ null point), then the line above it should have the same gap - insert zeros
9
+ instead of "null" if you want another behaviour. This also holds for the start
10
+ and end of the chart. Note that stacking a mix of positive and negative values
11
+ in most instances doesn't make sense (so it looks weird).
12
+
13
+ Two or more series are stacked when their "stack" attribute is set to the same
14
+ key (which can be any number or string or just "true"). To specify the default
15
+ stack, you can set the stack option like this:
16
+
17
+ series: {
18
+ stack: null/false, true, or a key (number/string)
19
+ }
20
+
21
+ You can also specify it for a single series, like this:
22
+
23
+ $.plot( $("#placeholder"), [{
24
+ data: [ ... ],
25
+ stack: true
26
+ }])
27
+
28
+ The stacking order is determined by the order of the data series in the array
29
+ (later series end up on top of the previous).
30
+
31
+ Internally, the plugin modifies the datapoints in each series, adding an
32
+ offset to the y value. For line series, extra data points are inserted through
33
+ interpolation. If there's a second y value, it's also adjusted (e.g for bar
34
+ charts or filled areas).
35
+
36
+ */
37
+
38
+ (function ($) {
39
+ var options = {
40
+ series: { stack: null } // or number/string
41
+ };
42
+
43
+ function init(plot) {
44
+ function findMatchingSeries(s, allseries) {
45
+ var res = null;
46
+ for (var i = 0; i < allseries.length; ++i) {
47
+ if (s == allseries[i])
48
+ break;
49
+
50
+ if (allseries[i].stack == s.stack)
51
+ res = allseries[i];
52
+ }
53
+
54
+ return res;
55
+ }
56
+
57
+ function stackData(plot, s, datapoints) {
58
+ if (s.stack == null || s.stack === false)
59
+ return;
60
+
61
+ var other = findMatchingSeries(s, plot.getData());
62
+ if (!other)
63
+ return;
64
+
65
+ var ps = datapoints.pointsize,
66
+ points = datapoints.points,
67
+ otherps = other.datapoints.pointsize,
68
+ otherpoints = other.datapoints.points,
69
+ newpoints = [],
70
+ px, py, intery, qx, qy, bottom,
71
+ withlines = s.lines.show,
72
+ horizontal = s.bars.horizontal,
73
+ withbottom = ps > 2 && (horizontal ? datapoints.format[2].x : datapoints.format[2].y),
74
+ withsteps = withlines && s.lines.steps,
75
+ fromgap = true,
76
+ keyOffset = horizontal ? 1 : 0,
77
+ accumulateOffset = horizontal ? 0 : 1,
78
+ i = 0, j = 0, l, m;
79
+
80
+ while (true) {
81
+ if (i >= points.length)
82
+ break;
83
+
84
+ l = newpoints.length;
85
+
86
+ if (points[i] == null) {
87
+ // copy gaps
88
+ for (m = 0; m < ps; ++m)
89
+ newpoints.push(points[i + m]);
90
+ i += ps;
91
+ }
92
+ else if (j >= otherpoints.length) {
93
+ // for lines, we can't use the rest of the points
94
+ if (!withlines) {
95
+ for (m = 0; m < ps; ++m)
96
+ newpoints.push(points[i + m]);
97
+ }
98
+ i += ps;
99
+ }
100
+ else if (otherpoints[j] == null) {
101
+ // oops, got a gap
102
+ for (m = 0; m < ps; ++m)
103
+ newpoints.push(null);
104
+ fromgap = true;
105
+ j += otherps;
106
+ }
107
+ else {
108
+ // cases where we actually got two points
109
+ px = points[i + keyOffset];
110
+ py = points[i + accumulateOffset];
111
+ qx = otherpoints[j + keyOffset];
112
+ qy = otherpoints[j + accumulateOffset];
113
+ bottom = 0;
114
+
115
+ if (px == qx) {
116
+ for (m = 0; m < ps; ++m)
117
+ newpoints.push(points[i + m]);
118
+
119
+ newpoints[l + accumulateOffset] += qy;
120
+ bottom = qy;
121
+
122
+ i += ps;
123
+ j += otherps;
124
+ }
125
+ else if (px > qx) {
126
+ // we got past point below, might need to
127
+ // insert interpolated extra point
128
+ if (withlines && i > 0 && points[i - ps] != null) {
129
+ intery = py + (points[i - ps + accumulateOffset] - py) * (qx - px) / (points[i - ps + keyOffset] - px);
130
+ newpoints.push(qx);
131
+ newpoints.push(intery + qy);
132
+ for (m = 2; m < ps; ++m)
133
+ newpoints.push(points[i + m]);
134
+ bottom = qy;
135
+ }
136
+
137
+ j += otherps;
138
+ }
139
+ else { // px < qx
140
+ if (fromgap && withlines) {
141
+ // if we come from a gap, we just skip this point
142
+ i += ps;
143
+ continue;
144
+ }
145
+
146
+ for (m = 0; m < ps; ++m)
147
+ newpoints.push(points[i + m]);
148
+
149
+ // we might be able to interpolate a point below,
150
+ // this can give us a better y
151
+ if (withlines && j > 0 && otherpoints[j - otherps] != null)
152
+ bottom = qy + (otherpoints[j - otherps + accumulateOffset] - qy) * (px - qx) / (otherpoints[j - otherps + keyOffset] - qx);
153
+
154
+ newpoints[l + accumulateOffset] += bottom;
155
+
156
+ i += ps;
157
+ }
158
+
159
+ fromgap = false;
160
+
161
+ if (l != newpoints.length && withbottom)
162
+ newpoints[l + 2] += bottom;
163
+ }
164
+
165
+ // maintain the line steps invariant
166
+ if (withsteps && l != newpoints.length && l > 0
167
+ && newpoints[l] != null
168
+ && newpoints[l] != newpoints[l - ps]
169
+ && newpoints[l + 1] != newpoints[l - ps + 1]) {
170
+ for (m = 0; m < ps; ++m)
171
+ newpoints[l + ps + m] = newpoints[l + m];
172
+ newpoints[l + 1] = newpoints[l - ps + 1];
173
+ }
174
+ }
175
+
176
+ datapoints.points = newpoints;
177
+ }
178
+
179
+ plot.hooks.processDatapoints.push(stackData);
180
+ }
181
+
182
+ $.plot.plugins.push({
183
+ init: init,
184
+ options: options,
185
+ name: 'stack',
186
+ version: '1.2'
187
+ });
188
+ })(jQuery);
@@ -0,0 +1,36 @@
1
+ /* Flot plugin for stacking data sets rather than overlyaing them.
2
+
3
+ Copyright (c) 2007-2013 IOLA and Ole Laursen.
4
+ Licensed under the MIT license.
5
+
6
+ The plugin assumes the data is sorted on x (or y if stacking horizontally).
7
+ For line charts, it is assumed that if a line has an undefined gap (from a
8
+ null point), then the line above it should have the same gap - insert zeros
9
+ instead of "null" if you want another behaviour. This also holds for the start
10
+ and end of the chart. Note that stacking a mix of positive and negative values
11
+ in most instances doesn't make sense (so it looks weird).
12
+
13
+ Two or more series are stacked when their "stack" attribute is set to the same
14
+ key (which can be any number or string or just "true"). To specify the default
15
+ stack, you can set the stack option like this:
16
+
17
+ series: {
18
+ stack: null/false, true, or a key (number/string)
19
+ }
20
+
21
+ You can also specify it for a single series, like this:
22
+
23
+ $.plot( $("#placeholder"), [{
24
+ data: [ ... ],
25
+ stack: true
26
+ }])
27
+
28
+ The stacking order is determined by the order of the data series in the array
29
+ (later series end up on top of the previous).
30
+
31
+ Internally, the plugin modifies the datapoints in each series, adding an
32
+ offset to the y value. For line series, extra data points are inserted through
33
+ interpolation. If there's a second y value, it's also adjusted (e.g for bar
34
+ charts or filled areas).
35
+
36
+ */(function(e){function n(e){function t(e,t){var n=null;for(var r=0;r<t.length;++r){if(e==t[r])break;t[r].stack==e.stack&&(n=t[r])}return n}function n(e,n,r){if(n.stack==null||n.stack===!1)return;var i=t(n,e.getData());if(!i)return;var s=r.pointsize,o=r.points,u=i.datapoints.pointsize,a=i.datapoints.points,f=[],l,c,h,p,d,v,m=n.lines.show,g=n.bars.horizontal,y=s>2&&(g?r.format[2].x:r.format[2].y),b=m&&n.lines.steps,w=!0,E=g?1:0,S=g?0:1,x=0,T=0,N,C;for(;;){if(x>=o.length)break;N=f.length;if(o[x]==null){for(C=0;C<s;++C)f.push(o[x+C]);x+=s}else if(T>=a.length){if(!m)for(C=0;C<s;++C)f.push(o[x+C]);x+=s}else if(a[T]==null){for(C=0;C<s;++C)f.push(null);w=!0,T+=u}else{l=o[x+E],c=o[x+S],p=a[T+E],d=a[T+S],v=0;if(l==p){for(C=0;C<s;++C)f.push(o[x+C]);f[N+S]+=d,v=d,x+=s,T+=u}else if(l>p){if(m&&x>0&&o[x-s]!=null){h=c+(o[x-s+S]-c)*(p-l)/(o[x-s+E]-l),f.push(p),f.push(h+d);for(C=2;C<s;++C)f.push(o[x+C]);v=d}T+=u}else{if(w&&m){x+=s;continue}for(C=0;C<s;++C)f.push(o[x+C]);m&&T>0&&a[T-u]!=null&&(v=d+(a[T-u+S]-d)*(l-p)/(a[T-u+E]-p)),f[N+S]+=v,x+=s}w=!1,N!=f.length&&y&&(f[N+2]+=v)}if(b&&N!=f.length&&N>0&&f[N]!=null&&f[N]!=f[N-s]&&f[N+1]!=f[N-s+1]){for(C=0;C<s;++C)f[N+s+C]=f[N+C];f[N+1]=f[N-s+1]}}r.points=f}e.hooks.processDatapoints.push(n)}var t={series:{stack:null}};e.plot.plugins.push({init:n,options:t,name:"stack",version:"1.2"})})(jQuery);
@@ -0,0 +1,71 @@
1
+ /* Flot plugin that adds some extra symbols for plotting points.
2
+
3
+ Copyright (c) 2007-2013 IOLA and Ole Laursen.
4
+ Licensed under the MIT license.
5
+
6
+ The symbols are accessed as strings through the standard symbol options:
7
+
8
+ series: {
9
+ points: {
10
+ symbol: "square" // or "diamond", "triangle", "cross"
11
+ }
12
+ }
13
+
14
+ */
15
+
16
+ (function ($) {
17
+ function processRawData(plot, series, datapoints) {
18
+ // we normalize the area of each symbol so it is approximately the
19
+ // same as a circle of the given radius
20
+
21
+ var handlers = {
22
+ square: function (ctx, x, y, radius, shadow) {
23
+ // pi * r^2 = (2s)^2 => s = r * sqrt(pi)/2
24
+ var size = radius * Math.sqrt(Math.PI) / 2;
25
+ ctx.rect(x - size, y - size, size + size, size + size);
26
+ },
27
+ diamond: function (ctx, x, y, radius, shadow) {
28
+ // pi * r^2 = 2s^2 => s = r * sqrt(pi/2)
29
+ var size = radius * Math.sqrt(Math.PI / 2);
30
+ ctx.moveTo(x - size, y);
31
+ ctx.lineTo(x, y - size);
32
+ ctx.lineTo(x + size, y);
33
+ ctx.lineTo(x, y + size);
34
+ ctx.lineTo(x - size, y);
35
+ },
36
+ triangle: function (ctx, x, y, radius, shadow) {
37
+ // pi * r^2 = 1/2 * s^2 * sin (pi / 3) => s = r * sqrt(2 * pi / sin(pi / 3))
38
+ var size = radius * Math.sqrt(2 * Math.PI / Math.sin(Math.PI / 3));
39
+ var height = size * Math.sin(Math.PI / 3);
40
+ ctx.moveTo(x - size/2, y + height/2);
41
+ ctx.lineTo(x + size/2, y + height/2);
42
+ if (!shadow) {
43
+ ctx.lineTo(x, y - height/2);
44
+ ctx.lineTo(x - size/2, y + height/2);
45
+ }
46
+ },
47
+ cross: function (ctx, x, y, radius, shadow) {
48
+ // pi * r^2 = (2s)^2 => s = r * sqrt(pi)/2
49
+ var size = radius * Math.sqrt(Math.PI) / 2;
50
+ ctx.moveTo(x - size, y - size);
51
+ ctx.lineTo(x + size, y + size);
52
+ ctx.moveTo(x - size, y + size);
53
+ ctx.lineTo(x + size, y - size);
54
+ }
55
+ };
56
+
57
+ var s = series.points.symbol;
58
+ if (handlers[s])
59
+ series.points.symbol = handlers[s];
60
+ }
61
+
62
+ function init(plot) {
63
+ plot.hooks.processDatapoints.push(processRawData);
64
+ }
65
+
66
+ $.plot.plugins.push({
67
+ init: init,
68
+ name: 'symbols',
69
+ version: '1.0'
70
+ });
71
+ })(jQuery);
@@ -0,0 +1,14 @@
1
+ /* Flot plugin that adds some extra symbols for plotting points.
2
+
3
+ Copyright (c) 2007-2013 IOLA and Ole Laursen.
4
+ Licensed under the MIT license.
5
+
6
+ The symbols are accessed as strings through the standard symbol options:
7
+
8
+ series: {
9
+ points: {
10
+ symbol: "square" // or "diamond", "triangle", "cross"
11
+ }
12
+ }
13
+
14
+ */(function(e){function t(e,t,n){var r={square:function(e,t,n,r,i){var s=r*Math.sqrt(Math.PI)/2;e.rect(t-s,n-s,s+s,s+s)},diamond:function(e,t,n,r,i){var s=r*Math.sqrt(Math.PI/2);e.moveTo(t-s,n),e.lineTo(t,n-s),e.lineTo(t+s,n),e.lineTo(t,n+s),e.lineTo(t-s,n)},triangle:function(e,t,n,r,i){var s=r*Math.sqrt(2*Math.PI/Math.sin(Math.PI/3)),o=s*Math.sin(Math.PI/3);e.moveTo(t-s/2,n+o/2),e.lineTo(t+s/2,n+o/2),i||(e.lineTo(t,n-o/2),e.lineTo(t-s/2,n+o/2))},cross:function(e,t,n,r,i){var s=r*Math.sqrt(Math.PI)/2;e.moveTo(t-s,n-s),e.lineTo(t+s,n+s),e.moveTo(t-s,n+s),e.lineTo(t+s,n-s)}},i=t.points.symbol;r[i]&&(t.points.symbol=r[i])}function n(e){e.hooks.processDatapoints.push(t)}e.plot.plugins.push({init:n,name:"symbols",version:"1.0"})})(jQuery);
@@ -0,0 +1,142 @@
1
+ /* Flot plugin for thresholding data.
2
+
3
+ Copyright (c) 2007-2013 IOLA and Ole Laursen.
4
+ Licensed under the MIT license.
5
+
6
+ The plugin supports these options:
7
+
8
+ series: {
9
+ threshold: {
10
+ below: number
11
+ color: colorspec
12
+ }
13
+ }
14
+
15
+ It can also be applied to a single series, like this:
16
+
17
+ $.plot( $("#placeholder"), [{
18
+ data: [ ... ],
19
+ threshold: { ... }
20
+ }])
21
+
22
+ An array can be passed for multiple thresholding, like this:
23
+
24
+ threshold: [{
25
+ below: number1
26
+ color: color1
27
+ },{
28
+ below: number2
29
+ color: color2
30
+ }]
31
+
32
+ These multiple threshold objects can be passed in any order since they are
33
+ sorted by the processing function.
34
+
35
+ The data points below "below" are drawn with the specified color. This makes
36
+ it easy to mark points below 0, e.g. for budget data.
37
+
38
+ Internally, the plugin works by splitting the data into two series, above and
39
+ below the threshold. The extra series below the threshold will have its label
40
+ cleared and the special "originSeries" attribute set to the original series.
41
+ You may need to check for this in hover events.
42
+
43
+ */
44
+
45
+ (function ($) {
46
+ var options = {
47
+ series: { threshold: null } // or { below: number, color: color spec}
48
+ };
49
+
50
+ function init(plot) {
51
+ function thresholdData(plot, s, datapoints, below, color) {
52
+ var ps = datapoints.pointsize, i, x, y, p, prevp,
53
+ thresholded = $.extend({}, s); // note: shallow copy
54
+
55
+ thresholded.datapoints = { points: [], pointsize: ps, format: datapoints.format };
56
+ thresholded.label = null;
57
+ thresholded.color = color;
58
+ thresholded.threshold = null;
59
+ thresholded.originSeries = s;
60
+ thresholded.data = [];
61
+
62
+ var origpoints = datapoints.points,
63
+ addCrossingPoints = s.lines.show;
64
+
65
+ var threspoints = [];
66
+ var newpoints = [];
67
+ var m;
68
+
69
+ for (i = 0; i < origpoints.length; i += ps) {
70
+ x = origpoints[i];
71
+ y = origpoints[i + 1];
72
+
73
+ prevp = p;
74
+ if (y < below)
75
+ p = threspoints;
76
+ else
77
+ p = newpoints;
78
+
79
+ if (addCrossingPoints && prevp != p && x != null
80
+ && i > 0 && origpoints[i - ps] != null) {
81
+ var interx = x + (below - y) * (x - origpoints[i - ps]) / (y - origpoints[i - ps + 1]);
82
+ prevp.push(interx);
83
+ prevp.push(below);
84
+ for (m = 2; m < ps; ++m)
85
+ prevp.push(origpoints[i + m]);
86
+
87
+ p.push(null); // start new segment
88
+ p.push(null);
89
+ for (m = 2; m < ps; ++m)
90
+ p.push(origpoints[i + m]);
91
+ p.push(interx);
92
+ p.push(below);
93
+ for (m = 2; m < ps; ++m)
94
+ p.push(origpoints[i + m]);
95
+ }
96
+
97
+ p.push(x);
98
+ p.push(y);
99
+ for (m = 2; m < ps; ++m)
100
+ p.push(origpoints[i + m]);
101
+ }
102
+
103
+ datapoints.points = newpoints;
104
+ thresholded.datapoints.points = threspoints;
105
+
106
+ if (thresholded.datapoints.points.length > 0) {
107
+ var origIndex = $.inArray(s, plot.getData());
108
+ // Insert newly-generated series right after original one (to prevent it from becoming top-most)
109
+ plot.getData().splice(origIndex + 1, 0, thresholded);
110
+ }
111
+
112
+ // FIXME: there are probably some edge cases left in bars
113
+ }
114
+
115
+ function processThresholds(plot, s, datapoints) {
116
+ if (!s.threshold)
117
+ return;
118
+
119
+ if (s.threshold instanceof Array) {
120
+ s.threshold.sort(function(a, b) {
121
+ return a.below - b.below;
122
+ });
123
+
124
+ $(s.threshold).each(function(i, th) {
125
+ thresholdData(plot, s, datapoints, th.below, th.color);
126
+ });
127
+ }
128
+ else {
129
+ thresholdData(plot, s, datapoints, s.threshold.below, s.threshold.color);
130
+ }
131
+ }
132
+
133
+ plot.hooks.processDatapoints.push(processThresholds);
134
+ }
135
+
136
+ $.plot.plugins.push({
137
+ init: init,
138
+ options: options,
139
+ name: 'threshold',
140
+ version: '1.2'
141
+ });
142
+ })(jQuery);