app/assets/javascripts/highcharts/modules/stock.js in highcharts-rails-6.0.0 vs app/assets/javascripts/highcharts/modules/stock.js in highcharts-rails-6.0.1

- old
+ new

@@ -1,7 +1,7 @@ /** - * @license Highcharts JS v6.0.0 (2017-10-04) + * @license Highcharts JS v6.0.1 (2017-10-05) * Highstock as a plugin for Highcharts * * (c) 2017 Torstein Honsi * * License: www.highcharts.com/license @@ -7378,27 +7378,26 @@ inputPosition = options.inputPosition, inputEnabled = options.inputEnabled, states = buttonTheme && buttonTheme.states, plotLeft = chart.plotLeft, buttonLeft, - pos = this.getPosition(), buttonGroup = rangeSelector.buttonGroup, group, groupHeight, rendered = rangeSelector.rendered, verticalAlign = rangeSelector.options.verticalAlign, legend = chart.legend, legendOptions = legend && legend.options, buttonPositionY = buttonPosition.y, inputPositionY = inputPosition.y, + animate = rendered || false, exportingX = 0, alignTranslateY, legendHeight, minPosition, - translateY, - translateX, - groupOffsetY; + translateY = 0, + translateX; if (options.enabled === false) { return; } @@ -7476,52 +7475,43 @@ rangeSelector.drawInput('max'); } } plotLeft = chart.plotLeft - chart.spacing[3]; - rangeSelector.updateButtonStates(); // detect collisiton with exporting if ( navButtonOptions && this.titleCollision(chart) && verticalAlign === 'top' && buttonPosition.align === 'right' && ( (buttonPosition.y + buttonGroup.getBBox().height - 12) < - ((navButtonOptions.y || 0) + navButtonOptions.height - chart.spacing[0]) + ((navButtonOptions.y || 0) + navButtonOptions.height) ) ) { exportingX = -40; } - // align button group - buttonGroup.align(extend({ - y: pos.buttonTop, - width: buttonGroup.getBBox().width, - x: exportingX - }, buttonPosition), true, chart.spacingBox); - - translateX = buttonGroup.alignAttr.translateX + exportingX; - - // detect left offset (axis title) or margin if (buttonPosition.align === 'left') { - translateX += ((plotLeft < 0) || (H.isNumber(chart.margin[3])) ? 0 : plotLeft) - chart.spacing[3]; + translateX = buttonPosition.x - chart.spacing[3]; } else if (buttonPosition.align === 'right') { - translateX -= chart.spacing[1] + (H.isNumber(chart.margin[3]) ? plotLeft : 0); + translateX = buttonPosition.x + exportingX - chart.spacing[1]; } - // Set / update the group position - buttonGroup.attr({ - translateY: pos.buttonTop, - translateX: translateX - }); + // align button group + buttonGroup.align({ + y: buttonPosition.y, + width: buttonGroup.getBBox().width, + align: buttonPosition.align, + x: translateX + }, true, chart.spacingBox); // skip animation - rangeSelector.group.placed = false; - rangeSelector.buttonGroup.placed = false; + rangeSelector.group.placed = animate; + rangeSelector.buttonGroup.placed = animate; if (inputEnabled !== false) { var inputGroupX, inputGroupWidth, @@ -7533,48 +7523,40 @@ navButtonOptions && this.titleCollision(chart) && verticalAlign === 'top' && inputPosition.align === 'right' && ( - (pos.inputTop - inputGroup.getBBox().height - 12) < + (inputPosition.y - inputGroup.getBBox().height - 12) < ((navButtonOptions.y || 0) + navButtonOptions.height + chart.spacing[0]) ) ) { exportingX = -40; } else { exportingX = 0; } - // Update the alignment to the updated spacing box - inputGroup.align(extend({ - y: pos.inputTop, - width: inputGroup.getBBox().width - }, inputPosition), true, chart.spacingBox); - - translateX = inputGroup.alignAttr.translateX + exportingX; - if (inputPosition.align === 'left') { - translateX += plotLeft; - } else if ( - inputPosition.align === 'right' - ) { - translateX = translateX - chart.axisOffset[1]; // yAxis offset + translateX = plotLeft; + } else if (inputPosition.align === 'right') { + translateX = -Math.max(chart.axisOffset[1], -exportingX); // yAxis offset } - // add y from user options - inputGroup.attr({ - translateY: pos.inputTop + 10, - translateX: translateX - (inputPosition.align === 'right' ? 2 : 0) // fix wrong getBBox() value on right align - }); + // Update the alignment to the updated spacing box + inputGroup.align({ + y: inputPosition.y, + width: inputGroup.getBBox().width, + align: inputPosition.align, + x: inputPosition.x + translateX - 2 // fix wrong getBBox() value on right align + }, true, chart.spacingBox); // detect collision - inputGroupX = inputGroup.translateX + inputGroup.alignOptions.x - + inputGroupX = inputGroup.alignAttr.translateX + inputGroup.alignOptions.x - exportingX + inputGroup.getBBox().x + 2; // getBBox for detecing left margin, 2px padding to not overlap input and label inputGroupWidth = inputGroup.alignOptions.width; - buttonGroupX = buttonGroup.translateX + buttonGroup.getBBox().x; + buttonGroupX = buttonGroup.alignAttr.translateX + buttonGroup.getBBox().x; buttonGroupWidth = buttonGroup.getBBox().width + 20; // 20 is minimal spacing between elements if ( (inputPosition.align === buttonPosition.align) || ( @@ -7582,58 +7564,55 @@ (inputGroupX + inputGroupWidth > buttonGroupX) && (buttonPositionY < (inputPositionY + inputGroup.getBBox().height)) ) ) { - // move the element to the second line inputGroup.attr({ - translateX: inputGroup.translateX, - translateY: inputGroup.translateY + buttonGroup.getBBox().height + 10 + translateX: inputGroup.alignAttr.translateX + (chart.axisOffset[1] >= -exportingX ? 0 : -exportingX), + translateY: inputGroup.alignAttr.translateY + buttonGroup.getBBox().height + 10 }); + } // Set or reset the input values rangeSelector.setInputValue('min', min); rangeSelector.setInputValue('max', max); // skip animation - rangeSelector.inputGroup.placed = false; + rangeSelector.inputGroup.placed = animate; } // vertical align rangeSelector.group.align({ verticalAlign: verticalAlign }, true, chart.spacingBox); // set position groupHeight = rangeSelector.group.getBBox().height + 20; // # 20 padding + alignTranslateY = rangeSelector.group.alignAttr.translateY; // calculate bottom position if (verticalAlign === 'bottom') { legendHeight = legendOptions && legendOptions.verticalAlign === 'bottom' && legendOptions.enabled && !legendOptions.floating ? legend.legendHeight + pick(legendOptions.margin, 10) : 0; groupHeight = groupHeight + legendHeight - 20; - } + translateY = alignTranslateY - groupHeight - (floating ? 0 : options.y) - 10; // 10 spacing - groupOffsetY = Math[verticalAlign === 'middle' ? 'max' : 'min'](inputPositionY, buttonPositionY); - - if (inputGroup && (inputPositionY < buttonPositionY) && verticalAlign === 'bottom') { - groupOffsetY += inputGroup.getBBox().height; } - // fix the position - alignTranslateY = rangeSelector.group.alignAttr.translateY; - minPosition = (inputPositionY < 0 && buttonPositionY < 0) ? 0 : groupOffsetY; - translateY = Math.floor(alignTranslateY - groupHeight - minPosition); - if (verticalAlign === 'top') { if (floating) { translateY = 0; - } else if (chart.spacing[0] !== chart.options.chart.spacing[0]) { // detect if spacing is customised - translateY -= (chart.spacing[0] - chart.options.chart.spacing[0]); } + + if (chart.titleOffset) { + translateY = chart.titleOffset + chart.options.title.margin; + } + + translateY += ((chart.margin[0] - chart.spacing[0]) || 0); + } else if (verticalAlign === 'middle') { if (inputPositionY === buttonPositionY) { if (inputPositionY < 0) { translateY = alignTranslateY + minPosition; } else { @@ -7646,18 +7625,15 @@ translateY = alignTranslateY - groupHeight + minPosition; } } } - translateY = Math.floor(translateY); + rangeSelector.group.translate( + options.x, + options.y + Math.floor(translateY) + ); - if (floating) { - translateY += options.y; - } - - rangeSelector.group.translate(0 + options.x, translateY - 3); // floor to avoid crisp edges, 3px to keep back compatibility - // translate HTML inputs if (inputEnabled !== false) { rangeSelector.minInput.style.marginTop = rangeSelector.group.translateY + 'px'; rangeSelector.maxInput.style.marginTop = rangeSelector.group.translateY + 'px'; } @@ -7670,20 +7646,21 @@ * @return {Number} Returns rangeSelector height */ getHeight: function() { var rangeSelector = this, options = rangeSelector.options, + rangeSelectorGroup = rangeSelector.group, inputPosition = options.inputPosition, buttonPosition = options.buttonPosition, yPosition = options.y, - rangeSelectorGroup = rangeSelector.group, buttonPositionY = buttonPosition.y, inputPositionY = inputPosition.y, rangeSelectorHeight = 0, minPosition; rangeSelectorHeight = rangeSelectorGroup ? (rangeSelectorGroup.getBBox(true).height) + 13 + yPosition : 0; // 13px to keep back compatibility + minPosition = Math.min(inputPositionY, buttonPositionY); if ( (inputPositionY < 0 && buttonPositionY < 0) || (inputPositionY > 0 && buttonPositionY > 0) @@ -7698,23 +7675,11 @@ * Detect collision with title or subtitle * @param {object} chart * @return {Boolean} Returns collision status */ titleCollision: function(chart) { - var status = false; - - if ( - (!H.isObject(chart.title) || - (chart.title && chart.title.getBBox().y > chart.plotTop) - ) && (!H.isObject(chart.subtitle) || - (chart.subtitle && chart.subtitle.getBBox().y > chart.plotTop) - ) - ) { - status = true; - } - - return status; + return !(chart.options.title.text || chart.options.subtitle.text); }, /** * Update the range selector with new options * @param {object} options @@ -7872,13 +7837,21 @@ }); wrap(Chart.prototype, 'render', function(proceed, options, callback) { var chart = this, + axes = chart.axes, rangeSelector = chart.rangeSelector, verticalAlign; if (rangeSelector) { + + each(axes, function(axis) { + axis.updateNames(); + axis.setScale(); + }); + + chart.getAxisMargins(); rangeSelector.render(); verticalAlign = rangeSelector.options.verticalAlign; if (!rangeSelector.options.floating) {