Skip to content

Commit eb82723

Browse files
committed
Revert completely to old tick algo
1 parent 3fe254b commit eb82723

File tree

5 files changed

+243
-110
lines changed

5 files changed

+243
-110
lines changed

src/plot_api/plot_api.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2945,7 +2945,11 @@ function getDiffFlags(oldContainer, newContainer, outerparts, opts) {
29452945
// so newContainer won't have them.
29462946
if((key === 'tick0' || key === 'dtick') && outerparts[0] !== 'geo') {
29472947
var tickMode = newContainer.tickmode;
2948-
if(tickMode === 'auto' || tickMode === 'array' || !tickMode) continue;
2948+
if(tickMode === 'auto' ||
2949+
tickMode === 'array' ||
2950+
tickMode === 'domain array' ||
2951+
tickMode === 'full domain' ||
2952+
!tickMode) continue;
29492953
}
29502954
// FIXME: Similarly for axis ranges for 3D
29512955
// contourcarpet doesn't HAVE zmin/zmax, they're just auto-added. It needs them.

src/plots/cartesian/axes.js

Lines changed: 78 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -682,10 +682,13 @@ axes.prepTicks = function(ax, opts) {
682682
if(ax._name === 'radialaxis') nt *= 2;
683683
}
684684

685-
if(!(ax.minor && ax.minor.tickmode !== 'array')) {
685+
if(!(ax.minor &&
686+
(ax.minor.tickmode !== 'array' &&
687+
ax.minor.tickmode !== 'domain array' &&
688+
ax.minor.tickmode !== 'full domain'))) {
686689
// add a couple of extra digits for filling in ticks when we
687690
// have explicit tickvals without tick text
688-
if(ax.tickmode === 'array') nt *= 100;
691+
if(ax.tickmode === 'array' || ax.tickmode === 'domain array' || ax.tickmode === 'full domain') nt *= 100;
689692
}
690693

691694
ax._roughDTick = Math.abs(rng[1] - rng[0]) / nt;
@@ -920,7 +923,12 @@ axes.calcTicks = function calcTicks(ax, opts) {
920923
var minorTicks = [];
921924

922925
var tickVals = [];
926+
var tickFractionalVals = [];
927+
tickFractionalVals._isSet = false;
928+
923929
var minorTickVals = [];
930+
var minorTickFractionalVals = [];
931+
minorTickFractionalVals._isSet = false;
924932

925933
var hasMinor = ax.minor && (ax.minor.ticks || ax.minor.showgrid);
926934

@@ -944,9 +952,61 @@ axes.calcTicks = function calcTicks(ax, opts) {
944952
axes.prepTicks(mockAx, opts);
945953
}
946954

955+
if(mockAx.tickmode === 'full domain') {
956+
var nt = mockAx.nticks; // does mockAx have nitkcs?
957+
if(nt === undefined) nt = 0;
958+
if(nt === 0) {
959+
// pass
960+
} else if(nt === 1) {
961+
tickVals = [0];
962+
} else if(nt === 2) {
963+
tickVals = [0, 1];
964+
} else {
965+
var increment = 1 / (nt - 1); // (nt-2) + 1
966+
tickVals.push(0);
967+
for(var tickIndex = 0; tickIndex < nt - 2; tickIndex++) {
968+
tickVals.push((tickIndex + 1) * increment);
969+
}
970+
tickVals.push(1);
971+
}
972+
if(major) {
973+
Lib.nestedProperty(ax, 'tickvals').set(tickVals);
974+
} else {
975+
Lib.nestedProperty(ax.minor, 'tickvals').set(tickVals);
976+
}
977+
}
978+
// tickmode 'domain array' is just 'array' but with a pre-calc step
979+
// original comment:
947980
// now that we've figured out the auto values for formatting
948981
// in case we're missing some ticktext, we can break out for array ticks
949-
if(mockAx.tickmode === 'array') {
982+
if(mockAx.tickmode === 'array' || mockAx.tickmode === 'domain array' || mockAx.tickmode === 'full domain') {
983+
// Mapping proportions to array:
984+
if(mockAx.tickmode === 'domain array' || mockAx.tickmode === 'full domain') {
985+
var width = (maxRange - minRange);
986+
if(axrev) width *= -1;
987+
var offset = !axrev ? minRange : maxRange;
988+
989+
var currentFractionalVals = [];
990+
var currentValsProp;
991+
if(major) {
992+
currentValsProp = Lib.nestedProperty(ax, 'tickvals'); // Do we need this?
993+
currentFractionalVals = tickFractionalVals = currentValsProp.get();
994+
tickFractionalVals._isSet = true;
995+
} else {
996+
currentValsProp = Lib.nestedProperty(ax.minor, 'tickvals');
997+
currentFractionalVals = minorTickFractionalVals = currentValsProp.get();
998+
minorTickFractionalVals._isSet = true;
999+
}
1000+
1001+
var mappedVals = Lib.simpleMap(currentFractionalVals,
1002+
function(fraction, offset, width, type) {
1003+
var mapped = offset + (width * fraction);
1004+
return (type === 'log') ? Math.pow(10, mapped) : mapped;
1005+
}, offset, width, type);
1006+
currentValsProp.set(mappedVals);
1007+
}
1008+
1009+
// Original 'array' only code
9501010
if(major) {
9511011
tickVals = [];
9521012
ticksOut = arrayTicks(ax, !isMinor);
@@ -1204,6 +1264,7 @@ axes.calcTicks = function calcTicks(ax, opts) {
12041264
ticksOut.push(t);
12051265
}
12061266
}
1267+
12071268
ticksOut = ticksOut.concat(minorTicks);
12081269

12091270
ax._inCalcTicks = false;
@@ -1213,6 +1274,18 @@ axes.calcTicks = function calcTicks(ax, opts) {
12131274
ticksOut[0].noTick = true;
12141275
}
12151276

1277+
// Reset tickvals back to domain array
1278+
if(tickFractionalVals._isSet) {
1279+
delete tickFractionalVals._isSet;
1280+
if(ax.tickmode === 'full domain') tickFractionalVals = [];
1281+
Lib.nestedProperty(ax, 'tickvals').set(tickFractionalVals);
1282+
}
1283+
if(minorTickFractionalVals._isSet) {
1284+
delete tickFractionalVals._isSet;
1285+
if(ax.minor.tickmode === 'full domain') tickFractionalVals = [];
1286+
Lib.nestedProperty(ax.minor, 'tickvals').set(minorTickFractionalVals);
1287+
}
1288+
12161289
return ticksOut;
12171290
};
12181291

@@ -1617,7 +1690,7 @@ axes.tickFirst = function(ax, opts) {
16171690
// more precision for hovertext
16181691
axes.tickText = function(ax, x, hover, noSuffixPrefix) {
16191692
var out = tickTextObj(ax, x);
1620-
var arrayMode = ax.tickmode === 'array';
1693+
var arrayMode = (ax.tickmode === 'array' || ax.tickmode === 'domain array' || ax.tickmode === 'full domain');
16211694
var extraPrecision = hover || arrayMode;
16221695
var axType = ax.type;
16231696
// TODO multicategory, if we allow ticktext / tickvals
@@ -3333,7 +3406,7 @@ axes.drawGrid = function(gd, ax, opts) {
33333406

33343407
var counterAx = opts.counterAxis;
33353408
if(counterAx && axes.shouldShowZeroLine(gd, ax, counterAx)) {
3336-
var isArrayMode = ax.tickmode === 'array';
3409+
var isArrayMode = (ax.tickmode === 'array' || ax.tickmode === 'domain array' || ax.tickmode === 'full domain');
33373410
for(var i = 0; i < majorVals.length; i++) {
33383411
var xi = majorVals[i].x;
33393412
if(isArrayMode ? !xi : (Math.abs(xi) < ax.dtick / 100)) {

src/plots/cartesian/layout_attributes.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var DAY_OF_WEEK = constants.WEEKDAY_PATTERN;
1414

1515
var minorTickmode = {
1616
valType: 'enumerated',
17-
values: ['auto', 'linear', 'array'],
17+
values: ['auto', 'linear', 'array', 'domain array', 'full domain'],
1818
editType: 'ticks',
1919
impliedEdits: {tick0: undefined, dtick: undefined},
2020
description: [
@@ -23,9 +23,16 @@ var minorTickmode = {
2323
'If *linear*, the placement of the ticks is determined by',
2424
'a starting position `tick0` and a tick step `dtick`',
2525
'(*linear* is the default value if `tick0` and `dtick` are provided).',
26-
'If *array*, the placement of the ticks is set via `tickvals`',
27-
'and the tick text is `ticktext`.',
28-
'(*array* is the default value if `tickvals` is provided).'
26+
'If *array*, the placement of the ticks is set via `tickvals`,',
27+
'which are actual values, and the tick text is `ticktext`.',
28+
'(*array* is the default value if `tickvals` is provided).',
29+
'If *full domain*, the number of ticks is set bia `nticks` but ticks',
30+
'are placed first at both axis ends and then at equal proportions',
31+
'between the axis. So `nticks=5` would put ticks at both ends and',
32+
'every quarter.',
33+
'If *domain array*, the placement is similiar to *array* except that',
34+
'`tickvals` are fractions between 0 and 1 representing distance on',
35+
'the corresponding axis.'
2936
].join(' ')
3037
};
3138

src/plots/cartesian/tick_value_defaults.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ module.exports = function handleTickValueDefaults(containerIn, containerOut, coe
2929
_dtick ? 'linear' :
3030
'auto';
3131
var tickmode = coerce(prefix + 'tickmode', tickmodeDefault);
32-
33-
if(tickmode === 'auto' || tickmode === 'sync') {
32+
if(tickmode === 'auto' || tickmode === 'sync' || tickmode === 'full domain') {
3433
coerce(prefix + 'nticks');
3534
} else if(tickmode === 'linear') {
3635
// dtick is usually a positive number, but there are some

0 commit comments

Comments
 (0)