Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Made the chart fit to the container even when the container has borde…

…rs and padding. Closes #824.
  • Loading branch information...
commit a9f6caca0cfe8624b14cfd20f72a580b58e2ebe1 1 parent 4154033
@highslide-software authored
View
6 build.xml
@@ -558,12 +558,10 @@
<exec executable="cmd" dir="${basedir}" osfamily="windows">
<arg value="/k start java -jar ${jstestdriver.jar} --port 4224"/>
</exec>
- <!--
- <java jar="${jstestdriver.jar}">
- <arg value="/-/-port"/>
+ <java jar="${jstestdriver.jar}" fork="true">
+ <arg value="--port"/>
<arg value="4224"/>
</java>
- -->
<echo message="Test server started at localhost:4224"/>
<echo message="Before running tests, remember to capture one or more browsers."/>
<echo message="Exit the server by pressing Control-C in the java window."/>
View
13 js/adapters/mootools-adapter.src.js
@@ -68,6 +68,19 @@ win.HighchartsAdapter = {
};
/*jslint unparam: false*/
},
+
+ /**
+ * Run a general method on the framework, following jQuery syntax
+ * @param {Object} el The HTML element
+ * @param {String} method Which method to run on the wrapped element
+ */
+ adapterRun: function (el, method) {
+
+ // This currently works for getting inner width and height. If adding
+ // more methods later, we need a conditional implementation for each.
+ return $(el).getStyle(method).toInt();
+
+ },
/**
* Downloads a script and executes a callback when done.
View
13 js/adapters/prototype-adapter.src.js
@@ -100,6 +100,19 @@ return {
});
}
},
+
+ /**
+ * Run a general method on the framework, following jQuery syntax
+ * @param {Object} el The HTML element
+ * @param {String} method Which method to run on the wrapped element
+ */
+ adapterRun: function (el, method) {
+
+ // This currently works for getting inner width and height. If adding
+ // more methods later, we need a conditional implementation for each.
+ return parseInt($(el).getStyle(method), 10);
+
+ },
/**
* Downloads a script and executes a callback when done.
View
64 js/highcharts.src.js
@@ -109,25 +109,6 @@ var UNDEFINED,
setMonth,
setFullYear,
- // check for a custom HighchartsAdapter defined prior to this file
- globalAdapter = win.HighchartsAdapter,
- adapter = globalAdapter || {},
-
- // Utility functions. If the HighchartsAdapter is not defined, adapter is an empty object
- // and all the utility functions will be null. In that case they are populated by the
- // default adapters below.
- getScript = adapter.getScript,
- each = adapter.each,
- grep = adapter.grep,
- offset = adapter.offset,
- map = adapter.map,
- merge = adapter.merge,
- addEvent = adapter.addEvent,
- removeEvent = adapter.removeEvent,
- fireEvent = adapter.fireEvent,
- washMouseEvent = adapter.washMouseEvent,
- animate = adapter.animate,
- stop = adapter.stop,
// lookup over the types and the associated classes
seriesTypes = {};
@@ -960,6 +941,29 @@ function setAnimation(animation, chart) {
globalAnimation = pick(animation, chart.animation);
}
+
+
+// check for a custom HighchartsAdapter defined prior to this file
+var globalAdapter = win.HighchartsAdapter,
+ adapter = globalAdapter || {},
+
+ // Utility functions. If the HighchartsAdapter is not defined, adapter is an empty object
+ // and all the utility functions will be null. In that case they are populated by the
+ // default adapters below.
+ adapterRun = adapter.adapterRun,
+ getScript = adapter.getScript,
+ each = adapter.each,
+ grep = adapter.grep,
+ offset = adapter.offset,
+ map = adapter.map,
+ merge = adapter.merge,
+ addEvent = adapter.addEvent,
+ removeEvent = adapter.removeEvent,
+ fireEvent = adapter.fireEvent,
+ washMouseEvent = adapter.washMouseEvent,
+ animate = adapter.animate,
+ stop = adapter.stop;
+
/*
* Define the adapter for frameworks. If an external adapter is not defined,
* Highcharts reverts to the built-in jQuery adapter.
@@ -978,6 +982,15 @@ if (!globalAdapter && win.jQuery) {
* @param {Function} callback
*/
getScript = jQ.getScript;
+
+ /**
+ * A direct link to jQuery methods. MooTools and Prototype adapters must be implemented for each case of method.
+ * @param {Object} elem The HTML element
+ * @param {String} method Which method to run on the wrapped element
+ */
+ adapterRun = function (elem, method) {
+ return jQ(elem)[method]();
+ };
/**
* Utility for iterating over an array. Parameters are reversed compared to jQuery.
@@ -9542,11 +9555,12 @@ Chart.prototype = {
getChartSize: function () {
var chart = this,
optionsChart = chart.options.chart,
- renderTo = chart.renderTo,
- renderToClone = chart.renderToClone;
+ renderTo = chart.renderToClone || chart.renderTo;
- chart.containerWidth = (renderToClone || renderTo).offsetWidth;
- chart.containerHeight = (renderToClone || renderTo).offsetHeight;
+ // get inner width and height from jQuery (#824)
+ chart.containerWidth = adapterRun(renderTo, 'width');
+ chart.containerHeight = adapterRun(renderTo, 'height');
+
chart.chartWidth = optionsChart.width || chart.containerWidth || 600;
chart.chartHeight = optionsChart.height ||
// the offsetHeight of an empty container is 0 in standard browsers, but 19 in IE7:
@@ -9749,8 +9763,8 @@ Chart.prototype = {
var reflowTimeout;
function reflow(e) {
- var width = optionsChart.width || renderTo.offsetWidth,
- height = optionsChart.height || renderTo.offsetHeight,
+ var width = optionsChart.width || adapterRun(renderTo, 'width'),
+ height = optionsChart.height || adapterRun(renderTo, 'height'),
target = e ? e.target : win; // #805 - MooTools doesn't supply e
// Width and height checks for display:none. Target is doc in IE8 and Opera,
View
64 js/highstock.src.js
@@ -109,25 +109,6 @@ var UNDEFINED,
setMonth,
setFullYear,
- // check for a custom HighchartsAdapter defined prior to this file
- globalAdapter = win.HighchartsAdapter,
- adapter = globalAdapter || {},
-
- // Utility functions. If the HighchartsAdapter is not defined, adapter is an empty object
- // and all the utility functions will be null. In that case they are populated by the
- // default adapters below.
- getScript = adapter.getScript,
- each = adapter.each,
- grep = adapter.grep,
- offset = adapter.offset,
- map = adapter.map,
- merge = adapter.merge,
- addEvent = adapter.addEvent,
- removeEvent = adapter.removeEvent,
- fireEvent = adapter.fireEvent,
- washMouseEvent = adapter.washMouseEvent,
- animate = adapter.animate,
- stop = adapter.stop,
// lookup over the types and the associated classes
seriesTypes = {};
@@ -960,6 +941,29 @@ function setAnimation(animation, chart) {
globalAnimation = pick(animation, chart.animation);
}
+
+
+// check for a custom HighchartsAdapter defined prior to this file
+var globalAdapter = win.HighchartsAdapter,
+ adapter = globalAdapter || {},
+
+ // Utility functions. If the HighchartsAdapter is not defined, adapter is an empty object
+ // and all the utility functions will be null. In that case they are populated by the
+ // default adapters below.
+ adapterRun = adapter.adapterRun,
+ getScript = adapter.getScript,
+ each = adapter.each,
+ grep = adapter.grep,
+ offset = adapter.offset,
+ map = adapter.map,
+ merge = adapter.merge,
+ addEvent = adapter.addEvent,
+ removeEvent = adapter.removeEvent,
+ fireEvent = adapter.fireEvent,
+ washMouseEvent = adapter.washMouseEvent,
+ animate = adapter.animate,
+ stop = adapter.stop;
+
/*
* Define the adapter for frameworks. If an external adapter is not defined,
* Highcharts reverts to the built-in jQuery adapter.
@@ -978,6 +982,15 @@ if (!globalAdapter && win.jQuery) {
* @param {Function} callback
*/
getScript = jQ.getScript;
+
+ /**
+ * A direct link to jQuery methods. MooTools and Prototype adapters must be implemented for each case of method.
+ * @param {Object} elem The HTML element
+ * @param {String} method Which method to run on the wrapped element
+ */
+ adapterRun = function (elem, method) {
+ return jQ(elem)[method]();
+ };
/**
* Utility for iterating over an array. Parameters are reversed compared to jQuery.
@@ -9542,11 +9555,12 @@ Chart.prototype = {
getChartSize: function () {
var chart = this,
optionsChart = chart.options.chart,
- renderTo = chart.renderTo,
- renderToClone = chart.renderToClone;
+ renderTo = chart.renderToClone || chart.renderTo;
- chart.containerWidth = (renderToClone || renderTo).offsetWidth;
- chart.containerHeight = (renderToClone || renderTo).offsetHeight;
+ // get inner width and height from jQuery (#824)
+ chart.containerWidth = adapterRun(renderTo, 'width');
+ chart.containerHeight = adapterRun(renderTo, 'height');
+
chart.chartWidth = optionsChart.width || chart.containerWidth || 600;
chart.chartHeight = optionsChart.height ||
// the offsetHeight of an empty container is 0 in standard browsers, but 19 in IE7:
@@ -9749,8 +9763,8 @@ Chart.prototype = {
var reflowTimeout;
function reflow(e) {
- var width = optionsChart.width || renderTo.offsetWidth,
- height = optionsChart.height || renderTo.offsetHeight,
+ var width = optionsChart.width || adapterRun(renderTo, 'width'),
+ height = optionsChart.height || adapterRun(renderTo, 'height'),
target = e ? e.target : win; // #805 - MooTools doesn't supply e
// Width and height checks for display:none. Target is doc in IE8 and Opera,
View
32 js/parts/Adapters.js
@@ -9,6 +9,29 @@ function setAnimation(animation, chart) {
globalAnimation = pick(animation, chart.animation);
}
+
+
+// check for a custom HighchartsAdapter defined prior to this file
+var globalAdapter = win.HighchartsAdapter,
+ adapter = globalAdapter || {},
+
+ // Utility functions. If the HighchartsAdapter is not defined, adapter is an empty object
+ // and all the utility functions will be null. In that case they are populated by the
+ // default adapters below.
+ adapterRun = adapter.adapterRun,
+ getScript = adapter.getScript,
+ each = adapter.each,
+ grep = adapter.grep,
+ offset = adapter.offset,
+ map = adapter.map,
+ merge = adapter.merge,
+ addEvent = adapter.addEvent,
+ removeEvent = adapter.removeEvent,
+ fireEvent = adapter.fireEvent,
+ washMouseEvent = adapter.washMouseEvent,
+ animate = adapter.animate,
+ stop = adapter.stop;
+
/*
* Define the adapter for frameworks. If an external adapter is not defined,
* Highcharts reverts to the built-in jQuery adapter.
@@ -27,6 +50,15 @@ if (!globalAdapter && win.jQuery) {
* @param {Function} callback
*/
getScript = jQ.getScript;
+
+ /**
+ * A direct link to jQuery methods. MooTools and Prototype adapters must be implemented for each case of method.
+ * @param {Object} elem The HTML element
+ * @param {String} method Which method to run on the wrapped element
+ */
+ adapterRun = function (elem, method) {
+ return jQ(elem)[method]();
+ };
/**
* Utility for iterating over an array. Parameters are reversed compared to jQuery.
View
13 js/parts/Chart.js
@@ -598,11 +598,12 @@ Chart.prototype = {
getChartSize: function () {
var chart = this,
optionsChart = chart.options.chart,
- renderTo = chart.renderTo,
- renderToClone = chart.renderToClone;
+ renderTo = chart.renderToClone || chart.renderTo;
- chart.containerWidth = (renderToClone || renderTo).offsetWidth;
- chart.containerHeight = (renderToClone || renderTo).offsetHeight;
+ // get inner width and height from jQuery (#824)
+ chart.containerWidth = adapterRun(renderTo, 'width');
+ chart.containerHeight = adapterRun(renderTo, 'height');
+
chart.chartWidth = optionsChart.width || chart.containerWidth || 600;
chart.chartHeight = optionsChart.height ||
// the offsetHeight of an empty container is 0 in standard browsers, but 19 in IE7:
@@ -805,8 +806,8 @@ Chart.prototype = {
var reflowTimeout;
function reflow(e) {
- var width = optionsChart.width || renderTo.offsetWidth,
- height = optionsChart.height || renderTo.offsetHeight,
+ var width = optionsChart.width || adapterRun(renderTo, 'width'),
+ height = optionsChart.height || adapterRun(renderTo, 'height'),
target = e ? e.target : win; // #805 - MooTools doesn't supply e
// Width and height checks for display:none. Target is doc in IE8 and Opera,
View
19 js/parts/Globals.js
@@ -94,25 +94,6 @@ var UNDEFINED,
setMonth,
setFullYear,
- // check for a custom HighchartsAdapter defined prior to this file
- globalAdapter = win.HighchartsAdapter,
- adapter = globalAdapter || {},
-
- // Utility functions. If the HighchartsAdapter is not defined, adapter is an empty object
- // and all the utility functions will be null. In that case they are populated by the
- // default adapters below.
- getScript = adapter.getScript,
- each = adapter.each,
- grep = adapter.grep,
- offset = adapter.offset,
- map = adapter.map,
- merge = adapter.merge,
- addEvent = adapter.addEvent,
- removeEvent = adapter.removeEvent,
- fireEvent = adapter.fireEvent,
- washMouseEvent = adapter.washMouseEvent,
- animate = adapter.animate,
- stop = adapter.stop,
// lookup over the types and the associated classes
seriesTypes = {};
View
15 test/unit/AdaptersTest.js
@@ -16,6 +16,21 @@ AdaptersTest.prototype.tearDown = function() {
};
/**
+ * Test general adapterRun.
+ */
+AdaptersTest.prototype.testAdapterRun = function() {
+
+ // Issue #824, inner width of container not computed
+ /*:DOC += <div id="outer" style="width: 100px"><div style="border: 10px solid red; padding: 10px" id="inner">Inner</div></div>*/
+ var inner = document.getElementById('inner');
+
+ assertNotUndefined('Inner div not undefined', inner);
+
+
+ assertEquals('Inner width', 60, adapterRun(inner, 'width'));
+};
+
+/**
* Test the each method.
*/
AdaptersTest.prototype.testEach = function() {
Please sign in to comment.
Something went wrong with that request. Please try again.