Skip to content

Commit

Permalink
Merge pull request #13191 from highcharts/ts/logarithmicaxis
Browse files Browse the repository at this point in the history
ts/logarithmicaxis
  • Loading branch information
TorsteinHonsi committed Mar 27, 2020
2 parents 02f2b53 + 2ffff1c commit daddf2e
Show file tree
Hide file tree
Showing 35 changed files with 706 additions and 474 deletions.
4 changes: 2 additions & 2 deletions js/modules/boost/wgl-renderer.js
Expand Up @@ -742,7 +742,7 @@ function GLRenderer(postRenderCallback) {
shader.setUniform('xAxisLen', axis.len);
shader.setUniform('xAxisPos', axis.pos);
shader.setUniform('xAxisCVSCoord', (!axis.horiz));
shader.setUniform('xAxisIsLog', axis.isLog);
shader.setUniform('xAxisIsLog', (!!axis.logarithmic));
shader.setUniform('xAxisReversed', (!!axis.reversed));
}
/**
Expand All @@ -761,7 +761,7 @@ function GLRenderer(postRenderCallback) {
shader.setUniform('yAxisLen', axis.len);
shader.setUniform('yAxisPos', axis.pos);
shader.setUniform('yAxisCVSCoord', (!axis.horiz));
shader.setUniform('yAxisIsLog', axis.isLog);
shader.setUniform('yAxisIsLog', (!!axis.logarithmic));
shader.setUniform('yAxisReversed', (!!axis.reversed));
}
/**
Expand Down
2 changes: 1 addition & 1 deletion js/modules/drag-panes.src.js
Expand Up @@ -453,7 +453,7 @@ var AxisResizer = /** @class */ (function () {
return AxisResizer;
}());
// Keep resizer reference on axis update
Axis.prototype.keepProps.push('resizer');
Axis.keepProps.push('resizer');
/* eslint-disable no-invalid-this */
// Add new AxisResizer, update or remove it
addEvent(Axis, 'afterRender', function () {
Expand Down
2 changes: 1 addition & 1 deletion js/modules/parallel-coordinates.src.js
Expand Up @@ -203,7 +203,7 @@ extend(ChartProto, /** @lends Highcharts.Chart.prototype */ {
}
});
// On update, keep parallelPosition.
AxisProto.keepProps.push('parallelPosition');
Axis.keepProps.push('parallelPosition');
// Update default options with predefined for a parallel coords.
addEvent(Axis, 'afterSetOptions', function (e) {
var axis = this, chart = axis.chart, axisPosition = ['left', 'width', 'height', 'top'];
Expand Down
2 changes: 1 addition & 1 deletion js/modules/solid-gauge.src.js
Expand Up @@ -117,7 +117,7 @@ colorAxisMethods = {
}
}
else {
if (this.isLog) {
if (this.logarithmic) {
value = this.val2lin(value);
}
pos = 1 - ((this.max - value) / (this.max - this.min));
Expand Down
2 changes: 1 addition & 1 deletion js/parts-3d/Series.js
Expand Up @@ -27,7 +27,7 @@ H.Series.prototype.translate3dPoints = function () {
for (i = 0; i < series.data.length; i++) {
rawPoint = series.data[i];
if (zAxis && zAxis.translate) {
zValue = zAxis.isLog && zAxis.val2lin ?
zValue = zAxis.logarithmic && zAxis.val2lin ?
zAxis.val2lin(rawPoint.z) :
rawPoint.z; // #4562
rawPoint.plotZ = zAxis.translate(zValue);
Expand Down
6 changes: 3 additions & 3 deletions js/parts-map/ColorAxis.js
Expand Up @@ -470,7 +470,7 @@ extend(ColorAxis.prototype, {
'legendItemWidth',
'legendItem',
'legendSymbol'
].concat(Axis.prototype.keepProps),
].concat(Axis.keepProps),
/* eslint-disable no-invalid-this, valid-jsdoc */
/**
* Initializes the color axis.
Expand Down Expand Up @@ -636,8 +636,8 @@ extend(ColorAxis.prototype, {
* @private
*/
normalizedValue: function (value) {
if (this.isLog) {
value = this.val2lin(value);
if (this.logarithmic) {
value = this.logarithmic.log2lin(value);
}
return 1 - ((this.max - value) /
((this.max - this.min) || 1));
Expand Down
2 changes: 1 addition & 1 deletion js/parts-more/BubbleSeries.js
Expand Up @@ -465,7 +465,7 @@ Axis.prototype.beforePadding = function () {
}
});
// Apply the padding to the min and max properties
if (activeSeries.length && range > 0 && !this.isLog) {
if (activeSeries.length && range > 0 && !this.logarithmic) {
pxMax -= axisLength;
transA *= (axisLength +
Math.max(0, pxMin) - // #8901
Expand Down
96 changes: 50 additions & 46 deletions js/parts/Axis.js
Expand Up @@ -259,7 +259,6 @@ var Axis = /** @class */ (function () {
this.hasVisibleSeries = void 0;
this.height = void 0;
this.isLinked = void 0;
this.isLog = void 0;
this.labelEdge = void 0; // @todo
this.labelFormatter = void 0;
this.left = void 0;
Expand Down Expand Up @@ -424,8 +423,7 @@ var Axis = /** @class */ (function () {
// Placeholder for plotlines and plotbands groups
axis.plotLinesAndBandsGroups = {};
// Shorthand types
axis.isLog = type === 'logarithmic';
axis.positiveValuesOnly = axis.isLog && !axis.allowNegativeLog;
axis.positiveValuesOnly = !!(axis.logarithmic && !options.allowNegativeLog);
// Flag, if axis is linked to another axis
axis.isLinked = defined(options.linkedTo);
/**
Expand Down Expand Up @@ -516,12 +514,6 @@ var Axis = /** @class */ (function () {
addEvent(axis, eventType, event);
}
});
// extend logarithmic axis
axis.lin2log = options.linearToLogConverter || axis.lin2log;
if (axis.isLog) {
axis.val2lin = axis.log2lin;
axis.lin2val = axis.lin2log;
}
fireEvent(this, 'afterInit');
};
/**
Expand Down Expand Up @@ -564,7 +556,7 @@ var Axis = /** @class */ (function () {
var axis = this.axis, value = this.value, time = axis.chart.time, categories = axis.categories, dateTimeLabelFormat = this.dateTimeLabelFormat, lang = defaultOptions.lang, numericSymbols = lang.numericSymbols, numSymMagnitude = lang.numericSymbolMagnitude || 1000, i = numericSymbols && numericSymbols.length, multi, ret, formatOption = axis.options.labels.format,
// make sure the same symbol is added for all labels on a linear
// axis
numericSymbolDetector = axis.isLog ?
numericSymbolDetector = axis.logarithmic ?
Math.abs(value) :
axis.tickInterval;
var chart = this.chart;
Expand Down Expand Up @@ -731,7 +723,7 @@ var Axis = /** @class */ (function () {
var axis = this.linkedParent || this, // #1417
sign = 1, cvsOffset = 0, localA = old ? axis.oldTransA : axis.transA, localMin = old ? axis.oldMin : axis.min, returnValue = 0, minPixelPadding = axis.minPixelPadding, doPostTranslate = (axis.isOrdinal ||
axis.isBroken ||
(axis.isLog && handleLog)) && axis.lin2val;
(axis.logarithmic && handleLog)) && axis.lin2val;
if (!localA) {
localA = axis.transA;
}
Expand Down Expand Up @@ -959,12 +951,13 @@ var Axis = /** @class */ (function () {
// If minor ticks get too dense, they are hard to read, and may cause
// long running script. So we don't draw them.
if (range && range / minorTickInterval < axis.len / 3) { // #3875
if (axis.isLog) {
var logarithmic_1 = axis.logarithmic;
if (logarithmic_1) {
// For each interval in the major ticks, compute the minor ticks
// separately.
this.paddedTicks.forEach(function (_pos, i, paddedTicks) {
if (i) {
minorTickPositions.push.apply(minorTickPositions, axis.getLogTickPositions(minorTickInterval, paddedTicks[i - 1], paddedTicks[i], true));
minorTickPositions.push.apply(minorTickPositions, logarithmic_1.getLogTickPositions(minorTickInterval, paddedTicks[i - 1], paddedTicks[i], true));
}
});
}
Expand Down Expand Up @@ -998,11 +991,11 @@ var Axis = /** @class */ (function () {
* @function Highcharts.Axis#adjustForMinRange
*/
Axis.prototype.adjustForMinRange = function () {
var axis = this, options = axis.options, min = axis.min, max = axis.max, zoomOffset, spaceAvailable, closestDataRange, i, distance, xData, loopLength, minArgs, maxArgs, minRange;
var axis = this, options = axis.options, min = axis.min, max = axis.max, log = axis.logarithmic, zoomOffset, spaceAvailable, closestDataRange, i, distance, xData, loopLength, minArgs, maxArgs, minRange;
// Set the automatic minimum range based on the closest point distance
if (axis.isXAxis &&
typeof axis.minRange === 'undefined' &&
!axis.isLog) {
!log) {
if (defined(options.min) || defined(options.max)) {
axis.minRange = null; // don't do this again
}
Expand Down Expand Up @@ -1038,8 +1031,8 @@ var Axis = /** @class */ (function () {
];
// If space is available, stay within the data range
if (spaceAvailable) {
minArgs[2] = axis.isLog ?
axis.log2lin(axis.dataMin) :
minArgs[2] = axis.logarithmic ?
axis.logarithmic.log2lin(axis.dataMin) :
axis.dataMin;
}
min = arrayMax(minArgs);
Expand All @@ -1049,8 +1042,8 @@ var Axis = /** @class */ (function () {
];
// If space is availabe, stay within the data range
if (spaceAvailable) {
maxArgs[2] = axis.isLog ?
axis.log2lin(axis.dataMax) :
maxArgs[2] = log ?
log.log2lin(axis.dataMax) :
axis.dataMax;
}
max = arrayMin(maxArgs);
Expand Down Expand Up @@ -1281,7 +1274,7 @@ var Axis = /** @class */ (function () {
* @fires Highcharts.Axis#event:foundExtremes
*/
Axis.prototype.setTickInterval = function (secondPass) {
var axis = this, chart = axis.chart, options = axis.options, isLog = axis.isLog, isXAxis = axis.isXAxis, isLinked = axis.isLinked, maxPadding = options.maxPadding, minPadding = options.minPadding, length, linkedParentExtremes, tickIntervalOption = options.tickInterval, minTickInterval, tickPixelIntervalOption = options.tickPixelInterval, categories = axis.categories, threshold = isNumber(axis.threshold) ? axis.threshold : null, softThreshold = axis.softThreshold, thresholdMin, thresholdMax, hardMin, hardMax;
var axis = this, chart = axis.chart, log = axis.logarithmic, options = axis.options, isXAxis = axis.isXAxis, isLinked = axis.isLinked, maxPadding = options.maxPadding, minPadding = options.minPadding, length, linkedParentExtremes, tickIntervalOption = options.tickInterval, minTickInterval, tickPixelIntervalOption = options.tickPixelInterval, categories = axis.categories, threshold = isNumber(axis.threshold) ? axis.threshold : null, softThreshold = axis.softThreshold, thresholdMin, thresholdMax, hardMin, hardMax;
if (!axis.dateTime && !categories && !isLinked) {
this.getTickAmount();
}
Expand Down Expand Up @@ -1315,7 +1308,7 @@ var Axis = /** @class */ (function () {
axis.min = pick(hardMin, thresholdMin, axis.dataMin);
axis.max = pick(hardMax, thresholdMax, axis.dataMax);
}
if (isLog) {
if (log) {
if (axis.positiveValuesOnly &&
!secondPass &&
Math.min(axis.min, pick(axis.dataMin, axis.min)) <= 0) { // #978
Expand All @@ -1325,8 +1318,8 @@ var Axis = /** @class */ (function () {
// The correctFloat cures #934, float errors on full tens. But it
// was too aggressive for #4360 because of conversion back to lin,
// therefore use precision 15.
axis.min = correctFloat(axis.log2lin(axis.min), 16);
axis.max = correctFloat(axis.log2lin(axis.max), 16);
axis.min = correctFloat(log.log2lin(axis.min), 16);
axis.max = correctFloat(log.log2lin(axis.max), 16);
}
// handle zoomed range
if (axis.range && defined(axis.max)) {
Expand Down Expand Up @@ -1461,7 +1454,7 @@ var Axis = /** @class */ (function () {
axis.tickInterval = minTickInterval;
}
// for linear axes, get magnitude and normalize the interval
if (!axis.dateTime && !isLog && !tickIntervalOption) {
if (!axis.dateTime && !axis.logarithmic && !tickIntervalOption) {
axis.tickInterval = normalizeTickInterval(axis.tickInterval, null, getMagnitude(axis.tickInterval),
// If the tick interval is between 0.5 and 5 and the axis max is
// in the order of thousands, chances are we are dealing with
Expand Down Expand Up @@ -1540,8 +1533,8 @@ var Axis = /** @class */ (function () {
else if (axis.dateTime) {
tickPositions = axis.getTimeTicks(axis.dateTime.normalizeTimeTickInterval(this.tickInterval, options.units), this.min, this.max, options.startOfWeek, axis.ordinal && axis.ordinal.positions, this.closestPointRange, true);
}
else if (this.isLog) {
tickPositions = axis.getLogTickPositions(this.tickInterval, this.min, this.max);
else if (axis.logarithmic) {
tickPositions = axis.logarithmic.getLogTickPositions(this.tickInterval, this.min, this.max);
}
else {
tickPositions = this.getLinearTickPositions(this.tickInterval, this.min, this.max);
Expand Down Expand Up @@ -1640,8 +1633,8 @@ var Axis = /** @class */ (function () {
* True if there are other axes.
*/
Axis.prototype.alignToOthers = function () {
var others = // Whether there is another axis to pair with this one
{}, hasOther, options = this.options;
var axis = this, others = // Whether there is another axis to pair with this one
{}, hasOther, options = axis.options;
if (
// Only if alignTicks is true
this.chart.options.chart.alignTicks !== false &&
Expand All @@ -1651,7 +1644,7 @@ var Axis = /** @class */ (function () {
options.endOnTick !== false &&
// Don't try to align ticks on a log axis, they are not evenly
// spaced (#6021)
!this.isLog) {
!axis.logarithmic) {
this.chart[this.coll].forEach(function (axis) {
var otherOptions = axis.options, horiz = axis.horiz, key = [
horiz ? otherOptions.left : otherOptions.top,
Expand Down Expand Up @@ -1679,11 +1672,11 @@ var Axis = /** @class */ (function () {
* @function Highcharts.Axis#getTickAmount
*/
Axis.prototype.getTickAmount = function () {
var options = this.options, tickAmount = options.tickAmount, tickPixelInterval = options.tickPixelInterval;
var axis = this, options = this.options, tickAmount = options.tickAmount, tickPixelInterval = options.tickPixelInterval;
if (!defined(options.tickInterval) &&
this.len < tickPixelInterval &&
!this.isRadial &&
!this.isLog &&
!axis.logarithmic &&
options.startOnTick &&
options.endOnTick) {
tickAmount = 2;
Expand Down Expand Up @@ -1964,13 +1957,14 @@ var Axis = /** @class */ (function () {
* An object containing extremes information.
*/
Axis.prototype.getExtremes = function () {
var axis = this, isLog = axis.isLog;
var axis = this;
var log = axis.logarithmic;
return {
min: isLog ?
correctFloat(axis.lin2log(axis.min)) :
min: log ?
correctFloat(log.lin2log(axis.min)) :
axis.min,
max: isLog ?
correctFloat(axis.lin2log(axis.max)) :
max: log ?
correctFloat(log.lin2log(axis.max)) :
axis.max,
dataMin: axis.dataMin,
dataMax: axis.dataMax,
Expand All @@ -1992,7 +1986,7 @@ var Axis = /** @class */ (function () {
* stay within the axis bounds.
*/
Axis.prototype.getThreshold = function (threshold) {
var axis = this, isLog = axis.isLog, realMin = isLog ? axis.lin2log(axis.min) : axis.min, realMax = isLog ? axis.lin2log(axis.max) : axis.max;
var axis = this, log = axis.logarithmic, realMin = log ? log.lin2log(axis.min) : axis.min, realMax = log ? log.lin2log(axis.max) : axis.max;
if (threshold === null || threshold === -Infinity) {
threshold = realMin;
}
Expand Down Expand Up @@ -2670,7 +2664,7 @@ var Axis = /** @class */ (function () {
* @fires Highcharts.Axis#event:afterRender
*/
Axis.prototype.render = function () {
var axis = this, chart = axis.chart, renderer = chart.renderer, options = axis.options, isLog = axis.isLog, isLinked = axis.isLinked, tickPositions = axis.tickPositions, axisTitle = axis.axisTitle, ticks = axis.ticks, minorTicks = axis.minorTicks, alternateBands = axis.alternateBands, stackLabelOptions = options.stackLabels, alternateGridColor = options.alternateGridColor, tickmarkOffset = axis.tickmarkOffset, axisLine = axis.axisLine, showAxis = axis.showAxis, animation = animObject(renderer.globalAnimation), from, to;
var axis = this, chart = axis.chart, log = axis.logarithmic, renderer = chart.renderer, options = axis.options, isLinked = axis.isLinked, tickPositions = axis.tickPositions, axisTitle = axis.axisTitle, ticks = axis.ticks, minorTicks = axis.minorTicks, alternateBands = axis.alternateBands, stackLabelOptions = options.stackLabels, alternateGridColor = options.alternateGridColor, tickmarkOffset = axis.tickmarkOffset, axisLine = axis.axisLine, showAxis = axis.showAxis, animation = animObject(renderer.globalAnimation), from, to;
// Reset
axis.labelEdge.length = 0;
axis.overlap = false;
Expand Down Expand Up @@ -2722,8 +2716,8 @@ var Axis = /** @class */ (function () {
}
from = pos + tickmarkOffset; // #949
alternateBands[pos].options = {
from: isLog ? axis.lin2log(from) : from,
to: isLog ? axis.lin2log(to) : to,
from: log ? log.lin2log(from) : from,
to: log ? log.lin2log(to) : to,
color: alternateGridColor
};
alternateBands[pos].render();
Expand Down Expand Up @@ -2820,6 +2814,18 @@ var Axis = /** @class */ (function () {
series.isDirty = true;
});
};
/**
* Returns an array of axis properties, that should be untouched during
* reinitialization.
*
* @private
* @function Highcharts.Axis#getKeepProps
*
* @return {Array<string>}
*/
Axis.prototype.getKeepProps = function () {
return (this.keepProps || Axis.keepProps);
};
/**
* Destroys an Axis instance. See {@link Axis#remove} for the API endpoint
* to fully remove the axis.
Expand Down Expand Up @@ -2866,7 +2872,7 @@ var Axis = /** @class */ (function () {
}
// Delete all properties and fall back to the prototype.
objectEach(axis, function (val, key) {
if (axis.keepProps.indexOf(key) === -1) {
if (axis.getKeepProps().indexOf(key) === -1) {
delete axis[key];
}
});
Expand Down Expand Up @@ -5808,12 +5814,10 @@ var Axis = /** @class */ (function () {
rotation: 0
}
};
return Axis;
}());
extend(Axis.prototype, {
// Properties to survive after destroy, needed for Axis.update (#4317,
// #5773, #5881).
keepProps: ['extKey', 'hcEvents', 'names', 'series', 'userMax', 'userMin']
});
Axis.keepProps = ['extKey', 'hcEvents', 'names', 'series', 'userMax', 'userMin'];
return Axis;
}());
H.Axis = Axis;
export default H.Axis;

0 comments on commit daddf2e

Please sign in to comment.