Skip to content

Commit 931199e

Browse files
committed
Use lib.simpleMap(); Refactor var names.
1 parent 00e884a commit 931199e

File tree

1 file changed

+27
-24
lines changed

1 file changed

+27
-24
lines changed

src/plots/cartesian/axes.js

+27-24
Original file line numberDiff line numberDiff line change
@@ -950,30 +950,33 @@ axes.calcTicks = function calcTicks(ax, opts) {
950950
// in case we're missing some ticktext, we can break out for array ticks
951951
if (mockAx.tickmode === 'array' || mockAx.tickmode === 'proportional') {
952952

953-
// Mapping proportions to array:
954-
var valsProp, proportionalVals, mappedVals;
955-
var distance = maxRange - minRange;
956-
var start = !axrev ? minRange : maxRange
957-
if (axrev) distance *= -1;
958-
if (mockAx.tickmode === 'proportional') {
959-
valsProp = major ? Lib.nestedProperty(ax, "tickvals") : Lib.nestedProperty(ax.minor, "tickvals")
960-
proportionalVals = valsProp.get()
961-
mappedVals = proportionalVals.map(function(v) { return start + (distance*v) })
962-
valsProp.set(mappedVals)
963-
}
964-
965-
// Original 'array' only code
966-
if(major) {
967-
tickVals = [];
968-
ticksOut = arrayTicks(ax);
969-
} else {
970-
minorTickVals = [];
971-
minorTicks = arrayTicks(ax);
972-
}
973-
974-
// Reset tickvals back to proportional
975-
if (mockAx.tickmode === 'proportional') valsProp.set(proportionalVals)
976-
continue;
953+
// Mapping proportions to array:
954+
var valsProp, fractionalVals;
955+
var width = maxRange - minRange;
956+
var offset = !axrev ? minRange : maxRange;
957+
if (axrev) width *= -1;
958+
if (mockAx.tickmode === 'proportional') {
959+
valsProp = major ? Lib.nestedProperty(ax, "tickvals") : Lib.nestedProperty(ax.minor, "tickvals");
960+
fractionalVals = valsProp.get();
961+
962+
var mappedVals = Lib.simpleMap(fractionalVals, function(fraction, offset, width) {
963+
return offset + (width*fraction);
964+
}, offset, width);
965+
valsProp.set(mappedVals);
966+
}
967+
968+
// Original 'array' only code
969+
if(major) {
970+
tickVals = [];
971+
ticksOut = arrayTicks(ax);
972+
} else {
973+
minorTickVals = [];
974+
minorTicks = arrayTicks(ax);
975+
}
976+
977+
// Reset tickvals back to proportional
978+
if (mockAx.tickmode === 'proportional') valsProp.set(fractionalVals);
979+
continue;
977980
}
978981

979982
// fill tickVals based on overlaying axis

0 commit comments

Comments
 (0)