alchemy 1.0.3 → 8.4.4

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 (189) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +24 -17
  3. data/README.md +538 -4
  4. data/lib/alchemy.rb +3 -2
  5. metadata +61 -223
  6. data/Rakefile +0 -21
  7. data/app/assets/fonts/alchemy/LiberationSans-Bold-webfont.eot +0 -0
  8. data/app/assets/fonts/alchemy/LiberationSans-Bold-webfont.svg +0 -154
  9. data/app/assets/fonts/alchemy/LiberationSans-Bold-webfont.ttf +0 -0
  10. data/app/assets/fonts/alchemy/LiberationSans-Bold-webfont.woff +0 -0
  11. data/app/assets/fonts/alchemy/LiberationSans-BoldItalic-webfont.eot +0 -0
  12. data/app/assets/fonts/alchemy/LiberationSans-BoldItalic-webfont.svg +0 -154
  13. data/app/assets/fonts/alchemy/LiberationSans-BoldItalic-webfont.ttf +0 -0
  14. data/app/assets/fonts/alchemy/LiberationSans-BoldItalic-webfont.woff +0 -0
  15. data/app/assets/fonts/alchemy/LiberationSans-Italic-webfont.eot +0 -0
  16. data/app/assets/fonts/alchemy/LiberationSans-Italic-webfont.svg +0 -154
  17. data/app/assets/fonts/alchemy/LiberationSans-Italic-webfont.ttf +0 -0
  18. data/app/assets/fonts/alchemy/LiberationSans-Italic-webfont.woff +0 -0
  19. data/app/assets/fonts/alchemy/LiberationSans-Regular-webfont.eot +0 -0
  20. data/app/assets/fonts/alchemy/LiberationSans-Regular-webfont.svg +0 -154
  21. data/app/assets/fonts/alchemy/LiberationSans-Regular-webfont.ttf +0 -0
  22. data/app/assets/fonts/alchemy/LiberationSans-Regular-webfont.woff +0 -0
  23. data/app/assets/fonts/alchemy/Red Hat Liberation License.txt +0 -78
  24. data/app/assets/fonts/alchemy/overpass_bold-web.eot +0 -0
  25. data/app/assets/fonts/alchemy/overpass_bold-web.svg +0 -470
  26. data/app/assets/fonts/alchemy/overpass_bold-web.ttf +0 -0
  27. data/app/assets/fonts/alchemy/overpass_bold-web.woff +0 -0
  28. data/app/assets/fonts/alchemy/overpass_regular-web.eot +0 -0
  29. data/app/assets/fonts/alchemy/overpass_regular-web.svg +0 -470
  30. data/app/assets/fonts/alchemy/overpass_regular-web.ttf +0 -0
  31. data/app/assets/fonts/alchemy/overpass_regular-web.woff +0 -0
  32. data/app/assets/images/alchemy/icons/action-icons.png +0 -0
  33. data/app/assets/images/alchemy/icons/arrow_icon.png +0 -0
  34. data/app/assets/images/alchemy/icons/chosen-sprite.png +0 -0
  35. data/app/assets/images/alchemy/icons/error_icon.png +0 -0
  36. data/app/assets/images/alchemy/icons/objects.png +0 -0
  37. data/app/assets/images/alchemy/icons/spinner.gif +0 -0
  38. data/app/assets/images/alchemy/icons/spinner_head.gif +0 -0
  39. data/app/assets/images/alchemy/icons/success_icon.png +0 -0
  40. data/app/assets/images/alchemy/icons/warning_icon.png +0 -0
  41. data/app/assets/javascripts/alchemy/flash_messages.js +0 -12
  42. data/app/assets/javascripts/alchemy/forms.js +0 -25
  43. data/app/assets/javascripts/alchemy/i18n.js +0 -36
  44. data/app/assets/javascripts/alchemy/login.js +0 -130
  45. data/app/assets/javascripts/alchemy/password.js +0 -99
  46. data/app/assets/stylesheets/alchemy/components/_chosen.scss +0 -423
  47. data/app/assets/stylesheets/alchemy/components/_content.scss +0 -58
  48. data/app/assets/stylesheets/alchemy/components/_helpers.scss +0 -38
  49. data/app/assets/stylesheets/alchemy/components/_media.scss +0 -49
  50. data/app/assets/stylesheets/alchemy/components/_media_object.scss +0 -22
  51. data/app/assets/stylesheets/alchemy/components/_normalize.scss +0 -396
  52. data/app/assets/stylesheets/alchemy/components/_shared.scss +0 -18
  53. data/app/assets/stylesheets/alchemy/components/buttons/_buttons.scss +0 -278
  54. data/app/assets/stylesheets/alchemy/components/buttons/_buttons_vars.scss +0 -11
  55. data/app/assets/stylesheets/alchemy/components/flash_messages/_flash_messages.scss +0 -93
  56. data/app/assets/stylesheets/alchemy/components/flash_messages/_flash_messages_vars.scss +0 -3
  57. data/app/assets/stylesheets/alchemy/components/fonts/_liberation.scss +0 -44
  58. data/app/assets/stylesheets/alchemy/components/fonts/_overpass.scss +0 -24
  59. data/app/assets/stylesheets/alchemy/components/footer/_footer.scss +0 -53
  60. data/app/assets/stylesheets/alchemy/components/footer/_footer_vars.scss +0 -4
  61. data/app/assets/stylesheets/alchemy/components/forms/_forms.scss +0 -552
  62. data/app/assets/stylesheets/alchemy/components/forms/_forms_ie.scss +0 -45
  63. data/app/assets/stylesheets/alchemy/components/forms/_forms_mixins.scss +0 -18
  64. data/app/assets/stylesheets/alchemy/components/forms/_forms_responsive.scss +0 -167
  65. data/app/assets/stylesheets/alchemy/components/forms/_forms_vars.scss +0 -25
  66. data/app/assets/stylesheets/alchemy/components/header/_header.scss +0 -216
  67. data/app/assets/stylesheets/alchemy/components/header/_header_vars.scss +0 -11
  68. data/app/assets/stylesheets/alchemy/components/login/_login.scss +0 -173
  69. data/app/assets/stylesheets/alchemy/components/login/_login_mixins.scss +0 -7
  70. data/app/assets/stylesheets/alchemy/components/login/_login_vars.scss +0 -19
  71. data/app/assets/stylesheets/alchemy/components/sprites/_sprites.scss +0 -110
  72. data/app/assets/stylesheets/alchemy/components/sprites/_sprites_mixins.scss +0 -9
  73. data/app/assets/stylesheets/alchemy/components/text/_text.scss +0 -30
  74. data/app/assets/stylesheets/alchemy/components/text/_text_vars.scss +0 -1
  75. data/app/assets/stylesheets/alchemy/composites/content_elements.scss +0 -6
  76. data/app/assets/stylesheets/alchemy/composites/login.scss +0 -9
  77. data/app/assets/stylesheets/alchemy/composites/shell.scss +0 -4
  78. data/app/assets/stylesheets/alchemy/partials/_base.scss +0 -8
  79. data/app/assets/stylesheets/alchemy/partials/_colors.scss +0 -99
  80. data/app/assets/stylesheets/alchemy/partials/_mixins.scss +0 -24
  81. data/app/assets/stylesheets/alchemy/partials/_vars.scss +0 -31
  82. data/app/helpers/alchemy/gettext_translations.rb +0 -28
  83. data/app/helpers/alchemy/layout_helper.rb +0 -35
  84. data/app/helpers/alchemy/rails_translations.rb +0 -21
  85. data/app/helpers/alchemy/translation_helper.rb +0 -19
  86. data/app/views/alchemy/layouts/_change_password_layout.html.haml +0 -20
  87. data/app/views/alchemy/layouts/_common_i18n.haml +0 -4
  88. data/app/views/alchemy/layouts/_header_layout.haml +0 -13
  89. data/app/views/alchemy/layouts/_login_layout.html.haml +0 -58
  90. data/app/views/alchemy/layouts/_user_session_layout.haml +0 -17
  91. data/app/views/alchemy/layouts/base.html.haml +0 -20
  92. data/app/views/alchemy/layouts/shell_layout.haml +0 -10
  93. data/lib/alchemy/engine.rb +0 -8
  94. data/lib/alchemy/version.rb +0 -3
  95. data/test/alchemy_test.rb +0 -7
  96. data/test/test_helper.rb +0 -9
  97. data/vendor/assets/javascripts/alchemy/handlebars.js +0 -2201
  98. data/vendor/assets/javascripts/alchemy/html5shiv.js +0 -298
  99. data/vendor/assets/javascripts/alchemy/jquery/jquery-1.6.2.js +0 -8981
  100. data/vendor/assets/javascripts/alchemy/jquery/plugins/chosen.jquery.js +0 -1003
  101. data/vendor/assets/javascripts/alchemy/jquery/plugins/flot-0.7/excanvas.js +0 -1427
  102. data/vendor/assets/javascripts/alchemy/jquery/plugins/flot-0.7/excanvas.min.js +0 -1
  103. data/vendor/assets/javascripts/alchemy/jquery/plugins/flot-0.7/jquery.colorhelpers.js +0 -179
  104. data/vendor/assets/javascripts/alchemy/jquery/plugins/flot-0.7/jquery.colorhelpers.min.js +0 -1
  105. data/vendor/assets/javascripts/alchemy/jquery/plugins/flot-0.7/jquery.flot.crosshair.js +0 -167
  106. data/vendor/assets/javascripts/alchemy/jquery/plugins/flot-0.7/jquery.flot.crosshair.min.js +0 -1
  107. data/vendor/assets/javascripts/alchemy/jquery/plugins/flot-0.7/jquery.flot.fillbetween.js +0 -183
  108. data/vendor/assets/javascripts/alchemy/jquery/plugins/flot-0.7/jquery.flot.fillbetween.min.js +0 -1
  109. data/vendor/assets/javascripts/alchemy/jquery/plugins/flot-0.7/jquery.flot.image.js +0 -238
  110. data/vendor/assets/javascripts/alchemy/jquery/plugins/flot-0.7/jquery.flot.image.min.js +0 -1
  111. data/vendor/assets/javascripts/alchemy/jquery/plugins/flot-0.7/jquery.flot.js +0 -2599
  112. data/vendor/assets/javascripts/alchemy/jquery/plugins/flot-0.7/jquery.flot.min.js +0 -6
  113. data/vendor/assets/javascripts/alchemy/jquery/plugins/flot-0.7/jquery.flot.navigate.js +0 -336
  114. data/vendor/assets/javascripts/alchemy/jquery/plugins/flot-0.7/jquery.flot.navigate.min.js +0 -1
  115. data/vendor/assets/javascripts/alchemy/jquery/plugins/flot-0.7/jquery.flot.pie.js +0 -750
  116. data/vendor/assets/javascripts/alchemy/jquery/plugins/flot-0.7/jquery.flot.pie.min.js +0 -1
  117. data/vendor/assets/javascripts/alchemy/jquery/plugins/flot-0.7/jquery.flot.resize.js +0 -60
  118. data/vendor/assets/javascripts/alchemy/jquery/plugins/flot-0.7/jquery.flot.resize.min.js +0 -1
  119. data/vendor/assets/javascripts/alchemy/jquery/plugins/flot-0.7/jquery.flot.selection.js +0 -344
  120. data/vendor/assets/javascripts/alchemy/jquery/plugins/flot-0.7/jquery.flot.selection.min.js +0 -1
  121. data/vendor/assets/javascripts/alchemy/jquery/plugins/flot-0.7/jquery.flot.stack.js +0 -184
  122. data/vendor/assets/javascripts/alchemy/jquery/plugins/flot-0.7/jquery.flot.stack.min.js +0 -1
  123. data/vendor/assets/javascripts/alchemy/jquery/plugins/flot-0.7/jquery.flot.symbol.js +0 -70
  124. data/vendor/assets/javascripts/alchemy/jquery/plugins/flot-0.7/jquery.flot.symbol.min.js +0 -1
  125. data/vendor/assets/javascripts/alchemy/jquery/plugins/flot-0.7/jquery.flot.threshold.js +0 -103
  126. data/vendor/assets/javascripts/alchemy/jquery/plugins/flot-0.7/jquery.flot.threshold.min.js +0 -1
  127. data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery-svg/blank.svg +0 -3
  128. data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery-svg/custom_test.js +0 -67
  129. data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery-svg/jquery.svg.css +0 -9
  130. data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery-svg/jquery.svg.js +0 -1101
  131. data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery-svg/jquery.svg.min.js +0 -7
  132. data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery-svg/jquery.svg.pack.js +0 -7
  133. data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery-svg/jquery.svgfilter.js +0 -396
  134. data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery-svg/jquery.svgfilter.min.js +0 -7
  135. data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery-svg/jquery.svgfilter.pack.js +0 -7
  136. data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery-svg/jquery.svggraph.js +0 -1337
  137. data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery-svg/jquery.svggraph.min.js +0 -7
  138. data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery-svg/jquery.svggraph.pack.js +0 -7
  139. data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery-svg/lion.svg +0 -161
  140. data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery-svg/test.js +0 -714
  141. data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.ajaxfileupload.js +0 -205
  142. data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.ba-bbq.js +0 -1137
  143. data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.ba-resize.js +0 -246
  144. data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.cookie.js +0 -92
  145. data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.easing.1.3.js +0 -205
  146. data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.fancyqueries.js +0 -106
  147. data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.flash.js +0 -288
  148. data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.form.js +0 -964
  149. data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.hoverIntent.js +0 -106
  150. data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.jeditable.ajaxupload.js +0 -62
  151. data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.jeditable.js +0 -556
  152. data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.jnotify.js +0 -210
  153. data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.jscrollpane.js +0 -1390
  154. data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.jscrollpane.min.js +0 -11
  155. data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.linkHover.js +0 -89
  156. data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.loadmask.min.js +0 -10
  157. data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.mousewheel.js +0 -78
  158. data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.multiselect.filter.js +0 -176
  159. data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.multiselect.js +0 -668
  160. data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.pack.js +0 -11
  161. data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.periodicalupdater.js +0 -175
  162. data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.sortElements.js +0 -75
  163. data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.sparkline.min.js +0 -94
  164. data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.text-overflow.js +0 -60
  165. data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.timepickr.js +0 -214
  166. data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.timers.js +0 -142
  167. data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.tipsy.js +0 -358
  168. data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.treeTable.js +0 -226
  169. data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.trunk8.js +0 -203
  170. data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.ui.multiselect.js +0 -338
  171. data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.ui.totop.js +0 -58
  172. data/vendor/assets/javascripts/alchemy/jquery/plugins/jquery.uitablefilter.js +0 -95
  173. data/vendor/assets/javascripts/alchemy/jquery/plugins/ui.spinner.js +0 -683
  174. data/vendor/assets/javascripts/alchemy/jquery-ui-1.8.11.custom/css/custom-theme/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  175. data/vendor/assets/javascripts/alchemy/jquery-ui-1.8.11.custom/css/custom-theme/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  176. data/vendor/assets/javascripts/alchemy/jquery-ui-1.8.11.custom/css/custom-theme/images/ui-bg_highlight-hard_75_dadada_1x100.png +0 -0
  177. data/vendor/assets/javascripts/alchemy/jquery-ui-1.8.11.custom/css/custom-theme/images/ui-bg_highlight-hard_75_e6e6e6_1x100.png +0 -0
  178. data/vendor/assets/javascripts/alchemy/jquery-ui-1.8.11.custom/css/custom-theme/images/ui-bg_highlight-hard_95_ffffff_1x100.png +0 -0
  179. data/vendor/assets/javascripts/alchemy/jquery-ui-1.8.11.custom/css/custom-theme/images/ui-bg_highlight-soft_80_e0e0e0_1x100.png +0 -0
  180. data/vendor/assets/javascripts/alchemy/jquery-ui-1.8.11.custom/css/custom-theme/images/ui-bg_inset-hard_65_ffffff_1x100.png +0 -0
  181. data/vendor/assets/javascripts/alchemy/jquery-ui-1.8.11.custom/css/custom-theme/images/ui-bg_inset-soft_95_fef1ec_1x100.png +0 -0
  182. data/vendor/assets/javascripts/alchemy/jquery-ui-1.8.11.custom/css/custom-theme/images/ui-icons_8f8f8f_256x240.png +0 -0
  183. data/vendor/assets/javascripts/alchemy/jquery-ui-1.8.11.custom/css/custom-theme/images/ui-icons_97baed_256x240.png +0 -0
  184. data/vendor/assets/javascripts/alchemy/jquery-ui-1.8.11.custom/css/custom-theme/images/ui-icons_cd0a0a_256x240.png +0 -0
  185. data/vendor/assets/javascripts/alchemy/jquery-ui-1.8.11.custom/css/custom-theme/jquery-ui-1.8.11.custom.css +0 -573
  186. data/vendor/assets/javascripts/alchemy/jquery-ui-1.8.11.custom/js/jquery-1.5.1.min.js +0 -16
  187. data/vendor/assets/javascripts/alchemy/jquery-ui-1.8.11.custom/js/jquery-ui-1.8.11.custom.min.js +0 -783
  188. data/vendor/assets/javascripts/alchemy/rails.js +0 -331
  189. data/vendor/assets/javascripts/alchemy/underscore-1.3.1.js +0 -999
