1. I am using Highcharts Stock, which means I have a navigator enabled by default. This results in having double series in `chart.series` (each base series has it's counterpart navigator series). So I added additional check when iterating through `chart.series` in order to skip navigator series and not take them into account in further `pointWidth` calculations. I check for `series.baseSeries` presence, as it indicates that series is navigator series (every navigator series has a reference on it's base series and vice versa):
Code: Select all
if (!series.visible || series.baseSeries) return;
2. `Math.max.apply(Math, Object.values(occurrences))` can produce `-Infinity` output if `Object.values(occurrences)` produces an empty array. As `-Infinity` is considered a truthy value, this results in `customColumnCount` taking a value of `-Infinity` instead of `columnCount` in this assignment:
Code: Select all
var customColumnCount = Math.max.apply(Math, Object.values(occurrences)) || columnCount;
so I replaced it with
Code: Select all
var occurrencesArr = Object.values(occurrences);
var customColumnCount = occurrencesArr.length ? Math.max.apply(Math, occurancesArr) : columnCount;
3. If we want to stick with ES5-compatibility, then `Object.values` should be replaced. For example:
Code: Select all
Object.keys(occurrences).map(function(key){return occurrences[key]});
Here is a final result with all the fixes applied:
https://jsfiddle.net/Cortez/okhfj19g/