Skip to content

Commit

Permalink
Merge branch 'master' into legend-events
Browse files Browse the repository at this point in the history
  • Loading branch information
etpinard committed Apr 30, 2018
2 parents 76b4b10 + 776ddca commit 47b1f44
Show file tree
Hide file tree
Showing 113 changed files with 2,214 additions and 1,138 deletions.
83 changes: 83 additions & 0 deletions lib/locales/sw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/**
* Copyright 2012-2018, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

module.exports = {
moduleType: 'locale',
name: 'sw',
dictionary: {
'Autoscale': 'Kigezo - otomatiki',
'Box Select': 'Teua kisanduku',
'Click to enter Colorscale title': 'Bonyeza kuandika kichwa cha Colorscale',
'Click to enter Component A title': 'Bonyeza kuandika kichwa cha sehemu A',
'Click to enter Component B title': 'Bonyeza kuandika kichwa cha sehemu B',
'Click to enter Component C title': 'Bonyeza kuandika kichwa cha sehemu C',
'Click to enter Plot title': 'Bonyeza kuandika kichwa cha Plot',
'Click to enter X axis title': 'Bonyeza kuandika kichwa cha mhimili wa X',
'Click to enter Y axis title': 'Bonyeza kuandika kichwa cha mhimili wa Y',
'Click to enter radial axis title': 'Bonyeza kuandika kichwa cha mhimili wa radial',
'Compare data on hover': 'Linganisha data kwa kuelea kielekezi',
'Double-click on legend to isolate one trace': 'Bonyeza mara mbili juu ya hadithi ili kutenganisha moja kwa moja',
'Double-click to zoom back out': 'Bonyeza mara mbili ili kuvuta nje',
'Download plot as a png': 'Pakua mpango kama png',
'Edit in Chart Studio': 'Hariri katika Chart studio',
'IE only supports svg. Changing format to svg.': 'IE inatumia tu svg. Tunabadilisha muundo kuwa svg.',
'Lasso Select': 'Kuteua lasso',
'Orbital rotation': 'Mzunguko wa mazao',
'Pan': 'Tandaza',
'Produced with Plotly': 'Ilitengenezwa na Plotly',
'Reset': 'Weka upya',
'Reset axes': 'Weka upya axes',
'Reset camera to default': 'Rudisha kamera kwenye uhifadhi wa default',
'Reset camera to last save': 'Rudisha kamera kwenye uhifadhi wa mwisho',
'Reset view': 'Weka upya mtazamo',
'Reset views': 'Weka upya maoni',
'Show closest data on hover': 'Onyesha data iliyo karibu zaidi kielekezi kinapoelea',
'Snapshot succeeded': 'Snapshot ilifanikiwa',
'Sorry, there was a problem downloading your snapshot!': 'Samahani, kulikuwa na shida kupakua picha yako!',
'Taking snapshot - this may take a few seconds': 'Kuchukua snapshot - hii inaweza kuchukua sekunde chache',
'Toggle Spike Lines': 'Badilisha Mistari ya Spike',
'Toggle show closest data on hover': 'Badilisha mabadiliko ya karibu zaidi kwenye hover',
'Turntable rotation': 'Zunguka kwa mhimili wa Z',
'Zoom': 'Vuta',
'Zoom in': 'Vuta nje',
'Zoom out': 'Vuta ndani',
'close:': 'funga:',
'high:': 'juu:',
'incoming flow count:': 'hesabu ya mtiririko unaokuja:',
'kde:': 'kde:',
'lat:': 'lat:',
'lon:': 'lon:',
'low:': 'chini:',
'lower fence:': 'fensi ya chini:',
'max:': 'upeo:',
'mean ± σ:': 'maana ± σ:',
'mean:': 'maana:',
'median:': 'wastani:',
'min:': 'kidogo:',
'new text': 'nakala mpya',
'open:': 'fungua:',
'outgoing flow count:': 'hesabu ya mtiririko unaotoka:',
'q1:': 'q1:',
'q3:': 'q3:',
'source:': 'chanzo:',
'target:': 'lengo:',
'trace': 'fuatilia',
'upper fence:': 'Fensi ya juu:'
},
format: {
days: ['Jumapili', 'Jumatatu', 'Jumanne', 'Jumatano', 'Alhamisi', 'Ijumaa', 'Jumamosi'],
shortDays: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
months: ['Januari', 'Februari', 'Machi', 'Aprili', 'Mei', 'Juni', 'Julai', 'Agosti', 'Septemba', 'Oktoba', 'Novemba', 'Desemba'],
shortMonths: ['Jan', 'Feb', 'Mar', 'Apr', 'Mei', 'Jun', 'Jul', 'Ago', 'Sep', 'Okt', 'Nov', 'Des'],
date: '%d/%m/%Y',
decimal: '.',
thousands: ','
}
};
73 changes: 49 additions & 24 deletions src/components/colorscale/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,47 @@ var flipScale = require('./flip_scale');


module.exports = function calc(trace, vals, containerStr, cLetter) {
var container, inputContainer;
var container = trace;
var inputContainer = trace._input;
var fullInputContainer = trace._fullInput;

// set by traces with groupby transforms
var updateStyle = trace.updateStyle;

function doUpdate(attr, inputVal, fullVal) {
if(fullVal === undefined) fullVal = inputVal;

if(updateStyle) {
updateStyle(trace._input, containerStr ? (containerStr + '.' + attr) : attr, inputVal);
}
else {
inputContainer[attr] = inputVal;
}

container[attr] = fullVal;
if(fullInputContainer && (trace !== trace._fullInput)) {
if(updateStyle) {
updateStyle(trace._fullInput, containerStr ? (containerStr + '.' + attr) : attr, fullVal);
}
else {
fullInputContainer[attr] = fullVal;
}
}
}

if(containerStr) {
container = Lib.nestedProperty(trace, containerStr).get();
inputContainer = Lib.nestedProperty(trace._input, containerStr).get();
}
else {
container = trace;
inputContainer = trace._input;
container = Lib.nestedProperty(container, containerStr).get();
inputContainer = Lib.nestedProperty(inputContainer, containerStr).get();
fullInputContainer = Lib.nestedProperty(fullInputContainer, containerStr).get() || {};
}

var autoAttr = cLetter + 'auto',
minAttr = cLetter + 'min',
maxAttr = cLetter + 'max',
auto = container[autoAttr],
min = container[minAttr],
max = container[maxAttr],
scl = container.colorscale;
var autoAttr = cLetter + 'auto';
var minAttr = cLetter + 'min';
var maxAttr = cLetter + 'max';
var auto = container[autoAttr];
var min = container[minAttr];
var max = container[maxAttr];
var scl = container.colorscale;

if(auto !== false || min === undefined) {
min = Lib.aggNums(Math.min, null, vals);
Expand All @@ -48,11 +71,8 @@ module.exports = function calc(trace, vals, containerStr, cLetter) {
max += 0.5;
}

container[minAttr] = min;
container[maxAttr] = max;

inputContainer[minAttr] = min;
inputContainer[maxAttr] = max;
doUpdate(minAttr, min);
doUpdate(maxAttr, max);

/*
* If auto was explicitly false but min or max was missing,
Expand All @@ -61,17 +81,22 @@ module.exports = function calc(trace, vals, containerStr, cLetter) {
* Otherwise make sure the trace still looks auto as far as later
* changes are concerned.
*/
inputContainer[autoAttr] = (auto !== false ||
(min === undefined && max === undefined));
doUpdate(autoAttr, (auto !== false || (min === undefined && max === undefined)));

