Skip to content

Commit 1426be7

Browse files
committed
Merge branch 'master' into funnelarea-traces
2 parents a9625b6 + 66b2f40 commit 1426be7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+13402
-348
lines changed

src/components/annotations/draw.js

Lines changed: 2 additions & 2 deletions
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')

src/components/colorbar/draw.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ function makeColorBarData(gd) {
140140
opts._id = 'cb' + trace.uid + (allowsMultiplotCbs && contName ? '-' + contName : '');
141141
opts._traceIndex = trace.index;
142142
opts._propPrefix = (contName ? contName + '.' : '') + 'colorbar.';
143+
opts._meta = trace._meta;
143144
calcOpts();
144145
out.push(opts);
145146
}
@@ -156,6 +157,7 @@ function makeColorBarData(gd) {
156157
opts = initOpts(cont.colorbar);
157158
opts._id = 'cb' + k;
158159
opts._propPrefix = k + '.colorbar.';
160+
opts._meta = fullLayout._meta;
159161

160162
cbOpt = {min: 'cmin', max: 'cmax'};
161163
if(colorAxOpts[0] !== 'heatmap') {
@@ -281,6 +283,7 @@ function drawColorBar(g, opts, gd) {
281283
propContainer: ax,
282284
propName: opts._propPrefix + 'title',
283285
traceIndex: opts._traceIndex,
286+
_meta: opts._meta,
284287
placeholder: fullLayout._dfltTitle.colorbar,
285288
containerGroup: g.select('.' + cn.cbtitle)
286289
};

src/components/fx/hover.js

Lines changed: 4 additions & 4 deletions
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) {

src/components/legend/attributes.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,33 @@ module.exports = {
9090
].join(' ')
9191
},
9292

93+
itemclick: {
94+
valType: 'enumerated',
95+
values: ['toggle', 'toggleothers', false],
96+
dflt: 'toggle',
97+
role: 'info',
98+
editType: 'legend',
99+
description: [
100+
'Determines the behavior on legend item click.',
101+
'*toggle* toggles the visibility of the item clicked on the graph.',
102+
'*toggleothers* makes the clicked item the sole visible item on the graph.',
103+
'*false* disable legend item click interactions.'
104+
].join(' ')
105+
},
106+
itemdoubleclick: {
107+
valType: 'enumerated',
108+
values: ['toggle', 'toggleothers', false],
109+
dflt: 'toggleothers',
110+
role: 'info',
111+
editType: 'legend',
112+
description: [
113+
'Determines the behavior on legend item double-click.',
114+
'*toggle* toggles the visibility of the item clicked on the graph.',
115+
'*toggleothers* makes the clicked item the sole visible item on the graph.',
116+
'*false* disable legend item double-click interactions.'
117+
].join(' ')
118+
},
119+
93120
x: {
94121
valType: 'number',
95122
min: -2,

src/components/legend/defaults.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ module.exports = function legendDefaults(layoutIn, layoutOut, fullData) {
103103

104104
coerce('itemsizing');
105105

106+
coerce('itemclick');
107+
coerce('itemdoubleclick');
108+
106109
coerce('x', defaultX);
107110
coerce('xanchor', defaultXAnchor);
108111
coerce('y', defaultY);

src/components/legend/draw.js

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

406406
var name = isPieLike ? 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');

src/components/legend/handle_click.js

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,29 @@ var Registry = require('../../registry');
1414
var SHOWISOLATETIP = true;
1515

1616
module.exports = function handleClick(g, gd, numClicks) {
17+
var fullLayout = gd._fullLayout;
18+
1719
if(gd._dragged || gd._editing) return;
1820

19-
var hiddenSlices = gd._fullLayout.hiddenlabels ?
20-
gd._fullLayout.hiddenlabels.slice() :
21+
var itemClick = fullLayout.legend.itemclick;
22+
var itemDoubleClick = fullLayout.legend.itemdoubleclick;
23+
24+
if(numClicks === 1 && itemClick === 'toggle' && itemDoubleClick === 'toggleothers' &&
25+
SHOWISOLATETIP && gd.data && gd._context.showTips
26+
) {
27+
Lib.notifier(Lib._(gd, 'Double-click on legend to isolate one trace'), 'long');
28+
SHOWISOLATETIP = false;
29+
} else {
30+
SHOWISOLATETIP = false;
31+
}
32+
33+
var mode;
34+
if(numClicks === 1) mode = itemClick;
35+
else if(numClicks === 2) mode = itemDoubleClick;
36+
if(!mode) return;
37+
38+
var hiddenSlices = fullLayout.hiddenlabels ?
39+
fullLayout.hiddenlabels.slice() :
2140
[];
2241

2342
var legendItem = g.data()[0][0];
@@ -85,21 +104,14 @@ module.exports = function handleClick(g, gd, numClicks) {
85104
}
86105
}
87106

88-
if(numClicks === 1 && SHOWISOLATETIP && gd.data && gd._context.showTips) {
89-
Lib.notifier(Lib._(gd, 'Double-click on legend to isolate one trace'), 'long');
90-
SHOWISOLATETIP = false;
91-
} else {
92-
SHOWISOLATETIP = false;
93-
}
94-
95107
if(Registry.traceIs(fullTrace, 'pie-like')) {
96108
var thisLabel = legendItem.label;
97109
var thisLabelIndex = hiddenSlices.indexOf(thisLabel);
98110

99-
if(numClicks === 1) {
111+
if(mode === 'toggle') {
100112
if(thisLabelIndex === -1) hiddenSlices.push(thisLabel);
101113
else hiddenSlices.splice(thisLabelIndex, 1);
102-
} else if(numClicks === 2) {
114+
} else if(mode === 'toggleothers') {
103115
hiddenSlices = [];
104116
gd.calcdata[0].forEach(function(d) {
105117
if(thisLabel !== d.label) {
@@ -126,7 +138,7 @@ module.exports = function handleClick(g, gd, numClicks) {
126138
}
127139
}
128140

129-
if(numClicks === 1) {
141+
if(mode === 'toggle') {
130142
var nextVisibility;
131143

132144
switch(fullTrace.visible) {
@@ -150,7 +162,7 @@ module.exports = function handleClick(g, gd, numClicks) {
150162
} else {
151163
setVisibility(fullTrace, nextVisibility);
152164
}
153-
} else if(numClicks === 2) {
165+
} else if(mode === 'toggleothers') {
154166
// Compute the clicked index. expandedIndex does what we want for expanded traces
155167
// but also culls hidden traces. That means we have some work to do.
156168
var isClicked, isInGroup, otherState;

src/components/rangeselector/draw.js

Lines changed: 4 additions & 4 deletions
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

src/components/sliders/draw.js

Lines changed: 4 additions & 8 deletions
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)

src/components/titles/index.js

Lines changed: 6 additions & 2 deletions
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;

0 commit comments

Comments
 (0)