|
class Dashing.Fullpie extends Dashing.Widget |
|
@accessor 'value' |
|
|
|
onData: (data) -> |
|
$(@node).fadeOut().fadeIn() |
|
@render(data.value) |
|
|
|
render: (data) -> |
|
if !data |
|
data = @get("value") |
|
if !data |
|
return |
|
#console.log "FullPie new" |
|
# this is a fix because data binding seems otherwise not work |
|
$(@node).children(".title").text($(@node).attr("data-title")) |
|
$(@node).children(".more-info").text($(@node).attr("data-moreinfo")) |
|
$(@node).children(".updated-at").text(@get('updatedAtMessage')) |
|
|
|
width = 260 #width |
|
height = 260 #height |
|
radius = 130 #radius |
|
|
|
color = d3.scale.ordinal() |
|
.domain([1,10]) |
|
#.range( ['#222222','#555555','#777777','#999999','#bbbbbb','#dddddd','#ffffff'] ) |
|
.range( ['#222222','#333333','#444444','#555555','#666666','#777777','#888888','#999999','#aaaaaa'] ) |
|
|
|
$(@node).children("svg").remove(); |
|
|
|
vis = d3.select(@node).append("svg:svg") |
|
.data([data]) |
|
.attr("width", width) |
|
.attr("height", height) |
|
.append("svg:g") |
|
.attr("transform", "translate(" + radius + "," + radius + ")") |
|
|
|
arc = d3.svg.arc().outerRadius(radius) |
|
pie = d3.layout.pie().value((d) -> d.value) |
|
|
|
arcs = vis.selectAll("g.slice") |
|
.data(pie) |
|
.enter().append("svg:g").attr("class", "slice") |
|
|
|
arcs.append("svg:path").attr("fill", (d, i) -> color i) |
|
.attr("fill-opacity", 0.4).attr("d", arc) |
|
|
|
sum=0 |
|
for val in data |
|
sum += val.value |
|
|
|
arcs.append("svg:text").attr("transform", (d, i) -> |
|
procent_val = Math.round(data[i].value/sum * 100) |
|
d.innerRadius = (radius * (100-procent_val)/100) - 45 #45=max text size/2 |
|
d.outerRadius = radius |
|
"translate(" + arc.centroid(d) + ")") |
|
.attr('fill', "#fff") |
|
.attr("text-anchor", "middle").text((d, i) -> data[i].label) |
|
.append('svg:tspan') |
|
.attr('x', 0) |
|
.attr('dy', 15) |
|
.attr('font-size', '70%') |
|
.text((d,i) -> Math.round(data[i].value/sum * 100) + '%') |
|
|
|
|
|
|
I realize this widget is a bit old but I've recently tried using it under smashing. Ironically, the pie graph doesn't reliably show up on a kiosk RaspberryPi running Chromium but works perfectly on my desktop. On the OSX Chrome, no javascript errors are thrown. On the Pi, the background of the widget shows at page load and occasionally I'll see the data at some later time. I don't have a good means of seeing if it's throwing any javascript errors. This is the only widget on the dashboard and the data is only 3 values. Any thoughts?