if(container.autocolorscale) {
if(min * max < 0) scl = scales.RdBu;
else if(min >= 0) scl = scales.Reds;
else scl = scales.Blues;

// reversescale is handled at the containerOut level
inputContainer.colorscale = scl;
if(container.reversescale) scl = flipScale(scl);
container.colorscale = scl;
doUpdate('colorscale', scl, container.reversescale ? flipScale(scl) : scl);

// We pushed a colorscale back to input, which will change the default autocolorscale next time
// to avoid spurious redraws from Plotly.react, update resulting autocolorscale now
// This is a conscious decision so that changing the data later does not unexpectedly
// give you a new colorscale
if(!inputContainer.autocolorscale) {
doUpdate('autocolorscale', false);
}
}
};
16 changes: 9 additions & 7 deletions src/components/fx/hover.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,9 @@ function _hover(gd, evt, subplot, noHoverEvent) {
if(hasUserCalledHover) {
if('xpx' in evt) xpx = evt.xpx;
else xpx = xaArray[0]._length / 2;
evt.pointerX = xpx + xaArray[0]._offset;

if('ypx' in evt) ypx = evt.ypx;
else ypx = yaArray[0]._length / 2;
evt.pointerY = ypx + yaArray[0]._offset;
}
else {
// fire the beforehover event and quit if it returns false
Expand All @@ -300,13 +298,14 @@ function _hover(gd, evt, subplot, noHoverEvent) {

// in case hover was called from mouseout into hovertext,
// it's possible you're not actually over the plot anymore
if(xpx < 0 || xpx > dbb.width || ypx < 0 || ypx > dbb.height) {
if(xpx < 0 || xpx > xaArray[0]._length || ypx < 0 || ypx > yaArray[0]._length) {
return dragElement.unhoverRaw(gd, evt);
}
evt.pointerX = evt.offsetX;
evt.pointerY = evt.offsetY;
}

evt.pointerX = xpx + xaArray[0]._offset;
evt.pointerY = ypx + yaArray[0]._offset;

if('xval' in evt) xvalArray = helpers.flat(subplots, evt.xval);
else xvalArray = helpers.p2c(xaArray, xpx);

Expand Down Expand Up @@ -713,9 +712,12 @@ function createHoverText(hoverData, opts, gd) {
s.attr('data-notex', 1);
});

var commonBgColor = commonLabelOpts.bgcolor || Color.defaultLine;
var commonStroke = commonLabelOpts.bordercolor || Color.contrast(commonBgColor);

lpath.style({
fill: commonLabelOpts.bgcolor || Color.defaultLine,
stroke: commonLabelOpts.bordercolor || Color.background,
fill: commonBgColor,
stroke: commonStroke
});

ltext.text(t0)
Expand Down
77 changes: 48 additions & 29 deletions src/components/legend/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ module.exports = function draw(gd) {

if(!gd._legendMouseDownTime) gd._legendMouseDownTime = 0;

var opts = fullLayout.legend,
legendData = fullLayout.showlegend && getLegendData(gd.calcdata, opts),
hiddenSlices = fullLayout.hiddenlabels || [];
var opts = fullLayout.legend;
var legendData = fullLayout.showlegend && getLegendData(gd.calcdata, opts);
var hiddenSlices = fullLayout.hiddenlabels || [];

if(!fullLayout.showlegend || !legendData.length) {
fullLayout._infolayer.selectAll('.legend').remove();
Expand All @@ -54,6 +54,17 @@ module.exports = function draw(gd) {
return;
}

var maxLength = 0;
for(var i = 0; i < legendData.length; i++) {
for(var j = 0; j < legendData[i].length; j++) {
var item = legendData[i][j][0];
var trace = item.trace;
var isPie = Registry.traceIs(trace, 'pie');
var name = isPie ? item.label : trace.name;
maxLength = Math.max(maxLength, name && name.length || 0);
}
}

var firstRender = false;
var legend = Lib.ensureSingle(fullLayout._infolayer, 'g', 'legend', function(s) {
s.attr('pointer-events', 'all');
Expand Down Expand Up @@ -109,7 +120,7 @@ module.exports = function draw(gd) {
})
.each(function() {
d3.select(this)
.call(drawTexts, gd)
.call(drawTexts, gd, maxLength)
.call(setupTraceToggle, gd);
});

Expand Down Expand Up @@ -377,38 +388,35 @@ function clickOrDoubleClick(gd, legend, clickedTrace, numClicks, evt) {
}
}

function drawTexts(g, gd) {
var legendItem = g.data()[0][0],
fullLayout = gd._fullLayout,
trace = legendItem.trace,
isPie = Registry.traceIs(trace, 'pie'),
traceIndex = trace.index,
name = isPie ? legendItem.label : trace.name;
function drawTexts(g, gd, maxLength) {
var legendItem = g.data()[0][0];
var fullLayout = gd._fullLayout;
var trace = legendItem.trace;
var isPie = Registry.traceIs(trace, 'pie');
var traceIndex = trace.index;
var name = isPie ? legendItem.label : trace.name;
var isEditable = gd._context.edits.legendText && !isPie;

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

text.attr('text-anchor', 'start')
textEl.attr('text-anchor', 'start')
.classed('user-select-none', true)
.call(Drawing.font, fullLayout.legend.font)
.text(name);
.text(isEditable ? ensureLength(name, maxLength) : name);

function textLayout(s) {
svgTextUtils.convertToTspans(s, gd, function() {
computeTextDimensions(g, gd);
});
}

if(gd._context.edits.legendText && !isPie) {
text.call(svgTextUtils.makeEditable, {gd: gd})
if(isEditable) {
textEl.call(svgTextUtils.makeEditable, {gd: gd, text: name})
.call(textLayout)
.on('edit', function(text) {
this.text(text)
.on('edit', function(newName) {
this.text(ensureLength(newName, maxLength))
.call(textLayout);

var origText = text;

if(!this.text()) text = ' \u0020\u0020 ';

var fullInput = legendItem.trace._fullInput || {};
var update = {};

Expand All @@ -418,24 +426,35 @@ function drawTexts(g, gd) {

var kcont = Lib.keyedContainer(fullInput, 'transforms[' + index + '].styles', 'target', 'value.name');

if(origText === '') {
kcont.remove(legendItem.trace._group);
} else {
kcont.set(legendItem.trace._group, text);
}
kcont.set(legendItem.trace._group, newName);

update = kcont.constructUpdate();
} else {
update.name = text;
update.name = newName;
}

return Registry.call('restyle', gd, update, traceIndex);
});
} else {
textLayout(text);
textLayout(textEl);
}
}

/*
* Make sure we have a reasonably clickable region.
* If this string is missing or very short, pad it with spaces out to at least
* 4 characters, up to the max length of other labels, on the assumption that
* most characters are wider than spaces so a string of spaces will usually be
* no wider than the real labels.
*/
function ensureLength(str, maxLength) {
var targetLength = Math.max(4, maxLength);
if(str && str.trim().length >= targetLength / 2) return str;
str = str || '';
for(var i = targetLength - str.length; i > 0; i--) str += ' ';
return str;
}

function setupTraceToggle(g, gd) {
var newMouseDownTime,
numClicks = 1;
Expand Down
9 changes: 6 additions & 3 deletions src/components/modebar/modebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,13 @@ proto.update = function(graphInfo, buttons) {
else this.element.className = 'modebar';

// if buttons or logo have changed, redraw modebar interior
var needsNewButtons = !this.hasButtons(buttons),
needsNewLogo = (this.hasLogo !== context.displaylogo);
var needsNewButtons = !this.hasButtons(buttons);
var needsNewLogo = (this.hasLogo !== context.displaylogo);
var needsNewLocale = (this.locale !== context.locale);

if(needsNewButtons || needsNewLogo) {
this.locale = context.locale;

if(needsNewButtons || needsNewLogo || needsNewLocale) {
this.removeAllButtons();

this.updateButtons(buttons);
Expand Down
4 changes: 2 additions & 2 deletions src/components/rangeslider/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,8 @@ function drawRangePlot(rangeSlider, gd, axisOpts, opts) {

Plots.supplyDefaults(mockFigure);

var xa = mockFigure._fullLayout.xaxis,
ya = mockFigure._fullLayout[oppAxisName];
var xa = mockFigure._fullLayout.xaxis;
var ya = mockFigure._fullLayout[oppAxisName];

var plotinfo = {
id: id,
Expand Down
Loading

0 comments on commit 47b1f44

Please sign in to comment.