Skip to content

Commit e7a2ffa

Browse files
committed
Add/calc tickmode "proportional" in cartesian/
- Create tickmode "proportional" - Map fractional tickvals to axis values w/ axis range: - Set ax.(minor?).tickvals to - Do that right before `arrayTicks()` is called - Every instance of `tickmode === "array"` gets `...|| "proportional"` This works well since tickmode "proportional" really just adds a preprocess step to tickmode "array". TODO: - Check if graph is reversed - Find where ticks are redrawn on zoom and make redraw proportional (will probably fix below) - Figure out why ticks not redrawn on double click/home - Add docs in layout
1 parent 1487f52 commit e7a2ffa

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

Diff for: src/plot_api/plot_api.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2945,7 +2945,7 @@ 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' || tickMode === 'array' || tickMode === 'proportional' || !tickMode) continue;
29492949
}
29502950
// FIXME: Similarly for axis ranges for 3D
29512951
// contourcarpet doesn't HAVE zmin/zmax, they're just auto-added. It needs them.

Diff for: src/plots/cartesian/axes.js

+21-5
Original file line numberDiff line numberDiff line change
@@ -682,10 +682,10 @@ 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 && (ax.minor.tickmode !== 'array' && ax.minor.tickmode !== 'proportional'))) {
686686
// add a couple of extra digits for filling in ticks when we
687687
// have explicit tickvals without tick text
688-
if(ax.tickmode === 'array') nt *= 100;
688+
if(ax.tickmode === 'array' || ax.tickmode === 'proportional') nt *= 100;
689689
}
690690

691691
ax._roughDTick = Math.abs(rng[1] - rng[0]) / nt;
@@ -944,9 +944,25 @@ axes.calcTicks = function calcTicks(ax, opts) {
944944
axes.prepTicks(mockAx, opts);
945945
}
946946

947+
console.log("mode:" + mockAx.tickmode)
948+
if (mockAx.tickmode === 'proportional') { // TODO: if we look at autorange, can we get rid of buffer
949+
var distance = maxRange - minRange;
950+
var vals = []
951+
if(major) {
952+
vals = Lib.nestedProperty(ax, "tickvals")
953+
} else {
954+
vals = Lib.nestedProperty(ax.minor, "tickvals")
955+
}
956+
var mappedVals = vals.get().map(function(x) { return minRange+(distance*x) })
957+
vals.set(mappedVals)
958+
// TODO: What happens if range reversed
959+
// TODO: Needs to be recalculated on auto
960+
// TODO: Disappears on double click
961+
}
962+
947963
// now that we've figured out the auto values for formatting
948964
// in case we're missing some ticktext, we can break out for array ticks
949-
if(mockAx.tickmode === 'array') {
965+
if(mockAx.tickmode === 'array' || mockAx.tickmode === 'proportional') {
950966
if(major) {
951967
tickVals = [];
952968
ticksOut = arrayTicks(ax);
@@ -1617,7 +1633,7 @@ axes.tickFirst = function(ax, opts) {
16171633
// more precision for hovertext
16181634
axes.tickText = function(ax, x, hover, noSuffixPrefix) {
16191635
var out = tickTextObj(ax, x);
1620-
var arrayMode = ax.tickmode === 'array';
1636+
var arrayMode = (ax.tickmode === 'array' || ax.tickmode === 'proportional');
16211637
var extraPrecision = hover || arrayMode;
16221638
var axType = ax.type;
16231639
// TODO multicategory, if we allow ticktext / tickvals
@@ -3333,7 +3349,7 @@ axes.drawGrid = function(gd, ax, opts) {
33333349

33343350
var counterAx = opts.counterAxis;
33353351
if(counterAx && axes.shouldShowZeroLine(gd, ax, counterAx)) {
3336-
var isArrayMode = ax.tickmode === 'array';
3352+
var isArrayMode = (ax.tickmode === 'array' || ax.tickmode === 'proportional');
33373353
for(var i = 0; i < majorVals.length; i++) {
33383354
var xi = majorVals[i].x;
33393355
if(isArrayMode ? !xi : (Math.abs(xi) < ax.dtick / 100)) {

Diff for: src/plots/cartesian/layout_attributes.js

+1-1
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', 'proportional'],
1818
editType: 'ticks',
1919
impliedEdits: {tick0: undefined, dtick: undefined},
2020
description: [

0 commit comments

Comments
 (0)