Skip to content

Commit afba178

Browse files
committed
Add tickmode 'full domain'
1 parent 7e93370 commit afba178

File tree

4 files changed

+47
-11
lines changed

4 files changed

+47
-11
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 === 'domain 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: 35 additions & 7 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' && ax.minor.tickmode !== 'domain 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' || ax.tickmode === 'domain 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;
@@ -948,14 +951,37 @@ axes.calcTicks = function calcTicks(ax, opts) {
948951
} else {
949952
axes.prepTicks(mockAx, opts);
950953
}
951-
954+
955+
if(mockAx.tickmode === 'full domain'){
956+
nt = mockAx.nticks; // does mockAx have nitkcs?
957+
var tickVals = [];
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-2);
966+
tickVals.push(0);
967+
for (let i = 0; i < nt-2; i++) {
968+
tickVals.push((i+1)*incremente);
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+
}
952978
// tickmode 'domain array' is just 'array' but with a pre-calc step
953979
// original comment:
954980
// now that we've figured out the auto values for formatting
955981
// in case we're missing some ticktext, we can break out for array ticks
956-
if(mockAx.tickmode === 'array' || mockAx.tickmode === 'domain array') {
982+
if(mockAx.tickmode === 'array' || mockAx.tickmode === 'domain array' || mockAx.tickmode === 'full domain' ) {
957983
// Mapping proportions to array:
958-
if(mockAx.tickmode === 'domain array') {
984+
if(mockAx.tickmode === 'domain array' || mockAx.tickmode === 'full domain') {
959985
var width = (maxRange - minRange);
960986
if(axrev) width *= -1;
961987
var offset = !axrev ? minRange : maxRange;
@@ -1251,10 +1277,12 @@ axes.calcTicks = function calcTicks(ax, opts) {
12511277
// Reset tickvals back to domain array
12521278
if(tickFractionalVals._isSet) {
12531279
delete tickFractionalVals._isSet;
1280+
if (ax.tickmode === 'full domain') tickFractionalVals = [];
12541281
Lib.nestedProperty(ax, 'tickvals').set(tickFractionalVals);
12551282
}
12561283
if(minorTickFractionalVals._isSet) {
12571284
delete tickFractionalVals._isSet;
1285+
if (ax.minor.tickmode === 'full domain') tickFractionalVals = [];
12581286
Lib.nestedProperty(ax.minor, 'tickvals').set(minorTickFractionalVals);
12591287
}
12601288

@@ -1662,7 +1690,7 @@ axes.tickFirst = function(ax, opts) {
16621690
// more precision for hovertext
16631691
axes.tickText = function(ax, x, hover, noSuffixPrefix) {
16641692
var out = tickTextObj(ax, x);
1665-
var arrayMode = (ax.tickmode === 'array' || ax.tickmode === 'domain array');
1693+
var arrayMode = (ax.tickmode === 'array' || ax.tickmode === 'domain array' || ax.tickmode === 'full domain');
16661694
var extraPrecision = hover || arrayMode;
16671695
var axType = ax.type;
16681696
// TODO multicategory, if we allow ticktext / tickvals
@@ -3378,7 +3406,7 @@ axes.drawGrid = function(gd, ax, opts) {
33783406

33793407
var counterAx = opts.counterAxis;
33803408
if(counterAx && axes.shouldShowZeroLine(gd, ax, counterAx)) {
3381-
var isArrayMode = (ax.tickmode === 'array' || ax.tickmode === 'domain array');
3409+
var isArrayMode = (ax.tickmode === 'array' || ax.tickmode === 'domain array' || ax.tickmode === 'full domain');
33823410
for(var i = 0; i < majorVals.length; i++) {
33833411
var xi = majorVals[i].x;
33843412
if(isArrayMode ? !xi : (Math.abs(xi) < ax.dtick / 100)) {

src/plots/cartesian/layout_attributes.js

Lines changed: 5 additions & 1 deletion
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', 'domain array'],
17+
values: ['auto', 'linear', 'array', 'domain array', 'full domain'],
1818
editType: 'ticks',
1919
impliedEdits: {tick0: undefined, dtick: undefined},
2020
description: [
@@ -26,6 +26,10 @@ var minorTickmode = {
2626
'If *array*, the placement of the ticks is set via `tickvals`,',
2727
'which are actual values, and the tick text is `ticktext`.',
2828
'(*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.',
2933
'If *domain array*, the placement is similiar to *array* except that',
3034
'`tickvals` are fractions between 0 and 1 representing distance on',
3135
'the corresponding axis.'

test/jasmine/tests/pikul_test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var createGraphDiv = require('../assets/create_graph_div');
55
var destroyGraphDiv = require('../assets/destroy_graph_div');
66

77
// Boilerplate taken from axes_test.js
8-
describe('When generating axes w/ `tickmode`:"proportional",', function() {
8+
describe('When generating axes w/ `tickmode`:"domain array",', function() {
99
var gd;
1010

1111
beforeEach(function() {
@@ -21,7 +21,7 @@ describe('When generating axes w/ `tickmode`:"proportional",', function() {
2121
function generateTickConfig(tickLen){
2222
// Intentionally configure to produce a single `(x|y)tick` class per tick
2323
// labels and tick marks each produce one, so one or the other
24-
standardConfig = {tickmode: 'proportional', ticklen: tickLen, showticklabels: false};
24+
standardConfig = {tickmode: 'domain array', ticklen: tickLen, showticklabels: false};
2525

2626
// Tick values will be random:
2727
var n = Math.floor(Math.random() * 100);

0 commit comments

Comments
 (0)