1
1
/**
2
- * plotly.js (basic) v1.20.4
2
+ * plotly.js (basic) v1.20.5
3
3
* Copyright 2012-2016, Plotly, Inc.
4
4
* All rights reserved.
5
5
* Licensed under the MIT license
@@ -25304,7 +25304,7 @@ exports.svgAttrs = {
25304
25304
var Plotly = require('./plotly');
25305
25305
25306
25306
// package version injected by `npm run preprocess`
25307
- exports.version = '1.20.4 ';
25307
+ exports.version = '1.20.5 ';
25308
25308
25309
25309
// inject promise polyfill
25310
25310
require('es6-promise').polyfill();
@@ -25414,17 +25414,16 @@ var isNumeric = require('fast-isnumeric');
25414
25414
25415
25415
var BADNUM = require('../constants/numerical').BADNUM;
25416
25416
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;
25420
25419
25421
25420
/**
25422
25421
* cleanNumber: remove common leading and trailing cruft
25423
25422
* Always returns either a number or BADNUM.
25424
25423
*/
25425
25424
module.exports = function cleanNumber(v) {
25426
25425
if(typeof v === 'string') {
25427
- v = v.replace(FRONTJUNK, '').replace(ENDJUNK , '');
25426
+ v = v.replace(JUNK , '');
25428
25427
}
25429
25428
25430
25429
if(isNumeric(v)) return Number(v);
@@ -34456,8 +34455,6 @@ axes.autoBin = function(data, ax, nbins, is2d) {
34456
34455
// in any case, set tickround to # of digits to round tick labels to,
34457
34456
// or codes to this effect for log and date scales
34458
34457
axes.calcTicks = function calcTicks(ax) {
34459
- if(ax.tickmode === 'array') return arrayTicks(ax);
34460
-
34461
34458
var rng = ax.range.map(ax.r2l);
34462
34459
34463
34460
// calculate max number of (auto) ticks to display based on plot size
@@ -34474,6 +34471,11 @@ axes.calcTicks = function calcTicks(ax) {
34474
34471
nt = Lib.constrain(ax._length / minPx, 4, 9) + 1;
34475
34472
}
34476
34473
}
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
+
34477
34479
axes.autoTicks(ax, Math.abs(rng[1] - rng[0]) / nt);
34478
34480
// check for a forced minimum dtick
34479
34481
if(ax._minDtick > 0 && ax.dtick < ax._minDtick * 2) {
@@ -34490,6 +34492,10 @@ axes.calcTicks = function calcTicks(ax) {
34490
34492
// now figure out rounding of tick values
34491
34493
autoTickRound(ax);
34492
34494
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
+
34493
34499
// find the first tick
34494
34500
ax._tmin = axes.tickFirst(ax);
34495
34501
@@ -34517,11 +34523,11 @@ axes.calcTicks = function calcTicks(ax) {
34517
34523
// show the exponent only on the last one
34518
34524
ax._tmax = vals[vals.length - 1];
34519
34525
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 = '';
34525
34531
ax._inCalcTicks = true;
34526
34532
34527
34533
var ticksOut = new Array(vals.length);
@@ -34549,8 +34555,17 @@ function arrayTicks(ax) {
34549
34555
// except with more precision to the numbers
34550
34556
if(!Array.isArray(text)) text = [];
34551
34557
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
+
34552
34567
for(i = 0; i < vals.length; i++) {
34553
- vali = ax.d2l (vals[i]);
34568
+ vali = tickVal2l (vals[i]);
34554
34569
if(vali > tickMin && vali < tickMax) {
34555
34570
if(text[i] === undefined) ticksOut[j] = axes.tickText(ax, vali);
34556
34571
else ticksOut[j] = tickTextObj(ax, vali, String(text[i]));
@@ -34875,13 +34890,14 @@ axes.tickText = function(ax, x, hover) {
34875
34890
hideexp,
34876
34891
arrayMode = ax.tickmode === 'array',
34877
34892
extraPrecision = hover || arrayMode,
34878
- i;
34893
+ i,
34894
+ tickVal2l = ax.type === 'category' ? ax.d2l_noadd : ax.d2l;
34879
34895
34880
34896
if(arrayMode && Array.isArray(ax.ticktext)) {
34881
34897
var rng = ax.range.map(ax.r2l),
34882
34898
minDiff = Math.abs(rng[1] - rng[0]) / 10000;
34883
34899
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;
34885
34901
}
34886
34902
if(i < ax.ticktext.length) {
34887
34903
out.text = String(ax.ticktext[i]);
@@ -34934,12 +34950,11 @@ function tickTextObj(ax, x, text) {
34934
34950
function formatDate(ax, out, hover, extraPrecision) {
34935
34951
var x = out.x,
34936
34952
tr = ax._tickround,
34937
- trOriginal = tr,
34938
34953
d = new Date(x),
34939
- // suffix completes the full date info, to be included
34954
+ // headPart completes the full date info, to be included
34940
34955
// with only the first tick or if any info before what's
34941
34956
// shown has changed
34942
- suffix ,
34957
+ headPart ,
34943
34958
tt;
34944
34959
if(hover && ax.hoverformat) {
34945
34960
tt = modDateFormat(ax.hoverformat, x);
@@ -34958,12 +34973,12 @@ function formatDate(ax, out, hover, extraPrecision) {
34958
34973
else if(tr === 'm') tt = monthFormat(d);
34959
34974
else {
34960
34975
if(tr === 'd') {
34961
- if(!hover) suffix = '<br>' + yearFormat(d);
34976
+ headPart = yearFormat(d);
34962
34977
34963
34978
tt = dayFormat(d);
34964
34979
}
34965
34980
else {
34966
- if(!hover) suffix = '<br>' + yearMonthDayFormat(d);
34981
+ headPart = yearMonthDayFormat(d);
34967
34982
34968
34983
tt = minuteFormat(d);
34969
34984
if(tr !== 'M') {
@@ -34973,17 +34988,34 @@ function formatDate(ax, out, hover, extraPrecision) {
34973
34988
.substr(1);
34974
34989
}
34975
34990
}
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
- }
34981
34991
}
34982
34992
}
34983
34993
}
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
+ }
34987
35019
}
34988
35020
out.text = tt;
34989
35021
}
@@ -40186,6 +40218,14 @@ module.exports = function setConvert(ax) {
40186
40218
return c === -1 ? BADNUM : c;
40187
40219
};
40188
40220
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
+
40189
40229
ax.d2l = ax.d2c;
40190
40230
ax.r2l = num;
40191
40231
ax.l2r = num;
0 commit comments