Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e2745f8

Browse files
Merge branch 'master' into cmid
2 parents d69f27c + 25fa0c2 commit e2745f8

File tree

91 files changed

+10948
-895
lines changed

Some content is hidden

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

91 files changed

+10948
-895
lines changed

src/components/fx/hover.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,7 @@ function _hover(gd, evt, subplot, noHoverEvent) {
738738
var EXTRA_STRING_REGEX = /<extra>([\s\S]*)<\/extra>/;
739739

740740
function createHoverText(hoverData, opts, gd) {
741+
var fullLayout = gd._fullLayout;
741742
var hovermode = opts.hovermode;
742743
var rotateLabels = opts.rotateLabels;
743744
var bgColor = opts.bgColor;
@@ -925,6 +926,10 @@ function createHoverText(hoverData, opts, gd) {
925926
if(d.nameOverride !== undefined) d.name = d.nameOverride;
926927

927928
if(d.name) {
929+
if(fullLayout.meta) {
930+
d.name = Lib.templateString(d.name, {meta: fullLayout.meta});
931+
}
932+
928933
name = svgTextUtils.plainText(d.name || '', {
929934
len: d.nameLength,
930935
allowedTags: ['br', 'sub', 'sup', 'b', 'i', 'em']
@@ -940,7 +945,7 @@ function createHoverText(hoverData, opts, gd) {
940945
text = d[(hovermode === 'x' ? 'y' : 'x') + 'Label'] || '';
941946
}
942947
else if(d.xLabel === undefined) {
943-
if(d.yLabel !== undefined) text = d.yLabel;
948+
if(d.yLabel !== undefined && d.trace.type !== 'scattercarpet') text = d.yLabel;
944949
}
945950
else if(d.yLabel === undefined) text = d.xLabel;
946951
else text = '(' + d.xLabel + ', ' + d.yLabel + ')';
@@ -970,7 +975,12 @@ function createHoverText(hoverData, opts, gd) {
970975
var hovertemplateLabels = d.hovertemplateLabels || d;
971976
var eventData = d.eventData[0] || {};
972977
if(hovertemplate) {
973-
text = Lib.hovertemplateString(hovertemplate, hovertemplateLabels, eventData);
978+
text = Lib.hovertemplateString(
979+
hovertemplate,
980+
hovertemplateLabels,
981+
eventData,
982+
{meta: fullLayout.meta}
983+
);
974984

975985
text = text.replace(EXTRA_STRING_REGEX, function(match, extra) {
976986
name = extra; // Assign name for secondary text label

src/components/fx/hovertemplate_attributes.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ module.exports = function(opts, extra) {
3131
valType: 'string',
3232
role: 'info',
3333
dflt: '',
34-
arrayOk: true,
35-
editType: 'none',
34+
editType: opts.editType || 'none',
3635
description: [
3736
'Template string used for rendering the information that appear on hover box.',
3837
'Note that this will override `hoverinfo`.',
@@ -46,5 +45,9 @@ module.exports = function(opts, extra) {
4645
].join(' ')
4746
};
4847

48+
if(opts.arrayOk !== false) {
49+
hovertemplate.arrayOk = true;
50+
}
51+
4952
return hovertemplate;
5053
};

src/components/legend/draw.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,9 +404,13 @@ function drawTexts(g, gd, maxLength) {
404404
var trace = legendItem.trace;
405405
var isPie = Registry.traceIs(trace, 'pie');
406406
var traceIndex = trace.index;
407-
var name = isPie ? legendItem.label : trace.name;
408407
var isEditable = gd._context.edits.legendText && !isPie;
409408

409+
var name = isPie ? legendItem.label : trace.name;
410+
if(fullLayout.meta) {
411+
name = Lib.templateString(name, {meta: fullLayout.meta});
412+
}
413+
410414
var textEl = Lib.ensureSingle(g, 'text', 'legendtext');
411415

412416
textEl.attr('text-anchor', 'start')

src/components/rangeselector/draw.js

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

Lines changed: 11 additions & 1 deletion
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

Lines changed: 7 additions & 1 deletion
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/lib/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,7 @@ lib.numSeparate = function(value, separators, separatethousands) {
994994
return x1 + x2;
995995
};
996996

997-
var TEMPLATE_STRING_REGEX = /%{([^\s%{}:]*)(:[^}]*)?}/g;
997+
lib.TEMPLATE_STRING_REGEX = /%{([^\s%{}:]*)(:[^}]*)?}/g;
998998
var SIMPLE_PROPERTY_REGEX = /^\w*$/;
999999

10001000
/**
@@ -1014,7 +1014,7 @@ lib.templateString = function(string, obj) {
10141014
// just in case it speeds things up *slightly*:
10151015
var getterCache = {};
10161016

1017-
return string.replace(TEMPLATE_STRING_REGEX, function(dummy, key) {
1017+
return string.replace(lib.TEMPLATE_STRING_REGEX, function(dummy, key) {
10181018
if(SIMPLE_PROPERTY_REGEX.test(key)) {
10191019
return obj[key] || '';
10201020
}
@@ -1047,7 +1047,7 @@ lib.hovertemplateString = function(string, labels) {
10471047
// just in case it speeds things up *slightly*:
10481048
var getterCache = {};
10491049

1050-
return string.replace(TEMPLATE_STRING_REGEX, function(match, key, format) {
1050+
return string.replace(lib.TEMPLATE_STRING_REGEX, function(match, key, format) {
10511051
var obj, value, i;
10521052
for(i = 2; i < args.length; i++) {
10531053
obj = args[i];

src/plot_api/plot_api.js

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1940,22 +1940,34 @@ exports.relayout = relayout;
19401940
// Optimization mostly for large splom traces where
19411941
// Plots.supplyDefaults can take > 100ms
19421942
function axRangeSupplyDefaultsByPass(gd, flags, specs) {
1943-
var k;
1943+
var fullLayout = gd._fullLayout;
19441944

19451945
if(!flags.axrange) return false;
19461946

1947-
for(k in flags) {
1947+
for(var k in flags) {
19481948
if(k !== 'axrange' && flags[k]) return false;
19491949
}
19501950

1951-
for(k in specs.rangesAltered) {
1952-
var axName = Axes.id2name(k);
1951+
for(var axId in specs.rangesAltered) {
1952+
var axName = Axes.id2name(axId);
19531953
var axIn = gd.layout[axName];
1954-
var axOut = gd._fullLayout[axName];
1954+
var axOut = fullLayout[axName];
19551955
axOut.autorange = axIn.autorange;
19561956
axOut.range = axIn.range.slice();
19571957
axOut.cleanRange();
1958+
1959+
if(axOut._matchGroup) {
1960+
for(var axId2 in axOut._matchGroup) {
1961+
if(axId2 !== axId) {
1962+
var ax2 = fullLayout[Axes.id2name(axId2)];
1963+
ax2.autorange = axOut.autorange;
1964+
ax2.range = axOut.range.slice();
1965+
ax2._input.range = axOut.range.slice();
1966+
}
1967+
}
1968+
}
19581969
}
1970+
19591971
return true;
19601972
}
19611973

@@ -1965,14 +1977,25 @@ function addAxRangeSequence(seq, rangesAltered) {
19651977
// executed after drawData
19661978
var drawAxes = rangesAltered ?
19671979
function(gd) {
1968-
var opts = {skipTitle: true};
1980+
var axIds = [];
1981+
var skipTitle = true;
1982+
19691983
for(var id in rangesAltered) {
1970-
if(Axes.getFromId(gd, id).automargin) {
1971-
opts = {};
1972-
break;
1984+
var ax = Axes.getFromId(gd, id);
1985+
axIds.push(id);
1986+
1987+
if(ax._matchGroup) {
1988+
for(var id2 in ax._matchGroup) {
1989+
if(!rangesAltered[id2]) {
1990+
axIds.push(id2);
1991+
}
1992+
}
19731993
}
1994+
1995+
if(ax.automargin) skipTitle = false;
19741996
}
1975-
return Axes.draw(gd, Object.keys(rangesAltered), opts);
1997+
1998+
return Axes.draw(gd, axIds, {skipTitle: skipTitle});
19761999
} :
19772000
function(gd) {
19782001
return Axes.draw(gd, 'redraw');

src/plot_api/subroutines.js

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -697,17 +697,49 @@ exports.redrawReglTraces = function(gd) {
697697
};
698698

699699
exports.doAutoRangeAndConstraints = function(gd) {
700+
var fullLayout = gd._fullLayout;
700701
var axList = Axes.list(gd, '', true);
702+
var matchGroups = fullLayout._axisMatchGroups || [];
703+
var ax;
701704

702705
for(var i = 0; i < axList.length; i++) {
703-
var ax = axList[i];
706+
ax = axList[i];
704707
cleanAxisConstraints(gd, ax);
705-
// in case margins changed, update scale
706-
ax.setScale();
707708
doAutoRange(gd, ax);
708709
}
709710

710711
enforceAxisConstraints(gd);
712+
713+
groupLoop:
714+
for(var j = 0; j < matchGroups.length; j++) {
715+
var group = matchGroups[j];
716+
var rng = null;
717+
var id;
718+
719+
for(id in group) {
720+
ax = Axes.getFromId(gd, id);
721+
if(ax.autorange === false) continue groupLoop;
722+
723+
if(rng) {
724+
if(rng[0] < rng[1]) {
725+
rng[0] = Math.min(rng[0], ax.range[0]);
726+
rng[1] = Math.max(rng[1], ax.range[1]);
727+
} else {
728+
rng[0] = Math.max(rng[0], ax.range[0]);
729+
rng[1] = Math.min(rng[1], ax.range[1]);
730+
}
731+
} else {
732+
rng = ax.range;
733+
}
734+
}
735+
736+
for(id in group) {
737+
ax = Axes.getFromId(gd, id);
738+
ax.range = rng.slice();
739+
ax._input.range = rng.slice();
740+
ax.setScale();
741+
}
742+
}
711743
};
712744

713745
// An initial paint must be completed before these components can be

src/plots/cartesian/autorange.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,8 @@ function concatExtremes(gd, ax) {
237237
}
238238

239239
function doAutoRange(gd, ax) {
240+
ax.setScale();
241+
240242
if(ax.autorange) {
241243
ax.range = getAutoRange(gd, ax);
242244

0 commit comments

Comments
 (0)