Skip to content

Commit

Permalink
Fixed #5376, Axis.getTitlePosition did not support font-size text val…
Browse files Browse the repository at this point in the history
…ues.
  • Loading branch information
jon-a-nygaard authored and TorsteinHonsi committed Aug 2, 2016
1 parent 9e68841 commit 3861ed4
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 21 deletions.
3 changes: 2 additions & 1 deletion js/highcharts.src.js
Expand Up @@ -8955,7 +8955,8 @@
offset = this.offset,
xOption = axisTitleOptions.x || 0,
yOption = axisTitleOptions.y || 0,
fontSize = pInt(axisTitleOptions.style.fontSize || 12),
renderer = this.chart.renderer,
fontSize = renderer.fontMetrics(axisTitleOptions.style.fontSize).f;

// the position in the length direction of the axis
alongAxis = {
Expand Down
3 changes: 2 additions & 1 deletion js/highmaps.src.js
Expand Up @@ -8681,7 +8681,8 @@
offset = this.offset,
xOption = axisTitleOptions.x || 0,
yOption = axisTitleOptions.y || 0,
fontSize = pInt(axisTitleOptions.style.fontSize || 12),
renderer = this.chart.renderer,
fontSize = renderer.fontMetrics(axisTitleOptions.style.fontSize).f;

// the position in the length direction of the axis
alongAxis = {
Expand Down
23 changes: 11 additions & 12 deletions js/highstock.src.js
Expand Up @@ -8955,7 +8955,8 @@
offset = this.offset,
xOption = axisTitleOptions.x || 0,
yOption = axisTitleOptions.y || 0,
fontSize = pInt(axisTitleOptions.style.fontSize || 12),
renderer = this.chart.renderer,
fontSize = renderer.fontMetrics(axisTitleOptions.style.fontSize).f;

// the position in the length direction of the axis
alongAxis = {
Expand Down Expand Up @@ -21085,9 +21086,9 @@
/**
* Extend the original method, make the tooltip's header reflect the grouped range
*/
wrap(Tooltip.prototype, 'tooltipFooterHeaderFormatter', function (proceed, point, isFooter) {
wrap(Tooltip.prototype, 'tooltipFooterHeaderFormatter', function (proceed, labelConfig, isFooter) {
var tooltip = this,
series = point.series,
series = labelConfig.series,
options = series.options,
tooltipOptions = series.tooltipOptions,
dataGroupingOptions = options.dataGrouping,
Expand All @@ -21100,7 +21101,7 @@
formattedKey;

// apply only to grouped series
if (xAxis && xAxis.options.type === 'datetime' && dataGroupingOptions && isNumber(point.key)) {
if (xAxis && xAxis.options.type === 'datetime' && dataGroupingOptions && isNumber(labelConfig.key)) {

// set variables
currentDataGrouping = series.currentDataGrouping;
Expand All @@ -21119,25 +21120,23 @@
// so if the least distance between points is one minute, show it, but if the
// least distance is one day, skip hours and minutes etc.
} else if (!xDateFormat && dateTimeLabelFormats) {
xDateFormat = tooltip.getXDateFormat(point, tooltipOptions, xAxis);
xDateFormat = tooltip.getXDateFormat(labelConfig, tooltipOptions, xAxis);
}

// now format the key
formattedKey = dateFormat(xDateFormat, point.key);
formattedKey = dateFormat(xDateFormat, labelConfig.key);
if (xDateFormatEnd) {
formattedKey += dateFormat(xDateFormatEnd, point.key + currentDataGrouping.totalRange - 1);
formattedKey += dateFormat(xDateFormatEnd, labelConfig.key + currentDataGrouping.totalRange - 1);
}

// return the replaced format
return format(tooltipOptions[(isFooter ? 'footer' : 'header') + 'Format'], {
point: extend(point, { key: formattedKey }),
series: series
});
labelConfig.point.key = labelConfig.key;
return format(tooltipOptions[(isFooter ? 'footer' : 'header') + 'Format'], labelConfig);

}

// else, fall back to the regular formatter
return proceed.call(tooltip, point, isFooter);
return proceed.call(tooltip, labelConfig, isFooter);
});

/**
Expand Down
3 changes: 2 additions & 1 deletion js/parts/Axis.js
Expand Up @@ -1990,7 +1990,8 @@ Axis.prototype = {
offset = this.offset,
xOption = axisTitleOptions.x || 0,
yOption = axisTitleOptions.y || 0,
fontSize = pInt(axisTitleOptions.style.fontSize || 12),
renderer = this.chart.renderer,
fontSize = renderer.fontMetrics(axisTitleOptions.style.fontSize).f;

// the position in the length direction of the axis
alongAxis = {
Expand Down
12 changes: 6 additions & 6 deletions js/parts/DataGrouping.js
Expand Up @@ -381,7 +381,7 @@ seriesProto.generatePoints = function () {
*/
wrap(Tooltip.prototype, 'tooltipFooterHeaderFormatter', function (proceed, point, isFooter) {
var tooltip = this,
series = point.series,
series = labelConfig.series,
options = series.options,
tooltipOptions = series.tooltipOptions,
dataGroupingOptions = options.dataGrouping,
Expand All @@ -394,7 +394,7 @@ wrap(Tooltip.prototype, 'tooltipFooterHeaderFormatter', function (proceed, point
formattedKey;

// apply only to grouped series
if (xAxis && xAxis.options.type === 'datetime' && dataGroupingOptions && isNumber(point.key)) {
if (xAxis && xAxis.options.type === 'datetime' && dataGroupingOptions && isNumber(labelConfig.key)) {

// set variables
currentDataGrouping = series.currentDataGrouping;
Expand All @@ -413,13 +413,13 @@ wrap(Tooltip.prototype, 'tooltipFooterHeaderFormatter', function (proceed, point
// so if the least distance between points is one minute, show it, but if the
// least distance is one day, skip hours and minutes etc.
} else if (!xDateFormat && dateTimeLabelFormats) {
xDateFormat = tooltip.getXDateFormat(point, tooltipOptions, xAxis);
xDateFormat = tooltip.getXDateFormat(labelConfig, tooltipOptions, xAxis);
}

// now format the key
formattedKey = dateFormat(xDateFormat, point.key);
formattedKey = dateFormat(xDateFormat, labelConfig.key);
if (xDateFormatEnd) {
formattedKey += dateFormat(xDateFormatEnd, point.key + currentDataGrouping.totalRange - 1);
formattedKey += dateFormat(xDateFormatEnd, labelConfig.key + currentDataGrouping.totalRange - 1);
}

// return the replaced format
Expand All @@ -431,7 +431,7 @@ wrap(Tooltip.prototype, 'tooltipFooterHeaderFormatter', function (proceed, point
}

// else, fall back to the regular formatter
return proceed.call(tooltip, point, isFooter);
return proceed.call(tooltip, labelConfig, isFooter);
});

/**
Expand Down
5 changes: 5 additions & 0 deletions samples/unit-tests/axis/gettitleposition/demo.details
@@ -0,0 +1,5 @@
---
resources:
- https://code.jquery.com/qunit/qunit-1.19.0.js
- https://code.jquery.com/qunit/qunit-1.19.0.css
...
7 changes: 7 additions & 0 deletions samples/unit-tests/axis/gettitleposition/demo.html
@@ -0,0 +1,7 @@
<script src="https://code.highcharts.com/highcharts.js"></script>


<div id="qunit"></div>
<div id="qunit-fixture"></div>

<div id="container" style="width: 600px; margin: 0 auto"></div>
64 changes: 64 additions & 0 deletions samples/unit-tests/axis/gettitleposition/demo.js
@@ -0,0 +1,64 @@
QUnit.test('getTitlePosition', function (assert) {
var getTitlePosition = Highcharts.Axis.prototype.getTitlePosition,
fontMetrics = Highcharts.Renderer.prototype.fontMetrics,
xAxis = {
axisTitleMargin: 30,
chart: {
renderer: {
fontMetrics: fontMetrics
}
},
height: 265,
horiz: true,
left: 93,
len: 729,
offset: 0,
opposite: undefined,
options: {
title: {
align: 'middle',
style: {
fontSize: 'x-large'
}
}
},
side: 2,
top: 53,
width: 729
},
yAxis = {
axisTitleMargin: 45.859375,
chart: {
renderer: {
fontMetrics: fontMetrics
}
},
height: 265,
horiz: false,
left: 93,
len: 265,
offset: -0,
opposite: undefined,
options: {
title: {
align: 'middle',
style: {
fontSize: 'x-large'
}
}
},
side: 3,
top: 53,
width: 729
};
assert.deepEqual(
getTitlePosition.call(xAxis),
{ "x": 457.5, "y": 360 },
'xAxis returns expected position'
);
assert.deepEqual(
getTitlePosition.call(yAxis),
{ "x": 47.140625, "y": 185.5 },
'yAxis returns expected position'
);
});

0 comments on commit 3861ed4

Please sign in to comment.