@@ -1,1337 +0,0 @@
1
- /* http://keith-wood.name/svg.html
2
- SVG graphing extension for jQuery v1.0.1.
3
- Written by Keith Wood (kbwood@iprimus.com.au) August 2007.
4
- Dual licensed under the GPL (http://dev.jquery.com/browser/trunk/jquery/GPL-LICENSE.txt) and
5
- MIT (http://dev.jquery.com/browser/trunk/jquery/MIT-LICENSE.txt) licenses.
6
- Please attribute the author if you use it. */
7
-
8
- var svgGraphing = null;
9
-
10
- (function($) { // Hide scope, no $ conflict
11
-
12
- svgManager.addExtension('graph', SVGGraph);
13
-
14
- // Singleton primary SVG graphing interface
15
- svgGraphing = new SVGGraphing();
16
-
17
- function SVGGraphing() {
18
- this.regional = [];
19
- this.regional[''] = {percentageText: 'Percentage'};
20
- this.region = this.regional[''];
21
- }
22
-
23
- $.extend(SVGGraphing.prototype, {
24
- _chartTypes: [],
25
-
26
- /* Add a new chart rendering type to the package.
27
- The rendering object must implement the following functions:
28
- getTitle(), getDescription(), getOptions(), drawChart(graph).
29
- @param id string - the ID of this graph renderer
30
- @param chartType object - the object implementing this chart type */
31
- addChartType: function(id, chartType) {
32
- this._chartTypes[id] = chartType;
33
- },
34
-
35
- /* Retrieve the list of chart types.
36
- @return object[string] - the array of chart types indexed by ID */
37
- chartTypes: function() {
38
- return this._chartTypes;
39
- }
40
- });
41
-
42
- /* Extension point for SVG graphing.
43
- Access through root.filters. */
44
- function SVGGraph(root) {
45
- this._root = root; // The attached SVG root object
46
- this._drawNow = true; // True for immediate update, false to wait for redraw call
47
- for (var id in svgGraphing._chartTypes) {
48
- this._chartType = svgGraphing._chartTypes[id]; // Use first graph renderer
49
- break;
50
- }
51
- this._chartOptions = {}; // Extra options for the graph type
52
- // The graph title and settings
53
- this._title = {value: '', offset: 25, settings: {text_anchor: 'middle'}};
54
- this._area = [0.1, 0.1, 0.8, 0.9]; // The chart area: left, top, right, bottom,
55
- // > 1 in pixels, <= 1 as proportion
56
- this._chartFormat = {fill: 'none', stroke: 'black'}; // The formatting for the chart area
57
- this._gridlines = []; // The formatting of the x- and y-gridlines
58
- this._series = []; // The series to be plotted, each is an object
59
- this._onstatus = null; // The callback function for status updates
60
- this._chartGroup = this._root.group(null, 'graph'); // The main group for the graph
61
-
62
- this.xAxis = new SVGGraphAxis(); // The main x-axis
63
- this.xAxis.title('', 40);
64
- this.yAxis = new SVGGraphAxis(); // The main y-axis
65
- this.yAxis.title('', 40);
66
- this.x2Axis = null; // The secondary x-axis
67
- this.y2Axis = null; // The secondary y-axis
68
- this.legend = new SVGGraphLegend(); // The chart legend
69
- }
70
-
71
- $.extend(SVGGraph.prototype, {
72
-
73
- /* Useful indexes. */
74
- X: 0,
75
- Y: 1,
76
- W: 2,
77
- H: 3,
78
- L: 0,
79
- T: 1,
80
- R: 2,
81
- B: 3,
82
-
83
- /* Standard percentage axis. */
84
- _percentageAxis: new SVGGraphAxis(svgGraphing.region.percentageText, 0, 100, 10, 0),
85
-
86
- /* Set or retrieve the type of chart to be rendered.
87
- See svgGraphing.getChartTypes() for the list of available types.
88
- @param id string - the ID of the chart type
89
- @param options object - additional settings for this chart type (optional)
90
- @return SVGGraph - this graph object or
91
- string - the chart type (if no parameters) */
92
- chartType: function(id, options) {
93
- if (arguments.length == 0) {
94
- return this._chartType;
95
- }
96
- var chartType = svgGraphing._chartTypes[id];
97
- if (chartType) {
98
- this._chartType = chartType;
99
- this._chartOptions = $.extend({}, options || {});
100
- }
101
- this._drawGraph();
102
- return this;
103
- },
104
-
105
- /* Set or retrieve additional options for the particular chart type.
106
- @param options object - the extra options
107
- @return SVGGraph - this graph object or
108
- object - the chart options (if no parameters) */
109
- chartOptions: function(options) {
110
- if (arguments.length == 0) {
111
- return this._chartOptions;
112
- }
113
- this._chartOptions = $.extend({}, options);
114
- this._drawGraph();
115
- return this;
116
- },
117
-
118
- /* Set or retrieve the background of the graph chart.
119
- @param fill string - how to fill the chart background
120
- @param stroke string - the colour of the outline (optional)
121
- @param settings object - additional formatting for the chart background (optional)
122
- @return SVGGraph - this graph object or
123
- object - the chart format (if no parameters) */
124
- chartFormat: function(fill, stroke, settings) {
125
- if (arguments.length == 0) {
126
- return this._chartFormat;
127
- }
128
- if (typeof stroke == 'object') {
129
- settings = stroke;
130
- stroke = null;
131
- }
132
- this._chartFormat = $.extend($.extend({fill: fill},
133
- (stroke ? {stroke: stroke} : {})), settings || {});
134
- this._drawGraph();
135
- return this;
136
- },
137
-
138
- /* Set or retrieve the main chart area.
139
- @param left number - > 1 is pixels, <= 1 is proportion of width or
140
- number[4] - for left, top, right, bottom
141
- @param top number - > 1 is pixels, <= 1 is proportion of height
142
- @param right number - > 1 is pixels, <= 1 is proportion of width
143
- @param bottom number - > 1 is pixels, <= 1 is proportion of height
144
- @return SVGGraph - this graph object or
145
- number[4] - the chart area: left, top, right, bottom (if no parameters) */
146
- chartArea: function(left, top, right, bottom) {
147
- if (arguments.length == 0) {
148
- return this._area;
149
- }
150
- this._area = (isArray(left) ? left : [left, top, right, bottom]);
151
- this._drawGraph();
152
- return this;
153
- },
154
-
155
- /* Set or retrieve the gridlines formatting for the graph chart.
156
- @param xSettings string - the colour of the gridlines along the x-axis, or
157
- object - formatting for the gridlines along the x-axis, or
158
- null for none
159
- @param ySettings string - the colour of the gridlines along the y-axis, or
160
- object - formatting for the gridlines along the y-axis, or
161
- null for none
162
- @return SVGGraph - this graph object or
163
- object[2] - the gridlines formatting (if no parameters) */
164
- gridlines: function(xSettings, ySettings) {
165
- if (arguments.length == 0) {
166
- return this._gridlines;
167
- }
168
- this._gridlines = [(typeof xSettings == 'string' ? {stroke: xSettings} : xSettings),
169
- (typeof ySettings == 'string' ? {stroke: ySettings} : ySettings)];
170
- this._drawGraph();
171
- return this;
172
- },
173
-
174
- /* Set or retrieve the title of the graph and its formatting.
175
- @param value string - the title
176
- @param offset number - the vertical positioning of the title
177
- > 1 is pixels, <= 1 is proportion of width (optional)
178
- @param settings object - formatting for the title (optional)
179
- @return SVGGraph - this graph object or
180
- object - value, offset, and settings for the title (if no parameters) */
181
- title: function(value, offset, settings) {
182
- if (arguments.length == 0) {
183
- return this._title;
184
- }
185
- if (typeof offset == 'object') {
186
- settings = offset;
187
- offset = null;
188
- }
189
- this._title = {value: value, offset: offset || this._title.offset,
190
- settings: $.extend({text_anchor: 'middle'}, settings || {})};
191
- this._drawGraph();
192
- return this;
193
- },
194
-
195
- /* Add a series of values to be plotted on the graph.
196
- @param name string - the name of this series
197
- @param values number[] - the values to be plotted
198
- @param fill string - how the plotted values are filled
199
- @param stroke string - the colour of the plotted lines
200
- @param strokeWidth number - the width of the plotted lines (optional)
201
- @param settings object - additional settings for the plotted values (optional)
202
- @return SVGGraph - this graph object */
203
- addSeries: function(name, values, fill, stroke, strokeWidth, settings) {
204
- if (typeof strokeWidth == 'object') {
205
- settings = strokeWidth;
206
- strokeWidth = null;
207
- }
208
- this._series[this._series.length] =
209
- new SVGGraphSeries(name, values, fill, stroke, strokeWidth, settings || {});
210
- this._drawGraph();
211
- return this;
212
- },
213
-
214
- /* Retrieve the series wrappers.
215
- @return SVGGraphSeries[] - the list of series */
216
- series: function() {
217
- return this._series;
218
- },
219
-
220
- /* Suppress drawing of the graph until redraw() is called.
221
- @return SVGGraph - this graph object */
222
- noDraw: function() {
223
- this._drawNow = false;
224
- return this;
225
- },
226
-
227
- /* Redraw the entire graph with the current settings and values.
228
- @return SVGGraph - this graph object */
229
- redraw: function() {
230
- this._drawNow = true;
231
- this._drawGraph();
232
- return this;
233
- },
234
-
235
- /* Set the callback function for status updates.
236
- @param onstatus function - the callback function
237
- @return SVGGraph - this graph object */
238
- status: function(onstatus) {
239
- this._onstatus = onstatus;
240
- return this;
241
- },
242
-
243
- /* Actually draw the graph (if allowed) based on the graph type set. */
244
- _drawGraph: function() {
245
- if (!this._drawNow) {
246
- return;
247
- }
248
- while (this._chartGroup.firstChild) {
249
- this._chartGroup.removeChild(this._chartGroup.firstChild);
250
- }
251
- if (!this._chartGroup.parent) {
252
- this._root._svg.appendChild(this._chartGroup);
253
- }
254
- this._chartType.drawGraph(this);
255
- },
256
-
257
- /* Draw the graph title - centred. */
258
- _drawTitle: function() {
259
- this._root.text(this._chartGroup, this._root._width() / 2, this._title.offset,
260
- this._title.value, this._title.settings);
261
- },
262
-
263
- /* Calculate the actual dimensions of the chart area.
264
- @param area number[4] - the area values to evaluate (optional)
265
- @return an array of dimension values: left, top, width, height */
266
- _getDims: function(area) {
267
- area = area || this._area;
268
- var left = (area[this.L] > 1 ? area[this.L] :
269
- this._root._width() * area[this.L]);
270
- var top = (area[this.T] > 1 ? area[this.T] :
271
- this._root._height() * area[this.T]);
272
- var width = (area[this.R] > 1 ? area[this.R] :
273
- this._root._width() * area[this.R]) - left;
274
- var height = (area[this.B] > 1 ? area[this.B] :
275
- this._root._height() * area[this.B]) - top;
276
- return [left, top, width, height];
277
- },
278
-
279
- /* Draw the chart background, including gridlines.
280
- @param noXGrid boolean - true to suppress the x-gridlines, false to draw them (optional)
281
- @param noYGrid boolean - true to suppress the y-gridlines, false to draw them (optional)
282
- @return the background group element */
283
- _drawChartBackground: function(noXGrid, noYGrid) {
284
- var bg = this._root.group(this._chartGroup, 'background');
285
- var dims = this._getDims();
286
- this._root.rect(bg, dims[this.X], dims[this.Y], dims[this.W], dims[this.H], this._chartFormat);
287
- if (this._gridlines[0] && this.yAxis._ticks.major && !noYGrid) {
288
- this._drawGridlines(bg, this.yAxis, true, dims, this._gridlines[0]);
289
- }
290
- if (this._gridlines[1] && this.xAxis._ticks.major && !noXGrid) {
291
- this._drawGridlines(bg, this.xAxis, false, dims, this._gridlines[1]);
292
- }
293
- return bg;
294
- },
295
-
296
- /* Draw one set of gridlines.
297
- @param bg element - the background group element
298
- @param axis SVGGraphAxis - the axis definition
299
- @param horiz boolean - true if horizontal, false if vertical
300
- @param dims number[] - the left, top, width, height of the chart area
301
- @param format object - additional settings for the gridlines */
302
- _drawGridlines: function(bg, axis, horiz, dims, format) {
303
- var g = this._root.group(bg, format);
304
- var scale = (horiz ? dims[this.H] : dims[this.W]) / (axis._scale.max - axis._scale.min);
305
- var major = Math.floor(axis._scale.min / axis._ticks.major) * axis._ticks.major;
306
- major = (major < axis._scale.min ? major + axis._ticks.major : major);
307
- while (major <= axis._scale.max) {
308
- var v = (horiz ? axis._scale.max - major : major - axis._scale.min) * scale +
309
- (horiz ? dims[this.Y] : dims[this.X]);
310
- this._root.line(g, (horiz ? dims[this.X] : v), (horiz ? v : dims[this.Y]),
311
- (horiz ? dims[this.X] + dims[this.W] : v), (horiz ? v : dims[this.Y] + dims[this.H]));
312
- major += axis._ticks.major;
313
- }
314
- },
315
-
316
- /* Draw the axes in their standard configuration.
317
- @param noX boolean - true to suppress the x-axes, false to draw it (optional) */
318
- _drawAxes: function(noX) {
319
- var dims = this._getDims();
320
- if (this.xAxis && !noX) {
321
- if (this.xAxis._title) {
322
- this._root.text(this._chartGroup, dims[this.X] + dims[this.W] / 2,
323
- dims[this.Y] + dims[this.H] + this.xAxis._titleOffset, this.xAxis._title);
324
- }
325
- this._drawAxis(this.xAxis, 'xAxis', dims[this.X], dims[this.Y] + dims[this.H],
326
- dims[this.X] + dims[this.W], dims[this.Y] + dims[this.H]);
327
- }
328
- if (this.yAxis) {
329
- if (this.yAxis._title) {
330
- this._root.text(this._chartGroup, 0, 0, this.yAxis._title, {text_anchor: 'middle',
331
- transform: 'translate(' + (dims[this.X] - this.yAxis._titleOffset) + ',' +
332
- (dims[this.Y] + dims[this.H] / 2) + ') rotate(-90)'});
333
- }
334
- this._drawAxis(this.yAxis, 'yAxis', dims[this.X], dims[this.Y],
335
- dims[this.X], dims[this.Y] + dims[this.H]);
336
- }
337
- if (this.x2Axis && !noX) {
338
- if (this.x2Axis._title) {
339
- this._root.text(this._chartGroup, dims[this.X] + dims[this.W] / 2,
340
- dims[this.X] - this.x2Axis._titleOffset, this.x2Axis._title);
341
- }
342
- this._drawAxis(this.x2Axis, 'x2Axis', dims[this.X], dims[this.Y],
343
- dims[this.X] + dims[this.W], dims[this.Y]);
344
- }
345
- if (this.y2Axis) {
346
- if (this.y2Axis._title) {
347
- this._root.text(this._chartGroup, 0, 0, this.y2Axis._title, {text_anchor: 'middle',
348
- transform: 'translate(' + (dims[this.X] + dims[this.W] + this.y2Axis._titleOffset) +
349
- ',' + (dims[this.Y] + dims[this.H] / 2) + ') rotate(-90)'});
350
- }
351
- this._drawAxis(this.y2Axis, 'y2Axis', dims[this.X] + dims[this.W], dims[this.Y],
352
- dims[this.X] + dims[this.W], dims[this.Y] + dims[this.H]);
353
- }
354
- },
355
-
356
- /* Draw an axis and its tick marks.
357
- @param axis SVGGraphAxis - the axis definition
358
- @param id string - the identifier for the axis group element
359
- @param x1 number - starting x-coodinate for the axis
360
- @param y1 number - starting y-coodinate for the axis
361
- @param x2 number - ending x-coodinate for the axis
362
- @param y2 number - ending y-coodinate for the axis */
363
- _drawAxis: function(axis, id, x1, y1, x2, y2) {
364
- var horiz = (y1 == y2);
365
- var gl = this._root.group(this._chartGroup, id, axis._lineFormat);
366
- var gt = this._root.group(this._chartGroup, id + 'Labels',
367
- $.extend({text_anchor: (horiz ? 'middle' : 'end')}, axis._labelFormat));
368
- this._root.line(gl, x1, y1, x2, y2);
369
- if (axis._ticks.major) {
370
- var bottomRight = (x2 > (this._root._width() / 2) &&
371
- y2 > (this._root._height() / 2));
372
- var scale = (horiz ? x2 - x1 : y2 - y1) / (axis._scale.max - axis._scale.min);
373
- var size = axis._ticks.size;
374
- var major = Math.floor(axis._scale.min / axis._ticks.major) * axis._ticks.major;
375
- major = (major < axis._scale.min ? major + axis._ticks.major : major);
376
- var minor = (!axis._ticks.minor ? axis._scale.max + 1 :
377
- Math.floor(axis._scale.min / axis._ticks.minor) * axis._ticks.minor);
378
- minor = (minor < axis._scale.min ? minor + axis._ticks.minor : minor);
379
- var offsets = this._getTickOffsets(axis, bottomRight);
380
- while (major <= axis._scale.max || minor <= axis._scale.max) {
381
- var cur = Math.min(major, minor);
382
- var len = (cur == major ? size : size / 2);
383
- var v = (horiz ? x1 : y1) +
384
- (horiz ? cur - axis._scale.min : axis._scale.max - cur) * scale;
385
- this._root.line(gl, (horiz ? v : x1 + len * offsets[0]),
386
- (horiz ? y1 + len * offsets[0] : v),
387
- (horiz ? v : x1 + len * offsets[1]),
388
- (horiz ? y1 + len * offsets[1] : v));
389
- if (cur == major) {
390
- this._root.text(gt, (horiz ? v : x1 - size), (horiz ? y1 + 2 * size : v),
391
- (axis._labels ? axis._labels[cur] : '' + cur));
392
- }
393
- major += (cur == major ? axis._ticks.major : 0);
394
- minor += (cur == minor ? axis._ticks.minor : 0);
395
- }
396
- }
397
- },
398
-
399
- /* Calculate offsets based on axis and tick positions.
400
- @param axis SVGGraphAxis - the axis definition
401
- @param bottomRight boolean - true if this axis is appearing on the bottom or
402
- right of the chart area, false if to the top or left
403
- @return the array of offset multipliers (-1..+1) */
404
- _getTickOffsets: function(axis, bottomRight) {
405
- return [(axis._ticks.position == (bottomRight ? 'in' : 'out') ||
406
- axis._ticks.position == 'both' ? -1 : 0),
407
- (axis._ticks.position == (bottomRight ? 'out' : 'in') ||
408
- axis._ticks.position == 'both' ? +1 : 0), ];
409
- },
410
-
411
- /* Retrieve the standard percentage axis.
412
- @return percentage axis */
413
- _getPercentageAxis: function() {
414
- this._percentageAxis._title = svgGraphing.region.percentageText;
415
- return this._percentageAxis;
416
- },
417
-
418
- /* Calculate the column totals across all the series. */
419
- _getTotals: function() {
420
- var totals = [];
421
- var numVal = (this._series.length ? this._series[0]._values.length : 0);
422
- for (var i = 0; i < numVal; i++) {
423
- totals[i] = 0;
424
- for (var j = 0; j < this._series.length; j++) {
425
- totals[i] += this._series[j]._values[i];
426
- }
427
- }
428
- return totals;
429
- },
430
-
431
- /* Draw the chart legend. */
432
- _drawLegend: function() {
433
- if (!this.legend._show) {
434
- return;
435
- }
436
- var g = this._root.group(this._chartGroup, 'legend');
437
- var dims = this._getDims(this.legend._area);
438
- this._root.rect(g, dims[this.X], dims[this.Y], dims[this.W], dims[this.H],
439
- this.legend._bgSettings);
440
- var horiz = dims[this.W] > dims[this.H];
441
- var numSer = this._series.length;
442
- var offset = (horiz ? dims[this.W] : dims[this.H]) / numSer;
443
- var xBase = dims[this.X] + 5;
444
- var yBase = dims[this.Y] + (horiz ? dims[this.H] / 2 : offset / 2);
445
- for (var i = 0; i < numSer; i++) {
446
- var series = this._series[i];
447
- this._root.rect(g, xBase + (horiz ? i * offset : 0),
448
- yBase + (horiz ? 0 : i * offset) - this.legend._sampleSize,
449
- this.legend._sampleSize, this.legend._sampleSize,
450
- {fill: series._fill, stroke: series._stroke, stroke_width: 1});
451
- this._root.text(g, xBase + (horiz ? i * offset : 0) + this.legend._sampleSize + 5,
452
- yBase + (horiz ? 0 : i * offset), series._name, this.legend._textSettings);
453
- }
454
- },
455
-
456
- /* Show the current value status on hover. */
457
- _showStatus: function(value) {
458
- var onStatus = (!this._onstatus ? '' :
459
- this._onstatus.toString().replace(/function (.*)\([\s\S]*/m, '$1'));
460
- return (!this._onstatus ? {} :
461
- {onmouseover: 'window.parent.' + onStatus + '(\'' + value + '\');',
462
- onmouseout: 'window.parent.' + onStatus + '(\'\');'});
463
- }
464
- });
465
-
466
- /* Details about each graph axis.
467
- @param title string - the title of the axis
468
- @param min number - the minimum value displayed on this axis
469
- @param max number - the maximum value displayed on this axis
470
- @param major number - the distance between major ticks
471
- @param minor number - the distance between minor ticks (optional)
472
- @return the new axis object */
473
- function SVGGraphAxis(title, min, max, major, minor) {
474
- /* Title of this axis. */
475
- this._title = title || '';
476
- /* Formatting settings for the title. */
477
- this._titleFormat = {};
478
- /* The offset for positioning the title. */
479
- this._titleOffset = 0;
480
- /* List of labels for this axis - one per possible value across all series. */
481
- this._labels = null;
482
- /* Formatting settings for the labels. */
483
- this._labelFormat = {};
484
- /* Formatting settings for the axis lines. */
485
- this._lineFormat = {stroke: 'black'};
486
- /* Tick mark options. */
487
- this._ticks = {major: major || 10, minor: minor || 0, size: 10, position: 'out'};
488
- /* Axis scale settings. */
489
- this._scale = {min: min || 0, max: max || 100};
490
- /* Where this axis crosses the other one. */
491
- this._crossAt = 0;
492
- }
493
-
494
- $.extend(SVGGraphAxis.prototype, {
495
-
496
- /* Set or retrieve the scale for this axis.
497
- @param min number - the minimum value shown
498
- @param max number - the maximum value shown
499
- @return SVGGraphAxis - this axis object or
500
- object - min and max values (if no parameters) */
501
- scale: function(min, max) {
502
- if (arguments.length == 0) {
503
- return this._scale;
504
- }
505
- this._scale.min = min;
506
- this._scale.max = max;
507
- return this;
508
- },
509
-
510
- /* Set or retrieve the ticks for this axis.
511
- @param major number - the distance between major ticks
512
- @param minor number - the distance between minor ticks
513
- @param size number - the length of the major ticks (minor are half) (optional)
514
- @param position string - the location of the ticks:
515
- 'in', 'out', 'both' (optional)
516
- @return SVGGraphAxis - this axis object or
517
- object - major, minor, size, and position values (if no parameters) */
518
- ticks: function(major, minor, size, position) {
519
- if (arguments.length == 0) {
520
- return this._ticks;
521
- }
522
- if (typeof size == 'string') {
523
- position = size;
524
- size = null;
525
- }
526
- this._ticks.major = major;
527
- this._ticks.minor = minor;
528
- this._ticks.size = size || 10;
529
- this._ticks.position = position || 'out';
530
- return this;
531
- },
532
-
533
- /* Set or retrieve the title for this axis.
534
- @param title string - the title text
535
- @param offset number - the distance to offset the title position (optional)
536
- @param format object - formatting settings for the title (optional)
537
- @return SVGGraphAxis - this axis object or
538
- object - title, offset, and format values (if no parameters) */
539
- title: function(title, offset, format) {
540
- if (arguments.length == 0) {
541
- return {title: this._title, offset: this._titleOffset, format: this._titleFormat};
542
- }
543
- if (typeof offset == 'object') {
544
- format = offset;
545
- offset = null;
546
- }
547
- this._title = title;
548
- if (offset != null) {
549
- this._titleOffset = offset;
550
- }
551
- if (format) {
552
- this._titleFormat = format;
553
- }
554
- return this;
555
- },
556
-
557
- /* Set or retrieve the labels for this axis.
558
- @param labels string[] - the text for each entry
559
- @param format object - formatting settings for the labels (optional)
560
- @return SVGGraphAxis - this axis object or
561
- object - labels and format values (if no parameters) */
562
- labels: function(labels, format) {
563
- if (arguments.length == 0) {
564
- return {labels: this._labels, format: this._labelFormat};
565
- }
566
- this._labels = labels;
567
- if (format) {
568
- this._labelFormat = format;
569
- }
570
- return this;
571
- },
572
-
573
- /* Set or retrieve the line formatting for this axis.
574
- @param colour string - the line's colour
575
- @param width number - the line's width (optional)
576
- @param settings object - additional formatting settings for the line (optional)
577
- @return SVGGraphAxis - this axis object or
578
- object - line formatting values (if no parameters) */
579
- line: function(colour, width, settings) {
580
- if (arguments.length == 0) {
581
- return this._lineFormat;
582
- }
583
- if (typeof width == 'object') {
584
- settings = width;
585
- width = null;
586
- }
587
- $.extend(this._lineFormat, {stroke: colour, stroke_width: width || 1});
588
- $.extend(this._lineFormat, settings || {});
589
- return this;
590
- }
591
- });
592
-
593
- var defaultSeriesFill = 'green';
594
- var defaultSeriesStroke = 'black';
595
-
596
- /* Details about each graph series.
597
- @param name string - the name of this series
598
- @param values number[] - the list of values to be plotted
599
- @param fill string - how the series should be displayed
600
- @param stroke string - the colour of the (out)line for the series
601
- @param strokeWidth number - the width of the (out)line for the series
602
- @param settings object - additional formatting settings
603
- @return the new series object */
604
- function SVGGraphSeries(name, values, fill, stroke, strokeWidth, settings) {
605
- /* The name of this series. */
606
- this._name = name || '';
607
- /* The list of values for this series. */
608
- this._values = values || [];
609
- /* Which axis this series applies to: 1 = primary, 2 = secondary. */
610
- this._axis = 1;
611
- /* How the series is plotted. */
612
- this._fill = fill || defaultSeriesFill;
613
- /* The colour for the (out)line. */
614
- this._stroke = stroke || defaultSeriesStroke;
615
- /* The (out)line width. */
616
- this._strokeWidth = strokeWidth || 1;
617
- /* Additional formatting settings for the series. */
618
- this._settings = settings || {};
619
- }
620
-
621
- $.extend(SVGGraphSeries.prototype, {
622
-
623
- /* Set or retrieve the name for this series.
624
- @param name string - the series' name
625
- @return SVGGraphSeries - this series object or
626
- string - the series name (if no parameters) */
627
- name: function(name) {
628
- if (arguments.length == 0) {
629
- return this._name;
630
- }
631
- this._name = name;
632
- return this;
633
- },
634
-
635
- /* Set or retrieve the values for this series.
636
- @param name string - the series' name (optional)
637
- @param values number[] - the values to be graphed
638
- @return SVGGraphSeries - this series object or
639
- number[] - the series values (if no parameters) */
640
- values: function(name, values) {
641
- if (arguments.length == 0) {
642
- return this._values;
643
- }
644
- if (isArray(name)) {
645
- valus = name;
646
- name = null;
647
- }
648
- this._name = name || this._name;
649
- this._values = values;
650
- return this;
651
- },
652
-
653
- /* Set or retrieve the formatting for this series.
654
- @param fill string - how the values are filled when plotted
655
- @param stroke string - the (out)line colour
656
- @param strokeWidth number - the line's width (optional)
657
- @param settings object - additional formatting settings for the series (optional)
658
- @return SVGGraphSeries - this series object or
659
- object - formatting settings (if no parameters) */
660
- format: function(fill, stroke, strokeWidth, settings) {
661
- if (arguments.length == 0) {
662
- return $.extend({fill: this._fill, stroke: this._stroke,
663
- stroke_width: this._strokeWidth}, this._settings);
664
- }
665
- if (typeof strokeWidth == 'object') {
666
- settings = strokeWidth;
667
- strokeWidth = null;
668
- }
669
- this._fill = fill || defaultSeriesFill;
670
- this._stroke = stroke || this._stroke;
671
- this._strokeWidth = strokeWidth || this._strokeWidth;
672
- $.extend(this._settings, settings || {});
673
- return this;
674
- }
675
- });
676
-
677
- /* Details about the graph legend.
678
- @param bgSettings object - additional formatting settings for the legend background (optional)
679
- @param textSettings object - additional formatting settings for the legend text (optional)
680
- @return the new legend object */
681
- function SVGGraphLegend(bgSettings, textSettings) {
682
- this._show = true; // Show the legend?
683
- this._area = [0.9, 0.1, 1.0, 0.9]; // The legend area: left, top, right, bottom,
684
- // > 1 in pixels, <= 1 as proportion
685
- this._sampleSize = 15; // Size of sample box
686
- this._bgSettings = bgSettings || {stroke: 'gray'}; // Additional formatting settings for the legend background
687
- this._textSettings = textSettings || {}; // Additional formatting settings for the text
688
- }
689
-
690
- $.extend(SVGGraphLegend.prototype, {
691
-
692
- /* Set or retrieve whether the legend should be shown.
693
- @param show boolean - true to display it, false to hide it
694
- @return SVGGraphLegend - this legend object or
695
- boolean - show the legend? (if no parameters) */
696
- show: function(show) {
697
- if (arguments.length == 0) {
698
- return this._show;
699
- }
700
- this._show = show;
701
- return this;
702
- },
703
-
704
- /* Set or retrieve the legend area.
705
- @param left number - > 1 is pixels, <= 1 is proportion of width or
706
- number[4] - for left, top, right, bottom
707
- @param top number - > 1 is pixels, <= 1 is proportion of height
708
- @param right number - > 1 is pixels, <= 1 is proportion of width
709
- @param bottom number - > 1 is pixels, <= 1 is proportion of height
710
- @return SVGGraphLegend - this legend object or
711
- number[4] - the legend area: left, top, right, bottom (if no parameters) */
712
- area: function(left, top, right, bottom) {
713
- if (arguments.length == 0) {
714
- return this._area;
715
- }
716
- this._area = (isArray(left) ? left : [left, top, right, bottom]);
717
- return this;
718
- },
719
-
720
- /* Set or retrieve additional settings for the legend area.
721
- @param sampleSize number - the size of the sample box to display (optional)
722
- @param bgSettings object - additional formatting settings for the legend background
723
- @param textSettings object - additional formatting settings for the legend text (optional)
724
- @return SVGGraphLegend - this legend object or
725
- object - bgSettings and textSettings for the legend (if no parameters) */
726
- settings: function(sampleSize, bgSettings, textSettings) {
727
- if (arguments.length == 0) {
728
- return {sampleSize: this._sampleSize, bgSettings: this._bgSettings,
729
- textSettings: this._textSettings};
730
- }
731
- if (typeof sampleSize == 'object') {
732
- textSettings = bgSettings;
733
- bgSettings = sampleSize;
734
- sampleSize = null;
735
- }
736
- if (sampleSize) {
737
- this._sampleSize = sampleSize;
738
- }
739
- this._bgSettings = bgSettings;
740
- if (textSettings) {
741
- this._textSettings = textSettings;
742
- }
743
- return this;
744
- }
745
- });
746
-
747
- //==============================================================================
748
-
749
- /* Round a number to a given number of decimal points. */
750
- function roundNumber(num, dec) {
751
- return Math.round(num * Math.pow(10, dec)) / Math.pow(10, dec);
752
- }
753
-
754
- var barOptions = ['barWidth (number) - the width of each bar',
755
- 'barGap (number) - the gap between sets of bars'];
756
-
757
- //------------------------------------------------------------------------------
758
-
759
- /* Draw a standard grouped column bar chart. */
760
- function SVGColumnChart() {
761
- }
762
-
763
- $.extend(SVGColumnChart.prototype, {
764
-
765
- /* Retrieve the display title for this chart type.
766
- @return the title */
767
- title: function() {
768
- return 'Basic column chart';
769
- },
770
-
771
- /* Retrieve a description of this chart type.
772
- @return its description */
773
- description: function() {
774
- return 'Compare sets of values as vertical bars with grouped categories.';
775
- },
776
-
777
- /* Retrieve a list of the options that may be set for this chart type.
778
- @return options list */
779
- options: function() {
780
- return barOptions;
781
- },
782
-
783
- /* Actually draw the graph in this type's style.
784
- @param graph object - the SVGGraph object */
785
- drawGraph: function(graph) {
786
- graph._drawChartBackground(true);
787
- var barWidth = graph._chartOptions.barWidth || 10;
788
- var barGap = graph._chartOptions.barGap || 10;
789
- var numSer = graph._series.length;
790
- var numVal = (numSer ? (graph._series[0])._values.length : 0);
791
- var dims = graph._getDims();
792
- var xScale = dims[graph.W] / ((numSer * barWidth + barGap) * numVal + barGap);
793
- var yScale = dims[graph.H] / (graph.yAxis._scale.max - graph.yAxis._scale.min);
794
- this._chart = graph._root.group(graph._chartGroup, 'chart');
795
- for (var i = 0; i < numSer; i++) {
796
- this._drawSeries(graph, i, numSer, barWidth, barGap, dims, xScale, yScale);
797
- }
798
- graph._drawTitle();
799
- graph._drawAxes(true);
800
- this._drawXAxis(graph, numSer, numVal, barWidth, barGap, dims, xScale);
801
- graph._drawLegend();
802
- },
803
-
804
- /* Plot an individual series. */
805
- _drawSeries: function(graph, cur, numSer, barWidth, barGap, dims, xScale, yScale) {
806
- var series = graph._series[cur];
807
- var g = graph._root.group(this._chart, 'series' + cur,
808
- $.extend({stroke: series._stroke,
809
- stroke_width: series._strokeWidth}, series._settings || {}));
810
- for (var i = 0; i < series._values.length; i++) {
811
- graph._root.rect(g,
812
- dims[graph.X] + xScale * (barGap + i * (numSer * barWidth + barGap) + (cur * barWidth)),
813
- dims[graph.Y] + yScale * (graph.yAxis._scale.max - series._values[i]),
814
- xScale * barWidth, yScale * series._values[i], $.extend({fill: series._fill},
815
- graph._showStatus(series._name + ' ' + series._values[i])));
816
- }
817
- },
818
-
819
- /* Draw the x-axis and its ticks. */
820
- _drawXAxis: function(graph, numSer, numVal, barWidth, barGap, dims, xScale) {
821
- var axis = graph.xAxis;
822
- if (axis._title) {
823
- graph._root.text(graph._chartGroup, dims[graph.X] + dims[graph.W] / 2,
824
- dims[graph.Y] + dims[graph.H] + axis._titleOffset,
825
- axis._title, {text_anchor: 'middle'});
826
- }
827
- var gl = graph._root.group(graph._chartGroup, 'xAxis', axis._lineFormat);
828
- var gt = graph._root.group(graph._chartGroup, 'xAxisLabels',
829
- $.extend({text_anchor: 'middle'}, axis._labelFormat));
830
- graph._root.line(gl, dims[graph.X], dims[graph.Y] + dims[graph.H],
831
- dims[graph.X] + dims[graph.W], dims[graph.Y] + dims[graph.H]);
832
- if (axis._ticks.major) {
833
- var offsets = graph._getTickOffsets(axis, true);
834
- for (var i = 1; i < numVal; i++) {
835
- var x = dims[graph.X] + xScale * (barGap / 2 + i * (numSer * barWidth + barGap));
836
- graph._root.line(gl, x, dims[graph.Y] + dims[graph.H] + offsets[0] * axis._ticks.size,
837
- x, dims[graph.Y] + dims[graph.H] + offsets[1] * axis._ticks.size);
838
- }
839
- for (var i = 0; i < numVal; i++) {
840
- var x = dims[graph.X] + xScale * (barGap / 2 + (i + 0.5) * (numSer * barWidth + barGap));
841
- graph._root.text(gt, x, dims[graph.Y] + dims[graph.H] + 2 * axis._ticks.size,
842
- (axis._labels ? axis._labels[i] : '' + i));
843
- }
844
- }
845
- }
846
- });
847
-
848
- //------------------------------------------------------------------------------
849
-
850
- /* Draw a stacked column bar chart. */
851
- function SVGStackedColumnChart() {
852
- }
853
-
854
- $.extend(SVGStackedColumnChart.prototype, {
855
-
856
- /* Retrieve the display title for this chart type.
857
- @return the title */
858
- title: function() {
859
- return 'Stacked column chart';
860
- },
861
-
862
- /* Retrieve a description of this chart type.
863
- @return its description */
864
- description: function() {
865
- return 'Compare sets of values as vertical bars showing ' +
866
- 'relative contributions to the whole for each category.';
867
- },
868
-
869
- /* Retrieve a list of the options that may be set for this chart type.
870
- @return options list */
871
- options: function() {
872
- return barOptions;
873
- },
874
-
875
- /* Actually draw the graph in this type's style.
876
- @param graph object - the SVGGraph object */
877
- drawGraph: function(graph) {
878
- var bg = graph._drawChartBackground(true, true);
879
- var dims = graph._getDims();
880
- if (graph._gridlines[0] && graph.xAxis._ticks.major) {
881
- graph._drawGridlines(bg, graph._getPercentageAxis(), true, dims, graph._gridlines[0]);
882
- }
883
- var barWidth = graph._chartOptions.barWidth || 10;
884
- var barGap = graph._chartOptions.barGap || 10;
885
- var numSer = graph._series.length;
886
- var numVal = (numSer ? (graph._series[0])._values.length : 0);
887
- var xScale = dims[graph.W] / ((barWidth + barGap) * numVal + barGap);
888
- var yScale = dims[graph.H];
889
- this._chart = graph._root.group(graph._chartGroup, 'chart');
890
- this._drawColumns(graph, numSer, numVal, barWidth, barGap, dims, xScale, yScale);
891
- graph._drawTitle();
892
- graph._root.text(graph._chartGroup, 0, 0, svgGraphing.region.percentageText,
893
- {text_anchor: 'middle', transform: 'translate(' + (dims[graph.X] - graph.yAxis._titleOffset) +
894
- ',' +(dims[graph.Y] + dims[graph.H] / 2) + ') rotate(-90)'});
895
- //graph._drawAxis(graph._getPercentageAxis(), 'yAxis',
896
- //dims[graph.X], dims[graph.Y], dims[graph.X], dims[graph.Y] + dims[graph.H]);
897
- this._drawXAxis(graph, numVal, barWidth, barGap, dims, xScale);
898
- graph._drawLegend();
899
- },
900
-
901
- /* Plot all of the columns. */
902
- _drawColumns: function(graph, numSer, numVal, barWidth, barGap, dims, xScale, yScale) {
903
- var totals = graph._getTotals();
904
- var accum = [];
905
- for (var i = 0; i < numVal; i++) {
906
- accum[i] = 0;
907
- }
908
- for (var s = 0; s < numSer; s++) {
909
- var series = graph._series[s];
910
- var g = graph._root.group(this._chart, 'series' + s,
911
- $.extend({stroke: series._stroke, stroke_width: series._strokeWidth},
912
- series._settings || {}));
913
- for (var i = 0; i < series._values.length; i++) {
914
- accum[i] += series._values[i];
915
- graph._root.rect(g,
916
- dims[graph.X] + xScale * (barGap + i * (barWidth + barGap)),
917
- dims[graph.Y] + yScale * (totals[i] - accum[i]) / totals[i],
918
- xScale * barWidth, yScale * series._values[i] / totals[i],
919
- $.extend({fill: series._fill}, graph._showStatus(series._name + ' ' +
920
- roundNumber(series._values[i] / totals[i] * 100, 2) + '%')));
921
- }
922
- }
923
- },
924
-
925
- /* Draw the x-axis and its ticks. */
926
- _drawXAxis: function(graph, numVal, barWidth, barGap, dims, xScale) {
927
- var axis = graph.xAxis;
928
- if (axis._title) {
929
- graph._root.text(graph._chartGroup, dims[graph.X] + dims[graph.W] / 2,
930
- dims[graph.Y] + dims[graph.H] + axis._titleOffset,
931
- axis._title, {text_anchor: 'middle'});
932
- }
933
- var gl = graph._root.group(graph._chartGroup, 'xAxis', axis._lineFormat);
934
- var gt = graph._root.group(graph._chartGroup, 'xAxisLabels',
935
- $.extend({text_anchor: 'middle'}, axis._labelFormat));
936
- graph._root.line(gl, dims[graph.X], dims[graph.Y] + dims[graph.H],
937
- dims[graph.X] + dims[graph.W], dims[graph.Y] + dims[graph.H]);
938
- if (axis._ticks.major) {
939
- var offsets = graph._getTickOffsets(axis, true);
940
- for (var i = 1; i < numVal; i++) {
941
- var x = dims[graph.X] + xScale * (barGap / 2 + i * (barWidth + barGap));
942
- graph._root.line(gl, x, dims[graph.Y] + dims[graph.H] + offsets[0] * axis._ticks.size,
943
- x, dims[graph.Y] + dims[graph.H] + offsets[1] * axis._ticks.size);
944
- }
945
- for (var i = 0; i < numVal; i++) {
946
- var x = dims[graph.X] + xScale * (barGap / 2 + (i + 0.5) * (barWidth + barGap));
947
- graph._root.text(gt, x, dims[graph.Y] + dims[graph.H] + 2 * axis._ticks.size,
948
- (axis._labels ? axis._labels[i] : '' + i));
949
- }
950
- }
951
- }
952
- });
953
-
954
- //------------------------------------------------------------------------------
955
-
956
- /* Draw a standard grouped row bar chart. */
957
- function SVGRowChart() {
958
- }
959
-
960
- $.extend(SVGRowChart.prototype, {
961
-
962
- /* Retrieve the display title for this chart type.
963
- @return the title */
964
- title: function() {
965
- return 'Basic row chart';
966
- },
967
-
968
- /* Retrieve a description of this chart type.
969
- @return its description */
970
- description: function() {
971
- return 'Compare sets of values as horizontal rows with grouped categories.';
972
- },
973
-
974
- /* Retrieve a list of the options that may be set for this chart type.
975
- @return options list */
976
- options: function() {
977
- return barOptions;
978
- },
979
-
980
- /* Actually draw the graph in this type's style.
981
- @param graph object - the SVGGraph object */
982
- drawGraph: function(graph) {
983
- var bg = graph._drawChartBackground(true, true);
984
- var dims = graph._getDims();
985
- graph._drawGridlines(bg, graph.yAxis, false, dims, graph._gridlines[0]);
986
- var barWidth = graph._chartOptions.barWidth || 10;
987
- var barGap = graph._chartOptions.barGap || 10;
988
- var numSer = graph._series.length;
989
- var numVal = (numSer ? (graph._series[0])._values.length : 0);
990
- var xScale = dims[graph.W] / (graph.yAxis._scale.max - graph.yAxis._scale.min);
991
- var yScale = dims[graph.H] / ((numSer * barWidth + barGap) * numVal + barGap);
992
- this._chart = graph._root.group(graph._chartGroup, 'chart');
993
- for (var i = 0; i < numSer; i++) {
994
- this._drawSeries(graph, i, numSer, barWidth, barGap, dims, xScale, yScale);
995
- }
996
- graph._drawTitle();
997
- this._drawAxes(graph, numSer, numVal, barWidth, barGap, dims, yScale);
998
- graph._drawLegend();
999
- },
1000
-
1001
- /* Plot an individual series. */
1002
- _drawSeries: function(graph, cur, numSer, barWidth, barGap, dims, xScale, yScale) {
1003
- var series = graph._series[cur];
1004
- var g = graph._root.group(this._chart, 'series' + cur,
1005
- $.extend({stroke: series._stroke, stroke_width: series._strokeWidth},
1006
- series._settings || {}));
1007
- for (var i = 0; i < series._values.length; i++) {
1008
- graph._root.rect(g,
1009
- dims[graph.X] + xScale * (0 - graph.yAxis._scale.min),
1010
- dims[graph.Y] + yScale * (barGap + i * (numSer * barWidth + barGap) + (cur * barWidth)),
1011
- xScale * series._values[i], yScale * barWidth, $.extend({fill: series._fill},
1012
- graph._showStatus(series._name + ' ' + series._values[i])));
1013
- }
1014
- },
1015
-
1016
- /* Draw the axes for this graph. */
1017
- _drawAxes: function(graph, numSer, numVal, barWidth, barGap, dims, yScale) {
1018
- // X-axis
1019
- var axis = graph.yAxis;
1020
- if (axis) {
1021
- if (axis._title) {
1022
- graph._root.text(graph._chartGroup, dims[graph.X] + dims[graph.W] / 2,
1023
- dims[graph.Y] + dims[graph.H] + axis._titleOffset, axis._title, axis._titleFormat);
1024
- }
1025
- graph._drawAxis(axis, 'xAxis', dims[graph.X], dims[graph.Y] + dims[graph.H],
1026
- dims[graph.X] + dims[graph.W], dims[graph.Y] + dims[graph.H]);
1027
- }
1028
- // Y-axis
1029
- var axis = graph.xAxis;
1030
- if (axis._title) {
1031
- graph._root.text(graph._chartGroup, 0, 0, axis._title, {text_anchor: 'middle',
1032
- transform: 'translate(' + (dims[graph.X] - axis._titleOffset) + ',' +
1033
- (dims[graph.Y] + dims[graph.H] / 2) + ') rotate(-90)'});
1034
- }
1035
- var gl = graph._root.group(graph._chartGroup, 'yAxis', axis._lineFormat);
1036
- var gt = graph._root.group(graph._chartGroup, 'yAxisLabels',
1037
- $.extend({text_anchor: 'end'}, axis._labelFormat));
1038
- graph._root.line(gl, dims[graph.X], dims[graph.Y], dims[graph.X], dims[graph.Y] + dims[graph.H]);
1039
- if (axis._ticks.major) {
1040
- var offsets = graph._getTickOffsets(axis, false);
1041
- for (var i = 1; i < numVal; i++) {
1042
- var y = dims[graph.Y] + yScale * (barGap / 2 + i * (numSer * barWidth + barGap));
1043
- graph._root.line(gl, dims[graph.X] + offsets[0] * axis._ticks.size, y,
1044
- dims[graph.X] + offsets[1] * axis._ticks.size, y);
1045
- }
1046
- for (var i = 0; i < numVal; i++) {
1047
- var y = dims[graph.Y] + yScale * (barGap / 2 + (i + 0.5) * (numSer * barWidth + barGap));
1048
- graph._root.text(gt, dims[graph.X] - axis._ticks.size, y,
1049
- (axis._labels ? axis._labels[i] : '' + i));
1050
- }
1051
- }
1052
- }
1053
- });
1054
-
1055
- //------------------------------------------------------------------------------
1056
-
1057
- /* Draw a stacked row bar chart. */
1058
- function SVGStackedRowChart() {
1059
- }
1060
-
1061
- $.extend(SVGStackedRowChart.prototype, {
1062
-
1063
- /* Retrieve the display title for this chart type.
1064
- @return the title */
1065
- title: function() {
1066
- return 'Stacked row chart';
1067
- },
1068
-
1069
- /* Retrieve a description of this chart type.
1070
- @return its description */
1071
- description: function() {
1072
- return 'Compare sets of values as horizontal bars showing ' +
1073
- 'relative contributions to the whole for each category.';
1074
- },
1075
-
1076
- /* Retrieve a list of the options that may be set for this chart type.
1077
- @return options list */
1078
- options: function() {
1079
- return barOptions;
1080
- },
1081
-
1082
- /* Actually draw the graph in this type's style.
1083
- @param graph object - the SVGGraph object */
1084
- drawGraph: function(graph) {
1085
- var bg = graph._drawChartBackground(true, true);
1086
- var dims = graph._getDims();
1087
- if (graph._gridlines[0] && graph.xAxis._ticks.major) {
1088
- graph._drawGridlines(bg, graph._getPercentageAxis(), false, dims, graph._gridlines[0]);
1089
- }
1090
- var barWidth = graph._chartOptions.barWidth || 10;
1091
- var barGap = graph._chartOptions.barGap || 10;
1092
- var numSer = graph._series.length;
1093
- var numVal = (numSer ? (graph._series[0])._values.length : 0);
1094
- var xScale = dims[graph.W];
1095
- var yScale = dims[graph.H] / ((barWidth + barGap) * numVal + barGap);
1096
- this._chart = graph._root.group(graph._chartGroup, 'chart');
1097
- this._drawRows(graph, numSer, numVal, barWidth, barGap, dims, xScale, yScale);
1098
- graph._drawTitle();
1099
- graph._root.text(graph._chartGroup, dims[graph.X] + dims[graph.W] / 2,
1100
- dims[graph.Y] + dims[graph.H] + graph.xAxis._titleOffset,
1101
- svgGraphing.region.percentageText, {text_anchor: 'middle'});
1102
- // graph._drawAxis(graph._getPercentageAxis(), 'xAxis',
1103
- // dims[graph.X], dims[graph.Y] + dims[graph.H],
1104
- // dims[graph.X] + dims[graph.W], dims[graph.Y] + dims[graph.H]);
1105
- // this._drawYAxis(graph, numVal, barWidth, barGap, dims, yScale);
1106
- graph._drawLegend();
1107
- },
1108
-
1109
- /* Plot all of the rows. */
1110
- _drawRows: function(graph, numSer, numVal, barWidth, barGap, dims, xScale, yScale) {
1111
- var totals = graph._getTotals();
1112
- var accum = [];
1113
- for (var i = 0; i < numVal; i++) {
1114
- accum[i] = 0;
1115
- }
1116
- for (var s = 0; s < numSer; s++) {
1117
- var series = graph._series[s];
1118
- var g = graph._root.group(this._chart, 'series' + s,
1119
- $.extend({stroke: series._stroke, stroke_width: series._strokeWidth},
1120
- series._settings || {}));
1121
- for (var i = 0; i < series._values.length; i++) {
1122
- graph._root.rect(g,
1123
- dims[graph.X] + xScale * accum[i] / totals[i],
1124
- dims[graph.Y] + yScale * (barGap + i * (barWidth + barGap)),
1125
- xScale * series._values[i] / totals[i], yScale * barWidth,
1126
- $.extend({fill: series._fill}, graph._showStatus(series._name + ' ' +
1127
- roundNumber(series._values[i] / totals[i] * 100, 2) + '%')));
1128
- accum[i] += series._values[i];
1129
- }
1130
- }
1131
- },
1132
-
1133
- /* Draw the y-axis and its ticks. */
1134
- _drawYAxis: function(graph, numVal, barWidth, barGap, dims, yScale) {
1135
- var axis = graph.xAxis;
1136
- if (axis._title) {
1137
- graph._root.text(graph._chartGroup, 0, 0, axis._title, {text_anchor: 'middle',
1138
- transform: 'translate(' + (dims[graph.X] - axis._titleOffset) + ',' +
1139
- (dims[graph.Y] + dims[graph.H] / 2) + ') rotate(-90)'});
1140
- }
1141
- var gl = graph._root.group(graph._chartGroup, 'yAxis', axis._lineFormat);
1142
- var gt = graph._root.group(graph._chartGroup, 'yAxisLabels',
1143
- $.extend({text_anchor: 'end'}, axis._labelFormat));
1144
- graph._root.line(gl, dims[graph.X], dims[graph.Y], dims[graph.X], dims[graph.Y] + dims[graph.H]);
1145
- if (axis._ticks.major) {
1146
- var offsets = graph._getTickOffsets(axis, false);
1147
- for (var i = 1; i < numVal; i++) {
1148
- var y = dims[graph.Y] + yScale * (barGap / 2 + i * (barWidth + barGap));
1149
- graph._root.line(gl, dims[graph.X] + offsets[0] * axis._ticks.size, y,
1150
- dims[graph.X] + offsets[1] * axis._ticks.size, y);
1151
- }
1152
- for (var i = 0; i < numVal; i++) {
1153
- var y = dims[graph.Y] + yScale * (barGap / 2 + (i + 0.5) * (barWidth + barGap));
1154
- graph._root.text(gt, dims[graph.X] - axis._ticks.size, y,
1155
- (axis._labels ? axis._labels[i] : '' + i));
1156
- }
1157
- }
1158
- }
1159
- });
1160
-
1161
- //------------------------------------------------------------------------------
1162
-
1163
- /* Draw a standard line chart. */
1164
- function SVGLineChart() {
1165
- }
1166
-
1167
- $.extend(SVGLineChart.prototype, {
1168
-
1169
- /* Retrieve the display title for this chart type.
1170
- @return the title */
1171
- title: function() {
1172
- return 'Basic line chart';
1173
- },
1174
-
1175
- /* Retrieve a description of this chart type.
1176
- @return its description */
1177
- description: function() {
1178
- return 'Compare sets of values as continuous lines.';
1179
- },
1180
-
1181
- /* Retrieve a list of the options that may be set for this chart type.
1182
- @return options list */
1183
- options: function() {
1184
- return [];
1185
- },
1186
-
1187
- /* Actually draw the graph in this type's style.
1188
- @param graph object - the SVGGraph object */
1189
- drawGraph: function(graph) {
1190
- graph._drawChartBackground();
1191
- var dims = graph._getDims();
1192
- var xScale = dims[graph.W] / (graph.xAxis._scale.max - graph.xAxis._scale.min);
1193
- var yScale = dims[graph.H] / (graph.yAxis._scale.max - graph.yAxis._scale.min);
1194
- this._chart = graph._root.group(graph._chartGroup, 'chart');
1195
- for (var i = 0; i < graph._series.length; i++) {
1196
- this._drawSeries(graph, i, dims, xScale, yScale);
1197
- }
1198
- graph._drawTitle();
1199
- graph._drawAxes();
1200
- graph._drawLegend();
1201
- },
1202
-
1203
- /* Plot an individual series. */
1204
- _drawSeries: function(graph, cur, dims, xScale, yScale) {
1205
- var series = graph._series[cur];
1206
- var path = graph._root.createPath();
1207
- for (var i = 0; i < series._values.length; i++) {
1208
- var x = dims[graph.X] + i * xScale;
1209
- var y = dims[graph.Y] + (graph.yAxis._scale.max - series._values[i]) * yScale;
1210
- if (i == 0) {
1211
- path.moveTo(x, y);
1212
- }
1213
- else {
1214
- path.lineTo(x, y);
1215
- }
1216
- }
1217
- graph._root.path(this._chart, path,
1218
- $.extend($.extend({id: 'series' + cur, fill: 'none', stroke: series._stroke,
1219
- stroke_width: series._strokeWidth}, graph._showStatus(series._name),
1220
- series._settings || {})));
1221
- }
1222
- });
1223
-
1224
- //------------------------------------------------------------------------------
1225
-
1226
- /* Draw a standard pie chart. */
1227
- function SVGPieChart() {
1228
- }
1229
-
1230
- $.extend(SVGPieChart.prototype, {
1231
-
1232
- _options: ['explode (number[]) - indexes of sections to explode out of the pie',
1233
- 'explodeDist (number) - the distance to move an exploded section',
1234
- 'pieGap (number) - the distance between pies for multiple values'],
1235
-
1236
- /* Retrieve the display title for this chart type.
1237
- @return the title */
1238
- title: function() {
1239
- return 'Pie chart';
1240
- },
1241
-
1242
- /* Retrieve a description of this chart type.
1243
- @return its description */
1244
- description: function() {
1245
- return 'Compare relative sizes of values as contributions to the whole.';
1246
- },
1247
-
1248
- /* Retrieve a list of the options that may be set for this chart type.
1249
- @return options list */
1250
- options: function() {
1251
- return this._options;
1252
- },
1253
-
1254
- /* Actually draw the graph in this type's style.
1255
- @param graph object - the SVGGraph object */
1256
- drawGraph: function(graph) {
1257
- graph._drawChartBackground(true, true);
1258
- this._chart = graph._root.group(graph._chartGroup, 'chart');
1259
- var dims = graph._getDims();
1260
- this._drawSeries(graph, dims);
1261
- graph._drawTitle();
1262
- graph._drawLegend();
1263
- },
1264
-
1265
- /* Plot all the series. */
1266
- _drawSeries: function(graph, dims) {
1267
- var totals = graph._getTotals();
1268
- var numSer = graph._series.length;
1269
- var numVal = (numSer ? (graph._series[0])._values.length : 0);
1270
- var path = graph._root.createPath();
1271
- var explode = graph._chartOptions.explode || [];
1272
- var explodeDist = graph._chartOptions.explodeDist || 10;
1273
- var pieGap = (numVal <= 1 ? 0 : graph._chartOptions.pieGap || 10);
1274
- var xBase = (dims[graph.W] - (numVal * pieGap) - pieGap) / numVal / 2;
1275
- var yBase = dims[graph.H] / 2;
1276
- var radius = Math.min(xBase, yBase) - (explode.length > 0 ? explodeDist : 0);
1277
- var gt = graph._root.group(graph._chartGroup, 'xAxisLabels',
1278
- $.extend({text_anchor: 'middle'}, graph.xAxis._labelFormat));
1279
- var gl = [];
1280
- for (var i = 0; i < numVal; i++) {
1281
- var cx = dims[graph.X] + xBase + (i * (2 * Math.min(xBase, yBase) + pieGap)) + pieGap;
1282
- var cy = dims[graph.Y] + yBase;
1283
- var curTotal = 0;
1284
- for (var j = 0; j < numSer; j++) {
1285
- var series = graph._series[j];
1286
- if (i == 0) {
1287
- gl[j] = graph._root.group(this._chart, 'series' + j,
1288
- $.extend({stroke: series._stroke, stroke_width: series._strokeWidth},
1289
- series._settings || {}));
1290
- }
1291
- if (series._values[i] == 0) {
1292
- continue;
1293
- }
1294
- var start = (curTotal / totals[i]) * 2 * Math.PI;
1295
- curTotal += series._values[i];
1296
- var end = (curTotal / totals[i]) * 2 * Math.PI;
1297
- var exploding = false;
1298
- for (var k = 0; k < explode.length; k++) {
1299
- if (explode[k] == j) {
1300
- exploding = true;
1301
- break;
1302
- }
1303
- }
1304
- var x = cx + (exploding ? explodeDist * Math.cos((start + end) / 2) : 0);
1305
- var y = cy + (exploding ? explodeDist * Math.sin((start + end) / 2) : 0);
1306
- var status = series._name + ' ' +
1307
- roundNumber((end - start) / 2 / Math.PI * 100, 2) + '%';
1308
- graph._root.path(gl[j], path.reset().moveTo(x, y).
1309
- lineTo(x + radius * Math.cos(start), y + radius * Math.sin(start)).
1310
- arcTo(radius, radius, 0, (end - start < Math.PI ? 0 : 1), 1,
1311
- x + radius * Math.cos(end), y + radius * Math.sin(end)).close(),
1312
- $.extend({fill: series._fill}, graph._showStatus(status)));
1313
- }
1314
- if (graph.xAxis) {
1315
- graph._root.text(gt, cx, dims[graph.Y] + dims[graph.H] + graph.xAxis._titleOffset,
1316
- graph.xAxis._labels[i])
1317
- }
1318
- }
1319
- }
1320
- });
1321
-
1322
- //------------------------------------------------------------------------------
1323
-
1324
- /* Determine whether an object is an array. */
1325
- function isArray(a) {
1326
- return (a.constructor && a.constructor.toString().match(/\Array\(\)/));
1327
- }
1328
-
1329
- // Basic chart types
1330
- svgGraphing.addChartType('column', new SVGColumnChart());
1331
- svgGraphing.addChartType('stackedColumn', new SVGStackedColumnChart());
1332
- svgGraphing.addChartType('row', new SVGRowChart());
1333
- svgGraphing.addChartType('stackedRow', new SVGStackedRowChart());
1334
- svgGraphing.addChartType('line', new SVGLineChart());
1335
- svgGraphing.addChartType('pie', new SVGPieChart());
1336
-
1337
- })(jQuery)