8000 use UTC milliseconds for internal representation of dates by alexcjohnson · Pull Request #1172 · plotly/plotly.js · GitHub
[go: up one dir, main page]

Skip to content

use UTC milliseconds for internal representation of dates #1172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 64 commits into from
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
e5916c4
update changelog for 1.20.0
etpinard Nov 15, 2016
d48c310
1.20.0
etpinard Nov 15, 2016
fcd9547
remove commented out code about 3d pie chart attributes
alexcjohnson Nov 15, 2016
e94b1d1
Merge pull request #1152 from plotly/no-3d-pies
alexcjohnson Nov 16, 2016
9583cfa
annotation: assign dflt pos if category IS NOT present
etpinard Nov 16, 2016
6e7d5d6
test: add annotations to mock 16
etpinard Nov 16, 2016
58b91e7
test: add annotation with category positions case
etpinard Nov 16, 2016
ca2e112
Merge pull request #1155 from plotly/annotation-category-fix
etpinard Nov 16, 2016
2204914
update changelog for 1.20.1
etpinard Nov 16, 2016
564f661
1.20.1
etpinard Nov 16, 2016
d7de2ae
issue #1160 fix
adamborowski Nov 17, 2016
665e56c
modebar: use axis r21 and l2r to compute zoom +/- ranges
etpinard Nov 17, 2016
8e9d458
test: test all cartesian axis types in modebar click cases
etpinard Nov 17, 2016
c45338d
test: use ax.r2l to assert range
etpinard Nov 17, 2016
8472254
bar: fix wrong bar size in hover labels
n-riesco Nov 17, 2016
1c32bc5
Merge pull request #1163 from n-riesco/pr-20161117-fix-issue-1157
etpinard Nov 17, 2016
f1b686f
test: assert up to yyyy-mm-dd for date ranges
etpinard Nov 17, 2016
4d9b02d
Merge pull request #1162 from plotly/modebar-date-zoom-fix
etpinard Nov 17, 2016
9e71209
update changelog for 1.20.2
etpinard Nov 17, 2016
775682f
1.20.2
etpinard Nov 17, 2016
6cf4283
tasks: fixup main bundle URLs
etpinard Nov 18, 2016
5971c16
Merge pull request #1166 from plotly/stats-fixup
etpinard Nov 18, 2016
fb44aee
fixing the non-fancy scattergl 'single data point' infinite loop
monfera Nov 18, 2016
bd34ec2
use UTC milliseconds for internal representation of dates
alexcjohnson Nov 19, 2016
9c645e7
if it works in Alaska it'll work anywhere.
alexcjohnson Nov 19, 2016
6d83c7b
verify our test environment has DST
alexcjohnson Nov 19, 2016
02e98a9
fix range selectors for UTC, and tests to run in arbitrary timezone
alexcjohnson Nov 19, 2016
c41a0b4
lint
alexcjohnson Nov 19, 2016
94f4d5f
test case for scattergl single data point
monfera Nov 19, 2016
fb0ff70
Merge pull request #1168 from monfera/scattergl-with-one-datapoint
etpinard Nov 21, 2016
1058366
Clone input trace
dy Nov 11, 2016
ea8ce86
Ignore line ending style
dy Nov 11, 2016
fa18648
Fix typo
dy Nov 11, 2016
ecd795a
test: add case for addTraces with exising data/traces
etpinard Nov 21, 2016
7e4c5c1
lint
etpinard Nov 21, 2016
6d2f655
Add check for failed binding comparison
rreusser Nov 21, 2016
6dc01d6
Make 'is simple binding' false for non-length-one arrays
rreusser Nov 21, 2016
125770b
Merge pull request #1175 from plotly/pr1136-clone-trace
etpinard Nov 21, 2016
242f3b4
Add test for non-present command arg value
rreusser Nov 21, 2016
218744d
Fix command api test that doesn't actually test anything
rreusser Nov 21, 2016
62c95f8
test: add jasmine test for #1169
etpinard Nov 21, 2016
63f455d
Merge pull request #1176 from plotly/fix-command-api-bug
etpinard Nov 21, 2016
a23a460
update changelog for 1.20.3
etpinard Nov 21, 2016
d9caee9
1.20.3
etpinard Nov 21, 2016
744041b
schema: fix defs.metaKeys field
etpinard Nov 21, 2016
bfba27d
Merge pull request #1182 from plotly/schema-metakey-fix
etpinard Nov 21, 2016
318fc48
update changelog for 1.20.4
etpinard Nov 21, 2016
48b0358
1.20.4
etpinard Nov 21, 2016
5f98edd
fix regression in lib/clean_number (alternate)
etpinard Nov 21, 2016
79fe7d5
turn front/end/global regex's into 1
etpinard Nov 21, 2016
b4da924
fix for date histograms with uniform bins
alexcjohnson Nov 22, 2016
2a57525
temp fix for histogram2d test in UTC environment
alexcjohnson Nov 22, 2016
846f2c7
Merge pull request #1185 from plotly/clean-datum-regression-alt
etpinard Nov 22, 2016
c130932
Merge pull request #1186 from plotly/fix-date-histograms
alexcjohnson Nov 22, 2016
426077a
handle and test a bunch of tickvals / ticktext edge cases
alexcjohnson Nov 22, 2016
27fb4b1
tighter test for when to remove seconds from date tick text
alexcjohnson Nov 22, 2016
74da7a4
include test that we didn't add any categories to category tickvals test
alexcjohnson Nov 22, 2016
77f745e
fix log axes tickvals default text formatting bug
alexcjohnson Nov 22, 2016
6762130
remove old (buggy) hovertext cruft, clean up and test edge cases
alexcjohnson Nov 23, 2016
c70f04a
suffix -> dateHead / headPart
alexcjohnson Nov 23, 2016
bd24421
Merge pull request #1191 from plotly/tickvals-edge-cases
alexcjohnson Nov 23, 2016
f35313a
update changelog for 1.20.5
etpinard Nov 23, 2016
0fc37d6
1.20.5
etpinard Nov 23, 2016
cd73020
Merge branch 'master' into dates-utc-backend
alexcjohnson Nov 23, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 56 additions & 23 deletions src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -611,8 +611,6 @@ axes.autoBin = function(data, ax, nbins, is2d) {
// in any case, set tickround to # of digits to round tick labels to,
// or codes to this effect for log and date scales
axes.calcTicks = function calcTicks(ax) {
if(ax.tickmode === 'array') return arrayTicks(ax);

var rng = ax.range.map(ax.r2l);

// calculate max number of (auto) ticks to display based on plot size
Expand All @@ -629,6 +627,11 @@ axes.calcTicks = function calcTicks(ax) {
nt = Lib.constrain(ax._length / minPx, 4, 9) + 1;
}
}

// add a couple of extra digits for filling in ticks when we
// have explicit tickvals without tick text
if(ax.tickmode === 'array') nt *= 100;

axes.autoTicks(ax, Math.abs(rng[1] - rng[0]) / nt);
// check for a forced minimum dtick
if(ax._minDtick > 0 && ax.dtick < ax._minDtick * 2) {
Expand All @@ -645,6 +648,10 @@ axes.calcTicks = function calcTicks(ax) {
// now figure out rounding of tick values
autoTickRound(ax);

// now that we've figured out the auto values for formatting
// in case we're missing some ticktext, we can break out for array ticks
if(ax.tickmode === 'array') return arrayTicks(ax);

// find the first tick
ax._tmin = axes.tickFirst(ax);

Expand Down Expand Up @@ -672,11 +679,11 @@ axes.calcTicks = function calcTicks(ax) {
// show the exponent only on the last one
ax._tmax = vals[vals.length - 1];

// for showing date suffixes: ax._prevSuffix holds what we showed most
// recently. Start with it cleared and mark that we're in calcTicks (ie
// calculating a whole string of these so we should care what the previous
// suffix was!)
ax._prevSuffix = '';
// for showing the rest of a date when the main tick label is only the
// latter part: ax._prevDateHead holds what we showed most recently.
// Start with it cleared and mark that we're in calcTicks (ie calculating a
// whole string of these so we should care what the previous date head was!)
ax._prevDateHead = '';
ax._inCalcTicks = true;

var ticksOut = new Array(vals.length);
Expand Down Expand Up @@ -704,8 +711,17 @@ function arrayTicks(ax) {
// except with more precision to the numbers
if(!Array.isArray(text)) text = [];

// make sure showing ticks doesn't accidentally add new categories
var tickVal2l = ax.type === 'category' ? ax.d2l_noadd : ax.d2l;

// array ticks on log axes always show the full number
// (if no explicit ticktext overrides it)
if(ax.type === 'log' && String(ax.dtick).charAt(0) !== 'L') {
ax.dtick = 'L' + Math.pow(10, Math.floor(Math.min(ax.range[0], ax.range[1])) - 1);
}

for(i = 0; i < vals.length; i++) {
vali = ax.d2l(vals[i]);
vali = tickVal2l(vals[i]);
if(vali > tickMin && vali < tickMax) {
if(text[i] === undefined) ticksOut[j] = axes.tickText(ax, vali);
else ticksOut[j] = tickTextObj(ax, vali, String(text[i]));
Expand Down Expand Up @@ -1030,13 +1046,14 @@ axes.tickText = function(ax, x, hover) {
hideexp,
arrayMode = ax.tickmode === 'array',
extraPrecision = hover || arrayMode,
i;
i,
tickVal2l = ax.type === 'category' ? ax.d2l_noadd : ax.d2l;

if(arrayMode && Array.isArray(ax.ticktext)) {
var rng = ax.range.map(ax.r2l),
minDiff = Math.abs(rng[1] - rng[0]) / 10000;
for(i = 0; i < ax.ticktext.length; i++) {
if(Math.abs(x - ax.d2l(ax.tickvals[i])) < minDiff) break;
if(Math.abs(x - tickVal2l(ax.tickvals[i])) < minDiff) break;
}
if(i < ax.ticktext.length) {
out.text = String(ax.ticktext[i]);
Expand Down Expand Up @@ -1089,12 +1106,11 @@ function tickTextObj(ax, x, text) {
10000 function formatDate(ax, out, hover, extraPrecision) {
var x = out.x,
tr = ax._tickround,
trOriginal = tr,
d = new Date(x),
// suffix completes the full date info, to be included
// headPart completes the full date info, to be included
// with only the first tick or if any info before what's
// shown has changed
suffix,
headPart,
tt;
if(hover && ax.hoverformat) {
tt = modDateFormat(ax.hoverformat, x);
Expand All @@ -1113,12 +1129,12 @@ function formatDate(ax, out, hover, extraPrecision) {
else if(tr === 'm') tt = monthFormat(d);
else {
if(tr === 'd') {
if(!hover) suffix = '<br>' + yearFormat(d);
headPart = yearFormat(d);

tt = dayFormat(d);
}
else {
if(!hover) suffix = '<br>' + yearMonthDayFormat(d);
headPart = yearMonthDayFormat(d);

tt = minuteFormat(d);
if(tr !== 'M') {
Expand All @@ -1128,17 +1144,34 @@ function formatDate(ax, out, hover, extraPrecision) {
.substr(1);
}
}
else if(trOriginal === 'd') {
// for hover on axes with day ticks, minuteFormat (which
// only includes %H:%M) isn't enough, you want the date too
tt = dayFormat(d) + ' ' + tt;
}
}
}
}
if(suffix && (!ax._inCalcTicks || (suffix !== ax._prevSuffix))) {
tt += suffix;
ax._prevSuffix = suffix;
if(hover || ax.tickmode === 'array') {
// we get extra precision in array mode or hover,
// but it may be useless, strip it off
if(tt === '00:00:00' || tt === '00:00') {
tt = headPart;
headPart = '';
}
else if(tt.length === 8) {
// strip off seconds if they're zero (zero fractional seconds
// are already omitted)
tt = tt.replace(/:00$/, '');
}
}

if(headPart) {
if(hover) {
// hover puts it all on one line, so headPart works best up front
// except for year headPart: turn this into "Jan 1, 2000" etc.
if(tr === 'd') tt += ', ' + headPart;
else tt = headPart + (tt ? ', ' + tt : '');
}
else if(!ax._inCalcTicks || (headPart !== ax._prevDateHead)) {
tt += '<br>' + headPart;
ax._prevDateHead = headPart;
}
}
out.text = tt;
}
Expand Down
8 changes: 8 additions & 0 deletions src/plots/cartesian/set_convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,14 @@ module.exports = function setConvert(ax) {
return c === -1 ? BADNUM : c;
};

ax.d2l_noadd = function(v) {
// d2c variant that that won't add categories but will also
// allow numbers to be mapped to the linearized axis positions
var index = ax._categories.indexOf(v);
if(index !== -1) return index;
if(typeof v === 'number') return v;
};

ax.d2l = ax.d2c;
ax.r2l = num;
ax.l2r = num;
Expand Down
Loading
0