statusicon = conf => {
const gauge = {};
const _f1 = d3.format(".1f");
const _config = conf ? conf: {rx:0, ry:0, activeStroke:"#9badbc", activeFill:"#9badbc", activeStrokeWidth:2,
status: [
{id:"icon1", text:"close", fontSize:16, textX:0, textY:0, width:80, height:25, fill:"none", x:0, y:0, rx:0, ry:0, stroke:"#9badbc", strokeWidth:2},
{id:"icon2", text:"open", fontSize:16, textX:0, textY:0, width:80, height:25, fill:"none", x:80, y:0, rx:0, ry:0, stroke:"#9badbc", strokeWidth:2},
]
}
gauge.updateShape = function(node,config){
config = Object.assign({},_config,config);
d3.select(node).selectAll("*").remove();
gauge.render(node,config) ;
}
gauge.updateValue = function(node,value){
let config = node.config;
let g = d3.select(node);
g.selectAll("rect")
.attr("fill", (d,i) => { return i==value ? config.activeFill:d.fill;} )
.attr("stroke", (d,i) => { return i==value ? config.activeStroke:d.stroke;} )
.attr("stroke-width", (d,i) => { return i==value ? config.activeStrokeWidth:d.strokeWidth;} )
;
}
gauge.render = function(node,config){
config = Object.assign({},_config,config);
node.config = config;
let g=d3.select(node)
.attr("transform","translate("+[config.x,config.y]+")") ;
let icon = g.selectAll("g.status")
.data(config.status, d => d.id)
.enter()
.append("g")
.attr("class","status")
icon
.append("rect")
.attr("width", d => d.width)
.attr("height", d => d.height)
.attr("fill" , d => d.fill)
.attr("stroke" , d => d.stroke)
.attr("stroke-width" , d => d.strokeWidth)
.attr("x", d => d.x )
.attr("y", d => d.y )
.attr("rx", d => d.rx )
.attr("ry", d => d.ry );
icon
.append("text")
.attr("fill","#fff")
.attr("x", d=> d.textX + d.x + d.width/2)
.attr("y", d=> d.textY + d.y + d.height/2)
.attr("font-size", d=> d.fontSize)
.attr("text-anchor", "middle")
.attr("dominant-baseline","middle")
.text(d=>d.text);
gauge.updateValue(node, config.value) ;
}
return gauge;
}