Published
Edited
Dec 4, 2019
Fork of Point Gauge
2 forks
Importers
3 stars
Insert cell
md`# Arc Gauge`
Insert cell
Insert cell
viewof value = slider({min:0, max:100, step:0.1, title:"input value" })
Insert cell
Insert cell
Insert cell
Insert cell
shapeStore ={
let xtype = {}
xtype.arcgauge = arcgauge();
return xtype
}
Insert cell
arcgauge = conf => {
const gauge = {};
const _f1 = d3.format(".1f");
const _config = conf ? conf : {min:0, max:100, bgRadius:40, bgArcWidth:5, bgColor:"#475b66", ftRadius:40, ftArcWidth:5, ftColor:"#ff9633", startAngle:-2.5, endAngle:2.5, cornerRadius:0, x:0, y:0} //default config
gauge.updateShape = function(node,config){
d3.select(node).selectAll("*").remove();
this.render(node,config) ;
};
gauge.updateValue = function(node,v){
node.value = v;
let g = d3.select(node)
g.select("text.tempText").text(function(d){return _f1(d.value);});

node.bgconf[1].endAngle = node.scale(v);
g.selectAll("path").data(node.bgconf,function(d){return d.id;})
.attr("d",function(d){
return d3.arc().innerRadius(d.innerR).outerRadius(d.outerR).cornerRadius(d.cornerRadius)
.startAngle(d.startAngle).endAngle(d.endAngle)();
});
};
gauge.render = function(node,config){
config = Object.assign({},_config,config);
node.scale = d3.scaleLinear().domain([config.min, config.max]).range([config.startAngle, config.endAngle]);
node.scale.clamp(true) ;
node.bgconf = [
{id: "bg", innerR: config.bgRadius, outerR: config.bgRadius+config.bgArcWidth, startAngle: config.startAngle, endAngle: config.endAngle, color: config.bgColor, cornerRadius:config.cornerRadius },
{id: "ft", innerR: config.ftRadius, outerR: config.ftRadius+config.ftArcWidth, startAngle: config.startAngle, endAngle: config.endAngle, color: config.ftColor, cornerRadius:config.cornerRadius }
];
let g=d3.select(node)
.attr("transform","translate("+[config.x,config.y]+")") ;
g.append("text")
.attr("class","tempText unselectable")
.attr("fill","#FFF")
.attr("x",-15)
.attr("y",5)
.text(_f1(config.value));
node.bgconf[1].endAngle = node.scale(config.value);
g.selectAll("path")
.data(node.bgconf,function(d){return d.id;})
.enter().append("path")
.attr("d",function(d){
return d3.arc().innerRadius(d.innerR).outerRadius(d.outerR).cornerRadius(d.cornerRadius)
.startAngle(d.startAngle).endAngle(d.endAngle)();
})
.attr("stroke",function(d){return d.color;})
.attr("fill",function(d){return d.color;});
}
return gauge ;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more