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

Function drawCurrentValue

src/components/sliders/draw.js:275–332  ·  view source on GitHub ↗
(sliderGroup, sliderOpts, valueOverride)

Source from the content-addressed store, hash-verified

273}
274
275function drawCurrentValue(sliderGroup, sliderOpts, valueOverride) {
276 if(!sliderOpts.currentvalue.visible) return;
277
278 var dims = sliderOpts._dims;
279 var x0, textAnchor;
280
281 switch(sliderOpts.currentvalue.xanchor) {
282 case 'right':
283 // This is anchored left and adjusted by the width of the longest label
284 // so that the prefix doesn't move. The goal of this is to emphasize
285 // what's actually changing and make the update less distracting.
286 x0 = dims.inputAreaLength - constants.currentValueInset - dims.currentValueMaxWidth;
287 textAnchor = 'left';
288 break;
289 case 'center':
290 x0 = dims.inputAreaLength * 0.5;
291 textAnchor = 'middle';
292 break;
293 default:
294 x0 = constants.currentValueInset;
295 textAnchor = 'left';
296 }
297
298 var text = Lib.ensureSingle(sliderGroup, 'text', constants.labelClass, function(s) {
299 s.attr({
300 'text-anchor': textAnchor,
301 'data-notex': 1
302 });
303 });
304
305 var str = sliderOpts.currentvalue.prefix ? sliderOpts.currentvalue.prefix : '';
306
307 if(typeof valueOverride === 'string') {
308 str += valueOverride;
309 } else {
310 var curVal = sliderOpts.steps[sliderOpts.active].label;
311 var _meta = sliderOpts._gd._fullLayout._meta;
312 if(_meta) curVal = Lib.templateString(curVal, _meta);
313 str += curVal;
314 }
315
316 if(sliderOpts.currentvalue.suffix) {
317 str += sliderOpts.currentvalue.suffix;
318 }
319
320 text.call(Drawing.font, sliderOpts.currentvalue.font)
321 .text(str)
322 .call(svgTextUtils.convertToTspans, sliderOpts._gd);
323
324 var lines = svgTextUtils.lineCount(text);
325
326 var y0 = (dims.currentValueMaxLines + 1 - lines) *
327 sliderOpts.currentvalue.font.size * LINE_SPACING;
328
329 svgTextUtils.positionText(text, x0, y0);
330
331 return text;
332}

Callers 1

findDimensionsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…