gentelella-rails 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (129) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +107 -0
  4. data/Rakefile +30 -0
  5. data/assets/javascripts/autosize.js +254 -0
  6. data/assets/javascripts/bootstrap-progressbar.js +168 -0
  7. data/assets/javascripts/bootstrap-wysiwyg.js +306 -0
  8. data/assets/javascripts/data_tables.coffee +12 -0
  9. data/assets/javascripts/data_tables/jquery.data_tables.js +15277 -0
  10. data/assets/javascripts/data_tables/net-bs.bootstrap.js +182 -0
  11. data/assets/javascripts/data_tables/net-buttons-bs.buttons.js +68 -0
  12. data/assets/javascripts/data_tables/net-buttons.buttons.flash.js +1325 -0
  13. data/assets/javascripts/data_tables/net-buttons.buttons.html5.js +1322 -0
  14. data/assets/javascripts/data_tables/net-buttons.buttons.js +1634 -0
  15. data/assets/javascripts/data_tables/net-buttons.buttons.print.js +172 -0
  16. data/assets/javascripts/data_tables/net-fixedheader.js +672 -0
  17. data/assets/javascripts/data_tables/net-keytable.js +883 -0
  18. data/assets/javascripts/data_tables/net-responsive-bs.js +81 -0
  19. data/assets/javascripts/data_tables/net-responsive.js +1232 -0
  20. data/assets/javascripts/data_tables/net-scroller.js +1349 -0
  21. data/assets/javascripts/echarts.js +56282 -0
  22. data/assets/javascripts/echarts.map.world.js +27 -0
  23. data/assets/javascripts/fullcalendar.js +14206 -0
  24. data/assets/javascripts/gauge.coffee +524 -0
  25. data/assets/javascripts/gentelella.coffee +50 -0
  26. data/assets/javascripts/jquery.autocomplete.js +979 -0
  27. data/assets/javascripts/jquery.easypiechart.js +360 -0
  28. data/assets/javascripts/jquery.flot.curvedLines.js +483 -0
  29. data/assets/javascripts/jquery.flot.curved_lines.js +483 -0
  30. data/assets/javascripts/jquery.flot.orderBars.js +201 -0
  31. data/assets/javascripts/jquery.flot.order_bars.js +201 -0
  32. data/assets/javascripts/jquery.flot.spline.js +212 -0
  33. data/assets/javascripts/jquery.hotkeys.js +204 -0
  34. data/assets/javascripts/jquery.mCustomScrollbar.concat.min.js +6 -0
  35. data/assets/javascripts/jquery.mCustomScrollbar.js +2425 -0
  36. data/assets/javascripts/jquery.sparkline.js +3063 -0
  37. data/assets/javascripts/jquery.tagsinput.js +390 -0
  38. data/assets/javascripts/jquery.vmap.js +1281 -0
  39. data/assets/javascripts/jqvmap/maps/continents/jquery.vmap.africa.js +2 -0
  40. data/assets/javascripts/jqvmap/maps/continents/jquery.vmap.asia.js +2 -0
  41. data/assets/javascripts/jqvmap/maps/continents/jquery.vmap.australia.js +2 -0
  42. data/assets/javascripts/jqvmap/maps/continents/jquery.vmap.europe.js +2 -0
  43. data/assets/javascripts/jqvmap/maps/continents/jquery.vmap.north-america.js +2 -0
  44. data/assets/javascripts/jqvmap/maps/continents/jquery.vmap.south-america.js +2 -0
  45. data/assets/javascripts/jqvmap/maps/jquery.vmap.algeria.js +2 -0
  46. data/assets/javascripts/jqvmap/maps/jquery.vmap.argentina.js +1 -0
  47. data/assets/javascripts/jqvmap/maps/jquery.vmap.brazil.js +2 -0
  48. data/assets/javascripts/jqvmap/maps/jquery.vmap.canada.js +2 -0
  49. data/assets/javascripts/jqvmap/maps/jquery.vmap.europe.js +2 -0
  50. data/assets/javascripts/jqvmap/maps/jquery.vmap.france.js +1 -0
  51. data/assets/javascripts/jqvmap/maps/jquery.vmap.germany.js +2 -0
  52. data/assets/javascripts/jqvmap/maps/jquery.vmap.greece.js +1 -0
  53. data/assets/javascripts/jqvmap/maps/jquery.vmap.iran.js +6 -0
  54. data/assets/javascripts/jqvmap/maps/jquery.vmap.iraq.js +1 -0
  55. data/assets/javascripts/jqvmap/maps/jquery.vmap.russia.js +2 -0
  56. data/assets/javascripts/jqvmap/maps/jquery.vmap.tunisia.js +2 -0
  57. data/assets/javascripts/jqvmap/maps/jquery.vmap.turkey.js +11 -0
  58. data/assets/javascripts/jqvmap/maps/jquery.vmap.usa.js +2 -0
  59. data/assets/javascripts/jqvmap/maps/jquery.vmap.world.js +2 -0
  60. data/assets/javascripts/jszip.js +9344 -0
  61. data/assets/javascripts/morris.js +1892 -0
  62. data/assets/javascripts/parsley.js.map +1 -0
  63. data/assets/javascripts/pdfmake.js +68149 -0
  64. data/assets/javascripts/pnotify.buttons.js +8 -0
  65. data/assets/javascripts/pnotify.js +31 -0
  66. data/assets/javascripts/pnotify.nonblock.js +6 -0
  67. data/assets/javascripts/prettify.coffee +29 -0
  68. data/assets/javascripts/prettify/lang-apollo.js +51 -0
  69. data/assets/javascripts/prettify/lang-basic.js +32 -0
  70. data/assets/javascripts/prettify/lang-clj.js +64 -0
  71. data/assets/javascripts/prettify/lang-css.js +159 -0
  72. data/assets/javascripts/prettify/lang-dart.js +88 -0
  73. data/assets/javascripts/prettify/lang-erlang.js +92 -0
  74. data/assets/javascripts/prettify/lang-go.js +58 -0
  75. data/assets/javascripts/prettify/lang-hs.js +101 -0
  76. data/assets/javascripts/prettify/lang-lisp.js +94 -0
  77. data/assets/javascripts/prettify/lang-llvm.js +61 -0
  78. data/assets/javascripts/prettify/lang-lua.js +59 -0
  79. data/assets/javascripts/prettify/lang-matlab.js +180 -0
  80. data/assets/javascripts/prettify/lang-ml.js +56 -0
  81. data/assets/javascripts/prettify/lang-mumps.js +139 -0
  82. data/assets/javascripts/prettify/lang-n.js +65 -0
  83. data/assets/javascripts/prettify/lang-pascal.js +32 -0
  84. data/assets/javascripts/prettify/lang-proto.js +35 -0
  85. data/assets/javascripts/prettify/lang-r.js +57 -0
  86. data/assets/javascripts/prettify/lang-rd.js +47 -0
  87. data/assets/javascripts/prettify/lang-scala.js +54 -0
  88. data/assets/javascripts/prettify/lang-sql.js +58 -0
  89. data/assets/javascripts/prettify/lang-tcl.js +62 -0
  90. data/assets/javascripts/prettify/lang-tex.js +46 -0
  91. data/assets/javascripts/prettify/lang-vb.js +66 -0
  92. data/assets/javascripts/prettify/lang-vhdl.js +34 -0
  93. data/assets/javascripts/prettify/lang-wiki.js +53 -0
  94. data/assets/javascripts/prettify/lang-xq.js +67 -0
  95. data/assets/javascripts/prettify/lang-yaml.js +27 -0
  96. data/assets/javascripts/prettify/prettify.js +1655 -0
  97. data/assets/javascripts/prettify/run_prettify.js +1905 -0
  98. data/assets/javascripts/raphael.js +8330 -0
  99. data/assets/javascripts/skycons.js +730 -0
  100. data/assets/javascripts/starrr.js +98 -0
  101. data/assets/javascripts/vfs_fonts.js +1 -0
  102. data/assets/stylesheets/bootstrap-progressbar-3.3.0-3.x.x.scss +74 -0
  103. data/assets/stylesheets/bootstrap-wysiwyg.css +88 -0
  104. data/assets/stylesheets/data_tables/net-bs.bootstrap.css +185 -0
  105. data/assets/stylesheets/data_tables/net-buttons-bs.buttons.css +102 -0
  106. data/assets/stylesheets/data_tables/net-fixedheader-bs.bootstrap.css +20 -0
  107. data/assets/stylesheets/data_tables/net-responsive-bs.bootstrap.css +181 -0
  108. data/assets/stylesheets/data_tables/net-scroller-bs.bootstrap.css +24 -0
  109. data/assets/stylesheets/fullcalendar.css +1406 -0
  110. data/assets/stylesheets/fullcalendar.print.css +208 -0
  111. data/assets/stylesheets/gentelella.scss +39 -0
  112. data/assets/stylesheets/jquery.mCustomScrollbar.css +1267 -0
  113. data/assets/stylesheets/jqvmap.css +50 -0
  114. data/assets/stylesheets/morris.css +2 -0
  115. data/assets/stylesheets/pnotify.buttons.css +1 -0
  116. data/assets/stylesheets/pnotify.css +1 -0
  117. data/assets/stylesheets/pnotify.nonblock.css +1 -0
  118. data/assets/stylesheets/prettify/prettify.css +52 -0
  119. data/assets/stylesheets/starrr.css +8 -0
  120. data/lib/generators/gentelella/install/USAGE +9 -0
  121. data/lib/generators/gentelella/install/install_generator.rb +14 -0
  122. data/lib/generators/gentelella/install/templates/gentelella-custom.js +5067 -0
  123. data/lib/generators/gentelella/install/templates/gentelella-custom.scss +4241 -0
  124. data/lib/gentelella-rails.rb +58 -0
  125. data/lib/gentelella/engine.rb +15 -0
  126. data/lib/gentelella/version.rb +3 -0
  127. data/lib/tasks/bower.rake +153 -0
  128. data/lib/tasks/gentelella/rails_tasks.rake +4 -0
  129. metadata +409 -0
