Skip to content

Instantly share code, notes, and snippets.

@joshdover
Last active December 10, 2015 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshdover/4451013 to your computer and use it in GitHub Desktop.
Save joshdover/4451013 to your computer and use it in GitHub Desktop.
GaugeView for Batman using JustGage
class Albedo.GaugeView extends Batman.View
@option 'title', 'max', 'min', 'value', 'better'
@::on 'appear', ->
@makeGauge()
makeGauge: ->
node = $(@get('node'))
node.attr 'id', @get('title')
# Add a new gauge using the prescribed options
new JustGage(
id: node.attr 'id'
value: Math.round(@get('value') * 10) / 10
min: @get('min') || 0
max: @get('max') || 100
title: @get('title').replace '_', ' '
gaugeWidthScale: 0.1
startAnimationType: 'bounce'
startAnimationTime: 1500
levelColors: @getColors()
)
getColors: ->
colors = ["#D60000", "#F57A00", "#FADA28", "#52D138"]
if @get('better') is 'min'
colors = colors.reverse()
return colors
.row
.span12
.row.gauges
.span4{"data-foreach-gauge" => "gauges"}
%div{"data-view" => "GaugeView", "data-view-value" => "gauge.average", "data-view-title" => "gauge.title", "data-view-max" => "5", "data-view-min" => "1"}
.center
%a.btn.disabled
%span{"data-bind" => "gauge.count"}
responses
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment