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,524 @@
1
+ # Request Animation Frame Polyfill
2
+ # CoffeeScript version of http://paulirish.com/2011/requestanimationframe-for-smart-animating/
3
+ do () ->
4
+ vendors = ['ms', 'moz', 'webkit', 'o']
5
+ for vendor in vendors
6
+ if window.requestAnimationFrame
7
+ break
8
+ window.requestAnimationFrame = window[vendor + 'RequestAnimationFrame']
9
+ window.cancelAnimationFrame = window[vendor + 'CancelAnimationFrame'] or window[vendor + 'CancelRequestAnimationFrame']
10
+
11
+ browserRequestAnimationFrame = null
12
+ lastId = 0
13
+ isCancelled = {}
14
+
15
+ if not requestAnimationFrame
16
+ window.requestAnimationFrame = (callback, element) ->
17
+ currTime = new Date().getTime()
18
+ timeToCall = Math.max(0, 16 - (currTime - lastTime))
19
+ id = window.setTimeout(() ->
20
+ callback(currTime + timeToCall)
21
+ , timeToCall)
22
+ lastTime = currTime + timeToCall
23
+ return id
24
+ # This implementation should only be used with the setTimeout()
25
+ # version of window.requestAnimationFrame().
26
+ window.cancelAnimationFrame = (id) ->
27
+ clearTimeout(id)
28
+ else if not window.cancelAnimationFrame
29
+ browserRequestAnimationFrame = window.requestAnimationFrame
30
+ window.requestAnimationFrame = (callback, element) ->
31
+ myId = ++lastId
32
+ browserRequestAnimationFrame(() ->
33
+ if not isCancelled[myId]
34
+ callback()
35
+ , element)
36
+ return myId
37
+ window.cancelAnimationFrame = (id) ->
38
+ isCancelled[id] = true
39
+
40
+ String.prototype.hashCode = () ->
41
+ hash = 0
42
+ if this.length == 0
43
+ return hash
44
+ for i in [0...this.length]
45
+ char = this.charCodeAt(i)
46
+ hash = ((hash << 5) - hash) + char
47
+ hash = hash & hash # Convert to 32bit integer
48
+ return hash
49
+
50
+ secondsToString = (sec) ->
51
+ hr = Math.floor(sec / 3600)
52
+ min = Math.floor((sec - (hr * 3600))/60)
53
+ sec -= ((hr * 3600) + (min * 60))
54
+ sec += ''
55
+ min += ''
56
+ while min.length < 2
57
+ min = '0' + min
58
+ while sec.length < 2
59
+ sec = '0' + sec
60
+ hr = if hr then hr + ':' else ''
61
+ return hr + min + ':' + sec
62
+
63
+ formatNumber = (num) ->
64
+ return addCommas(num.toFixed(0))
65
+
66
+ updateObjectValues = (obj1, obj2) ->
67
+ for own key, val of obj2
68
+ obj1[key] = val
69
+ return obj1
70
+
71
+ mergeObjects = (obj1, obj2) ->
72
+ out = {}
73
+ for own key, val of obj1
74
+ out[key] = val
75
+ for own key, val of obj2
76
+ out[key] = val
77
+ return out
78
+
79
+ addCommas = (nStr) ->
80
+ nStr += ''
81
+ x = nStr.split('.')
82
+ x1 = x[0]
83
+ x2 = ''
84
+ if x.length > 1
85
+ x2 = '.' + x[1]
86
+ rgx = /(\d+)(\d{3})/
87
+ while rgx.test(x1)
88
+ x1 = x1.replace(rgx, '$1' + ',' + '$2')
89
+ return x1 + x2
90
+
91
+ cutHex = (nStr) ->
92
+ if nStr.charAt(0) == "#"
93
+ return nStr.substring(1,7)
94
+ return nStr
95
+
96
+ class ValueUpdater
97
+ animationSpeed: 32
98
+ constructor: (addToAnimationQueue=true, @clear=true) ->
99
+ if addToAnimationQueue
100
+ AnimationUpdater.add(@)
101
+
102
+ update: (force=false) ->
103
+ if force or @displayedValue != @value
104
+ if @ctx and @clear
105
+ @ctx.clearRect(0, 0, @canvas.width, @canvas.height)
106
+ diff = @value - @displayedValue
107
+ if Math.abs(diff / @animationSpeed) <= 0.001
108
+ @displayedValue = @value
109
+ else
110
+ @displayedValue = @displayedValue + diff / @animationSpeed
111
+ @render()
112
+ return true
113
+ return false
114
+
115
+ class BaseGauge extends ValueUpdater
116
+ displayScale: 1
117
+
118
+ setTextField: (textField) ->
119
+ @textField = if textField instanceof TextRenderer then textField else new TextRenderer(textField)
120
+
121
+ setMinValue: (@minValue, updateStartValue=true) ->
122
+ if updateStartValue
123
+ @displayedValue = @minValue
124
+ for gauge in @gp or []
125
+ gauge.displayedValue = @minValue
126
+
127
+ setOptions: (options=null) ->
128
+ @options = mergeObjects(@options, options)
129
+ if @textField
130
+ @textField.el.style.fontSize = options.fontSize + 'px'
131
+
132
+ if @options.angle > .5
133
+ @gauge.options.angle = .5
134
+ @configDisplayScale()
135
+ return @
136
+
137
+ configDisplayScale: () ->
138
+ prevDisplayScale = @displayScale
139
+
140
+ if @options.highDpiSupport == false
141
+ delete @displayScale
142
+ else
143
+ devicePixelRatio = window.devicePixelRatio or 1
144
+ backingStorePixelRatio =
145
+ @ctx.webkitBackingStorePixelRatio or
146
+ @ctx.mozBackingStorePixelRatio or
147
+ @ctx.msBackingStorePixelRatio or
148
+ @ctx.oBackingStorePixelRatio or
149
+ @ctx.backingStorePixelRatio or 1
150
+ @displayScale = devicePixelRatio / backingStorePixelRatio
151
+
152
+ if @displayScale != prevDisplayScale
153
+ width = @canvas.G__width or @canvas.width
154
+ height = @canvas.G__height or @canvas.height
155
+ @canvas.width = width * @displayScale
156
+ @canvas.height = height * @displayScale
157
+ @canvas.style.width = "#{width}px"
158
+ @canvas.style.height = "#{height}px"
159
+ @canvas.G__width = width
160
+ @canvas.G__height = height
161
+
162
+ return @
163
+
164
+ class TextRenderer
165
+ constructor: (@el) ->
166
+
167
+ # Default behaviour, override to customize rendering
168
+ render: (gauge) ->
169
+ @el.innerHTML = formatNumber(gauge.displayedValue)
170
+
171
+ class AnimatedText extends ValueUpdater
172
+ displayedValue: 0
173
+ value: 0
174
+
175
+ setVal: (value) ->
176
+ @value = 1 * value
177
+
178
+ constructor: (@elem, @text=false) ->
179
+ @value = 1 * @elem.innerHTML
180
+ if @text
181
+ @value = 0
182
+ render: () ->
183
+ if @text
184
+ textVal = secondsToString(@displayedValue.toFixed(0))
185
+ else
186
+ textVal = addCommas(formatNumber(@displayedValue))
187
+ @elem.innerHTML = textVal
188
+
189
+ AnimatedTextFactory =
190
+ create: (objList) ->
191
+ out = []
192
+ for elem in objList
193
+ out.push(new AnimatedText(elem))
194
+ return out
195
+
196
+ class GaugePointer extends ValueUpdater
197
+ displayedValue: 0
198
+ value: 0
199
+ options:
200
+ strokeWidth: 0.035
201
+ length: 0.1
202
+ color: "#000000"
203
+
204
+ constructor: (@gauge) ->
205
+ @ctx = @gauge.ctx
206
+ @canvas = @gauge.canvas
207
+ super(false, false)
208
+ @setOptions()
209
+
210
+ setOptions: (options=null) ->
211
+ updateObjectValues(@options, options)
212
+ @length = @canvas.height * @options.length
213
+ @strokeWidth = @canvas.height * @options.strokeWidth
214
+ @maxValue = @gauge.maxValue
215
+ @minValue = @gauge.minValue
216
+ @animationSpeed = @gauge.animationSpeed
217
+ @options.angle = @gauge.options.angle
218
+
219
+ render: () ->
220
+ angle = @gauge.getAngle.call(@, @displayedValue)
221
+ centerX = @canvas.width / 2
222
+ centerY = @canvas.height * 0.9
223
+
224
+ x = Math.round(centerX + @length * Math.cos(angle))
225
+ y = Math.round(centerY + @length * Math.sin(angle))
226
+
227
+ startX = Math.round(centerX + @strokeWidth * Math.cos(angle - Math.PI/2))
228
+ startY = Math.round(centerY + @strokeWidth * Math.sin(angle - Math.PI/2))
229
+
230
+ endX = Math.round(centerX + @strokeWidth * Math.cos(angle + Math.PI/2))
231
+ endY = Math.round(centerY + @strokeWidth * Math.sin(angle + Math.PI/2))
232
+
233
+ @ctx.fillStyle = @options.color
234
+ @ctx.beginPath()
235
+
236
+ @ctx.arc(centerX, centerY, @strokeWidth, 0, Math.PI*2, true)
237
+ @ctx.fill()
238
+
239
+ @ctx.beginPath()
240
+ @ctx.moveTo(startX, startY)
241
+ @ctx.lineTo(x, y)
242
+ @ctx.lineTo(endX, endY)
243
+ @ctx.fill()
244
+
245
+ class Bar
246
+ constructor: (@elem) ->
247
+ updateValues: (arrValues) ->
248
+ @value = arrValues[0]
249
+ @maxValue = arrValues[1]
250
+ @avgValue = arrValues[2]
251
+ @render()
252
+
253
+ render: () ->
254
+ if @textField
255
+ @textField.text(formatNumber(@value))
256
+
257
+ if @maxValue == 0
258
+ @maxValue = @avgValue * 2
259
+
260
+ valPercent = (@value / @maxValue) * 100
261
+ avgPercent = (@avgValue / @maxValue) * 100
262
+
263
+ $(".bar-value", @elem).css({"width": valPercent + "%"})
264
+ $(".typical-value", @elem).css({"width": avgPercent + "%"})
265
+
266
+ class Gauge extends BaseGauge
267
+ elem: null
268
+ value: [20] # we support multiple pointers
269
+ maxValue: 80
270
+ minValue: 0
271
+ displayedAngle: 0
272
+ displayedValue: 0
273
+ lineWidth: 40
274
+ paddingBottom: 0.1
275
+ percentColors: null,
276
+ options:
277
+ colorStart: "#6fadcf"
278
+ colorStop: undefined
279
+ gradientType: 0 # 0 : radial, 1 : linear
280
+ strokeColor: "#e0e0e0"
281
+ pointer:
282
+ length: 0.8
283
+ strokeWidth: 0.035
284
+ angle: 0.15
285
+ lineWidth: 0.44
286
+ fontSize: 40
287
+ limitMax: false
288
+
289
+ constructor: (@canvas) ->
290
+ super()
291
+ @percentColors = null
292
+ if typeof G_vmlCanvasManager != 'undefined'
293
+ @canvas = window.G_vmlCanvasManager.initElement(@canvas)
294
+ @ctx = @canvas.getContext('2d')
295
+ @gp = [new GaugePointer(@)]
296
+ @setOptions()
297
+ @render()
298
+
299
+ setOptions: (options=null) ->
300
+ super(options)
301
+ @configPercentColors()
302
+ @lineWidth = @canvas.height * (1 - @paddingBottom) * @options.lineWidth # .2 - .7
303
+ @radius = @canvas.height * (1 - @paddingBottom) - @lineWidth
304
+ @ctx.clearRect(0, 0, @canvas.width, @canvas.height)
305
+ @render()
306
+ for gauge in @gp
307
+ gauge.setOptions(@options.pointer)
308
+ gauge.render()
309
+ return @
310
+
311
+ configPercentColors: () ->
312
+ @percentColors = null;
313
+ if (@options.percentColors != undefined)
314
+ @percentColors = new Array()
315
+ for i in [0..(@options.percentColors.length-1)]
316
+ rval = parseInt((cutHex(@options.percentColors[i][1])).substring(0,2),16)
317
+ gval = parseInt((cutHex(@options.percentColors[i][1])).substring(2,4),16)
318
+ bval = parseInt((cutHex(@options.percentColors[i][1])).substring(4,6),16)
319
+ @percentColors[i] = { pct: @options.percentColors[i][0], color: { r: rval, g: gval, b: bval } }
320
+
321
+ set: (value) ->
322
+
323
+ if not (value instanceof Array)
324
+ value = [value]
325
+ # check if we have enough GaugePointers initialized
326
+ # lazy initialization
327
+ if value.length > @gp.length
328
+ for i in [0...(value.length - @gp.length)]
329
+ @gp.push(new GaugePointer(@))
330
+
331
+ # get max value and update pointer(s)
332
+ i = 0
333
+ max_hit = false
334
+
335
+ for val in value
336
+ if val > @maxValue
337
+ @maxValue = @value * 1.1
338
+ max_hit = true
339
+ @gp[i].value = val
340
+ @gp[i++].setOptions({maxValue: @maxValue, angle: @options.angle})
341
+ @value = value[value.length - 1] # TODO: Span maybe??
342
+
343
+ if max_hit
344
+ unless @options.limitMax
345
+ AnimationUpdater.run()
346
+ else
347
+ AnimationUpdater.run()
348
+
349
+ getAngle: (value) ->
350
+ return (1 + @options.angle) * Math.PI + ((value - @minValue) / (@maxValue - @minValue)) * (1 - @options.angle * 2) * Math.PI
351
+
352
+ getColorForPercentage: (pct, grad) ->
353
+ if pct == 0
354
+ color = @percentColors[0].color;
355
+ else
356
+ color = @percentColors[@percentColors.length - 1].color;
357
+ for i in [0..(@percentColors.length - 1)]
358
+ if (pct <= @percentColors[i].pct)
359
+ if grad == true
360
+ # Gradually change between colors
361
+ startColor = @percentColors[i - 1]
362
+ endColor = @percentColors[i]
363
+ rangePct = (pct - startColor.pct) / (endColor.pct - startColor.pct) # How far between both colors
364
+ color = {
365
+ r: Math.floor(startColor.color.r * (1 - rangePct) + endColor.color.r * rangePct),
366
+ g: Math.floor(startColor.color.g * (1 - rangePct) + endColor.color.g * rangePct),
367
+ b: Math.floor(startColor.color.b * (1 - rangePct) + endColor.color.b * rangePct)
368
+ }
369
+ else
370
+ color = @percentColors[i].color
371
+ break
372
+ return 'rgb(' + [color.r, color.g, color.b].join(',') + ')'
373
+
374
+ getColorForValue: (val, grad) ->
375
+ pct = (val - @minValue) / (@maxValue - @minValue)
376
+ return @getColorForPercentage(pct, grad);
377
+
378
+ render: () ->
379
+ # Draw using canvas
380
+ w = @canvas.width / 2
381
+ h = @canvas.height * (1 - @paddingBottom)
382
+ displayedAngle = @getAngle(@displayedValue)
383
+ if @textField
384
+ @textField.render(@)
385
+
386
+ @ctx.lineCap = "butt"
387
+ if @options.customFillStyle != undefined
388
+ fillStyle = @options.customFillStyle(@)
389
+ else if @percentColors != null
390
+ fillStyle = @getColorForValue(@displayedValue, true)
391
+ else if @options.colorStop != undefined
392
+ if @options.gradientType == 0
393
+ fillStyle = this.ctx.createRadialGradient(w, h, 9, w, h, 70);
394
+ else
395
+ fillStyle = this.ctx.createLinearGradient(0, 0, w, 0);
396
+ fillStyle.addColorStop(0, @options.colorStart)
397
+ fillStyle.addColorStop(1, @options.colorStop)
398
+ else
399
+ fillStyle = @options.colorStart
400
+ @ctx.strokeStyle = fillStyle
401
+
402
+ @ctx.beginPath()
403
+ @ctx.arc(w, h, @radius, (1 + @options.angle) * Math.PI, displayedAngle, false)
404
+ @ctx.lineWidth = @lineWidth
405
+ @ctx.stroke()
406
+
407
+ @ctx.strokeStyle = @options.strokeColor
408
+ @ctx.beginPath()
409
+ @ctx.arc(w, h, @radius, displayedAngle, (2 - @options.angle) * Math.PI, false)
410
+ @ctx.stroke()
411
+ for gauge in @gp
412
+ gauge.update(true)
413
+
414
+
415
+ class BaseDonut extends BaseGauge
416
+ lineWidth: 15
417
+ displayedValue: 0
418
+ value: 33
419
+ maxValue: 80
420
+ minValue: 0
421
+
422
+ options:
423
+ lineWidth: 0.10
424
+ colorStart: "#6f6ea0"
425
+ colorStop: "#c0c0db"
426
+ strokeColor: "#eeeeee"
427
+ shadowColor: "#d5d5d5"
428
+ angle: 0.35
429
+
430
+ constructor: (@canvas) ->
431
+ super()
432
+ if typeof G_vmlCanvasManager != 'undefined'
433
+ @canvas = window.G_vmlCanvasManager.initElement(@canvas)
434
+ @ctx = @canvas.getContext('2d')
435
+ @setOptions()
436
+ @render()
437
+
438
+ getAngle: (value) ->
439
+ return (1 - @options.angle) * Math.PI + ((value - @minValue) / (@maxValue - @minValue)) * ((2 + @options.angle) - (1 - @options.angle)) * Math.PI
440
+
441
+ setOptions: (options=null) ->
442
+ super(options)
443
+ @lineWidth = @canvas.height * @options.lineWidth
444
+ @radius = @canvas.height / 2 - @lineWidth/2
445
+ return @
446
+
447
+ set: (value) ->
448
+ @value = value
449
+ if @value > @maxValue
450
+ @maxValue = @value * 1.1
451
+ AnimationUpdater.run()
452
+
453
+ render: () ->
454
+ displayedAngle = @getAngle(@displayedValue)
455
+ w = @canvas.width / 2
456
+ h = @canvas.height / 2
457
+
458
+ if @textField
459
+ @textField.render(@)
460
+
461
+ grdFill = @ctx.createRadialGradient(w, h, 39, w, h, 70)
462
+ grdFill.addColorStop(0, @options.colorStart)
463
+ grdFill.addColorStop(1, @options.colorStop)
464
+
465
+ start = @radius - @lineWidth / 2
466
+ stop = @radius + @lineWidth / 2
467
+
468
+ @ctx.strokeStyle = @options.strokeColor
469
+ @ctx.beginPath()
470
+ @ctx.arc(w, h, @radius, (1 - @options.angle) * Math.PI, (2 + @options.angle) * Math.PI, false)
471
+ @ctx.lineWidth = @lineWidth
472
+ @ctx.lineCap = "round"
473
+ @ctx.stroke()
474
+
475
+ @ctx.strokeStyle = grdFill
476
+ @ctx.beginPath()
477
+ @ctx.arc(w, h, @radius, (1 - @options.angle) * Math.PI, displayedAngle, false)
478
+ @ctx.stroke()
479
+
480
+
481
+ class Donut extends BaseDonut
482
+ strokeGradient: (w, h, start, stop) ->
483
+ grd = @ctx.createRadialGradient(w, h, start, w, h, stop)
484
+ grd.addColorStop(0, @options.shadowColor)
485
+ grd.addColorStop(0.12, @options._orgStrokeColor)
486
+ grd.addColorStop(0.88, @options._orgStrokeColor)
487
+ grd.addColorStop(1, @options.shadowColor)
488
+ return grd
489
+
490
+ setOptions: (options=null) ->
491
+ super(options)
492
+ w = @canvas.width / 2
493
+ h = @canvas.height / 2
494
+ start = @radius - @lineWidth / 2
495
+ stop = @radius + @lineWidth / 2
496
+ @options._orgStrokeColor = @options.strokeColor
497
+ @options.strokeColor = @strokeGradient(w, h, start, stop)
498
+ return @
499
+
500
+ window.AnimationUpdater =
501
+ elements: []
502
+ animId: null
503
+
504
+ addAll: (list) ->
505
+ for elem in list
506
+ AnimationUpdater.elements.push(elem)
507
+
508
+ add: (object) ->
509
+ AnimationUpdater.elements.push(object)
510
+
511
+ run: () ->
512
+ animationFinished = true
513
+ for elem in AnimationUpdater.elements
514
+ if elem.update()
515
+ animationFinished = false
516
+ if not animationFinished
517
+ AnimationUpdater.animId = requestAnimationFrame(AnimationUpdater.run)
518
+ else
519
+ cancelAnimationFrame(AnimationUpdater.animId)
520
+
521
+ window.Gauge = Gauge
522
+ window.Donut = Donut
523
+ window.BaseDonut = BaseDonut
524
+ window.TextRenderer = TextRenderer