8000 tickvals / ticktext edge cases by alexcjohnson · Pull Request #1191 · plotly/plotly.js · GitHub
[go: up one dir, main page]

Skip to content

tickvals / ticktext edge cases #1191

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

Merged
merged 6 commits into from
Nov 23, 2016
Merged
Changes from 1 commit
Commits
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
Prev Previous commit
suffix -> dateHead / headPart
  • Loading branch information
alexcjohnson committed Nov 23, 2016
commit c70f04a5b08e7e91f220ddbe6499a792aa203203
40 changes: 20 additions & 20 deletions src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
8000 Expand Up @@ -679,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 = '';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

ax._inCalcTicks = true;

var ticksOut = new Array(vals.length);
Expand Down Expand Up @@ -1107,10 +1107,10 @@ function formatDate(ax, out, hover, extraPrecision) {
var x = out.x,
tr = ax._tickround,
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 @@ -1129,12 +1129,12 @@ function formatDate(ax, out, hover, extraPrecision) {
else if(tr === 'm') tt = monthFormat(d);
else {
if(tr === 'd') {
suffix = yearFormat(d);
headPart = yearFormat(d);

tt = dayFormat(d);
}
else {
suffix = yearMonthDayFormat(d);
headPart = yearMonthDayFormat(d);

tt = minuteFormat(d);
if(tr !== 'M') {
Expand All @@ -1151,8 +1151,8 @@ function formatDate(ax, out, hover, extraPrecision) {
// 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 = suffix;
suffix = '';
tt = headPart;
headPart = '';
}
else if(tt.length === 8) {
// strip off seconds if they're zero (zero fractional seconds
Expand All @@ -1161,16 +1161,16 @@ function formatDate(ax, out, hover, extraPrecision) {
}
}

if(suffix) {
if(headPart) {
if(hover) {
// hover puts it all on one line, so suffix works best up front
// except for year suffix: turn this into "Jan 1, 2000" etc.
if(tr === 'd') tt += ', ' + suffix;
else tt = suffix + (tt ? ', ' + tt : '');
}
else if(!ax._inCalcTicks || (suffix !== ax._prevSuffix)) {
tt += '<br>' + suffix;
ax._prevSuffix = suffix;
// 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
0