MCPcopy Index your code
hub / github.com/plotly/plotly.js / drawAngularGauge

Function drawAngularGauge

src/traces/indicator/plot.js:341–516  ·  view source on GitHub ↗
(gd, plotGroup, cd, opts)

Source from the content-addressed store, hash-verified

339}
340
341function drawAngularGauge(gd, plotGroup, cd, opts) {
342 var trace = cd[0].trace;
343
344 var size = opts.size;
345 var radius = opts.radius;
346 var innerRadius = opts.innerRadius;
347 var gaugeBg = opts.gaugeBg;
348 var gaugeOutline = opts.gaugeOutline;
349 var gaugePosition = [size.l + size.w / 2, size.t + size.h / 2 + radius / 2];
350 var gauge = opts.gauge;
351 var axisLayer = opts.layer;
352
353 var transitionOpts = opts.transitionOpts;
354 var onComplete = opts.onComplete;
355
356 // circular gauge
357 var theta = Math.PI / 2;
358 function valueToAngle(v) {
359 var min = trace.gauge.axis.range[0];
360 var max = trace.gauge.axis.range[1];
361 var angle = (v - min) / (max - min) * Math.PI - theta;
362 if(angle < -theta) return -theta;
363 if(angle > theta) return theta;
364 return angle;
365 }
366
367 function arcPathGenerator(size) {
368 return d3.svg.arc()
369 .innerRadius((innerRadius + radius) / 2 - size / 2 * (radius - innerRadius))
370 .outerRadius((innerRadius + radius) / 2 + size / 2 * (radius - innerRadius))
371 .startAngle(-theta);
372 }
373
374 function drawArc(p) {
375 p
376 .attr('d', function(d) {
377 return arcPathGenerator(d.thickness)
378 .startAngle(valueToAngle(d.range[0]))
379 .endAngle(valueToAngle(d.range[1]))();
380 });
381 }
382
383 // preparing axis
384 var ax, vals, transFn, tickSign;
385
386 // Enter gauge and axis
387 gauge.enter().append('g').classed('angular', true);
388 gauge.attr('transform', strTranslate(gaugePosition[0], gaugePosition[1]));
389
390 axisLayer.enter().append('g')
391 .classed('angularaxis', true)
392 .classed('crisp', true);
393 axisLayer.selectAll('g.' + 'xangularaxis' + 'tick,path,text').remove();
394
395 ax = mockAxis(gd, trace.gauge.axis);
396 ax.type = 'linear';
397 ax.range = trace.gauge.axis.range;
398 ax._id = 'xangularaxis'; // or 'y', but I don't think this makes a difference here

Callers 1

plot.jsFile · 0.85

Calls 7

mockAxisFunction · 0.85
t2gFunction · 0.85
arcPathGeneratorFunction · 0.85
arcTweenFunction · 0.85
valueToAngleFunction · 0.85
_transFnFunction · 0.70
hasTransitionFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…