Skip to content

Commit 23bcbfc

Browse files
committed
use _meta helpers in all components that support meta
1 parent 28cd420 commit 23bcbfc

File tree

10 files changed

+55
-36
lines changed

10 files changed

+55
-36
lines changed

Diff for: src/components/annotations/draw.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
212212

213213
var font = options.font;
214214

215-
var text = fullLayout.meta ?
216-
Lib.templateString(options.text, {meta: fullLayout.meta}) :
215+
var text = fullLayout._meta ?
216+
Lib.templateString(options.text, fullLayout._meta) :
217217
options.text;
218218

219219
var annText = annTextGroupInner.append('text')

Diff for: src/components/fx/hover.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -887,8 +887,8 @@ function createHoverText(hoverData, opts, gd) {
887887
if(d.nameOverride !== undefined) d.name = d.nameOverride;
888888

889889
if(d.name) {
890-
if(fullLayout.meta) {
891-
d.name = Lib.templateString(d.name, {meta: fullLayout.meta});
890+
if(d.trace._meta) {
891+
d.name = Lib.templateString(d.name, d.trace._meta);
892892
}
893893
name = plainText(d.name, d.nameLength);
894894
}
@@ -925,7 +925,7 @@ function createHoverText(hoverData, opts, gd) {
925925
}
926926

927927
// hovertemplate
928-
var d3locale = gd._fullLayout._d3locale;
928+
var d3locale = fullLayout._d3locale;
929929
var hovertemplate = d.hovertemplate || false;
930930
var hovertemplateLabels = d.hovertemplateLabels || d;
931931
var eventData = d.eventData[0] || {};
@@ -935,7 +935,7 @@ function createHoverText(hoverData, opts, gd) {
935935
hovertemplateLabels,
936936
d3locale,
937937
eventData,
938-
{meta: fullLayout.meta}
938+
d.trace._meta
939939
);
940940

941941
text = text.replace(EXTRA_STRING_REGEX, function(match, extra) {

Diff for: src/components/legend/draw.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,8 @@ function drawTexts(g, gd, maxLength) {
404404
var isEditable = gd._context.edits.legendText && !isPie;
405405

406406
var name = isPie ? legendItem.label : trace.name;
407-
if(fullLayout.meta) {
408-
name = Lib.templateString(name, {meta: fullLayout.meta});
407+
if(trace._meta) {
408+
name = Lib.templateString(name, trace._meta);
409409
}
410410

411411
var textEl = Lib.ensureSingle(g, 'text', 'legendtext');

Diff for: src/components/rangeselector/draw.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,14 @@ function drawButtonText(button, selectorLayout, d, gd) {
149149
});
150150

151151
text.call(Drawing.font, selectorLayout.font)
152-
.text(getLabel(d, gd._fullLayout.meta))
152+
.text(getLabel(d, gd._fullLayout._meta))
153153
.call(textLayout);
154154
}
155155

156-
function getLabel(opts, meta) {
156+
function getLabel(opts, _meta) {
157157
if(opts.label) {
158-
return meta ?
159-
Lib.templateString(opts.label, {meta: meta}) :
158+
return _meta ?
159+
Lib.templateString(opts.label, _meta) :
160160
opts.label;
161161
}
162162

Diff for: src/components/sliders/draw.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -315,10 +315,8 @@ function drawCurrentValue(sliderGroup, sliderOpts, valueOverride) {
315315
str += valueOverride;
316316
} else {
317317
var curVal = sliderOpts.steps[sliderOpts.active].label;
318-
var meta = sliderOpts._gd._fullLayout.meta;
319-
if(meta) {
320-
curVal = Lib.templateString(curVal, {meta: meta});
321-
}
318+
var _meta = sliderOpts._gd._fullLayout._meta;
319+
if(_meta) curVal = Lib.templateString(curVal, _meta);
322320
str += curVal;
323321
}
324322

@@ -367,10 +365,8 @@ function drawLabel(item, data, sliderOpts) {
367365
});
368366

369367
var tx = data.step.label;
370-
var meta = sliderOpts._gd._fullLayout.meta;
371-
if(meta) {
372-
tx = Lib.templateString(tx, {meta: meta});
373-
}
368+
var _meta = sliderOpts._gd._fullLayout._meta;
369+
if(_meta) tx = Lib.templateString(tx, _meta);
374370

375371
text.call(Drawing.font, sliderOpts.font)
376372
.text(tx)

Diff for: src/components/titles/index.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ var numStripRE = / [XY][0-9]* /;
5353
* offset - shift up/down in the rotated frame (unused?)
5454
* containerGroup - if an svg <g> element already exists to hold this
5555
* title, include here. Otherwise it will go in fullLayout._infolayer
56+
* _meta {object (optional} - meta key-value to for title with
57+
* Lib.templateString, default to fullLayout._meta, if not provided
5658
*
5759
* @return {selection} d3 selection of title container group
5860
*/
@@ -97,8 +99,10 @@ function draw(gd, titleClass, options) {
9799
if(!editable) txt = '';
98100
}
99101

100-
if(fullLayout.meta) {
101-
txt = Lib.templateString(txt, {meta: fullLayout.meta});
102+
if(options._meta) {
103+
txt = Lib.templateString(txt, options._meta);
104+
} else if(fullLayout._meta) {
105+
txt = Lib.templateString(txt, fullLayout._meta);
102106
}
103107

104108
var elShouldExist = txt || editable;

Diff for: src/components/updatemenus/draw.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -438,10 +438,8 @@ function drawItemText(item, menuOpts, itemOpts, gd) {
438438
});
439439

440440
var tx = itemOpts.label;
441-
var meta = gd._fullLayout.meta;
442-
if(meta) {
443-
tx = Lib.templateString(tx, {meta: meta});
444-
}
441+
var _meta = gd._fullLayout._meta;
442+
if(_meta) tx = Lib.templateString(tx, _meta);
445443

446444
text.call(Drawing.font, menuOpts.font)
447445
.text(tx)

Diff for: src/plots/gl3d/layout/convert.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ proto.merge = function(fullLayout, sceneLayout) {
8383
}
8484

8585
// Axes labels
86-
opts.labels[i] = fullLayout.meta ?
87-
Lib.templateString(axes.title.text, {meta: fullLayout.meta}) :
86+
opts.labels[i] = fullLayout._meta ?
87+
Lib.templateString(axes.title.text, fullLayout._meta) :
8888
axes.title.text;
8989

9090
if('font' in axes.title) {

Diff for: src/traces/pie/plot.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,10 @@ function plot(gd, cdpie) {
204204
s.attr('data-notex', 1);
205205
});
206206

207-
var txt = fullLayout.meta ?
208-
Lib.templateString(trace.title.text, {meta: fullLayout.meta}) :
209-
trace.title.text;
207+
var txt = trace.title.text;
208+
if(trace._meta) {
209+
txt = Lib.templateString(txt, trace._meta);
210+
}
210211

211212
titleText.text(txt)
212213
.attr({
@@ -481,18 +482,18 @@ function determineInsideTextFont(trace, pt, layoutFont) {
481482
}
482483

483484
function prerenderTitles(cdpie, gd) {
484-
var fullLayout = gd._fullLayout;
485-
486485
var cd0, trace;
486+
487487
// Determine the width and height of the title for each pie.
488488
for(var i = 0; i < cdpie.length; i++) {
489489
cd0 = cdpie[i][0];
490490
trace = cd0.trace;
491491

492492
if(trace.title.text) {
493-
var txt = fullLayout.meta ?
494-
Lib.templateString(trace.title.text, {meta: fullLayout.meta}) :
495-
trace.title.text;
493+
var txt = trace.title.text;
494+
if(trace._meta) {
495+
txt = Lib.templateString(txt, trace._meta);
496+
}
496497

497498
var dummyTitle = Drawing.tester.append('text')
498499
.attr('data-notex', 1)

Diff for: test/jasmine/tests/hover_label_test.js

+20
Original file line numberDiff line numberDiff line change
@@ -1975,6 +1975,26 @@ describe('hover info', function() {
19751975
.catch(failTest)
19761976
.then(done);
19771977
});
1978+
1979+
it('should work with trace meta references', function(done) {
1980+
var gd = document.getElementById('graph');
1981+
1982+
Plotly.update(gd, {
1983+
meta: {yname: 'Yy', xname: 'Xx'},
1984+
hovertemplate: 'TRACE -- %{meta.yname}<extra>%{meta.xname}</extra>'
1985+
})
1986+
.then(function() {
1987+
Fx.hover('graph', evt, 'xy');
1988+
1989+
assertHoverLabelContent({
1990+
nums: 'TRACE -- Yy',
1991+
name: 'Xx',
1992+
axis: '0.388'
1993+
});
1994+
})
1995+
.catch(failTest)
1996+
.then(done);
1997+
});
19781998
});
19791999

19802000
it('should work with trace.name linked to layout.meta', function(done) {

0 commit comments

Comments
 (0)