简体   繁体   中英

Dashing: Number widget background color

Can the number widget be used multiple times on the same dashboard?

eg I want to show a current score for each team member, one widget per team member with an up/down arrow comparing the current score with the last score, if the score is up the widget background is Green if it is down the widget background is Red.

My .rb file passes data from an excel file.

Every widget shows the correct current score Every widget shows the correct up/down arrow ALL widgets show the same but opposite color of what I want despite the .coffee showing to the contrary.

It's as is if the loop to detect which color the background should be stops after the first `pass.

Bug or bad code? number4.coffee

class Dashing.Number4 extends Dashing.Widget

@accessor 'current', Dashing.AnimatedValue

@accessor 'difference', ->
if @get('last')
last = parseInt(@get('last'))
current = parseInt(@get('current'))
if last != 0
diff = Math.abs(Math.round((current - last) / last * 100))
"#{diff}%"
else
""

@accessor 'arrow', ->
if @get('last')
if parseInt(@get('current')) > parseInt(@get('last')) then 'fa fa-arrow-up' else 'fa fa-arrow-down'

constructor: ->
super

@onData(Dashing.lastEvents[@id]) if Dashing.lastEvents[@id]
onData: (data) ->
if parseInt(@get('current')) > parseInt(@get('last')) then $(@node).css('background-color', '#006600') else $(@node).css('background-color', '#660000')

number4.scss

//
// ----------------------------------------------------------------------------
// Mixins
// ----------------------------------------------------------------------------
@mixin transition($transition-property, $transition-time, $method) {
-webkit-transition: $transition-property $transition-time $method;
-moz-transition: $transition-property $transition-time $method;
-o-transition: $transition-property $transition-time $method;
transition: $transition-property $transition-time $method;
}

// ----------------------------------------------------------------------------
// Sass declarations
// ----------------------------------------------------------------------------
$value-color: #fff;

$title-color: rgba(255, 255, 255, 0.7);
$moreinfo-color: rgba(255, 255, 255, 0.7);

// ----------------------------------------------------------------------------
// Widget-number styles
// ----------------------------------------------------------------------------
.widget-number4 {

.title {
color: $title-color;
font-size: 40px;

 }

.value {
color: $value-color;

}

.change-rate {
font-weight: 500;
font-size: 30px;
color: $value-color;
}

.more-info {
color: $moreinfo-color;
font-size: 23px;
bottom: 40px;

}

.updated-at {
color: white;
font-size: 23px;
}

}

You can use a widget multiple times on a single dashboard but it sounds like you have that part working already.

You need to fade out the widget, set the background-color, and then the fade in again. Otherwise you will not see the background color change as the rendering has already occurred.

 onData: (data) -> if @get('last') if parseInt(@get('current')) > parseInt(@get('last')) then $(@node).fadeOut().css('background-color', "#006600").fadeIn() else $(@node).fadeOut().css('background-color', "#660000").fadeIn() 

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM