streamlinesocial / highcharts-regression

Linear and non-linear regression support for highcharts
MIT License
73 stars 64 forks source link

Error when having multiple line charts with ON and OFF Regression #71

Open ruidiasbraga opened 6 years ago

ruidiasbraga commented 6 years ago

Dear phpepe,

I found a problem when adding more then one series to the regression library, I need to have all ON to have regression and cannot be selective regarding which one I would like to have a regression line,

found the problem to be in the (library code) line 88

    H.wrap(H.Chart.prototype, 'init', function (proceed) {
        var series = arguments[1].series;
        var extraSeries = [];
        var i = 0;
        for (i = 0; i < series.length; i++) {
            var s = series[i];
            var extraSerie = processSerie(s, 'init', this);
            extraSeries.push(extraSerie);
            arguments[1].series[i].rendered = true;
        }

        if (extraSerie) {
            arguments[1].series = series.concat(extraSeries);
        }

        proceed.apply(this, Array.prototype.slice.call(arguments, 1));

    });

I made a few changes to prevent adding undefined series in the case of regression being OFF and when the last series was undefined the validation seemed to not address this issue, so, I changed it as well (concat). With this I can now have a mix of series with regression ON and OFF without any problem.

    H.wrap(H.Chart.prototype, 'init', function (proceed) {
        var series = arguments[1].series;
        var extraSeries = [];
        for (var i = 0; i < series.length; i++) {

            var extraSerie = processSerie(series[i], 'init', this);
            arguments[1].series[i].rendered = true;

            if (extraSerie) {
                extraSeries.push(extraSerie);
            }
        }

        if (series && extraSeries.length > 0) {
            arguments[1].series = series.concat(extraSeries);
        }

        proceed.apply(this, Array.prototype.slice.call(arguments, 1));

    });

Do you want to add this correction by yourself and validate it, you should I submit a fix? Best Regards

phpepe commented 6 years ago

Thanks ! this is an old issue, reported on #66 . If you think this fix that bug, are you confortable creating pull requests ? Otherwise I need to find a time to pick your code from the comment, test and push to master.

ruidiasbraga commented 6 years ago

I will do the pull request ;) Thanks!