@@ -0,0 +1,3063 @@
1
+ /**
2
+ *
3
+ * jquery.sparkline.js
4
+ *
5
+ * v2.1.3
6
+ * (c) Splunk, Inc
7
+ * Contact: Gareth Watts (gareth@splunk.com)
8
+ * http://omnipotent.net/jquery.sparkline/
9
+ *
10
+ * Generates inline sparkline charts from data supplied either to the method
11
+ * or inline in HTML
12
+ *
13
+ * Compatible with Internet Explorer 6.0+ and modern browsers equipped with the canvas tag
14
+ * (Firefox 2.0+, Safari, Opera, etc)
15
+ *
16
+ * License: New BSD License
17
+ *
18
+ * Copyright (c) 2012, Splunk Inc.
19
+ * All rights reserved.
20
+ *
21
+ * Redistribution and use in source and binary forms, with or without modification,
22
+ * are permitted provided that the following conditions are met:
23
+ *
24
+ * * Redistributions of source code must retain the above copyright notice,
25
+ * this list of conditions and the following disclaimer.
26
+ * * Redistributions in binary form must reproduce the above copyright notice,
27
+ * this list of conditions and the following disclaimer in the documentation
28
+ * and/or other materials provided with the distribution.
29
+ * * Neither the name of Splunk Inc nor the names of its contributors may
30
+ * be used to endorse or promote products derived from this software without
31
+ * specific prior written permission.
32
+ *
33
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
34
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
35
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
36
+ * SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
37
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
38
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
40
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
41
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42
+ *
43
+ *
44
+ * Usage:
45
+ * $(selector).sparkline(values, options)
46
+ *
47
+ * If values is undefined or set to 'html' then the data values are read from the specified tag:
48
+ * <p>Sparkline: <span class="sparkline">1,4,6,6,8,5,3,5</span></p>
49
+ * $('.sparkline').sparkline();
50
+ * There must be no spaces in the enclosed data set
51
+ *
52
+ * Otherwise values must be an array of numbers or null values
53
+ * <p>Sparkline: <span id="sparkline1">This text replaced if the browser is compatible</span></p>
54
+ * $('#sparkline1').sparkline([1,4,6,6,8,5,3,5])
55
+ * $('#sparkline2').sparkline([1,4,6,null,null,5,3,5])
56
+ *
57
+ * Values can also be specified in an HTML comment, or as a values attribute:
58
+ * <p>Sparkline: <span class="sparkline"><!--1,4,6,6,8,5,3,5 --></span></p>
59
+ * <p>Sparkline: <span class="sparkline" values="1,4,6,6,8,5,3,5"></span></p>
60
+ * $('.sparkline').sparkline();
61
+ *
62
+ * For line charts, x values can also be specified:
63
+ * <p>Sparkline: <span class="sparkline">1:1,2.7:4,3.4:6,5:6,6:8,8.7:5,9:3,10:5</span></p>
64
+ * $('#sparkline1').sparkline([ [1,1], [2.7,4], [3.4,6], [5,6], [6,8], [8.7,5], [9,3], [10,5] ])
65
+ *
66
+ * By default, options should be passed in as the second argument to the sparkline function:
67
+ * $('.sparkline').sparkline([1,2,3,4], {type: 'bar'})
68
+ *
69
+ * Options can also be set by passing them on the tag itself. This feature is disabled by default though
70
+ * as there's a slight performance overhead:
71
+ * $('.sparkline').sparkline([1,2,3,4], {enableTagOptions: true})
72
+ * <p>Sparkline: <span class="sparkline" sparkType="bar" sparkBarColor="red">loading</span></p>
73
+ * Prefix all options supplied as tag attribute with "spark" (configurable by setting tagOptionsPrefix)
74
+ *
75
+ * Supported options:
76
+ * lineColor - Color of the line used for the chart
77
+ * fillColor - Color used to fill in the chart - Set to '' or false for a transparent chart
78
+ * width - Width of the chart - Defaults to 3 times the number of values in pixels
79
+ * height - Height of the chart - Defaults to the height of the containing element
80
+ * chartRangeMin - Specify the minimum value to use for the Y range of the chart - Defaults to the minimum value supplied
81
+ * chartRangeMax - Specify the maximum value to use for the Y range of the chart - Defaults to the maximum value supplied
82
+ * chartRangeClip - Clip out of range values to the max/min specified by chartRangeMin and chartRangeMax
83
+ * chartRangeMinX - Specify the minimum value to use for the X range of the chart - Defaults to the minimum value supplied
84
+ * chartRangeMaxX - Specify the maximum value to use for the X range of the chart - Defaults to the maximum value supplied
85
+ * composite - If true then don't erase any existing chart attached to the tag, but draw
86
+ * another chart over the top - Note that width and height are ignored if an
87
+ * existing chart is detected.
88
+ * tagValuesAttribute - Name of tag attribute to check for data values - Defaults to 'values'
89
+ * enableTagOptions - Whether to check tags for sparkline options
90
+ * tagOptionsPrefix - Prefix used for options supplied as tag attributes - Defaults to 'spark'
91
+ * disableHiddenCheck - If set to true, then the plugin will assume that charts will never be drawn into a
92
+ * hidden dom element, avoding a browser reflow
93
+ * disableInteraction - If set to true then all mouseover/click interaction behaviour will be disabled,
94
+ * making the plugin perform much like it did in 1.x
95
+ * disableTooltips - If set to true then tooltips will be disabled - Defaults to false (tooltips enabled)
96
+ * disableHighlight - If set to true then highlighting of selected chart elements on mouseover will be disabled
97
+ * defaults to false (highlights enabled)
98
+ * highlightLighten - Factor to lighten/darken highlighted chart values by - Defaults to 1.4 for a 40% increase
99
+ * tooltipContainer - Specify which DOM element the tooltip should be rendered into - defaults to document.body
100
+ * tooltipClassname - Optional CSS classname to apply to tooltips - If not specified then a default style will be applied
101
+ * tooltipOffsetX - How many pixels away from the mouse pointer to render the tooltip on the X axis
102
+ * tooltipOffsetY - How many pixels away from the mouse pointer to render the tooltip on the r axis
103
+ * tooltipFormatter - Optional callback that allows you to override the HTML displayed in the tooltip
104
+ * callback is given arguments of (sparkline, options, fields)
105
+ * tooltipChartTitle - If specified then the tooltip uses the string specified by this setting as a title
106
+ * tooltipFormat - A format string or SPFormat object (or an array thereof for multiple entries)
107
+ * to control the format of the tooltip
108
+ * tooltipPrefix - A string to prepend to each field displayed in a tooltip
109
+ * tooltipSuffix - A string to append to each field displayed in a tooltip
110
+ * tooltipSkipNull - If true then null values will not have a tooltip displayed (defaults to true)
111
+ * tooltipValueLookups - An object or range map to map field values to tooltip strings
112
+ * (eg. to map -1 to "Lost", 0 to "Draw", and 1 to "Win")
113
+ * numberFormatter - Optional callback for formatting numbers in tooltips
114
+ * numberDigitGroupSep - Character to use for group separator in numbers "1,234" - Defaults to ","
115
+ * numberDecimalMark - Character to use for the decimal point when formatting numbers - Defaults to "."
116
+ * numberDigitGroupCount - Number of digits between group separator - Defaults to 3
117
+ *
118
+ * There are 7 types of sparkline, selected by supplying a "type" option of 'line' (default),
119
+ * 'bar', 'tristate', 'bullet', 'discrete', 'pie' or 'box'
120
+ * line - Line chart. Options:
121
+ * spotColor - Set to '' to not end each line in a circular spot
122
+ * minSpotColor - If set, color of spot at minimum value
123
+ * maxSpotColor - If set, color of spot at maximum value
124
+ * spotRadius - Radius in pixels
125
+ * lineWidth - Width of line in pixels
126
+ * normalRangeMin
127
+ * normalRangeMax - If set draws a filled horizontal bar between these two values marking the "normal"
128
+ * or expected range of values
129
+ * normalRangeColor - Color to use for the above bar
130
+ * drawNormalOnTop - Draw the normal range above the chart fill color if true
131
+ * defaultPixelsPerValue - Defaults to 3 pixels of width for each value in the chart
132
+ * highlightSpotColor - The color to use for drawing a highlight spot on mouseover - Set to null to disable
133
+ * highlightLineColor - The color to use for drawing a highlight line on mouseover - Set to null to disable
134
+ * valueSpots - Specify which points to draw spots on, and in which color. Accepts a range map
135
+ *
136
+ * bar - Bar chart. Options:
137
+ * barColor - Color of bars for postive values
138
+ * negBarColor - Color of bars for negative values
139
+ * zeroColor - Color of bars with zero values
140
+ * nullColor - Color of bars with null values - Defaults to omitting the bar entirely
141
+ * barWidth - Width of bars in pixels
142
+ * colorMap - Optional mappnig of values to colors to override the *BarColor values above
143
+ * can be an Array of values to control the color of individual bars or a range map
144
+ * to specify colors for individual ranges of values
145
+ * barSpacing - Gap between bars in pixels
146
+ * zeroAxis - Centers the y-axis around zero if true
147
+ *
148
+ * tristate - Charts values of win (>0), lose (<0) or draw (=0)
149
+ * posBarColor - Color of win values
150
+ * negBarColor - Color of lose values
151
+ * zeroBarColor - Color of draw values
152
+ * barWidth - Width of bars in pixels
153
+ * barSpacing - Gap between bars in pixels
154
+ * colorMap - Optional mappnig of values to colors to override the *BarColor values above
155
+ * can be an Array of values to control the color of individual bars or a range map
156
+ * to specify colors for individual ranges of values
157
+ *
158
+ * discrete - Options:
159
+ * lineHeight - Height of each line in pixels - Defaults to 30% of the graph height
160
+ * thesholdValue - Values less than this value will be drawn using thresholdColor instead of lineColor
161
+ * thresholdColor
162
+ *
163
+ * bullet - Values for bullet graphs msut be in the order: target, performance, range1, range2, range3, ...
164
+ * options:
165
+ * targetColor - The color of the vertical target marker
166
+ * targetWidth - The width of the target marker in pixels
167
+ * performanceColor - The color of the performance measure horizontal bar
168
+ * rangeColors - Colors to use for each qualitative range background color
169
+ *
170
+ * pie - Pie chart. Options:
171
+ * sliceColors - An array of colors to use for pie slices
172
+ * offset - Angle in degrees to offset the first slice - Try -90 or +90
173
+ * borderWidth - Width of border to draw around the pie chart, in pixels - Defaults to 0 (no border)
174
+ * borderColor - Color to use for the pie chart border - Defaults to #000
175
+ *
176
+ * box - Box plot. Options:
177
+ * raw - Set to true to supply pre-computed plot points as values
178
+ * values should be: low_outlier, low_whisker, q1, median, q3, high_whisker, high_outlier
179
+ * When set to false you can supply any number of values and the box plot will
180
+ * be computed for you. Default is false.
181
+ * showOutliers - Set to true (default) to display outliers as circles
182
+ * outlierIQR - Interquartile range used to determine outliers. Default 1.5
183
+ * boxLineColor - Outline color of the box
184
+ * boxFillColor - Fill color for the box
185
+ * whiskerColor - Line color used for whiskers
186
+ * outlierLineColor - Outline color of outlier circles
187
+ * outlierFillColor - Fill color of the outlier circles
188
+ * spotRadius - Radius of outlier circles
189
+ * medianColor - Line color of the median line
190
+ * target - Draw a target cross hair at the supplied value (default undefined)
191
+ *
192
+ *
193
+ *
194
+ * Examples:
195
+ * $('#sparkline1').sparkline(myvalues, { lineColor: '#f00', fillColor: false });
196
+ * $('.barsparks').sparkline('html', { type:'bar', height:'40px', barWidth:5 });
197
+ * $('#tristate').sparkline([1,1,-1,1,0,0,-1], { type:'tristate' }):
198
+ * $('#discrete').sparkline([1,3,4,5,5,3,4,5], { type:'discrete' });
199
+ * $('#bullet').sparkline([10,12,12,9,7], { type:'bullet' });
200
+ * $('#pie').sparkline([1,1,2], { type:'pie' });
201
+ */
202
+
203
+ /*jslint regexp: true, browser: true, jquery: true, white: true, nomen: false, plusplus: false, maxerr: 500, indent: 4 */
204
+
205
+ (function(document, Math, undefined) { // performance/minified-size optimization
206
+ (function(factory) {
207
+ if(typeof define === 'function' && define.amd) {
208
+ define(['jquery'], factory);
209
+ } else if (jQuery && !jQuery.fn.sparkline) {
210
+ factory(jQuery);
211
+ }
212
+ }
213
+ (function($) {
214
+ 'use strict';
215
+
216
+ var UNSET_OPTION = {},
217
+ getDefaults, createClass, SPFormat, clipval, quartile, normalizeValue, normalizeValues,
218
+ remove, isNumber, all, sum, addCSS, ensureArray, formatNumber, RangeMap,
219
+ MouseHandler, Tooltip, barHighlightMixin,
220
+ line, bar, tristate, discrete, bullet, pie, box, defaultStyles, initStyles,
221
+ VShape, VCanvas_base, VCanvas_canvas, VCanvas_vml, pending, shapeCount = 0;
222
+
223
+ /**
224
+ * Default configuration settings
225
+ */
226
+ getDefaults = function () {
227
+ return {
228
+ // Settings common to most/all chart types
229
+ common: {
230
+ type: 'line',
231
+ lineColor: '#00f',
232
+ fillColor: '#cdf',
233
+ defaultPixelsPerValue: 3,
234
+ width: 'auto',
235
+ height: 'auto',
236
+ composite: false,
237
+ tagValuesAttribute: 'values',
238
+ tagOptionsPrefix: 'spark',
239
+ enableTagOptions: false,
240
+ enableHighlight: true,
241
+ highlightLighten: 1.4,
242
+ tooltipSkipNull: true,
243
+ tooltipPrefix: '',
244
+ tooltipSuffix: '',
245
+ disableHiddenCheck: false,
246
+ numberFormatter: false,
247
+ numberDigitGroupCount: 3,
248
+ numberDigitGroupSep: ',',
249
+ numberDecimalMark: '.',
250
+ disableTooltips: false,
251
+ disableInteraction: false
252
+ },
253
+ // Defaults for line charts
254
+ line: {
255
+ spotColor: '#f80',
256
+ highlightSpotColor: '#5f5',
257
+ highlightLineColor: '#f22',
258
+ spotRadius: 1.5,
259
+ minSpotColor: '#f80',
260
+ maxSpotColor: '#f80',
261
+ lineWidth: 1,
262
+ normalRangeMin: undefined,
263
+ normalRangeMax: undefined,
264
+ normalRangeColor: '#ccc',
265
+ drawNormalOnTop: false,
266
+ chartRangeMin: undefined,
267
+ chartRangeMax: undefined,
268
+ chartRangeMinX: undefined,
269
+ chartRangeMaxX: undefined,
270
+ tooltipFormat: new SPFormat('<span style="color: {{color}}">&#9679;</span> {{prefix}}{{y}}{{suffix}}')
271
+ },
272
+ // Defaults for bar charts
273
+ bar: {
274
+ barColor: '#3366cc',
275
+ negBarColor: '#f44',
276
+ stackedBarColor: ['#3366cc', '#dc3912', '#ff9900', '#109618', '#66aa00',
277
+ '#dd4477', '#0099c6', '#990099'],
278
+ zeroColor: undefined,
279
+ nullColor: undefined,
280
+ zeroAxis: true,
281
+ barWidth: 4,
282
+ barSpacing: 1,
283
+ chartRangeMax: undefined,
284
+ chartRangeMin: undefined,
285
+ chartRangeClip: false,
286
+ colorMap: undefined,
287
+ tooltipFormat: new SPFormat('<span style="color: {{color}}">&#9679;</span> {{prefix}}{{value}}{{suffix}}')
288
+ },
289
+ // Defaults for tristate charts
290
+ tristate: {
291
+ barWidth: 4,
292
+ barSpacing: 1,
293
+ posBarColor: '#6f6',
294
+ negBarColor: '#f44',
295
+ zeroBarColor: '#999',
296
+ colorMap: {},
297
+ tooltipFormat: new SPFormat('<span style="color: {{color}}">&#9679;</span> {{value:map}}'),
298
+ tooltipValueLookups: { map: { '-1': 'Loss', '0': 'Draw', '1': 'Win' } }
299
+ },
300
+ // Defaults for discrete charts
301
+ discrete: {
302
+ lineHeight: 'auto',
303
+ thresholdColor: undefined,
304
+ thresholdValue: 0,
305
+ chartRangeMax: undefined,
306
+ chartRangeMin: undefined,
307
+ chartRangeClip: false,
308
+ tooltipFormat: new SPFormat('{{prefix}}{{value}}{{suffix}}')
309
+ },
310
+ // Defaults for bullet charts
311
+ bullet: {
312
+ targetColor: '#f33',
313
+ targetWidth: 3, // width of the target bar in pixels
314
+ performanceColor: '#33f',
315
+ rangeColors: ['#d3dafe', '#a8b6ff', '#7f94ff'],
316
+ base: undefined, // set this to a number to change the base start number
317
+ tooltipFormat: new SPFormat('{{fieldkey:fields}} - {{value}}'),
318
+ tooltipValueLookups: { fields: {r: 'Range', p: 'Performance', t: 'Target'} }
319
+ },
320
+ // Defaults for pie charts
321
+ pie: {
322
+ offset: 0,
323
+ sliceColors: ['#3366cc', '#dc3912', '#ff9900', '#109618', '#66aa00',
324
+ '#dd4477', '#0099c6', '#990099'],
325
+ borderWidth: 0,
326
+ borderColor: '#000',
327
+ tooltipFormat: new SPFormat('<span style="color: {{color}}">&#9679;</span> {{value}} ({{percent.1}}%)')
328
+ },
329
+ // Defaults for box plots
330
+ box: {
331
+ raw: false,
332
+ boxLineColor: '#000',
333
+ boxFillColor: '#cdf',
334
+ whiskerColor: '#000',
335
+ outlierLineColor: '#333',
336
+ outlierFillColor: '#fff',
337
+ medianColor: '#f00',
338
+ showOutliers: true,
339
+ outlierIQR: 1.5,
340
+ spotRadius: 1.5,
341
+ target: undefined,
342
+ targetColor: '#4a2',
343
+ chartRangeMax: undefined,
344
+ chartRangeMin: undefined,
345
+ tooltipFormat: new SPFormat('{{field:fields}}: {{value}}'),
346
+ tooltipFormatFieldlistKey: 'field',
347
+ tooltipValueLookups: { fields: { lq: 'Lower Quartile', med: 'Median',
348
+ uq: 'Upper Quartile', lo: 'Left Outlier', ro: 'Right Outlier',
349
+ lw: 'Left Whisker', rw: 'Right Whisker'} }
350
+ }
351
+ };
352
+ };
353
+
354
+ // You can have tooltips use a css class other than jqstooltip by specifying tooltipClassname
355
+ defaultStyles = '.jqstooltip { ' +
356
+ 'position: absolute;' +
357
+ 'left: 0px;' +
358
+ 'top: 0px;' +
359
+ 'visibility: hidden;' +
360
+ 'background: rgb(0, 0, 0) transparent;' +
361
+ 'background-color: rgba(0,0,0,0.6);' +
362
+ 'filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#99000000, endColorstr=#99000000);' +
363
+ '-ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#99000000, endColorstr=#99000000)";' +
364
+ 'color: white;' +
365
+ 'font: 10px arial, san serif;' +
366
+ 'text-align: left;' +
367
+ 'white-space: nowrap;' +
368
+ 'padding: 5px;' +
369
+ 'border: 1px solid white;' +
370
+ 'box-sizing: content-box;' +
371
+ 'z-index: 10000;' +
372
+ '}' +
373
+ '.jqsfield { ' +
374
+ 'color: white;' +
375
+ 'font: 10px arial, san serif;' +
376
+ 'text-align: left;' +
377
+ '}';
378
+
379
+ /**
380
+ * Utilities
381
+ */
382
+
383
+ createClass = function (/* [baseclass, [mixin, ...]], definition */) {
384
+ var Class, args;
385
+ Class = function () {
386
+ this.init.apply(this, arguments);
387
+ };
388
+ if (arguments.length > 1) {
389
+ if (arguments[0]) {
390
+ Class.prototype = $.extend(new arguments[0](), arguments[arguments.length - 1]);
391
+ Class._super = arguments[0].prototype;
392
+ } else {
393
+ Class.prototype = arguments[arguments.length - 1];
394
+ }
395
+ if (arguments.length > 2) {
396
+ args = Array.prototype.slice.call(arguments, 1, -1);
397
+ args.unshift(Class.prototype);
398
+ $.extend.apply($, args);
399
+ }
400
+ } else {
401
+ Class.prototype = arguments[0];
402
+ }
403
+ Class.prototype.cls = Class;
404
+ return Class;
405
+ };
406
+
407
+ /**
408
+ * Wraps a format string for tooltips
409
+ * {{x}}
410
+ * {{x.2}
411
+ * {{x:months}}
412
+ */
413
+ $.SPFormatClass = SPFormat = createClass({
414
+ fre: /\{\{([\w.]+?)(:(.+?))?\}\}/g,
415
+ precre: /(\w+)\.(\d+)/,
416
+
417
+ init: function (format, fclass) {
418
+ this.format = format;
419
+ this.fclass = fclass;
420
+ },
421
+
422
+ render: function (fieldset, lookups, options) {
423
+ var self = this,
424
+ fields = fieldset,
425
+ match, token, lookupkey, fieldvalue, prec;
426
+ return this.format.replace(this.fre, function () {
427
+ var lookup;
428
+ token = arguments[1];
429
+ lookupkey = arguments[3];
430
+ match = self.precre.exec(token);
431
+ if (match) {
432
+ prec = match[2];
433
+ token = match[1];
434
+ } else {
435
+ prec = false;
436
+ }
437
+ fieldvalue = fields[token];
438
+ if (fieldvalue === undefined) {
439
+ return '';
440
+ }
441
+ if (lookupkey && lookups && lookups[lookupkey]) {
442
+ lookup = lookups[lookupkey];
443
+ if (lookup.get) { // RangeMap
444
+ return lookups[lookupkey].get(fieldvalue) || fieldvalue;
445
+ } else {
446
+ return lookups[lookupkey][fieldvalue] || fieldvalue;
447
+ }
448
+ }
449
+ if (isNumber(fieldvalue)) {
450
+ if (options.get('numberFormatter')) {
451
+ fieldvalue = options.get('numberFormatter')(fieldvalue);
452
+ } else {
453
+ fieldvalue = formatNumber(fieldvalue, prec,
454
+ options.get('numberDigitGroupCount'),
455
+ options.get('numberDigitGroupSep'),
456
+ options.get('numberDecimalMark'));
457
+ }
458
+ }
459
+ return fieldvalue;
460
+ });
461
+ }
462
+ });
463
+
464
+ // convience method to avoid needing the new operator
465
+ $.spformat = function(format, fclass) {
466
+ return new SPFormat(format, fclass);
467
+ };
468
+
469
+ clipval = function (val, min, max) {
470
+ if (val < min) {
471
+ return min;
472
+ }
473
+ if (val > max) {
474
+ return max;
475
+ }
476
+ return val;
477
+ };
478
+
479
+ quartile = function (values, q) {
480
+ var vl;
481
+ if (q === 2) {
482
+ vl = Math.floor(values.length / 2);
483
+ return values.length % 2 ? values[vl] : (values[vl-1] + values[vl]) / 2;
484
+ } else {
485
+ if (values.length % 2 ) { // odd
486
+ vl = (values.length * q + q) / 4;
487
+ return vl % 1 ? (values[Math.floor(vl)] + values[Math.floor(vl) - 1]) / 2 : values[vl-1];
488
+ } else { //even
489
+ vl = (values.length * q + 2) / 4;
490
+ return vl % 1 ? (values[Math.floor(vl)] + values[Math.floor(vl) - 1]) / 2 : values[vl-1];
491
+
492
+ }
493
+ }
494
+ };
495
+
496
+ normalizeValue = function (val) {
497
+ var nf;
498
+ switch (val) {
499
+ case 'undefined':
500
+ val = undefined;
501
+ break;
502
+ case 'null':
503
+ val = null;
504
+ break;
505
+ case 'true':
506
+ val = true;
507
+ break;
508
+ case 'false':
509
+ val = false;
510
+ break;
511
+ default:
512
+ nf = parseFloat(val);
513
+ if (val == nf) {
514
+ val = nf;
515
+ }
516
+ }
517
+ return val;
518
+ };
519
+
520
+ normalizeValues = function (vals) {
521
+ var i, result = [];
522
+ for (i = vals.length; i--;) {
523
+ result[i] = normalizeValue(vals[i]);
524
+ }
525
+ return result;
526
+ };
527
+
528
+ remove = function (vals, filter) {
529
+ var i, vl, result = [];
530
+ for (i = 0, vl = vals.length; i < vl; i++) {
531
+ if (vals[i] !== filter) {
532
+ result.push(vals[i]);
533
+ }
534
+ }
535
+ return result;
536
+ };
537
+
538
+ isNumber = function (num) {
539
+ return !isNaN(parseFloat(num)) && isFinite(num);
540
+ };
541
+
542
+ formatNumber = function (num, prec, groupsize, groupsep, decsep) {
543
+ var p, i;
544
+ num = (prec === false ? parseFloat(num).toString() : num.toFixed(prec)).split('');
545
+ p = (p = $.inArray('.', num)) < 0 ? num.length : p;
546
+ if (p < num.length) {
547
+ num[p] = decsep;
548
+ }
549
+ for (i = p - groupsize; i > 0; i -= groupsize) {
550
+ num.splice(i, 0, groupsep);
551
+ }
552
+ return num.join('');
553
+ };
554
+
555
+ // determine if all values of an array match a value
556
+ // returns true if the array is empty
557
+ all = function (val, arr, ignoreNull) {
558
+ var i;
559
+ for (i = arr.length; i--; ) {
560
+ if (ignoreNull && arr[i] === null) continue;
561
+ if (arr[i] !== val) {
562
+ return false;
563
+ }
564
+ }
565
+ return true;
566
+ };
567
+
568
+ // sums the numeric values in an array, ignoring other values
569
+ sum = function (vals) {
570
+ var total = 0, i;
571
+ for (i = vals.length; i--;) {
572
+ total += typeof vals[i] === 'number' ? vals[i] : 0;
573
+ }
574
+ return total;
575
+ };
576
+
577
+ ensureArray = function (val) {
578
+ return $.isArray(val) ? val : [val];
579
+ };
580
+
581
+ // http://paulirish.com/2008/bookmarklet-inject-new-css-rules/
582
+ addCSS = function(css) {
583
+ var tag, iefail;
584
+ if (document.createStyleSheet) {
585
+ try {
586
+ document.createStyleSheet().cssText = css;
587
+ return;
588
+ } catch (e) {
589
+ // IE <= 9 maxes out at 31 stylesheets; inject into page instead.
590
+ iefail = true;
591
+ }
592
+ }
593
+ tag = document.createElement('style');
594
+ tag.type = 'text/css';
595
+ document.getElementsByTagName('head')[0].appendChild(tag);
596
+ if (iefail) {
597
+ document.styleSheets[document.styleSheets.length - 1].cssText = css;
598
+ } else {
599
+ tag[(typeof document.body.style.WebkitAppearance == 'string') /* webkit only */ ? 'innerText' : 'innerHTML'] = css;
600
+ }
601
+ };
602
+
603
+ // Provide a cross-browser interface to a few simple drawing primitives
604
+ $.fn.simpledraw = function (width, height, useExisting, interact) {
605
+ var target, mhandler;
606
+ if (useExisting && (target = this.data('_jqs_vcanvas'))) {
607
+ return target;
608
+ }
609
+
610
+ if ($.fn.sparkline.canvas === false) {
611
+ // We've already determined that neither Canvas nor VML are available
612
+ return false;
613
+
614
+ } else if ($.fn.sparkline.canvas === undefined) {
615
+ // No function defined yet -- need to see if we support Canvas or VML
616
+ var el = document.createElement('canvas');
617
+ if (!!(el.getContext && el.getContext('2d'))) {
618
+ // Canvas is available
619
+ $.fn.sparkline.canvas = function(width, height, target, interact) {
620
+ return new VCanvas_canvas(width, height, target, interact);
621
+ };
622
+ } else if (document.namespaces && !document.namespaces.v) {
623
+ // VML is available
624
+ document.namespaces.add('v', 'urn:schemas-microsoft-com:vml', '#default#VML');
625
+ $.fn.sparkline.canvas = function(width, height, target, interact) {
626
+ return new VCanvas_vml(width, height, target);
627
+ };
628
+ } else {
629
+ // Neither Canvas nor VML are available
630
+ $.fn.sparkline.canvas = false;
631
+ return false;
632
+ }
633
+ }
634
+
635
+ if (width === undefined) {
636
+ width = $(this).innerWidth();
637
+ }
638
+ if (height === undefined) {
639
+ height = $(this).innerHeight();
640
+ }
641
+
642
+ target = $.fn.sparkline.canvas(width, height, this, interact);
643
+
644
+ mhandler = $(this).data('_jqs_mhandler');
645
+ if (mhandler) {
646
+ mhandler.registerCanvas(target);
647
+ }
648
+ return target;
649
+ };
650
+
651
+ $.fn.cleardraw = function () {
652
+ var target = this.data('_jqs_vcanvas');
653
+ if (target) {
654
+ target.reset();
655
+ }
656
+ };
657
+
658
+ $.RangeMapClass = RangeMap = createClass({
659
+ init: function (map) {
660
+ var key, range, rangelist = [];
661
+ for (key in map) {
662
+ if (map.hasOwnProperty(key) && typeof key === 'string' && key.indexOf(':') > -1) {
663
+ range = key.split(':');
664
+ range[0] = range[0].length === 0 ? -Infinity : parseFloat(range[0]);
665
+ range[1] = range[1].length === 0 ? Infinity : parseFloat(range[1]);
666
+ range[2] = map[key];
667
+ rangelist.push(range);
668
+ }
669
+ }
670
+ this.map = map;
671
+ this.rangelist = rangelist || false;
672
+ },
673
+
674
+ get: function (value) {
675
+ var rangelist = this.rangelist,
676
+ i, range, result;
677
+ if ((result = this.map[value]) !== undefined) {
678
+ return result;
679
+ }
680
+ if (rangelist) {
681
+ for (i = rangelist.length; i--;) {
682
+ range = rangelist[i];
683
+ if (range[0] <= value && range[1] >= value) {
684
+ return range[2];
685
+ }
686
+ }
687
+ }
688
+ return undefined;
689
+ }
690
+ });
691
+
692
+ // Convenience function
693
+ $.range_map = function(map) {
694
+ return new RangeMap(map);
695
+ };
696
+
697
+ MouseHandler = createClass({
698
+ init: function (el, options) {
699
+ var $el = $(el);
700
+ this.$el = $el;
701
+ this.options = options;
702
+ this.currentPageX = 0;
703
+ this.currentPageY = 0;
704
+ this.el = el;
705
+ this.splist = [];
706
+ this.tooltip = null;
707
+ this.over = false;
708
+ this.displayTooltips = !options.get('disableTooltips');
709
+ this.highlightEnabled = !options.get('disableHighlight');
710
+ },
711
+
712
+ registerSparkline: function (sp) {
713
+ this.splist.push(sp);
714
+ if (this.over) {
715
+ this.updateDisplay();
716
+ }
717
+ },
718
+
719
+ registerCanvas: function (canvas) {
720
+ var $canvas = $(canvas.canvas);
721
+ this.canvas = canvas;
722
+ this.$canvas = $canvas;
723
+ $canvas.mouseenter($.proxy(this.mouseenter, this));
724
+ $canvas.mouseleave($.proxy(this.mouseleave, this));
725
+ $canvas.click($.proxy(this.mouseclick, this));
726
+ },
727
+
728
+ reset: function (removeTooltip) {
729
+ this.splist = [];
730
+ if (this.tooltip && removeTooltip) {
731
+ this.tooltip.remove();
732
+ this.tooltip = undefined;
733
+ }
734
+ },
735
+
736
+ mouseclick: function (e) {
737
+ var clickEvent = $.Event('sparklineClick');
738
+ clickEvent.originalEvent = e;
739
+ clickEvent.sparklines = this.splist;
740
+ this.$el.trigger(clickEvent);
741
+ },
742
+
743
+ mouseenter: function (e) {
744
+ $(document.body).unbind('mousemove.jqs');
745
+ $(document.body).bind('mousemove.jqs', $.proxy(this.mousemove, this));
746
+ this.over = true;
747
+ this.currentPageX = e.pageX;
748
+ this.currentPageY = e.pageY;
749
+ this.currentEl = e.target;
750
+ if (!this.tooltip && this.displayTooltips) {
751
+ this.tooltip = new Tooltip(this.options);
752
+ this.tooltip.updatePosition(e.pageX, e.pageY);
753
+ }
754
+ this.updateDisplay();
755
+ },
756
+
757
+ mouseleave: function () {
758
+ $(document.body).unbind('mousemove.jqs');
759
+ var splist = this.splist,
760
+ spcount = splist.length,
761
+ needsRefresh = false,
762
+ sp, i;
763
+ this.over = false;
764
+ this.currentEl = null;
765
+
766
+ if (this.tooltip) {
767
+ this.tooltip.remove();
768
+ this.tooltip = null;
769
+ }
770
+
771
+ for (i = 0; i < spcount; i++) {
772
+ sp = splist[i];
773
+ if (sp.clearRegionHighlight()) {
774
+ needsRefresh = true;
775
+ }
776
+ }
777
+
778
+ if (needsRefresh) {
779
+ this.canvas.render();
780
+ }
781
+ },
782
+
783
+ mousemove: function (e) {
784
+ this.currentPageX = e.pageX;
785
+ this.currentPageY = e.pageY;
786
+ this.currentEl = e.target;
787
+ if (this.tooltip) {
788
+ this.tooltip.updatePosition(e.pageX, e.pageY);
789
+ }
790
+ this.updateDisplay();
791
+ },
792
+
793
+ updateDisplay: function () {
794
+ var splist = this.splist,
795
+ spcount = splist.length,
796
+ needsRefresh = false,
797
+ offset = this.$canvas.offset(),
798
+ localX = this.currentPageX - offset.left,
799
+ localY = this.currentPageY - offset.top,
800
+ tooltiphtml, sp, i, result, changeEvent;
801
+ if (!this.over) {
802
+ return;
803
+ }
804
+ for (i = 0; i < spcount; i++) {
805
+ sp = splist[i];
806
+ result = sp.setRegionHighlight(this.currentEl, localX, localY);
807
+ if (result) {
808
+ needsRefresh = true;
809
+ }
810
+ }
811
+ if (needsRefresh) {
812
+ changeEvent = $.Event('sparklineRegionChange');
813
+ changeEvent.sparklines = this.splist;
814
+ this.$el.trigger(changeEvent);
815
+ if (this.tooltip) {
816
+ tooltiphtml = '';
817
+ for (i = 0; i < spcount; i++) {
818
+ sp = splist[i];
819
+ tooltiphtml += sp.getCurrentRegionTooltip();
820
+ }
821
+ this.tooltip.setContent(tooltiphtml);
822
+ }
823
+ if (!this.disableHighlight) {
824
+ this.canvas.render();
825
+ }
826
+ }
827
+ if (result === null) {
828
+ this.mouseleave();
829
+ }
830
+ }
831
+ });
832
+
833
+
834
+ Tooltip = createClass({
835
+ sizeStyle: 'position: static !important;' +
836
+ 'display: block !important;' +
837
+ 'visibility: hidden !important;' +
838
+ 'float: left !important;',
839
+
840
+ init: function (options) {
841
+ var tooltipClassname = options.get('tooltipClassname', 'jqstooltip'),
842
+ sizetipStyle = this.sizeStyle,
843
+ offset;
844
+ this.container = options.get('tooltipContainer') || document.body;
845
+ this.tooltipOffsetX = options.get('tooltipOffsetX', 10);
846
+ this.tooltipOffsetY = options.get('tooltipOffsetY', 12);
847
+ // remove any previous lingering tooltip
848
+ $('#jqssizetip').remove();
849
+ $('#jqstooltip').remove();
850
+ this.sizetip = $('<div/>', {
851
+ id: 'jqssizetip',
852
+ style: sizetipStyle,
853
+ 'class': tooltipClassname
854
+ });
855
+ this.tooltip = $('<div/>', {
856
+ id: 'jqstooltip',
857
+ 'class': tooltipClassname
858
+ }).appendTo(this.container);
859
+ // account for the container's location
860
+ offset = this.tooltip.offset();
861
+ this.offsetLeft = offset.left;
862
+ this.offsetTop = offset.top;
863
+ this.hidden = true;
864
+ $(window).unbind('resize.jqs scroll.jqs');
865
+ $(window).bind('resize.jqs scroll.jqs', $.proxy(this.updateWindowDims, this));
866
+ this.updateWindowDims();
867
+ },
868
+
869
+ updateWindowDims: function () {
870
+ this.scrollTop = $(window).scrollTop();
871
+ this.scrollLeft = $(window).scrollLeft();
872
+ this.scrollRight = this.scrollLeft + $(window).width();
873
+ this.updatePosition();
874
+ },
875
+
876
+ getSize: function (content) {
877
+ this.sizetip.html(content).appendTo(this.container);
878
+ this.width = this.sizetip.width() + 1;
879
+ this.height = this.sizetip.height();
880
+ this.sizetip.remove();
881
+ },
882
+
883
+ setContent: function (content) {
884
+ if (!content) {
885
+ this.tooltip.css('visibility', 'hidden');
886
+ this.hidden = true;
887
+ return;
888
+ }
889
+ this.getSize(content);
890
+ this.tooltip.html(content)
891
+ .css({
892
+ 'width': this.width,
893
+ 'height': this.height,
894
+ 'visibility': 'visible'
895
+ });
896
+ if (this.hidden) {
897
+ this.hidden = false;
898
+ this.updatePosition();
899
+ }
900
+ },
901
+
902
+ updatePosition: function (x, y) {
903
+ if (x === undefined) {
904
+ if (this.mousex === undefined) {
905
+ return;
906
+ }
907
+ x = this.mousex - this.offsetLeft;
908
+ y = this.mousey - this.offsetTop;
909
+
910
+ } else {
911
+ this.mousex = x = x - this.offsetLeft;
912
+ this.mousey = y = y - this.offsetTop;
913
+ }
914
+ if (!this.height || !this.width || this.hidden) {
915
+ return;
916
+ }
917
+
918
+ y -= this.height + this.tooltipOffsetY;
919
+ x += this.tooltipOffsetX;
920
+
921
+ if (y < this.scrollTop) {
922
+ y = this.scrollTop;
923
+ }
924
+ if (x < this.scrollLeft) {
925
+ x = this.scrollLeft;
926
+ } else if (x + this.width > this.scrollRight) {
927
+ x = this.scrollRight - this.width;
928
+ }
929
+
930
+ this.tooltip.css({
931
+ 'left': x,
932
+ 'top': y
933
+ });
934
+ },
935
+
936
+ remove: function () {
937
+ this.tooltip.remove();
938
+ this.sizetip.remove();
939
+ this.sizetip = this.tooltip = undefined;
940
+ $(window).unbind('resize.jqs scroll.jqs');
941
+ }
942
+ });
943
+
944
+ initStyles = function() {
945
+ addCSS(defaultStyles);
946
+ };
947
+
948
+ $(initStyles);
949
+
950
+ pending = [];
951
+ $.fn.sparkline = function (userValues, userOptions) {
952
+ return this.each(function () {
953
+ var options = new $.fn.sparkline.options(this, userOptions),
954
+ $this = $(this),
955
+ render, i;
956
+ render = function () {
957
+ var values, width, height, tmp, mhandler, sp, vals;
958
+ if (userValues === 'html' || userValues === undefined) {
959
+ vals = this.getAttribute(options.get('tagValuesAttribute'));
960
+ if (vals === undefined || vals === null) {
961
+ vals = $this.html();
962
+ }
963
+ values = vals.replace(/(^\s*<!--)|(-->\s*$)|\s+/g, '').split(',');
964
+ } else {
965
+ values = userValues;
966
+ }
967
+
968
+ width = options.get('width') === 'auto' ? values.length * options.get('defaultPixelsPerValue') : options.get('width');
969
+ if (options.get('height') === 'auto') {
970
+ if (!options.get('composite') || !$.data(this, '_jqs_vcanvas')) {
971
+ // must be a better way to get the line height
972
+ tmp = document.createElement('span');
973
+ tmp.innerHTML = 'a';
974
+ $this.html(tmp);
975
+ height = $(tmp).innerHeight() || $(tmp).height();
976
+ $(tmp).remove();
977
+ tmp = null;
978
+ }
979
+ } else {
980
+ height = options.get('height');
981
+ }
982
+
983
+ if (!options.get('disableInteraction')) {
984
+ mhandler = $.data(this, '_jqs_mhandler');
985
+ if (!mhandler) {
986
+ mhandler = new MouseHandler(this, options);
987
+ $.data(this, '_jqs_mhandler', mhandler);
988
+ } else if (!options.get('composite')) {
989
+ mhandler.reset();
990
+ }
991
+ } else {
992
+ mhandler = false;
993
+ }
994
+
995
+ if (options.get('composite') && !$.data(this, '_jqs_vcanvas')) {
996
+ if (!$.data(this, '_jqs_errnotify')) {
997
+ alert('Attempted to attach a composite sparkline to an element with no existing sparkline');
998
+ $.data(this, '_jqs_errnotify', true);
999
+ }
1000
+ return;
1001
+ }
1002
+
1003
+ sp = new $.fn.sparkline[options.get('type')](this, values, options, width, height);
1004
+
1005
+ sp.render();
1006
+
1007
+ if (mhandler) {
1008
+ mhandler.registerSparkline(sp);
1009
+ }
1010
+ };
1011
+ if (($(this).html() && !options.get('disableHiddenCheck') && $(this).is(':hidden')) || !$(this).parents('body').length) {
1012
+ if (!options.get('composite') && $.data(this, '_jqs_pending')) {
1013
+ // remove any existing references to the element
1014
+ for (i = pending.length; i; i--) {
1015
+ if (pending[i - 1][0] == this) {
1016
+ pending.splice(i - 1, 1);
1017
+ }
1018
+ }
1019
+ }
1020
+ pending.push([this, render]);
1021
+ $.data(this, '_jqs_pending', true);
1022
+ } else {
1023
+ render.call(this);
1024
+ }
1025
+ });
1026
+ };
1027
+
1028
+ $.fn.sparkline.defaults = getDefaults();
1029
+
1030
+
1031
+ $.sparkline_display_visible = function () {
1032
+ var el, i, pl;
1033
+ var done = [];
1034
+ for (i = 0, pl = pending.length; i < pl; i++) {
1035
+ el = pending[i][0];
1036
+ if ($(el).is(':visible') && !$(el).parents().is(':hidden')) {
1037
+ pending[i][1].call(el);
1038
+ $.data(pending[i][0], '_jqs_pending', false);
1039
+ done.push(i);
1040
+ } else if (!$(el).closest('html').length && !$.data(el, '_jqs_pending')) {
1041
+ // element has been inserted and removed from the DOM
1042
+ // If it was not yet inserted into the dom then the .data request
1043
+ // will return true.
1044
+ // removing from the dom causes the data to be removed.
1045
+ $.data(pending[i][0], '_jqs_pending', false);
1046
+ done.push(i);
1047
+ }
1048
+ }
1049
+ for (i = done.length; i; i--) {
1050
+ pending.splice(done[i - 1], 1);
1051
+ }
1052
+ };
1053
+
1054
+
1055
+ /**
1056
+ * User option handler
1057
+ */
1058
+ $.fn.sparkline.options = createClass({
1059
+ init: function (tag, userOptions) {
1060
+ var extendedOptions, defaults, base, tagOptionType;
1061
+ this.userOptions = userOptions = userOptions || {};
1062
+ this.tag = tag;
1063
+ this.tagValCache = {};
1064
+ defaults = $.fn.sparkline.defaults;
1065
+ base = defaults.common;
1066
+ this.tagOptionsPrefix = userOptions.enableTagOptions && (userOptions.tagOptionsPrefix || base.tagOptionsPrefix);
1067
+
1068
+ tagOptionType = this.getTagSetting('type');
1069
+ if (tagOptionType === UNSET_OPTION) {
1070
+ extendedOptions = defaults[userOptions.type || base.type];
1071
+ } else {
1072
+ extendedOptions = defaults[tagOptionType];
1073
+ }
1074
+ this.mergedOptions = $.extend({}, base, extendedOptions, userOptions);
1075
+ },
1076
+
1077
+
1078
+ getTagSetting: function (key) {
1079
+ var prefix = this.tagOptionsPrefix,
1080
+ val, i, pairs, keyval;
1081
+ if (prefix === false || prefix === undefined) {
1082
+ return UNSET_OPTION;
1083
+ }
1084
+ if (this.tagValCache.hasOwnProperty(key)) {
1085
+ val = this.tagValCache.key;
1086
+ } else {
1087
+ val = this.tag.getAttribute(prefix + key);
1088
+ if (val === undefined || val === null) {
1089
+ val = UNSET_OPTION;
1090
+ } else if (val.substr(0, 1) === '[') {
1091
+ val = val.substr(1, val.length - 2).split(',');
1092
+ for (i = val.length; i--;) {
1093
+ val[i] = normalizeValue(val[i].replace(/(^\s*)|(\s*$)/g, ''));
1094
+ }
1095
+ } else if (val.substr(0, 1) === '{') {
1096
+ pairs = val.substr(1, val.length - 2).split(',');
1097
+ val = {};
1098
+ for (i = pairs.length; i--;) {
1099
+ keyval = pairs[i].split(':', 2);
1100
+ val[keyval[0].replace(/(^\s*)|(\s*$)/g, '')] = normalizeValue(keyval[1].replace(/(^\s*)|(\s*$)/g, ''));
1101
+ }
1102
+ } else {
1103
+ val = normalizeValue(val);
1104
+ }
1105
+ this.tagValCache.key = val;
1106
+ }
1107
+ return val;
1108
+ },
1109
+
1110
+ get: function (key, defaultval) {
1111
+ var tagOption = this.getTagSetting(key),
1112
+ result;
1113
+ if (tagOption !== UNSET_OPTION) {
1114
+ return tagOption;
1115
+ }
1116
+ return (result = this.mergedOptions[key]) === undefined ? defaultval : result;
1117
+ }
1118
+ });
1119
+
1120
+
1121
+ $.fn.sparkline._base = createClass({
1122
+ disabled: false,
1123
+
1124
+ init: function (el, values, options, width, height) {
1125
+ this.el = el;
1126
+ this.$el = $(el);
1127
+ this.values = values;
1128
+ this.options = options;
1129
+ this.width = width;
1130
+ this.height = height;
1131
+ this.currentRegion = undefined;
1132
+ },
1133
+
1134
+ /**
1135
+ * Setup the canvas
1136
+ */
1137
+ initTarget: function () {
1138
+ var interactive = !this.options.get('disableInteraction');
1139
+ if (!(this.target = this.$el.simpledraw(this.width, this.height, this.options.get('composite'), interactive))) {
1140
+ this.disabled = true;
1141
+ } else {
1142
+ this.canvasWidth = this.target.pixelWidth;
1143
+ this.canvasHeight = this.target.pixelHeight;
1144
+ }
1145
+ },
1146
+
1147
+ /**
1148
+ * Actually render the chart to the canvas
1149
+ */
1150
+ render: function () {
1151
+ if (this.disabled) {
1152
+ this.el.innerHTML = '';
1153
+ return false;
1154
+ }
1155
+ return true;
1156
+ },
1157
+
1158
+ /**
1159
+ * Return a region id for a given x/y co-ordinate
1160
+ */
1161
+ getRegion: function (x, y) {
1162
+ },
1163
+
1164
+ /**
1165
+ * Highlight an item based on the moused-over x,y co-ordinate
1166
+ */
1167
+ setRegionHighlight: function (el, x, y) {
1168
+ var currentRegion = this.currentRegion,
1169
+ highlightEnabled = !this.options.get('disableHighlight'),
1170
+ newRegion;
1171
+ if (x > this.canvasWidth || y > this.canvasHeight || x < 0 || y < 0) {
1172
+ return null;
1173
+ }
1174
+ newRegion = this.getRegion(el, x, y);
1175
+ if (currentRegion !== newRegion) {
1176
+ if (currentRegion !== undefined && highlightEnabled) {
1177
+ this.removeHighlight();
1178
+ }
1179
+ this.currentRegion = newRegion;
1180
+ if (newRegion !== undefined && highlightEnabled) {
1181
+ this.renderHighlight();
1182
+ }
1183
+ return true;
1184
+ }
1185
+ return false;
1186
+ },
1187
+
1188
+ /**
1189
+ * Reset any currently highlighted item
1190
+ */
1191
+ clearRegionHighlight: function () {
1192
+ if (this.currentRegion !== undefined) {
1193
+ this.removeHighlight();
1194
+ this.currentRegion = undefined;
1195
+ return true;
1196
+ }
1197
+ return false;
1198
+ },
1199
+
1200
+ renderHighlight: function () {
1201
+ this.changeHighlight(true);
1202
+ },
1203
+
1204
+ removeHighlight: function () {
1205
+ this.changeHighlight(false);
1206
+ },
1207
+
1208
+ changeHighlight: function (highlight) {},
1209
+
1210
+ /**
1211
+ * Fetch the HTML to display as a tooltip
1212
+ */
1213
+ getCurrentRegionTooltip: function () {
1214
+ var options = this.options,
1215
+ header = '',
1216
+ entries = [],
1217
+ fields, formats, formatlen, fclass, text, i,
1218
+ showFields, showFieldsKey, newFields, fv,
1219
+ formatter, format, fieldlen, j;
1220
+ if (this.currentRegion === undefined) {
1221
+ return '';
1222
+ }
1223
+ fields = this.getCurrentRegionFields();
1224
+ formatter = options.get('tooltipFormatter');
1225
+ if (formatter) {
1226
+ return formatter(this, options, fields);
1227
+ }
1228
+ if (options.get('tooltipChartTitle')) {
1229
+ header += '<div class="jqs jqstitle">' + options.get('tooltipChartTitle') + '</div>\n';
1230
+ }
1231
+ formats = this.options.get('tooltipFormat');
1232
+ if (!formats) {
1233
+ return '';
1234
+ }
1235
+ if (!$.isArray(formats)) {
1236
+ formats = [formats];
1237
+ }
1238
+ if (!$.isArray(fields)) {
1239
+ fields = [fields];
1240
+ }
1241
+ showFields = this.options.get('tooltipFormatFieldlist');
1242
+ showFieldsKey = this.options.get('tooltipFormatFieldlistKey');
1243
+ if (showFields && showFieldsKey) {
1244
+ // user-selected ordering of fields
1245
+ newFields = [];
1246
+ for (i = fields.length; i--;) {
1247
+ fv = fields[i][showFieldsKey];
1248
+ if ((j = $.inArray(fv, showFields)) != -1) {
1249
+ newFields[j] = fields[i];
1250
+ }
1251
+ }
1252
+ fields = newFields;
1253
+ }
1254
+ formatlen = formats.length;
1255
+ fieldlen = fields.length;
1256
+ for (i = 0; i < formatlen; i++) {
1257
+ format = formats[i];
1258
+ if (typeof format === 'string') {
1259
+ format = new SPFormat(format);
1260
+ }
1261
+ fclass = format.fclass || 'jqsfield';
1262
+ for (j = 0; j < fieldlen; j++) {
1263
+ if (!fields[j].isNull || !options.get('tooltipSkipNull')) {
1264
+ $.extend(fields[j], {
1265
+ prefix: options.get('tooltipPrefix'),
1266
+ suffix: options.get('tooltipSuffix')
1267
+ });
1268
+ text = format.render(fields[j], options.get('tooltipValueLookups'), options);
1269
+ entries.push('<div class="' + fclass + '">' + text + '</div>');
1270
+ }
1271
+ }
1272
+ }
1273
+ if (entries.length) {
1274
+ return header + entries.join('\n');
1275
+ }
1276
+ return '';
1277
+ },
1278
+
1279
+ getCurrentRegionFields: function () {},
1280
+
1281
+ calcHighlightColor: function (color, options) {
1282
+ var highlightColor = options.get('highlightColor'),
1283
+ lighten = options.get('highlightLighten'),
1284
+ parse, mult, rgbnew, i;
1285
+ if (highlightColor) {
1286
+ return highlightColor;
1287
+ }
1288
+ if (lighten) {
1289
+ // extract RGB values
1290
+ parse = /^#([0-9a-f])([0-9a-f])([0-9a-f])$/i.exec(color) || /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(color);
1291
+ if (parse) {
1292
+ rgbnew = [];
1293
+ mult = color.length === 4 ? 16 : 1;
1294
+ for (i = 0; i < 3; i++) {
1295
+ rgbnew[i] = clipval(Math.round(parseInt(parse[i + 1], 16) * mult * lighten), 0, 255);
1296
+ }
1297
+ return 'rgb(' + rgbnew.join(',') + ')';
1298
+ }
1299
+
1300
+ }
1301
+ return color;
1302
+ }
1303
+
1304
+ });
1305
+
1306
+ barHighlightMixin = {
1307
+ changeHighlight: function (highlight) {
1308
+ var currentRegion = this.currentRegion,
1309
+ target = this.target,
1310
+ shapeids = this.regionShapes[currentRegion],
1311
+ newShapes;
1312
+ // will be null if the region value was null
1313
+ if (shapeids) {
1314
+ newShapes = this.renderRegion(currentRegion, highlight);
1315
+ if ($.isArray(newShapes) || $.isArray(shapeids)) {
1316
+ target.replaceWithShapes(shapeids, newShapes);
1317
+ this.regionShapes[currentRegion] = $.map(newShapes, function (newShape) {
1318
+ return newShape.id;
1319
+ });
1320
+ } else {
1321
+ target.replaceWithShape(shapeids, newShapes);
1322
+ this.regionShapes[currentRegion] = newShapes.id;
1323
+ }
1324
+ }
1325
+ },
1326
+
1327
+ render: function () {
1328
+ var values = this.values,
1329
+ target = this.target,
1330
+ regionShapes = this.regionShapes,
1331
+ shapes, ids, i, j;
1332
+
1333
+ if (!this.cls._super.render.call(this)) {
1334
+ return;
1335
+ }
1336
+ for (i = values.length; i--;) {
1337
+ shapes = this.renderRegion(i);
1338
+ if (shapes) {
1339
+ if ($.isArray(shapes)) {
1340
+ ids = [];
1341
+ for (j = shapes.length; j--;) {
1342
+ shapes[j].append();
1343
+ ids.push(shapes[j].id);
1344
+ }
1345
+ regionShapes[i] = ids;
1346
+ } else {
1347
+ shapes.append();
1348
+ regionShapes[i] = shapes.id; // store just the shapeid
1349
+ }
1350
+ } else {
1351
+ // null value
1352
+ regionShapes[i] = null;
1353
+ }
1354
+ }
1355
+ target.render();
1356
+ }
1357
+ };
1358
+
1359
+ /**
1360
+ * Line charts
1361
+ */
1362
+ $.fn.sparkline.line = line = createClass($.fn.sparkline._base, {
1363
+ type: 'line',
1364
+
1365
+ init: function (el, values, options, width, height) {
1366
+ line._super.init.call(this, el, values, options, width, height);
1367
+ this.vertices = [];
1368
+ this.regionMap = [];
1369
+ this.xvalues = [];
1370
+ this.yvalues = [];
1371
+ this.yminmax = [];
1372
+ this.hightlightSpotId = null;
1373
+ this.lastShapeId = null;
1374
+ this.initTarget();
1375
+ },
1376
+
1377
+ getRegion: function (el, x, y) {
1378
+ var i,
1379
+ regionMap = this.regionMap; // maps regions to value positions
1380
+ for (i = regionMap.length; i--;) {
1381
+ if (regionMap[i] !== null && x >= regionMap[i][0] && x <= regionMap[i][1]) {
1382
+ return regionMap[i][2];
1383
+ }
1384
+ }
1385
+ return undefined;
1386
+ },
1387
+
1388
+ getCurrentRegionFields: function () {
1389
+ var currentRegion = this.currentRegion;
1390
+ return {
1391
+ isNull: this.yvalues[currentRegion] === null,
1392
+ x: this.xvalues[currentRegion],
1393
+ y: this.yvalues[currentRegion],
1394
+ color: this.options.get('lineColor'),
1395
+ fillColor: this.options.get('fillColor'),
1396
+ offset: currentRegion
1397
+ };
1398
+ },
1399
+
1400
+ renderHighlight: function () {
1401
+ var currentRegion = this.currentRegion,
1402
+ target = this.target,
1403
+ vertex = this.vertices[currentRegion],
1404
+ options = this.options,
1405
+ spotRadius = options.get('spotRadius'),
1406
+ highlightSpotColor = options.get('highlightSpotColor'),
1407
+ highlightLineColor = options.get('highlightLineColor'),
1408
+ highlightSpot, highlightLine;
1409
+
1410
+ if (!vertex) {
1411
+ return;
1412
+ }
1413
+ if (spotRadius && highlightSpotColor) {
1414
+ highlightSpot = target.drawCircle(vertex[0], vertex[1],
1415
+ spotRadius, undefined, highlightSpotColor);
1416
+ this.highlightSpotId = highlightSpot.id;
1417
+ target.insertAfterShape(this.lastShapeId, highlightSpot);
1418
+ }
1419
+ if (highlightLineColor) {
1420
+ highlightLine = target.drawLine(vertex[0], this.canvasTop, vertex[0],
1421
+ this.canvasTop + this.canvasHeight, highlightLineColor);
1422
+ this.highlightLineId = highlightLine.id;
1423
+ target.insertAfterShape(this.lastShapeId, highlightLine);
1424
+ }
1425
+ },
1426
+
1427
+ removeHighlight: function () {
1428
+ var target = this.target;
1429
+ if (this.highlightSpotId) {
1430
+ target.removeShapeId(this.highlightSpotId);
1431
+ this.highlightSpotId = null;
1432
+ }
1433
+ if (this.highlightLineId) {
1434
+ target.removeShapeId(this.highlightLineId);
1435
+ this.highlightLineId = null;
1436
+ }
1437
+ },
1438
+
1439
+ scanValues: function () {
1440
+ var values = this.values,
1441
+ valcount = values.length,
1442
+ xvalues = this.xvalues,
1443
+ yvalues = this.yvalues,
1444
+ yminmax = this.yminmax,
1445
+ i, val, isStr, isArray, sp;
1446
+ for (i = 0; i < valcount; i++) {
1447
+ val = values[i];
1448
+ isStr = typeof(values[i]) === 'string';
1449
+ isArray = typeof(values[i]) === 'object' && values[i] instanceof Array;
1450
+ sp = isStr && values[i].split(':');
1451
+ if (isStr && sp.length === 2) { // x:y
1452
+ xvalues.push(Number(sp[0]));
1453
+ yvalues.push(Number(sp[1]));
1454
+ yminmax.push(Number(sp[1]));
1455
+ } else if (isArray) {
1456
+ xvalues.push(val[0]);
1457
+ yvalues.push(val[1]);
1458
+ yminmax.push(val[1]);
1459
+ } else {
1460
+ xvalues.push(i);
1461
+ if (values[i] === null || values[i] === 'null') {
1462
+ yvalues.push(null);
1463
+ } else {
1464
+ yvalues.push(Number(val));
1465
+ yminmax.push(Number(val));
1466
+ }
1467
+ }
1468
+ }
1469
+ if (this.options.get('xvalues')) {
1470
+ xvalues = this.options.get('xvalues');
1471
+ }
1472
+
1473
+ this.maxy = this.maxyorg = Math.max.apply(Math, yminmax);
1474
+ this.miny = this.minyorg = Math.min.apply(Math, yminmax);
1475
+
1476
+ this.maxx = Math.max.apply(Math, xvalues);
1477
+ this.minx = Math.min.apply(Math, xvalues);
1478
+
1479
+ this.xvalues = xvalues;
1480
+ this.yvalues = yvalues;
1481
+ this.yminmax = yminmax;
1482
+
1483
+ },
1484
+
1485
+ processRangeOptions: function () {
1486
+ var options = this.options,
1487
+ normalRangeMin = options.get('normalRangeMin'),
1488
+ normalRangeMax = options.get('normalRangeMax');
1489
+
1490
+ if (normalRangeMin !== undefined) {
1491
+ if (normalRangeMin < this.miny) {
1492
+ this.miny = normalRangeMin;
1493
+ }
1494
+ if (normalRangeMax > this.maxy) {
1495
+ this.maxy = normalRangeMax;
1496
+ }
1497
+ }
1498
+ if (options.get('chartRangeMin') !== undefined && (options.get('chartRangeClip') || options.get('chartRangeMin') < this.miny)) {
1499
+ this.miny = options.get('chartRangeMin');
1500
+ }
1501
+ if (options.get('chartRangeMax') !== undefined && (options.get('chartRangeClip') || options.get('chartRangeMax') > this.maxy)) {
1502
+ this.maxy = options.get('chartRangeMax');
1503
+ }
1504
+ if (options.get('chartRangeMinX') !== undefined && (options.get('chartRangeClipX') || options.get('chartRangeMinX') < this.minx)) {
1505
+ this.minx = options.get('chartRangeMinX');
1506
+ }
1507
+ if (options.get('chartRangeMaxX') !== undefined && (options.get('chartRangeClipX') || options.get('chartRangeMaxX') > this.maxx)) {
1508
+ this.maxx = options.get('chartRangeMaxX');
1509
+ }
1510
+
1511
+ },
1512
+
1513
+ drawNormalRange: function (canvasLeft, canvasTop, canvasHeight, canvasWidth, rangey) {
1514
+ var normalRangeMin = this.options.get('normalRangeMin'),
1515
+ normalRangeMax = this.options.get('normalRangeMax'),
1516
+ ytop = canvasTop + Math.round(canvasHeight - (canvasHeight * ((normalRangeMax - this.miny) / rangey))),
1517
+ height = Math.round((canvasHeight * (normalRangeMax - normalRangeMin)) / rangey);
1518
+ this.target.drawRect(canvasLeft, ytop, canvasWidth, height, undefined, this.options.get('normalRangeColor')).append();
1519
+ },
1520
+
1521
+ render: function () {
1522
+ var options = this.options,
1523
+ target = this.target,
1524
+ canvasWidth = this.canvasWidth,
1525
+ canvasHeight = this.canvasHeight,
1526
+ vertices = this.vertices,
1527
+ spotRadius = options.get('spotRadius'),
1528
+ regionMap = this.regionMap,
1529
+ rangex, rangey, yvallast,
1530
+ canvasTop, canvasLeft,
1531
+ vertex, path, paths, x, y, xnext, xpos, xposnext,
1532
+ last, next, yvalcount, lineShapes, fillShapes, plen,
1533
+ valueSpots, hlSpotsEnabled, color, xvalues, yvalues, i;
1534
+
1535
+ if (!line._super.render.call(this)) {
1536
+ return;
1537
+ }
1538
+
1539
+ this.scanValues();
1540
+ this.processRangeOptions();
1541
+
1542
+ xvalues = this.xvalues;
1543
+ yvalues = this.yvalues;
1544
+
1545
+ if (!this.yminmax.length || this.yvalues.length < 2) {
1546
+ // empty or all null valuess
1547
+ return;
1548
+ }
1549
+
1550
+ canvasTop = canvasLeft = 0;
1551
+
1552
+ rangex = this.maxx - this.minx === 0 ? 1 : this.maxx - this.minx;
1553
+ rangey = this.maxy - this.miny === 0 ? 1 : this.maxy - this.miny;
1554
+ yvallast = this.yvalues.length - 1;
1555
+
1556
+ if (spotRadius && (canvasWidth < (spotRadius * 4) || canvasHeight < (spotRadius * 4))) {
1557
+ spotRadius = 0;
1558
+ }
1559
+ if (spotRadius) {
1560
+ // adjust the canvas size as required so that spots will fit
1561
+ hlSpotsEnabled = options.get('highlightSpotColor') && !options.get('disableInteraction');
1562
+ if (hlSpotsEnabled || options.get('minSpotColor') || (options.get('spotColor') && yvalues[yvallast] === this.miny)) {
1563
+ canvasHeight -= Math.ceil(spotRadius);
1564
+ }
1565
+ if (hlSpotsEnabled || options.get('maxSpotColor') || (options.get('spotColor') && yvalues[yvallast] === this.maxy)) {
1566
+ canvasHeight -= Math.ceil(spotRadius);
1567
+ canvasTop += Math.ceil(spotRadius);
1568
+ }
1569
+ if (hlSpotsEnabled ||
1570
+ ((options.get('minSpotColor') || options.get('maxSpotColor')) && (yvalues[0] === this.miny || yvalues[0] === this.maxy))) {
1571
+ canvasLeft += Math.ceil(spotRadius);
1572
+ canvasWidth -= Math.ceil(spotRadius);
1573
+ }
1574
+ if (hlSpotsEnabled || options.get('spotColor') ||
1575
+ (options.get('minSpotColor') || options.get('maxSpotColor') &&
1576
+ (yvalues[yvallast] === this.miny || yvalues[yvallast] === this.maxy))) {
1577
+ canvasWidth -= Math.ceil(spotRadius);
1578
+ }
1579
+ }
1580
+
1581
+
1582
+ canvasHeight--;
1583
+
1584
+ if (options.get('normalRangeMin') !== undefined && !options.get('drawNormalOnTop')) {
1585
+ this.drawNormalRange(canvasLeft, canvasTop, canvasHeight, canvasWidth, rangey);
1586
+ }
1587
+
1588
+ path = [];
1589
+ paths = [path];
1590
+ last = next = null;
1591
+ yvalcount = yvalues.length;
1592
+ for (i = 0; i < yvalcount; i++) {
1593
+ x = xvalues[i];
1594
+ xnext = xvalues[i + 1];
1595
+ y = yvalues[i];
1596
+ xpos = canvasLeft + Math.round((x - this.minx) * (canvasWidth / rangex));
1597
+ xposnext = i < yvalcount - 1 ? canvasLeft + Math.round((xnext - this.minx) * (canvasWidth / rangex)) : canvasWidth;
1598
+ next = xpos + ((xposnext - xpos) / 2);
1599
+ regionMap[i] = [last || 0, next, i];
1600
+ last = next;
1601
+ if (y === null) {
1602
+ if (i) {
1603
+ if (yvalues[i - 1] !== null) {
1604
+ path = [];
1605
+ paths.push(path);
1606
+ }
1607
+ vertices.push(null);
1608
+ }
1609
+ } else {
1610
+ if (y < this.miny) {
1611
+ y = this.miny;
1612
+ }
1613
+ if (y > this.maxy) {
1614
+ y = this.maxy;
1615
+ }
1616
+ if (!path.length) {
1617
+ // previous value was null
1618
+ path.push([xpos, canvasTop + canvasHeight]);
1619
+ }
1620
+ vertex = [xpos, canvasTop + Math.round(canvasHeight - (canvasHeight * ((y - this.miny) / rangey)))];
1621
+ path.push(vertex);
1622
+ vertices.push(vertex);
1623
+ }
1624
+ }
1625
+
1626
+ lineShapes = [];
1627
+ fillShapes = [];
1628
+ plen = paths.length;
1629
+ for (i = 0; i < plen; i++) {
1630
+ path = paths[i];
1631
+ if (path.length) {
1632
+ if (options.get('fillColor')) {
1633
+ path.push([path[path.length - 1][0], (canvasTop + canvasHeight)]);
1634
+ fillShapes.push(path.slice(0));
1635
+ path.pop();
1636
+ }
1637
+ // if there's only a single point in this path, then we want to display it
1638
+ // as a vertical line which means we keep path[0] as is
1639
+ if (path.length > 2) {
1640
+ // else we want the first value
1641
+ path[0] = [path[0][0], path[1][1]];
1642
+ }
1643
+ lineShapes.push(path);
1644
+ }
1645
+ }
1646
+
1647
+ // draw the fill first, then optionally the normal range, then the line on top of that
1648
+ plen = fillShapes.length;
1649
+ for (i = 0; i < plen; i++) {
1650
+ target.drawShape(fillShapes[i],
1651
+ options.get('fillColor'), options.get('fillColor')).append();
1652
+ }
1653
+
1654
+ if (options.get('normalRangeMin') !== undefined && options.get('drawNormalOnTop')) {
1655
+ this.drawNormalRange(canvasLeft, canvasTop, canvasHeight, canvasWidth, rangey);
1656
+ }
1657
+
1658
+ plen = lineShapes.length;
1659
+ for (i = 0; i < plen; i++) {
1660
+ target.drawShape(lineShapes[i], options.get('lineColor'), undefined,
1661
+ options.get('lineWidth')).append();
1662
+ }
1663
+
1664
+ if (spotRadius && options.get('valueSpots')) {
1665
+ valueSpots = options.get('valueSpots');
1666
+ if (valueSpots.get === undefined) {
1667
+ valueSpots = new RangeMap(valueSpots);
1668
+ }
1669
+ for (i = 0; i < yvalcount; i++) {
1670
+ color = valueSpots.get(yvalues[i]);
1671
+ if (color) {
1672
+ target.drawCircle(canvasLeft + Math.round((xvalues[i] - this.minx) * (canvasWidth / rangex)),
1673
+ canvasTop + Math.round(canvasHeight - (canvasHeight * ((yvalues[i] - this.miny) / rangey))),
1674
+ spotRadius, undefined,
1675
+ color).append();
1676
+ }
1677
+ }
1678
+
1679
+ }
1680
+ if (spotRadius && options.get('spotColor') && yvalues[yvallast] !== null) {
1681
+ target.drawCircle(canvasLeft + Math.round((xvalues[xvalues.length - 1] - this.minx) * (canvasWidth / rangex)),
1682
+ canvasTop + Math.round(canvasHeight - (canvasHeight * ((yvalues[yvallast] - this.miny) / rangey))),
1683
+ spotRadius, undefined,
1684
+ options.get('spotColor')).append();
1685
+ }
1686
+ if (this.maxy !== this.minyorg) {
1687
+ if (spotRadius && options.get('minSpotColor')) {
1688
+ x = xvalues[$.inArray(this.minyorg, yvalues)];
1689
+ target.drawCircle(canvasLeft + Math.round((x - this.minx) * (canvasWidth / rangex)),
1690
+ canvasTop + Math.round(canvasHeight - (canvasHeight * ((this.minyorg - this.miny) / rangey))),
1691
+ spotRadius, undefined,
1692
+ options.get('minSpotColor')).append();
1693
+ }
1694
+ if (spotRadius && options.get('maxSpotColor')) {
1695
+ x = xvalues[$.inArray(this.maxyorg, yvalues)];
1696
+ target.drawCircle(canvasLeft + Math.round((x - this.minx) * (canvasWidth / rangex)),
1697
+ canvasTop + Math.round(canvasHeight - (canvasHeight * ((this.maxyorg - this.miny) / rangey))),
1698
+ spotRadius, undefined,
1699
+ options.get('maxSpotColor')).append();
1700
+ }
1701
+ }
1702
+
1703
+ this.lastShapeId = target.getLastShapeId();
1704
+ this.canvasTop = canvasTop;
1705
+ target.render();
1706
+ }
1707
+ });
1708
+
1709
+ /**
1710
+ * Bar charts
1711
+ */
1712
+ $.fn.sparkline.bar = bar = createClass($.fn.sparkline._base, barHighlightMixin, {
1713
+ type: 'bar',
1714
+
1715
+ init: function (el, values, options, width, height) {
1716
+ var barWidth = parseInt(options.get('barWidth'), 10),
1717
+ barSpacing = parseInt(options.get('barSpacing'), 10),
1718
+ chartRangeMin = options.get('chartRangeMin'),
1719
+ chartRangeMax = options.get('chartRangeMax'),
1720
+ chartRangeClip = options.get('chartRangeClip'),
1721
+ stackMin = Infinity,
1722
+ stackMax = -Infinity,
1723
+ isStackString, groupMin, groupMax, stackRanges,
1724
+ numValues, i, vlen, range, zeroAxis, xaxisOffset, min, max, clipMin, clipMax,
1725
+ stacked, vlist, j, slen, svals, val, yoffset, yMaxCalc, canvasHeightEf;
1726
+ bar._super.init.call(this, el, values, options, width, height);
1727
+
1728
+ // scan values to determine whether to stack bars
1729
+ for (i = 0, vlen = values.length; i < vlen; i++) {
1730
+ val = values[i];
1731
+ isStackString = typeof(val) === 'string' && val.indexOf(':') > -1;
1732
+ if (isStackString || $.isArray(val)) {
1733
+ stacked = true;
1734
+ if (isStackString) {
1735
+ val = values[i] = normalizeValues(val.split(':'));
1736
+ }
1737
+ val = remove(val, null); // min/max will treat null as zero
1738
+ groupMin = Math.min.apply(Math, val);
1739
+ groupMax = Math.max.apply(Math, val);
1740
+ if (groupMin < stackMin) {
1741
+ stackMin = groupMin;
1742
+ }
1743
+ if (groupMax > stackMax) {
1744
+ stackMax = groupMax;
1745
+ }
1746
+ }
1747
+ }
1748
+
1749
+ this.stacked = stacked;
1750
+ this.regionShapes = {};
1751
+ this.barWidth = barWidth;
1752
+ this.barSpacing = barSpacing;
1753
+ this.totalBarWidth = barWidth + barSpacing;
1754
+ this.width = width = (values.length * barWidth) + ((values.length - 1) * barSpacing);
1755
+
1756
+ this.initTarget();
1757
+
1758
+ if (chartRangeClip) {
1759
+ clipMin = chartRangeMin === undefined ? -Infinity : chartRangeMin;
1760
+ clipMax = chartRangeMax === undefined ? Infinity : chartRangeMax;
1761
+ }
1762
+
1763
+ numValues = [];
1764
+ stackRanges = stacked ? [] : numValues;
1765
+ var stackTotals = [];
1766
+ var stackRangesNeg = [];
1767
+ for (i = 0, vlen = values.length; i < vlen; i++) {
1768
+ if (stacked) {
1769
+ vlist = values[i];
1770
+ values[i] = svals = [];
1771
+ stackTotals[i] = 0;
1772
+ stackRanges[i] = stackRangesNeg[i] = 0;
1773
+ for (j = 0, slen = vlist.length; j < slen; j++) {
1774
+ val = svals[j] = chartRangeClip ? clipval(vlist[j], clipMin, clipMax) : vlist[j];
1775
+ if (val !== null) {
1776
+ if (val > 0) {
1777
+ stackTotals[i] += val;
1778
+ }
1779
+ if (stackMin < 0 && stackMax > 0) {
1780
+ if (val < 0) {
1781
+ stackRangesNeg[i] += Math.abs(val);
1782
+ } else {
1783
+ stackRanges[i] += val;
1784
+ }
1785
+ } else {
1786
+ stackRanges[i] += Math.abs(val - (val < 0 ? stackMax : stackMin));
1787
+ }
1788
+ numValues.push(val);
1789
+ }
1790
+ }
1791
+ } else {
1792
+ val = chartRangeClip ? clipval(values[i], clipMin, clipMax) : values[i];
1793
+ val = values[i] = normalizeValue(val);
1794
+ if (val !== null) {
1795
+ numValues.push(val);
1796
+ }
1797
+ }
1798
+ }
1799
+ this.max = max = Math.max.apply(Math, numValues);
1800
+ this.min = min = Math.min.apply(Math, numValues);
1801
+ this.stackMax = stackMax = stacked ? Math.max.apply(Math, stackTotals) : max;
1802
+ this.stackMin = stackMin = stacked ? Math.min.apply(Math, numValues) : min;
1803
+
1804
+ if (options.get('chartRangeMin') !== undefined && (options.get('chartRangeClip') || options.get('chartRangeMin') < min)) {
1805
+ min = options.get('chartRangeMin');
1806
+ }
1807
+ if (options.get('chartRangeMax') !== undefined && (options.get('chartRangeClip') || options.get('chartRangeMax') > max)) {
1808
+ max = options.get('chartRangeMax');
1809
+ }
1810
+
1811
+ this.zeroAxis = zeroAxis = options.get('zeroAxis', true);
1812
+ if (min <= 0 && max >= 0 && zeroAxis) {
1813
+ xaxisOffset = 0;
1814
+ } else if (zeroAxis == false) {
1815
+ xaxisOffset = min;
1816
+ } else if (min > 0) {
1817
+ xaxisOffset = min;
1818
+ } else {
1819
+ xaxisOffset = max;
1820
+ }
1821
+ this.xaxisOffset = xaxisOffset;
1822
+
1823
+ range = stacked ? (Math.max.apply(Math, stackRanges) + Math.max.apply(Math, stackRangesNeg)) : max - min;
1824
+
1825
+ // as we plot zero/min values a single pixel line, we add a pixel to all other
1826
+ // values - Reduce the effective canvas size to suit
1827
+ this.canvasHeightEf = (zeroAxis && min < 0) ? this.canvasHeight - 2 : this.canvasHeight - 1;
1828
+
1829
+ if (min < xaxisOffset) {
1830
+ yMaxCalc = (stacked && max >= 0) ? stackMax : max;
1831
+ yoffset = (yMaxCalc - xaxisOffset) / range * this.canvasHeight;
1832
+ if (yoffset !== Math.ceil(yoffset)) {
1833
+ this.canvasHeightEf -= 2;
1834
+ yoffset = Math.ceil(yoffset);
1835
+ }
1836
+ } else {
1837
+ yoffset = this.canvasHeight;
1838
+ }
1839
+ this.yoffset = yoffset;
1840
+
1841
+ if ($.isArray(options.get('colorMap'))) {
1842
+ this.colorMapByIndex = options.get('colorMap');
1843
+ this.colorMapByValue = null;
1844
+ } else {
1845
+ this.colorMapByIndex = null;
1846
+ this.colorMapByValue = options.get('colorMap');
1847
+ if (this.colorMapByValue && this.colorMapByValue.get === undefined) {
1848
+ this.colorMapByValue = new RangeMap(this.colorMapByValue);
1849
+ }
1850
+ }
1851
+
1852
+ this.range = range;
1853
+ },
1854
+
1855
+ getRegion: function (el, x, y) {
1856
+ var result = Math.floor(x / this.totalBarWidth);
1857
+ return (result < 0 || result >= this.values.length) ? undefined : result;
1858
+ },
1859
+
1860
+ getCurrentRegionFields: function () {
1861
+ var currentRegion = this.currentRegion,
1862
+ values = ensureArray(this.values[currentRegion]),
1863
+ result = [],
1864
+ value, i;
1865
+ for (i = values.length; i--;) {
1866
+ value = values[i];
1867
+ result.push({
1868
+ isNull: value === null,
1869
+ value: value,
1870
+ color: this.calcColor(i, value, currentRegion),
1871
+ offset: currentRegion
1872
+ });
1873
+ }
1874
+ return result;
1875
+ },
1876
+
1877
+ calcColor: function (stacknum, value, valuenum) {
1878
+ var colorMapByIndex = this.colorMapByIndex,
1879
+ colorMapByValue = this.colorMapByValue,
1880
+ options = this.options,
1881
+ color, newColor;
1882
+ if (this.stacked) {
1883
+ color = options.get('stackedBarColor');
1884
+ } else {
1885
+ color = (value < 0) ? options.get('negBarColor') : options.get('barColor');
1886
+ }
1887
+ if (value === 0 && options.get('zeroColor') !== undefined) {
1888
+ color = options.get('zeroColor');
1889
+ }
1890
+ if (colorMapByValue && (newColor = colorMapByValue.get(value))) {
1891
+ color = newColor;
1892
+ } else if (colorMapByIndex && colorMapByIndex.length > valuenum) {
1893
+ color = colorMapByIndex[valuenum];
1894
+ }
1895
+ return $.isArray(color) ? color[stacknum % color.length] : color;
1896
+ },
1897
+
1898
+ /**
1899
+ * Render bar(s) for a region
1900
+ */
1901
+ renderRegion: function (valuenum, highlight) {
1902
+ var vals = this.values[valuenum],
1903
+ options = this.options,
1904
+ xaxisOffset = this.xaxisOffset,
1905
+ result = [],
1906
+ range = this.range,
1907
+ stacked = this.stacked,
1908
+ target = this.target,
1909
+ x = valuenum * this.totalBarWidth,
1910
+ canvasHeightEf = this.canvasHeightEf,
1911
+ yoffset = this.yoffset,
1912
+ y, height, color, isNull, yoffsetNeg, i, valcount, val, minPlotted, allMin;
1913
+
1914
+ vals = $.isArray(vals) ? vals : [vals];
1915
+ valcount = vals.length;
1916
+ val = vals[0];
1917
+ isNull = all(null, vals);
1918
+ allMin = all(xaxisOffset, vals, true);
1919
+
1920
+ if (isNull) {
1921
+ if (options.get('nullColor')) {
1922
+ color = highlight ? options.get('nullColor') : this.calcHighlightColor(options.get('nullColor'), options);
1923
+ y = (yoffset > 0) ? yoffset - 1 : yoffset;
1924
+ return target.drawRect(x, y, this.barWidth - 1, 0, color, color);
1925
+ } else {
1926
+ return undefined;
1927
+ }
1928
+ }
1929
+ yoffsetNeg = yoffset;
1930
+ for (i = 0; i < valcount; i++) {
1931
+ val = vals[i];
1932
+
1933
+ if (stacked && val === xaxisOffset) {
1934
+ if (!allMin || minPlotted) {
1935
+ continue;
1936
+ }
1937
+ minPlotted = true;
1938
+ }
1939
+
1940
+ if (range > 0) {
1941
+ height = Math.floor(canvasHeightEf * ((Math.abs(val - xaxisOffset) / range))) + 1;
1942
+ } else {
1943
+ height = 1;
1944
+ }
1945
+ if (val < xaxisOffset || (val === xaxisOffset && yoffset === 0)) {
1946
+ y = yoffsetNeg;
1947
+ yoffsetNeg += height;
1948
+ } else {
1949
+ y = yoffset - height;
1950
+ yoffset -= height;
1951
+ }
1952
+ color = this.calcColor(i, val, valuenum);
1953
+ if (highlight) {
1954
+ color = this.calcHighlightColor(color, options);
1955
+ }
1956
+ result.push(target.drawRect(x, y, this.barWidth - 1, height - 1, color, color));
1957
+ }
1958
+ if (result.length === 1) {
1959
+ return result[0];
1960
+ }
1961
+ return result;
1962
+ }
1963
+ });
1964
+
1965
+ /**
1966
+ * Tristate charts
1967
+ */
1968
+ $.fn.sparkline.tristate = tristate = createClass($.fn.sparkline._base, barHighlightMixin, {
1969
+ type: 'tristate',
1970
+
1971
+ init: function (el, values, options, width, height) {
1972
+ var barWidth = parseInt(options.get('barWidth'), 10),
1973
+ barSpacing = parseInt(options.get('barSpacing'), 10);
1974
+ tristate._super.init.call(this, el, values, options, width, height);
1975
+
1976
+ this.regionShapes = {};
1977
+ this.barWidth = barWidth;
1978
+ this.barSpacing = barSpacing;
1979
+ this.totalBarWidth = barWidth + barSpacing;
1980
+ this.values = $.map(values, Number);
1981
+ this.width = width = (values.length * barWidth) + ((values.length - 1) * barSpacing);
1982
+
1983
+ if ($.isArray(options.get('colorMap'))) {
1984
+ this.colorMapByIndex = options.get('colorMap');
1985
+ this.colorMapByValue = null;
1986
+ } else {
1987
+ this.colorMapByIndex = null;
1988
+ this.colorMapByValue = options.get('colorMap');
1989
+ if (this.colorMapByValue && this.colorMapByValue.get === undefined) {
1990
+ this.colorMapByValue = new RangeMap(this.colorMapByValue);
1991
+ }
1992
+ }
1993
+ this.initTarget();
1994
+ },
1995
+
1996
+ getRegion: function (el, x, y) {
1997
+ return Math.floor(x / this.totalBarWidth);
1998
+ },
1999
+
2000
+ getCurrentRegionFields: function () {
2001
+ var currentRegion = this.currentRegion;
2002
+ return {
2003
+ isNull: this.values[currentRegion] === undefined,
2004
+ value: this.values[currentRegion],
2005
+ color: this.calcColor(this.values[currentRegion], currentRegion),
2006
+ offset: currentRegion
2007
+ };
2008
+ },
2009
+
2010
+ calcColor: function (value, valuenum) {
2011
+ var values = this.values,
2012
+ options = this.options,
2013
+ colorMapByIndex = this.colorMapByIndex,
2014
+ colorMapByValue = this.colorMapByValue,
2015
+ color, newColor;
2016
+
2017
+ if (colorMapByValue && (newColor = colorMapByValue.get(value))) {
2018
+ color = newColor;
2019
+ } else if (colorMapByIndex && colorMapByIndex.length > valuenum) {
2020
+ color = colorMapByIndex[valuenum];
2021
+ } else if (values[valuenum] < 0) {
2022
+ color = options.get('negBarColor');
2023
+ } else if (values[valuenum] > 0) {
2024
+ color = options.get('posBarColor');
2025
+ } else {
2026
+ color = options.get('zeroBarColor');
2027
+ }
2028
+ return color;
2029
+ },
2030
+
2031
+ renderRegion: function (valuenum, highlight) {
2032
+ var values = this.values,
2033
+ options = this.options,
2034
+ target = this.target,
2035
+ canvasHeight, height, halfHeight,
2036
+ x, y, color;
2037
+
2038
+ canvasHeight = target.pixelHeight;
2039
+ halfHeight = Math.round(canvasHeight / 2);
2040
+
2041
+ x = valuenum * this.totalBarWidth;
2042
+ if (values[valuenum] < 0) {
2043
+ y = halfHeight;
2044
+ height = halfHeight - 1;
2045
+ } else if (values[valuenum] > 0) {
2046
+ y = 0;
2047
+ height = halfHeight - 1;
2048
+ } else {
2049
+ y = halfHeight - 1;
2050
+ height = 2;
2051
+ }
2052
+ color = this.calcColor(values[valuenum], valuenum);
2053
+ if (color === null) {
2054
+ return;
2055
+ }
2056
+ if (highlight) {
2057
+ color = this.calcHighlightColor(color, options);
2058
+ }
2059
+ return target.drawRect(x, y, this.barWidth - 1, height - 1, color, color);
2060
+ }
2061
+ });
2062
+
2063
+ /**
2064
+ * Discrete charts
2065
+ */
2066
+ $.fn.sparkline.discrete = discrete = createClass($.fn.sparkline._base, barHighlightMixin, {
2067
+ type: 'discrete',
2068
+
2069
+ init: function (el, values, options, width, height) {
2070
+ discrete._super.init.call(this, el, values, options, width, height);
2071
+
2072
+ this.regionShapes = {};
2073
+ this.values = values = $.map(values, Number);
2074
+ this.min = Math.min.apply(Math, values);
2075
+ this.max = Math.max.apply(Math, values);
2076
+ this.range = this.max - this.min;
2077
+ this.width = width = options.get('width') === 'auto' ? values.length * 2 : this.width;
2078
+ this.interval = Math.floor(width / values.length);
2079
+ this.itemWidth = width / values.length;
2080
+ if (options.get('chartRangeMin') !== undefined && (options.get('chartRangeClip') || options.get('chartRangeMin') < this.min)) {
2081
+ this.min = options.get('chartRangeMin');
2082
+ }
2083
+ if (options.get('chartRangeMax') !== undefined && (options.get('chartRangeClip') || options.get('chartRangeMax') > this.max)) {
2084
+ this.max = options.get('chartRangeMax');
2085
+ }
2086
+ this.initTarget();
2087
+ if (this.target) {
2088
+ this.lineHeight = options.get('lineHeight') === 'auto' ? Math.round(this.canvasHeight * 0.3) : options.get('lineHeight');
2089
+ }
2090
+ },
2091
+
2092
+ getRegion: function (el, x, y) {
2093
+ return Math.floor(x / this.itemWidth);
2094
+ },
2095
+
2096
+ getCurrentRegionFields: function () {
2097
+ var currentRegion = this.currentRegion;
2098
+ return {
2099
+ isNull: this.values[currentRegion] === undefined,
2100
+ value: this.values[currentRegion],
2101
+ offset: currentRegion
2102
+ };
2103
+ },
2104
+
2105
+ renderRegion: function (valuenum, highlight) {
2106
+ var values = this.values,
2107
+ options = this.options,
2108
+ min = this.min,
2109
+ max = this.max,
2110
+ range = this.range,
2111
+ interval = this.interval,
2112
+ target = this.target,
2113
+ canvasHeight = this.canvasHeight,
2114
+ lineHeight = this.lineHeight,
2115
+ pheight = canvasHeight - lineHeight,
2116
+ ytop, val, color, x;
2117
+
2118
+ val = clipval(values[valuenum], min, max);
2119
+ x = valuenum * interval;
2120
+ ytop = Math.round(pheight - pheight * ((val - min) / range));
2121
+ color = (options.get('thresholdColor') && val < options.get('thresholdValue')) ? options.get('thresholdColor') : options.get('lineColor');
2122
+ if (highlight) {
2123
+ color = this.calcHighlightColor(color, options);
2124
+ }
2125
+ return target.drawLine(x, ytop, x, ytop + lineHeight, color);
2126
+ }
2127
+ });
2128
+
2129
+ /**
2130
+ * Bullet charts
2131
+ */
2132
+ $.fn.sparkline.bullet = bullet = createClass($.fn.sparkline._base, {
2133
+ type: 'bullet',
2134
+
2135
+ init: function (el, values, options, width, height) {
2136
+ var min, max, vals;
2137
+ bullet._super.init.call(this, el, values, options, width, height);
2138
+
2139
+ // values: target, performance, range1, range2, range3
2140
+ this.values = values = normalizeValues(values);
2141
+ // target or performance could be null
2142
+ vals = values.slice();
2143
+ vals[0] = vals[0] === null ? vals[2] : vals[0];
2144
+ vals[1] = values[1] === null ? vals[2] : vals[1];
2145
+ min = Math.min.apply(Math, values);
2146
+ max = Math.max.apply(Math, values);
2147
+ if (options.get('base') === undefined) {
2148
+ min = min < 0 ? min : 0;
2149
+ } else {
2150
+ min = options.get('base');
2151
+ }
2152
+ this.min = min;
2153
+ this.max = max;
2154
+ this.range = max - min;
2155
+ this.shapes = {};
2156
+ this.valueShapes = {};
2157
+ this.regiondata = {};
2158
+ this.width = width = options.get('width') === 'auto' ? '4.0em' : width;
2159
+ this.target = this.$el.simpledraw(width, height, options.get('composite'));
2160
+ if (!values.length) {
2161
+ this.disabled = true;
2162
+ }
2163
+ this.initTarget();
2164
+ },
2165
+
2166
+ getRegion: function (el, x, y) {
2167
+ var shapeid = this.target.getShapeAt(el, x, y);
2168
+ return (shapeid !== undefined && this.shapes[shapeid] !== undefined) ? this.shapes[shapeid] : undefined;
2169
+ },
2170
+
2171
+ getCurrentRegionFields: function () {
2172
+ var currentRegion = this.currentRegion;
2173
+ return {
2174
+ fieldkey: currentRegion.substr(0, 1),
2175
+ value: this.values[currentRegion.substr(1)],
2176
+ region: currentRegion
2177
+ };
2178
+ },
2179
+
2180
+ changeHighlight: function (highlight) {
2181
+ var currentRegion = this.currentRegion,
2182
+ shapeid = this.valueShapes[currentRegion],
2183
+ shape;
2184
+ delete this.shapes[shapeid];
2185
+ switch (currentRegion.substr(0, 1)) {
2186
+ case 'r':
2187
+ shape = this.renderRange(currentRegion.substr(1), highlight);
2188
+ break;
2189
+ case 'p':
2190
+ shape = this.renderPerformance(highlight);
2191
+ break;
2192
+ case 't':
2193
+ shape = this.renderTarget(highlight);
2194
+ break;
2195
+ }
2196
+ this.valueShapes[currentRegion] = shape.id;
2197
+ this.shapes[shape.id] = currentRegion;
2198
+ this.target.replaceWithShape(shapeid, shape);
2199
+ },
2200
+
2201
+ renderRange: function (rn, highlight) {
2202
+ var rangeval = this.values[rn],
2203
+ rangewidth = Math.round(this.canvasWidth * ((rangeval - this.min) / this.range)),
2204
+ color = this.options.get('rangeColors')[rn - 2];
2205
+ if (highlight) {
2206
+ color = this.calcHighlightColor(color, this.options);
2207
+ }
2208
+ return this.target.drawRect(0, 0, rangewidth - 1, this.canvasHeight - 1, color, color);
2209
+ },
2210
+
2211
+ renderPerformance: function (highlight) {
2212
+ var perfval = this.values[1],
2213
+ perfwidth = Math.round(this.canvasWidth * ((perfval - this.min) / this.range)),
2214
+ color = this.options.get('performanceColor');
2215
+ if (highlight) {
2216
+ color = this.calcHighlightColor(color, this.options);
2217
+ }
2218
+ return this.target.drawRect(0, Math.round(this.canvasHeight * 0.3), perfwidth - 1,
2219
+ Math.round(this.canvasHeight * 0.4) - 1, color, color);
2220
+ },
2221
+
2222
+ renderTarget: function (highlight) {
2223
+ var targetval = this.values[0],
2224
+ x = Math.round(this.canvasWidth * ((targetval - this.min) / this.range) - (this.options.get('targetWidth') / 2)),
2225
+ targettop = Math.round(this.canvasHeight * 0.10),
2226
+ targetheight = this.canvasHeight - (targettop * 2),
2227
+ color = this.options.get('targetColor');
2228
+ if (highlight) {
2229
+ color = this.calcHighlightColor(color, this.options);
2230
+ }
2231
+ return this.target.drawRect(x, targettop, this.options.get('targetWidth') - 1, targetheight - 1, color, color);
2232
+ },
2233
+
2234
+ render: function () {
2235
+ var vlen = this.values.length,
2236
+ target = this.target,
2237
+ i, shape;
2238
+ if (!bullet._super.render.call(this)) {
2239
+ return;
2240
+ }
2241
+ for (i = 2; i < vlen; i++) {
2242
+ shape = this.renderRange(i).append();
2243
+ this.shapes[shape.id] = 'r' + i;
2244
+ this.valueShapes['r' + i] = shape.id;
2245
+ }
2246
+ if (this.values[1] !== null) {
2247
+ shape = this.renderPerformance().append();
2248
+ this.shapes[shape.id] = 'p1';
2249
+ this.valueShapes.p1 = shape.id;
2250
+ }
2251
+ if (this.values[0] !== null) {
2252
+ shape = this.renderTarget().append();
2253
+ this.shapes[shape.id] = 't0';
2254
+ this.valueShapes.t0 = shape.id;
2255
+ }
2256
+ target.render();
2257
+ }
2258
+ });
2259
+
2260
+ /**
2261
+ * Pie charts
2262
+ */
2263
+ $.fn.sparkline.pie = pie = createClass($.fn.sparkline._base, {
2264
+ type: 'pie',
2265
+
2266
+ init: function (el, values, options, width, height) {
2267
+ var total = 0, i;
2268
+
2269
+ pie._super.init.call(this, el, values, options, width, height);
2270
+
2271
+ this.shapes = {}; // map shape ids to value offsets
2272
+ this.valueShapes = {}; // maps value offsets to shape ids
2273
+ this.values = values = $.map(values, Number);
2274
+
2275
+ if (options.get('width') === 'auto') {
2276
+ this.width = this.height;
2277
+ }
2278
+
2279
+ if (values.length > 0) {
2280
+ for (i = values.length; i--;) {
2281
+ total += values[i];
2282
+ }
2283
+ }
2284
+ this.total = total;
2285
+ this.initTarget();
2286
+ this.radius = Math.floor(Math.min(this.canvasWidth, this.canvasHeight) / 2);
2287
+ },
2288
+
2289
+ getRegion: function (el, x, y) {
2290
+ var shapeid = this.target.getShapeAt(el, x, y);
2291
+ return (shapeid !== undefined && this.shapes[shapeid] !== undefined) ? this.shapes[shapeid] : undefined;
2292
+ },
2293
+
2294
+ getCurrentRegionFields: function () {
2295
+ var currentRegion = this.currentRegion;
2296
+ return {
2297
+ isNull: this.values[currentRegion] === undefined,
2298
+ value: this.values[currentRegion],
2299
+ percent: this.values[currentRegion] / this.total * 100,
2300
+ color: this.options.get('sliceColors')[currentRegion % this.options.get('sliceColors').length],
2301
+ offset: currentRegion
2302
+ };
2303
+ },
2304
+
2305
+ changeHighlight: function (highlight) {
2306
+ var currentRegion = this.currentRegion,
2307
+ newslice = this.renderSlice(currentRegion, highlight),
2308
+ shapeid = this.valueShapes[currentRegion];
2309
+ delete this.shapes[shapeid];
2310
+ this.target.replaceWithShape(shapeid, newslice);
2311
+ this.valueShapes[currentRegion] = newslice.id;
2312
+ this.shapes[newslice.id] = currentRegion;
2313
+ },
2314
+
2315
+ renderSlice: function (valuenum, highlight) {
2316
+ var target = this.target,
2317
+ options = this.options,
2318
+ radius = this.radius,
2319
+ borderWidth = options.get('borderWidth'),
2320
+ offset = options.get('offset'),
2321
+ circle = 2 * Math.PI,
2322
+ values = this.values,
2323
+ total = this.total,
2324
+ next = offset ? (2*Math.PI)*(offset/360) : 0,
2325
+ start, end, i, vlen, color;
2326
+
2327
+ vlen = values.length;
2328
+ for (i = 0; i < vlen; i++) {
2329
+ start = next;
2330
+ end = next;
2331
+ if (total > 0) { // avoid divide by zero
2332
+ end = next + (circle * (values[i] / total));
2333
+ }
2334
+ if (valuenum === i) {
2335
+ color = options.get('sliceColors')[i % options.get('sliceColors').length];
2336
+ if (highlight) {
2337
+ color = this.calcHighlightColor(color, options);
2338
+ }
2339
+
2340
+ return target.drawPieSlice(radius, radius, radius - borderWidth, start, end, undefined, color);
2341
+ }
2342
+ next = end;
2343
+ }
2344
+ },
2345
+
2346
+ render: function () {
2347
+ var target = this.target,
2348
+ values = this.values,
2349
+ options = this.options,
2350
+ radius = this.radius,
2351
+ borderWidth = options.get('borderWidth'),
2352
+ shape, i;
2353
+
2354
+ if (!pie._super.render.call(this)) {
2355
+ return;
2356
+ }
2357
+ if (borderWidth) {
2358
+ target.drawCircle(radius, radius, Math.floor(radius - (borderWidth / 2)),
2359
+ options.get('borderColor'), undefined, borderWidth).append();
2360
+ }
2361
+ for (i = values.length; i--;) {
2362
+ if (values[i]) { // don't render zero values
2363
+ shape = this.renderSlice(i).append();
2364
+ this.valueShapes[i] = shape.id; // store just the shapeid
2365
+ this.shapes[shape.id] = i;
2366
+ }
2367
+ }
2368
+ target.render();
2369
+ }
2370
+ });
2371
+
2372
+ /**
2373
+ * Box plots
2374
+ */
2375
+ $.fn.sparkline.box = box = createClass($.fn.sparkline._base, {
2376
+ type: 'box',
2377
+
2378
+ init: function (el, values, options, width, height) {
2379
+ box._super.init.call(this, el, values, options, width, height);
2380
+ this.values = $.map(values, Number);
2381
+ this.width = options.get('width') === 'auto' ? '4.0em' : width;
2382
+ this.initTarget();
2383
+ if (!this.values.length) {
2384
+ this.disabled = 1;
2385
+ }
2386
+ },
2387
+
2388
+ /**
2389
+ * Simulate a single region
2390
+ */
2391
+ getRegion: function () {
2392
+ return 1;
2393
+ },
2394
+
2395
+ getCurrentRegionFields: function () {
2396
+ var result = [
2397
+ { field: 'lq', value: this.quartiles[0] },
2398
+ { field: 'med', value: this.quartiles[1] },
2399
+ { field: 'uq', value: this.quartiles[2] }
2400
+ ];
2401
+ if (this.loutlier !== undefined) {
2402
+ result.push({ field: 'lo', value: this.loutlier});
2403
+ }
2404
+ if (this.routlier !== undefined) {
2405
+ result.push({ field: 'ro', value: this.routlier});
2406
+ }
2407
+ if (this.lwhisker !== undefined) {
2408
+ result.push({ field: 'lw', value: this.lwhisker});
2409
+ }
2410
+ if (this.rwhisker !== undefined) {
2411
+ result.push({ field: 'rw', value: this.rwhisker});
2412
+ }
2413
+ return result;
2414
+ },
2415
+
2416
+ render: function () {
2417
+ var target = this.target,
2418
+ values = this.values,
2419
+ vlen = values.length,
2420
+ options = this.options,
2421
+ canvasWidth = this.canvasWidth,
2422
+ canvasHeight = this.canvasHeight,
2423
+ minValue = options.get('chartRangeMin') === undefined ? Math.min.apply(Math, values) : options.get('chartRangeMin'),
2424
+ maxValue = options.get('chartRangeMax') === undefined ? Math.max.apply(Math, values) : options.get('chartRangeMax'),
2425
+ canvasLeft = 0,
2426
+ lwhisker, loutlier, iqr, q1, q2, q3, rwhisker, routlier, i,
2427
+ size, unitSize;
2428
+
2429
+ if (!box._super.render.call(this)) {
2430
+ return;
2431
+ }
2432
+
2433
+ if (options.get('raw')) {
2434
+ if (options.get('showOutliers') && values.length > 5) {
2435
+ loutlier = values[0];
2436
+ lwhisker = values[1];
2437
+ q1 = values[2];
2438
+ q2 = values[3];
2439
+ q3 = values[4];
2440
+ rwhisker = values[5];
2441
+ routlier = values[6];
2442
+ } else {
2443
+ lwhisker = values[0];
2444
+ q1 = values[1];
2445
+ q2 = values[2];
2446
+ q3 = values[3];
2447
+ rwhisker = values[4];
2448
+ }
2449
+ } else {
2450
+ values.sort(function (a, b) { return a - b; });
2451
+ q1 = quartile(values, 1);
2452
+ q2 = quartile(values, 2);
2453
+ q3 = quartile(values, 3);
2454
+ iqr = q3 - q1;
2455
+ if (options.get('showOutliers')) {
2456
+ lwhisker = rwhisker = undefined;
2457
+ for (i = 0; i < vlen; i++) {
2458
+ if (lwhisker === undefined && values[i] > q1 - (iqr * options.get('outlierIQR'))) {
2459
+ lwhisker = values[i];
2460
+ }
2461
+ if (values[i] < q3 + (iqr * options.get('outlierIQR'))) {
2462
+ rwhisker = values[i];
2463
+ }
2464
+ }
2465
+ loutlier = values[0];
2466
+ routlier = values[vlen - 1];
2467
+ } else {
2468
+ lwhisker = values[0];
2469
+ rwhisker = values[vlen - 1];
2470
+ }
2471
+ }
2472
+ this.quartiles = [q1, q2, q3];
2473
+ this.lwhisker = lwhisker;
2474
+ this.rwhisker = rwhisker;
2475
+ this.loutlier = loutlier;
2476
+ this.routlier = routlier;
2477
+
2478
+ unitSize = canvasWidth / (maxValue - minValue + 1);
2479
+ if (options.get('showOutliers')) {
2480
+ canvasLeft = Math.ceil(options.get('spotRadius'));
2481
+ canvasWidth -= 2 * Math.ceil(options.get('spotRadius'));
2482
+ unitSize = canvasWidth / (maxValue - minValue + 1);
2483
+ if (loutlier < lwhisker) {
2484
+ target.drawCircle((loutlier - minValue) * unitSize + canvasLeft,
2485
+ canvasHeight / 2,
2486
+ options.get('spotRadius'),
2487
+ options.get('outlierLineColor'),
2488
+ options.get('outlierFillColor')).append();
2489
+ }
2490
+ if (routlier > rwhisker) {
2491
+ target.drawCircle((routlier - minValue) * unitSize + canvasLeft,
2492
+ canvasHeight / 2,
2493
+ options.get('spotRadius'),
2494
+ options.get('outlierLineColor'),
2495
+ options.get('outlierFillColor')).append();
2496
+ }
2497
+ }
2498
+
2499
+ // box
2500
+ target.drawRect(
2501
+ Math.round((q1 - minValue) * unitSize + canvasLeft),
2502
+ Math.round(canvasHeight * 0.1),
2503
+ Math.round((q3 - q1) * unitSize),
2504
+ Math.round(canvasHeight * 0.8),
2505
+ options.get('boxLineColor'),
2506
+ options.get('boxFillColor')).append();
2507
+ // left whisker
2508
+ target.drawLine(
2509
+ Math.round((lwhisker - minValue) * unitSize + canvasLeft),
2510
+ Math.round(canvasHeight / 2),
2511
+ Math.round((q1 - minValue) * unitSize + canvasLeft),
2512
+ Math.round(canvasHeight / 2),
2513
+ options.get('lineColor')).append();
2514
+ target.drawLine(
2515
+ Math.round((lwhisker - minValue) * unitSize + canvasLeft),
2516
+ Math.round(canvasHeight / 4),
2517
+ Math.round((lwhisker - minValue) * unitSize + canvasLeft),
2518
+ Math.round(canvasHeight - canvasHeight / 4),
2519
+ options.get('whiskerColor')).append();
2520
+ // right whisker
2521
+ target.drawLine(Math.round((rwhisker - minValue) * unitSize + canvasLeft),
2522
+ Math.round(canvasHeight / 2),
2523
+ Math.round((q3 - minValue) * unitSize + canvasLeft),
2524
+ Math.round(canvasHeight / 2),
2525
+ options.get('lineColor')).append();
2526
+ target.drawLine(
2527
+ Math.round((rwhisker - minValue) * unitSize + canvasLeft),
2528
+ Math.round(canvasHeight / 4),
2529
+ Math.round((rwhisker - minValue) * unitSize + canvasLeft),
2530
+ Math.round(canvasHeight - canvasHeight / 4),
2531
+ options.get('whiskerColor')).append();
2532
+ // median line
2533
+ target.drawLine(
2534
+ Math.round((q2 - minValue) * unitSize + canvasLeft),
2535
+ Math.round(canvasHeight * 0.1),
2536
+ Math.round((q2 - minValue) * unitSize + canvasLeft),
2537
+ Math.round(canvasHeight * 0.9),
2538
+ options.get('medianColor')).append();
2539
+ if (options.get('target')) {
2540
+ size = Math.ceil(options.get('spotRadius'));
2541
+ target.drawLine(
2542
+ Math.round((options.get('target') - minValue) * unitSize + canvasLeft),
2543
+ Math.round((canvasHeight / 2) - size),
2544
+ Math.round((options.get('target') - minValue) * unitSize + canvasLeft),
2545
+ Math.round((canvasHeight / 2) + size),
2546
+ options.get('targetColor')).append();
2547
+ target.drawLine(
2548
+ Math.round((options.get('target') - minValue) * unitSize + canvasLeft - size),
2549
+ Math.round(canvasHeight / 2),
2550
+ Math.round((options.get('target') - minValue) * unitSize + canvasLeft + size),
2551
+ Math.round(canvasHeight / 2),
2552
+ options.get('targetColor')).append();
2553
+ }
2554
+ target.render();
2555
+ }
2556
+ });
2557
+
2558
+ // Setup a very simple "virtual canvas" to make drawing the few shapes we need easier
2559
+ // This is accessible as $(foo).simpledraw()
2560
+
2561
+ VShape = createClass({
2562
+ init: function (target, id, type, args) {
2563
+ this.target = target;
2564
+ this.id = id;
2565
+ this.type = type;
2566
+ this.args = args;
2567
+ },
2568
+ append: function () {
2569
+ this.target.appendShape(this);
2570
+ return this;
2571
+ }
2572
+ });
2573
+
2574
+ VCanvas_base = createClass({
2575
+ _pxregex: /(\d+)(px)?\s*$/i,
2576
+
2577
+ init: function (width, height, target) {
2578
+ if (!width) {
2579
+ return;
2580
+ }
2581
+ this.width = width;
2582
+ this.height = height;
2583
+ this.target = target;
2584
+ this.lastShapeId = null;
2585
+ if (target[0]) {
2586
+ target = target[0];
2587
+ }
2588
+ $.data(target, '_jqs_vcanvas', this);
2589
+ },
2590
+
2591
+ drawLine: function (x1, y1, x2, y2, lineColor, lineWidth) {
2592
+ return this.drawShape([[x1, y1], [x2, y2]], lineColor, lineWidth);
2593
+ },
2594
+
2595
+ drawShape: function (path, lineColor, fillColor, lineWidth) {
2596
+ return this._genShape('Shape', [path, lineColor, fillColor, lineWidth]);
2597
+ },
2598
+
2599
+ drawCircle: function (x, y, radius, lineColor, fillColor, lineWidth) {
2600
+ return this._genShape('Circle', [x, y, radius, lineColor, fillColor, lineWidth]);
2601
+ },
2602
+
2603
+ drawPieSlice: function (x, y, radius, startAngle, endAngle, lineColor, fillColor) {
2604
+ return this._genShape('PieSlice', [x, y, radius, startAngle, endAngle, lineColor, fillColor]);
2605
+ },
2606
+
2607
+ drawRect: function (x, y, width, height, lineColor, fillColor) {
2608
+ return this._genShape('Rect', [x, y, width, height, lineColor, fillColor]);
2609
+ },
2610
+
2611
+ getElement: function () {
2612
+ return this.canvas;
2613
+ },
2614
+
2615
+ /**
2616
+ * Return the most recently inserted shape id
2617
+ */
2618
+ getLastShapeId: function () {
2619
+ return this.lastShapeId;
2620
+ },
2621
+
2622
+ /**
2623
+ * Clear and reset the canvas
2624
+ */
2625
+ reset: function () {
2626
+ alert('reset not implemented');
2627
+ },
2628
+
2629
+ _insert: function (el, target) {
2630
+ $(target).html(el);
2631
+ },
2632
+
2633
+ /**
2634
+ * Calculate the pixel dimensions of the canvas
2635
+ */
2636
+ _calculatePixelDims: function (width, height, canvas) {
2637
+ // XXX This should probably be a configurable option
2638
+ var match;
2639
+ match = this._pxregex.exec(height);
2640
+ if (match) {
2641
+ this.pixelHeight = match[1];
2642
+ } else {
2643
+ this.pixelHeight = $(canvas).height();
2644
+ }
2645
+ match = this._pxregex.exec(width);
2646
+ if (match) {
2647
+ this.pixelWidth = match[1];
2648
+ } else {
2649
+ this.pixelWidth = $(canvas).width();
2650
+ }
2651
+ },
2652
+
2653
+ /**
2654
+ * Generate a shape object and id for later rendering
2655
+ */
2656
+ _genShape: function (shapetype, shapeargs) {
2657
+ var id = shapeCount++;
2658
+ shapeargs.unshift(id);
2659
+ return new VShape(this, id, shapetype, shapeargs);
2660
+ },
2661
+
2662
+ /**
2663
+ * Add a shape to the end of the render queue
2664
+ */
2665
+ appendShape: function (shape) {
2666
+ alert('appendShape not implemented');
2667
+ },
2668
+
2669
+ /**
2670
+ * Replace one shape with another
2671
+ */
2672
+ replaceWithShape: function (shapeid, shape) {
2673
+ alert('replaceWithShape not implemented');
2674
+ },
2675
+
2676
+ /**
2677
+ * Insert one shape after another in the render queue
2678
+ */
2679
+ insertAfterShape: function (shapeid, shape) {
2680
+ alert('insertAfterShape not implemented');
2681
+ },
2682
+
2683
+ /**
2684
+ * Remove a shape from the queue
2685
+ */
2686
+ removeShapeId: function (shapeid) {
2687
+ alert('removeShapeId not implemented');
2688
+ },
2689
+
2690
+ /**
2691
+ * Find a shape at the specified x/y co-ordinates
2692
+ */
2693
+ getShapeAt: function (el, x, y) {
2694
+ alert('getShapeAt not implemented');
2695
+ },
2696
+
2697
+ /**
2698
+ * Render all queued shapes onto the canvas
2699
+ */
2700
+ render: function () {
2701
+ alert('render not implemented');
2702
+ }
2703
+ });
2704
+
2705
+ VCanvas_canvas = createClass(VCanvas_base, {
2706
+ init: function (width, height, target, interact) {
2707
+ VCanvas_canvas._super.init.call(this, width, height, target);
2708
+ this.canvas = document.createElement('canvas');
2709
+ if (target[0]) {
2710
+ target = target[0];
2711
+ }
2712
+ $.data(target, '_jqs_vcanvas', this);
2713
+ $(this.canvas).css({ display: 'inline-block', width: width, height: height, verticalAlign: 'top' });
2714
+ this._insert(this.canvas, target);
2715
+ this._calculatePixelDims(width, height, this.canvas);
2716
+ this.canvas.width = this.pixelWidth;
2717
+ this.canvas.height = this.pixelHeight;
2718
+ this.interact = interact;
2719
+ this.shapes = {};
2720
+ this.shapeseq = [];
2721
+ this.currentTargetShapeId = undefined;
2722
+ $(this.canvas).css({width: this.pixelWidth, height: this.pixelHeight});
2723
+ },
2724
+
2725
+ _getContext: function (lineColor, fillColor, lineWidth) {
2726
+ var context = this.canvas.getContext('2d');
2727
+ if (lineColor !== undefined) {
2728
+ context.strokeStyle = lineColor;
2729
+ }
2730
+ context.lineWidth = lineWidth === undefined ? 1 : lineWidth;
2731
+ if (fillColor !== undefined) {
2732
+ context.fillStyle = fillColor;
2733
+ }
2734
+ return context;
2735
+ },
2736
+
2737
+ reset: function () {
2738
+ var context = this._getContext();
2739
+ context.clearRect(0, 0, this.pixelWidth, this.pixelHeight);
2740
+ this.shapes = {};
2741
+ this.shapeseq = [];
2742
+ this.currentTargetShapeId = undefined;
2743
+ },
2744
+
2745
+ _drawShape: function (shapeid, path, lineColor, fillColor, lineWidth) {
2746
+ var context = this._getContext(lineColor, fillColor, lineWidth),
2747
+ i, plen;
2748
+ context.beginPath();
2749
+ context.moveTo(path[0][0] + 0.5, path[0][1] + 0.5);
2750
+ for (i = 1, plen = path.length; i < plen; i++) {
2751
+ context.lineTo(path[i][0] + 0.5, path[i][1] + 0.5); // the 0.5 offset gives us crisp pixel-width lines
2752
+ }
2753
+ if (lineColor !== undefined) {
2754
+ context.stroke();
2755
+ }
2756
+ if (fillColor !== undefined) {
2757
+ context.fill();
2758
+ }
2759
+ if (this.targetX !== undefined && this.targetY !== undefined &&
2760
+ context.isPointInPath(this.targetX, this.targetY)) {
2761
+ this.currentTargetShapeId = shapeid;
2762
+ }
2763
+ },
2764
+
2765
+ _drawCircle: function (shapeid, x, y, radius, lineColor, fillColor, lineWidth) {
2766
+ var context = this._getContext(lineColor, fillColor, lineWidth);
2767
+ context.beginPath();
2768
+ context.arc(x, y, radius, 0, 2 * Math.PI, false);
2769
+ if (this.targetX !== undefined && this.targetY !== undefined &&
2770
+ context.isPointInPath(this.targetX, this.targetY)) {
2771
+ this.currentTargetShapeId = shapeid;
2772
+ }
2773
+ if (lineColor !== undefined) {
2774
+ context.stroke();
2775
+ }
2776
+ if (fillColor !== undefined) {
2777
+ context.fill();
2778
+ }
2779
+ },
2780
+
2781
+ _drawPieSlice: function (shapeid, x, y, radius, startAngle, endAngle, lineColor, fillColor) {
2782
+ var context = this._getContext(lineColor, fillColor);
2783
+ context.beginPath();
2784
+ context.moveTo(x, y);
2785
+ context.arc(x, y, radius, startAngle, endAngle, false);
2786
+ context.lineTo(x, y);
2787
+ context.closePath();
2788
+ if (lineColor !== undefined) {
2789
+ context.stroke();
2790
+ }
2791
+ if (fillColor) {
2792
+ context.fill();
2793
+ }
2794
+ if (this.targetX !== undefined && this.targetY !== undefined &&
2795
+ context.isPointInPath(this.targetX, this.targetY)) {
2796
+ this.currentTargetShapeId = shapeid;
2797
+ }
2798
+ },
2799
+
2800
+ _drawRect: function (shapeid, x, y, width, height, lineColor, fillColor) {
2801
+ return this._drawShape(shapeid, [[x, y], [x + width, y], [x + width, y + height], [x, y + height], [x, y]], lineColor, fillColor);
2802
+ },
2803
+
2804
+ appendShape: function (shape) {
2805
+ this.shapes[shape.id] = shape;
2806
+ this.shapeseq.push(shape.id);
2807
+ this.lastShapeId = shape.id;
2808
+ return shape.id;
2809
+ },
2810
+
2811
+ replaceWithShape: function (shapeid, shape) {
2812
+ var shapeseq = this.shapeseq,
2813
+ i;
2814
+ this.shapes[shape.id] = shape;
2815
+ for (i = shapeseq.length; i--;) {
2816
+ if (shapeseq[i] == shapeid) {
2817
+ shapeseq[i] = shape.id;
2818
+ }
2819
+ }
2820
+ delete this.shapes[shapeid];
2821
+ },
2822
+
2823
+ replaceWithShapes: function (shapeids, shapes) {
2824
+ var shapeseq = this.shapeseq,
2825
+ shapemap = {},
2826
+ sid, i, first;
2827
+
2828
+ for (i = shapeids.length; i--;) {
2829
+ shapemap[shapeids[i]] = true;
2830
+ }
2831
+ for (i = shapeseq.length; i--;) {
2832
+ sid = shapeseq[i];
2833
+ if (shapemap[sid]) {
2834
+ shapeseq.splice(i, 1);
2835
+ delete this.shapes[sid];
2836
+ first = i;
2837
+ }
2838
+ }
2839
+ for (i = shapes.length; i--;) {
2840
+ shapeseq.splice(first, 0, shapes[i].id);
2841
+ this.shapes[shapes[i].id] = shapes[i];
2842
+ }
2843
+
2844
+ },
2845
+
2846
+ insertAfterShape: function (shapeid, shape) {
2847
+ var shapeseq = this.shapeseq,
2848
+ i;
2849
+ for (i = shapeseq.length; i--;) {
2850
+ if (shapeseq[i] === shapeid) {
2851
+ shapeseq.splice(i + 1, 0, shape.id);
2852
+ this.shapes[shape.id] = shape;
2853
+ return;
2854
+ }
2855
+ }
2856
+ },
2857
+
2858
+ removeShapeId: function (shapeid) {
2859
+ var shapeseq = this.shapeseq,
2860
+ i;
2861
+ for (i = shapeseq.length; i--;) {
2862
+ if (shapeseq[i] === shapeid) {
2863
+ shapeseq.splice(i, 1);
2864
+ break;
2865
+ }
2866
+ }
2867
+ delete this.shapes[shapeid];
2868
+ },
2869
+
2870
+ getShapeAt: function (el, x, y) {
2871
+ this.targetX = x;
2872
+ this.targetY = y;
2873
+ this.render();
2874
+ return this.currentTargetShapeId;
2875
+ },
2876
+
2877
+ render: function () {
2878
+ var shapeseq = this.shapeseq,
2879
+ shapes = this.shapes,
2880
+ shapeCount = shapeseq.length,
2881
+ context = this._getContext(),
2882
+ shapeid, shape, i;
2883
+ context.clearRect(0, 0, this.pixelWidth, this.pixelHeight);
2884
+ for (i = 0; i < shapeCount; i++) {
2885
+ shapeid = shapeseq[i];
2886
+ shape = shapes[shapeid];
2887
+ this['_draw' + shape.type].apply(this, shape.args);
2888
+ }
2889
+ if (!this.interact) {
2890
+ // not interactive so no need to keep the shapes array
2891
+ this.shapes = {};
2892
+ this.shapeseq = [];
2893
+ }
2894
+ }
2895
+
2896
+ });
2897
+
2898
+ VCanvas_vml = createClass(VCanvas_base, {
2899
+ init: function (width, height, target) {
2900
+ var groupel;
2901
+ VCanvas_vml._super.init.call(this, width, height, target);
2902
+ if (target[0]) {
2903
+ target = target[0];
2904
+ }
2905
+ $.data(target, '_jqs_vcanvas', this);
2906
+ this.canvas = document.createElement('span');
2907
+ $(this.canvas).css({ display: 'inline-block', position: 'relative', overflow: 'hidden', width: width, height: height, margin: '0px', padding: '0px', verticalAlign: 'top'});
2908
+ this._insert(this.canvas, target);
2909
+ this._calculatePixelDims(width, height, this.canvas);
2910
+ this.canvas.width = this.pixelWidth;
2911
+ this.canvas.height = this.pixelHeight;
2912
+ groupel = '<v:group coordorigin="0 0" coordsize="' + this.pixelWidth + ' ' + this.pixelHeight + '"' +
2913
+ ' style="position:absolute;top:0;left:0;width:' + this.pixelWidth + 'px;height=' + this.pixelHeight + 'px;"></v:group>';
2914
+ this.canvas.insertAdjacentHTML('beforeEnd', groupel);
2915
+ this.group = $(this.canvas).children()[0];
2916
+ this.rendered = false;
2917
+ this.prerender = '';
2918
+ },
2919
+
2920
+ _drawShape: function (shapeid, path, lineColor, fillColor, lineWidth) {
2921
+ var vpath = [],
2922
+ initial, stroke, fill, closed, vel, plen, i;
2923
+ for (i = 0, plen = path.length; i < plen; i++) {
2924
+ vpath[i] = '' + (path[i][0]) + ',' + (path[i][1]);
2925
+ }
2926
+ initial = vpath.splice(0, 1);
2927
+ lineWidth = lineWidth === undefined ? 1 : lineWidth;
2928
+ stroke = lineColor === undefined ? ' stroked="false" ' : ' strokeWeight="' + lineWidth + 'px" strokeColor="' + lineColor + '" ';
2929
+ fill = fillColor === undefined ? ' filled="false"' : ' fillColor="' + fillColor + '" filled="true" ';
2930
+ closed = vpath[0] === vpath[vpath.length - 1] ? 'x ' : '';
2931
+ vel = '<v:shape coordorigin="0 0" coordsize="' + this.pixelWidth + ' ' + this.pixelHeight + '" ' +
2932
+ ' id="jqsshape' + shapeid + '" ' +
2933
+ stroke +
2934
+ fill +
2935
+ ' style="position:absolute;left:0px;top:0px;height:' + this.pixelHeight + 'px;width:' + this.pixelWidth + 'px;padding:0px;margin:0px;" ' +
2936
+ ' path="m ' + initial + ' l ' + vpath.join(', ') + ' ' + closed + 'e">' +
2937
+ ' </v:shape>';
2938
+ return vel;
2939
+ },
2940
+
2941
+ _drawCircle: function (shapeid, x, y, radius, lineColor, fillColor, lineWidth) {
2942
+ var stroke, fill, vel;
2943
+ x -= radius;
2944
+ y -= radius;
2945
+ stroke = lineColor === undefined ? ' stroked="false" ' : ' strokeWeight="' + lineWidth + 'px" strokeColor="' + lineColor + '" ';
2946
+ fill = fillColor === undefined ? ' filled="false"' : ' fillColor="' + fillColor + '" filled="true" ';
2947
+ vel = '<v:oval ' +
2948
+ ' id="jqsshape' + shapeid + '" ' +
2949
+ stroke +
2950
+ fill +
2951
+ ' style="position:absolute;top:' + y + 'px; left:' + x + 'px; width:' + (radius * 2) + 'px; height:' + (radius * 2) + 'px"></v:oval>';
2952
+ return vel;
2953
+
2954
+ },
2955
+
2956
+ _drawPieSlice: function (shapeid, x, y, radius, startAngle, endAngle, lineColor, fillColor) {
2957
+ var vpath, startx, starty, endx, endy, stroke, fill, vel;
2958
+ if (startAngle === endAngle) {
2959
+ return ''; // VML seems to have problem when start angle equals end angle.
2960
+ }
2961
+ if ((endAngle - startAngle) === (2 * Math.PI)) {
2962
+ startAngle = 0.0; // VML seems to have a problem when drawing a full circle that doesn't start 0
2963
+ endAngle = (2 * Math.PI);
2964
+ }
2965
+
2966
+ startx = x + Math.round(Math.cos(startAngle) * radius);
2967
+ starty = y + Math.round(Math.sin(startAngle) * radius);
2968
+ endx = x + Math.round(Math.cos(endAngle) * radius);
2969
+ endy = y + Math.round(Math.sin(endAngle) * radius);
2970
+
2971
+ if (startx === endx && starty === endy) {
2972
+ if ((endAngle - startAngle) < Math.PI) {
2973
+ // Prevent very small slices from being mistaken as a whole pie
2974
+ return '';
2975
+ }
2976
+ // essentially going to be the entire circle, so ignore startAngle
2977
+ startx = endx = x + radius;
2978
+ starty = endy = y;
2979
+ }
2980
+
2981
+ if (startx === endx && starty === endy && (endAngle - startAngle) < Math.PI) {
2982
+ return '';
2983
+ }
2984
+
2985
+ vpath = [x - radius, y - radius, x + radius, y + radius, startx, starty, endx, endy];
2986
+ stroke = lineColor === undefined ? ' stroked="false" ' : ' strokeWeight="1px" strokeColor="' + lineColor + '" ';
2987
+ fill = fillColor === undefined ? ' filled="false"' : ' fillColor="' + fillColor + '" filled="true" ';
2988
+ vel = '<v:shape coordorigin="0 0" coordsize="' + this.pixelWidth + ' ' + this.pixelHeight + '" ' +
2989
+ ' id="jqsshape' + shapeid + '" ' +
2990
+ stroke +
2991
+ fill +
2992
+ ' style="position:absolute;left:0px;top:0px;height:' + this.pixelHeight + 'px;width:' + this.pixelWidth + 'px;padding:0px;margin:0px;" ' +
2993
+ ' path="m ' + x + ',' + y + ' wa ' + vpath.join(', ') + ' x e">' +
2994
+ ' </v:shape>';
2995
+ return vel;
2996
+ },
2997
+
2998
+ _drawRect: function (shapeid, x, y, width, height, lineColor, fillColor) {
2999
+ return this._drawShape(shapeid, [[x, y], [x, y + height], [x + width, y + height], [x + width, y], [x, y]], lineColor, fillColor);
3000
+ },
3001
+
3002
+ reset: function () {
3003
+ this.group.innerHTML = '';
3004
+ },
3005
+
3006
+ appendShape: function (shape) {
3007
+ var vel = this['_draw' + shape.type].apply(this, shape.args);
3008
+ if (this.rendered) {
3009
+ this.group.insertAdjacentHTML('beforeEnd', vel);
3010
+ } else {
3011
+ this.prerender += vel;
3012
+ }
3013
+ this.lastShapeId = shape.id;
3014
+ return shape.id;
3015
+ },
3016
+
3017
+ replaceWithShape: function (shapeid, shape) {
3018
+ var existing = $('#jqsshape' + shapeid),
3019
+ vel = this['_draw' + shape.type].apply(this, shape.args);
3020
+ existing[0].outerHTML = vel;
3021
+ },
3022
+
3023
+ replaceWithShapes: function (shapeids, shapes) {
3024
+ // replace the first shapeid with all the new shapes then toast the remaining old shapes
3025
+ var existing = $('#jqsshape' + shapeids[0]),
3026
+ replace = '',
3027
+ slen = shapes.length,
3028
+ i;
3029
+ for (i = 0; i < slen; i++) {
3030
+ replace += this['_draw' + shapes[i].type].apply(this, shapes[i].args);
3031
+ }
3032
+ existing[0].outerHTML = replace;
3033
+ for (i = 1; i < shapeids.length; i++) {
3034
+ $('#jqsshape' + shapeids[i]).remove();
3035
+ }
3036
+ },
3037
+
3038
+ insertAfterShape: function (shapeid, shape) {
3039
+ var existing = $('#jqsshape' + shapeid),
3040
+ vel = this['_draw' + shape.type].apply(this, shape.args);
3041
+ existing[0].insertAdjacentHTML('afterEnd', vel);
3042
+ },
3043
+
3044
+ removeShapeId: function (shapeid) {
3045
+ var existing = $('#jqsshape' + shapeid);
3046
+ this.group.removeChild(existing[0]);
3047
+ },
3048
+
3049
+ getShapeAt: function (el, x, y) {
3050
+ var shapeid = el.id.substr(8);
3051
+ return shapeid;
3052
+ },
3053
+
3054
+ render: function () {
3055
+ if (!this.rendered) {
3056
+ // batch the intial render into a single repaint
3057
+ this.group.innerHTML = this.prerender;
3058
+ this.rendered = true;
3059
+ }
3060
+ }
3061
+ });
3062
+
3063
+ }))}(document, Math));