11/**
2- * plotly.js (basic) v1.20.4
2+ * plotly.js (basic) v1.20.5
33* Copyright 2012-2016, Plotly, Inc.
44* All rights reserved.
55* Licensed under the MIT license
@@ -25304,7 +25304,7 @@ exports.svgAttrs = {
2530425304var Plotly = require('./plotly');
2530525305
2530625306// package version injected by `npm run preprocess`
25307- exports.version = '1.20.4 ';
25307+ exports.version = '1.20.5 ';
2530825308
2530925309// inject promise polyfill
2531025310require('es6-promise').polyfill();
@@ -25414,17 +25414,16 @@ var isNumeric = require('fast-isnumeric');
2541425414
2541525415var BADNUM = require('../constants/numerical').BADNUM;
2541625416
25417- // precompile these regex's for speed
25418- var FRONTJUNK = /^['"%,$#\s']+/;
25419- var ENDJUNK = /['"%,$#\s']+$/;
25417+ // precompile for speed
25418+ var JUNK = /^['"%,$#\s']+|[, ]|['"%,$#\s']+$/g;
2542025419
2542125420/**
2542225421 * cleanNumber: remove common leading and trailing cruft
2542325422 * Always returns either a number or BADNUM.
2542425423 */
2542525424module.exports = function cleanNumber(v) {
2542625425 if(typeof v === 'string') {
25427- v = v.replace(FRONTJUNK, '').replace(ENDJUNK , '');
25426+ v = v.replace(JUNK , '');
2542825427 }
2542925428
2543025429 if(isNumeric(v)) return Number(v);
@@ -34456,8 +34455,6 @@ axes.autoBin = function(data, ax, nbins, is2d) {
3445634455// in any case, set tickround to # of digits to round tick labels to,
3445734456// or codes to this effect for log and date scales
3445834457axes.calcTicks = function calcTicks(ax) {
34459- if(ax.tickmode === 'array') return arrayTicks(ax);
34460-
3446134458 var rng = ax.range.map(ax.r2l);
3446234459
3446334460 // calculate max number of (auto) ticks to display based on plot size
@@ -34474,6 +34471,11 @@ axes.calcTicks = function calcTicks(ax) {
3447434471 nt = Lib.constrain(ax._length / minPx, 4, 9) + 1;
3447534472 }
3447634473 }
34474+
34475+ // add a couple of extra digits for filling in ticks when we
34476+ // have explicit tickvals without tick text
34477+ if(ax.tickmode === 'array') nt *= 100;
34478+
3447734479 axes.autoTicks(ax, Math.abs(rng[1] - rng[0]) / nt);
3447834480 // check for a forced minimum dtick
3447934481 if(ax._minDtick > 0 && ax.dtick < ax._minDtick * 2) {
@@ -34490,6 +34492,10 @@ axes.calcTicks = function calcTicks(ax) {
3449034492 // now figure out rounding of tick values
3449134493 autoTickRound(ax);
3449234494
34495+ // now that we've figured out the auto values for formatting
34496+ // in case we're missing some ticktext, we can break out for array ticks
34497+ if(ax.tickmode === 'array') return arrayTicks(ax);
34498+
3449334499 // find the first tick
3449434500 ax._tmin = axes.tickFirst(ax);
3449534501
@@ -34517,11 +34523,11 @@ axes.calcTicks = function calcTicks(ax) {
3451734523 // show the exponent only on the last one
3451834524 ax._tmax = vals[vals.length - 1];
3451934525
34520- // for showing date suffixes: ax._prevSuffix holds what we showed most
34521- // recently. Start with it cleared and mark that we're in calcTicks (ie
34522- // calculating a whole string of these so we should care what the previous
34523- // suffix was!)
34524- ax._prevSuffix = '';
34526+ // for showing the rest of a date when the main tick label is only the
34527+ // latter part: ax._prevDateHead holds what we showed most recently.
34528+ // Start with it cleared and mark that we're in calcTicks (ie calculating a
34529+ // whole string of these so we should care what the previous date head was!)
34530+ ax._prevDateHead = '';
3452534531 ax._inCalcTicks = true;
3452634532
3452734533 var ticksOut = new Array(vals.length);
@@ -34549,8 +34555,17 @@ function arrayTicks(ax) {
3454934555 // except with more precision to the numbers
3455034556 if(!Array.isArray(text)) text = [];
3455134557
34558+ // make sure showing ticks doesn't accidentally add new categories
34559+ var tickVal2l = ax.type === 'category' ? ax.d2l_noadd : ax.d2l;
34560+
34561+ // array ticks on log axes always show the full number
34562+ // (if no explicit ticktext overrides it)
34563+ if(ax.type === 'log' && String(ax.dtick).charAt(0) !== 'L') {
34564+ ax.dtick = 'L' + Math.pow(10, Math.floor(Math.min(ax.range[0], ax.range[1])) - 1);
34565+ }
34566+
3455234567 for(i = 0; i < vals.length; i++) {
34553- vali = ax.d2l (vals[i]);
34568+ vali = tickVal2l (vals[i]);
3455434569 if(vali > tickMin && vali < tickMax) {
3455534570 if(text[i] === undefined) ticksOut[j] = axes.tickText(ax, vali);
3455634571 else ticksOut[j] = tickTextObj(ax, vali, String(text[i]));
@@ -34875,13 +34890,14 @@ axes.tickText = function(ax, x, hover) {
3487534890 hideexp,
3487634891 arrayMode = ax.tickmode === 'array',
3487734892 extraPrecision = hover || arrayMode,
34878- i;
34893+ i,
34894+ tickVal2l = ax.type === 'category' ? ax.d2l_noadd : ax.d2l;
3487934895
3488034896 if(arrayMode && Array.isArray(ax.ticktext)) {
3488134897 var rng = ax.range.map(ax.r2l),
3488234898 minDiff = Math.abs(rng[1] - rng[0]) / 10000;
3488334899 for(i = 0; i < ax.ticktext.length; i++) {
34884- if(Math.abs(x - ax.d2l (ax.tickvals[i])) < minDiff) break;
34900+ if(Math.abs(x - tickVal2l (ax.tickvals[i])) < minDiff) break;
3488534901 }
3488634902 if(i < ax.ticktext.length) {
3488734903 out.text = String(ax.ticktext[i]);
@@ -34934,12 +34950,11 @@ function tickTextObj(ax, x, text) {
3493434950function formatDate(ax, out, hover, extraPrecision) {
3493534951 var x = out.x,
3493634952 tr = ax._tickround,
34937- trOriginal = tr,
3493834953 d = new Date(x),
34939- // suffix completes the full date info, to be included
34954+ // headPart completes the full date info, to be included
3494034955 // with only the first tick or if any info before what's
3494134956 // shown has changed
34942- suffix ,
34957+ headPart ,
3494334958 tt;
3494434959 if(hover && ax.hoverformat) {
3494534960 tt = modDateFormat(ax.hoverformat, x);
@@ -34958,12 +34973,12 @@ function formatDate(ax, out, hover, extraPrecision) {
3495834973 else if(tr === 'm') tt = monthFormat(d);
3495934974 else {
3496034975 if(tr === 'd') {
34961- if(!hover) suffix = '<br>' + yearFormat(d);
34976+ headPart = yearFormat(d);
3496234977
3496334978 tt = dayFormat(d);
3496434979 }
3496534980 else {
34966- if(!hover) suffix = '<br>' + yearMonthDayFormat(d);
34981+ headPart = yearMonthDayFormat(d);
3496734982
3496834983 tt = minuteFormat(d);
3496934984 if(tr !== 'M') {
@@ -34973,17 +34988,34 @@ function formatDate(ax, out, hover, extraPrecision) {
3497334988 .substr(1);
3497434989 }
3497534990 }
34976- else if(trOriginal === 'd') {
34977- // for hover on axes with day ticks, minuteFormat (which
34978- // only includes %H:%M) isn't enough, you want the date too
34979- tt = dayFormat(d) + ' ' + tt;
34980- }
3498134991 }
3498234992 }
3498334993 }
34984- if(suffix && (!ax._inCalcTicks || (suffix !== ax._prevSuffix))) {
34985- tt += suffix;
34986- ax._prevSuffix = suffix;
34994+ if(hover || ax.tickmode === 'array') {
34995+ // we get extra precision in array mode or hover,
34996+ // but it may be useless, strip it off
34997+ if(tt === '00:00:00' || tt === '00:00') {
34998+ tt = headPart;
34999+ headPart = '';
35000+ }
35001+ else if(tt.length === 8) {
35002+ // strip off seconds if they're zero (zero fractional seconds
35003+ // are already omitted)
35004+ tt = tt.replace(/:00$/, '');
35005+ }
35006+ }
35007+
35008+ if(headPart) {
35009+ if(hover) {
35010+ // hover puts it all on one line, so headPart works best up front
35011+ // except for year headPart: turn this into "Jan 1, 2000" etc.
35012+ if(tr === 'd') tt += ', ' + headPart;
35013+ else tt = headPart + (tt ? ', ' + tt : '');
35014+ }
35015+ else if(!ax._inCalcTicks || (headPart !== ax._prevDateHead)) {
35016+ tt += '<br>' + headPart;
35017+ ax._prevDateHead = headPart;
35018+ }
3498735019 }
3498835020 out.text = tt;
3498935021}
@@ -40186,6 +40218,14 @@ module.exports = function setConvert(ax) {
4018640218 return c === -1 ? BADNUM : c;
4018740219 };
4018840220
40221+ ax.d2l_noadd = function(v) {
40222+ // d2c variant that that won't add categories but will also
40223+ // allow numbers to be mapped to the linearized axis positions
40224+ var index = ax._categories.indexOf(v);
40225+ if(index !== -1) return index;
40226+ if(typeof v === 'number') return v;
40227+ };
40228+
4018940229 ax.d2l = ax.d2c;
4019040230 ax.r2l = num;
4019140231 ax.l2r = num;
0 commit comments