Skip to content

Commit d42dd73

Browse files
committed
Restore proportional array later in loop:
Plotly does some math on the ticks, sometimes comrparing major and minor values, so we have to store both in their own separate values and then restore them to their attribute at the very end so plotly has them throughout the calculating process.
1 parent ddfaad7 commit d42dd73

File tree

1 file changed

+37
-15
lines changed

1 file changed

+37
-15
lines changed

src/plots/cartesian/axes.js

+37-15
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,12 @@ axes.calcTicks = function calcTicks(ax, opts) {
920920
var minorTicks = [];
921921

922922
var tickVals = [];
923+
var tickFractionalVals = [];
924+
tickFractionalVals._isSet = false
925+
923926
var minorTickVals = [];
927+
var minorTickFractionalVals = [];
928+
minorTickFractionalVals._isSet = false
924929

925930
var hasMinor = ax.minor && (ax.minor.ticks || ax.minor.showgrid);
926931

@@ -950,18 +955,29 @@ axes.calcTicks = function calcTicks(ax, opts) {
950955
// in case we're missing some ticktext, we can break out for array ticks
951956
if(mockAx.tickmode === 'array' || mockAx.tickmode === 'proportional') {
952957
// Mapping proportions to array:
953-
var valsProp, fractionalVals;
954-
var width = maxRange - minRange;
955-
var offset = !axrev ? minRange : maxRange;
956-
if(axrev) width *= -1;
957958
if(mockAx.tickmode === 'proportional') {
958-
valsProp = major ? Lib.nestedProperty(ax, 'tickvals') : Lib.nestedProperty(ax.minor, 'tickvals');
959-
fractionalVals = valsProp.get();
960-
var mappedVals = Lib.simpleMap(fractionalVals, function(fraction, offset, width, type) {
961-
var mapped = offset + (width * fraction);
962-
return (type === 'log') ? Math.pow(10, mapped) : mapped;
963-
}, offset, width, type);
964-
valsProp.set(mappedVals);
959+
var width = (maxRange - minRange);
960+
if(axrev) width *= -1;
961+
var offset = !axrev ? minRange : maxRange;
962+
963+
var currentFractionalVals = [];
964+
var currentValsProp;
965+
if(major) {
966+
currentValsProp = Lib.nestedProperty(ax, 'tickvals'); // Do we need this?
967+
currentFractionalVals = tickFractionalVals = currentValsProp.get();
968+
tickFractionalVals._isSet = true
969+
} else {
970+
currentValsProp = Lib.nestedProperty(ax.minor, 'tickvals');
971+
currentFractionalVals = minorTickFractionalVals = currentValsProp.get();
972+
minorTickFractionalVals._isSet = true
973+
}
974+
975+
var mappedVals = Lib.simpleMap(currentFractionalVals,
976+
function(fraction, offset, width, type) {
977+
var mapped = offset + (width * fraction);
978+
return (type === 'log') ? Math.pow(10, mapped) : mapped;
979+
}, offset, width, type);
980+
currentValsProp.set(mappedVals);
965981
}
966982

967983
// Original 'array' only code
@@ -972,11 +988,8 @@ axes.calcTicks = function calcTicks(ax, opts) {
972988
minorTickVals = [];
973989
minorTicks = arrayTicks(ax);
974990
}
975-
976-
// Reset tickvals back to proportional
977-
if(mockAx.tickmode === 'proportional') valsProp.set(fractionalVals);
978991
continue;
979-
}
992+
}
980993

981994
// fill tickVals based on overlaying axis
982995
if(mockAx.tickmode === 'sync') {
@@ -1225,6 +1238,7 @@ axes.calcTicks = function calcTicks(ax, opts) {
12251238
ticksOut.push(t);
12261239
}
12271240
}
1241+
12281242
ticksOut = ticksOut.concat(minorTicks);
12291243

12301244
ax._inCalcTicks = false;
@@ -1234,6 +1248,14 @@ axes.calcTicks = function calcTicks(ax, opts) {
12341248
ticksOut[0].noTick = true;
12351249
}
12361250

1251+
// Reset tickvals back to proportional
1252+
if (tickFractionalVals._isSet) {
1253+
Lib.nestedProperty(ax, 'tickvals').set(tickFractionalVals)
1254+
}
1255+
if (minorTickFractionalVals._isSet){
1256+
Lib.nestedProperty(ax.minor, 'tickvals').set(minorTickFractionalVals);
1257+
}
1258+
12371259
return ticksOut;
12381260
};
12391261

0 commit comments

Comments
 (0)