Skip to content

Commit 1808fef

Browse files
committedFeb 15, 2019
add layout.meta support to rangeselector, updatemenus and sliders labels
1 parent ddadef1 commit 1808fef

File tree

6 files changed

+60
-9
lines changed

6 files changed

+60
-9
lines changed
 

‎src/components/rangeselector/draw.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ var FROM_BR = alignmentConstants.FROM_BR;
2626
var constants = require('./constants');
2727
var getUpdateObject = require('./get_update_object');
2828

29-
3029
module.exports = function draw(gd) {
3130
var fullLayout = gd._fullLayout;
3231

@@ -152,12 +151,16 @@ function drawButtonText(button, selectorLayout, d, gd) {
152151
});
153152

154153
text.call(Drawing.font, selectorLayout.font)
155-
.text(getLabel(d))
154+
.text(getLabel(d, gd._fullLayout.meta))
156155
.call(textLayout);
157156
}
158157

159-
function getLabel(opts) {
160-
if(opts.label) return opts.label;
158+
function getLabel(opts, meta) {
159+
if(opts.label) {
160+
return meta ?
161+
Lib.templateString(opts.label, {meta: meta}) :
162+
opts.label;
163+
}
161164

162165
if(opts.step === 'all') return 'all';
163166

‎src/components/sliders/draw.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,10 @@ function drawCurrentValue(sliderGroup, sliderOpts, valueOverride) {
317317
str += valueOverride;
318318
} else {
319319
var curVal = sliderOpts.steps[sliderOpts.active].label;
320+
var meta = sliderOpts._gd._fullLayout.meta;
321+
if(meta) {
322+
curVal = Lib.templateString(curVal, {meta: meta});
323+
}
320324
str += curVal;
321325
}
322326

@@ -364,8 +368,14 @@ function drawLabel(item, data, sliderOpts) {
364368
});
365369
});
366370

371+
var tx = data.step.label;
372+
var meta = sliderOpts._gd._fullLayout.meta;
373+
if(meta) {
374+
tx = Lib.templateString(tx, {meta: meta});
375+
}
376+
367377
text.call(Drawing.font, sliderOpts.font)
368-
.text(data.step.label)
378+
.text(tx)
369379
.call(svgTextUtils.convertToTspans, sliderOpts._gd);
370380

371381
return text;

‎src/components/updatemenus/draw.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,14 @@ function drawItemText(item, menuOpts, itemOpts, gd) {
442442
});
443443
});
444444

445+
var tx = itemOpts.label;
446+
var meta = gd._fullLayout.meta;
447+
if(meta) {
448+
tx = Lib.templateString(tx, {meta: meta});
449+
}
450+
445451
text.call(Drawing.font, menuOpts.font)
446-
.text(itemOpts.label)
452+
.text(tx)
447453
.call(svgTextUtils.convertToTspans, gd);
448454
}
449455

‎src/plots/layout_attributes.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,9 @@ module.exports = {
416416
editType: 'plot',
417417
description: [
418418
'Assigns extra meta information that can be used in various `text` attributes.',
419-
'Attributes such as the graph, axis and colorbar `title.text` and annotation `text`',
420-
'support `meta`. One can access `meta` fields using template strings:',
419+
'Attributes such as the graph, axis and colorbar `title.text`, annotation `text`',
420+
'`trace.name` in legend items, `rangeselector`, `updatemenues` and `sliders` `label` text',
421+
'all support `meta`. One can access `meta` fields using template strings:',
421422
'`%{meta[i]}` where `i` is the index of the `meta`',
422423
'item in question.'
423424
].join(' ')
-1.33 KB
Loading

‎test/image/mocks/layout_metatext.json

+32-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,16 @@
3535
"title": {"text": "This graph is %{meta[2]}"},
3636
"xaxis": {
3737
"domain": {"row": 0, "column": 0},
38-
"title": {"text": "Worth more than %{meta[4]} %{meta[1]}"}
38+
"title": {"text": "Worth more than %{meta[4]} %{meta[1]}"},
39+
"rangeselector": {
40+
"buttons": [{
41+
"step": "all"
42+
}, {
43+
"step": "month",
44+
"count": 2,
45+
"label": "backup %{meta[2]}"
46+
}]
47+
}
3948
},
4049
"yaxis": {
4150
"domain": {"row": 0, "column": 0},
@@ -81,6 +90,28 @@
8190
"yref": "y",
8291
"x": "2019-02-10",
8392
"y": 2
93+
}],
94+
95+
"updatemenus": [{
96+
"buttons": [{
97+
"label": "Btn-%{meta[0]}",
98+
"method": "restyle",
99+
"args": ["visible", false]
100+
}],
101+
"y": 1,
102+
"yanchor": "bottom"
103+
}],
104+
105+
"sliders": [{
106+
"steps": [{
107+
"label": "step-%{meta[0]}",
108+
"method": "restyle",
109+
"args": ["marker.color", "red"]
110+
}, {
111+
"label": "step-%{meta[1]}",
112+
"method": "restyle",
113+
"args": ["marker.color", "blue"]
114+
}]
84115
}]
85116
}
86117
}

0 commit comments

Comments
 (0)
Please sign in to comment.