Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception when same params object is used to call MG.data_graphic multiple times #401

Closed
reppners opened this issue Mar 31, 2015 · 12 comments
Labels
Milestone

Comments

@reppners
Copy link

Tried out the new option and it breaks for me with this message.

[Error] Error: undefined is not a function (evaluating 'n.getMinutes()')
M@http://localhost:9000/vendor/d3/d3.min.js:1:31145
t@http://localhost:9000/vendor/d3/d3.min.js:1:14408
http://localhost:9000/vendor/metrics-graphics/dist/metricsgraphics.js:1522:57
http://localhost:9000/vendor/metrics-graphics/dist/metricsgraphics.js:1606:64
http://localhost:9000/vendor/d3/d3.min.js:3:12215
http://localhost:9000/vendor/d3/d3.min.js:3:14541
Y@http://localhost:9000/vendor/d3/d3.min.js:1:4475
each@http://localhost:9000/vendor/d3/d3.min.js:3:14513
text@http://localhost:9000/vendor/d3/d3.min.js:3:12169
mg_add_x_tick_labels@http://localhost:9000/vendor/metrics-graphics/dist/metricsgraphics.js:1605:26
x_axis@http://localhost:9000/vendor/metrics-graphics/dist/metricsgraphics.js:1304:29
init@http://localhost:9000/vendor/metrics-graphics/dist/metricsgraphics.js:2373:19
line@http://localhost:9000/vendor/metrics-graphics/dist/metricsgraphics.js:3091:18
data_graphic@http://localhost:9000/vendor/metrics-graphics/dist/metricsgraphics.js:222:24
redraw@http://localhost:9000/scripts/directives/chart.js:126:36
http://localhost:9000/scripts/directives/chart.js:178:23
http://localhost:9000/vendor/angular/angular.min.js:122:292
$digest@http://localhost:9000/vendor/angular/angular.min.js:123:358
$apply@http://localhost:9000/vendor/angular/angular.min.js:126:300
http://localhost:9000/vendor/angular/angular.min.js:90:366
(anonyme Funktion) (angular.min.js, line 102)
(anonyme Funktion) (angular.min.js, line 76)
$digest (angular.min.js, line 124)
$apply (angular.min.js, line 126)
(anonyme Funktion) (angular.min.js, line 90)

Used data structure is:

realtime: {
            data: [
                 {
                       date: new Date(),
                       value: Math.random() * (100 - 0) + 0
                 },
                 ...
            ],
            options: {
                description: 'New data is shown as it comes in',
                title: 'Realtime updates',
                x_accessor: 'date',
                y_accessor: 'value',
                max_y: 120,
                xax_start_at_min: true,
                transition_on_update: true,
                y_extended_ticks: true,
                interpolate: 'linear'
            }
        }

You can checkout this branch where it is demonstrated.

@almossawi
Copy link
Contributor

Don't you get that error irrespective of xax_start_at_min? I can take a closer look a little later. Here's a slightly modified version of your code and the result when run here:

var data = [];
for (var i = 0; i < 100; i++) {
    data.push({
        date: i,
        value: Math.random() * (100 - 0) + 0
     })
}

MG.data_graphic({
    description: 'New data is shown as it comes in',
    title: 'Realtime updates',
    data: data,
    max_y: 120,
    xax_start_at_min: true,
    transition_on_update: true,
    y_extended_ticks: true,
    interpolate: 'linear',
    target: '.result'
});

screen shot 2015-03-31 at 8 54 40 am

@reppners
Copy link
Author

No, I tracked it down to flipping the sax_start_at_min option.
I should add that I dynamically change the min_x and max_x option to keep added data in the center of the graph. The logic is implemented here

I put together the logic in a minimal form for the interactive demo:

var data = [];

var options = {
    description: 'New data is shown as it comes in',
    title: 'Realtime updates',
    max_y: 120,
    xax_start_at_min: true,
    transition_on_update: true,
    y_extended_ticks: true,
    interpolate: 'linear',
    x_accessor: 'date',
    y_accessor: 'value',
    target: '.result'
 };

 setInterval(function () {

    var date = new Date();

    // set min and max when some data is present
    if (data.length > 6) {

        options.min_x = data[data.length - 3].date.getTime();
        options.max_x = options.min_x + 6000;
    }

    // add new value
    data.push({
        date: date,
        value: Math.random() * (100 - 0) + 0
    });

    options.data = data;

    MG.data_graphic(options);
}, 1000);

Interestingly enough this fails regardless of xax_start_at_min but at the same line as my initially reported exception, namely: metricsgraphics.js, 1522

@almossawi
Copy link
Contributor

This may well be related to #393, which I'm currently looking at.

Using the same params object on multiple calls to MG.data_graphic appears to be the culprit. Add this right before your penultimate line (i.e. MG.data_graphic(options)) and see if it fixes the issues, modulo the initial console error:

delete options.xax_format;

@reppners
Copy link
Author

This helps with the minimal example. The issue persists for the angular-directive as I already worked around this issue by deep copying the options before invoking MG.data_graphic with the deep copied options.

@almossawi
Copy link
Contributor

With the change that I just committed, this slightly modified block now works for me. Would you mind verifying, please.

var data = [];

var options = {
    description: 'New data is shown as it comes in',
    title: 'Realtime updates',
    max_y: 120,
    xax_start_at_min: true,
    transition_on_update: true,
    y_extended_ticks: true,
    interpolate: 'linear',
    x_accessor: 'date',
    y_accessor: 'value',
    target: '.result'
 };

 setInterval(function () {
    var date = new Date();

    //set min and max when some data is present
    if (data.length > 6) {
        options.min_x = new Date(+data[data.length - 3].date);
        options.max_x = new Date(+options.min_x + 6000);
    }

    // add new value
    data.push({
        date: date,
        value: Math.random() * (100 - 0) + 0
    });
    options.data = data;
    MG.data_graphic(options);
}, 1000);

@reppners
Copy link
Author

Yes, this improved the behavior but there is still a exception.

[Error] Error: undefined is not a function (evaluating 'n.getHours()')
I@http://localhost:9000/vendor/d3/d3.min.js:1:30942
t@http://localhost:9000/vendor/d3/d3.min.js:1:14408
http://localhost:9000/vendor/metrics-graphics/dist/metricsgraphics.js:1673:43
http://localhost:9000/vendor/d3/d3.min.js:3:12215
http://localhost:9000/vendor/d3/d3.min.js:3:14541
Y@http://localhost:9000/vendor/d3/d3.min.js:1:4475
each@http://localhost:9000/vendor/d3/d3.min.js:3:14513
text@http://localhost:9000/vendor/d3/d3.min.js:3:12169
mg_add_x_tick_labels@http://localhost:9000/vendor/metrics-graphics/dist/metricsgraphics.js:1672:30
x_axis@http://localhost:9000/vendor/metrics-graphics/dist/metricsgraphics.js:1304:29
init@http://localhost:9000/vendor/metrics-graphics/dist/metricsgraphics.js:2373:19
line@http://localhost:9000/vendor/metrics-graphics/dist/metricsgraphics.js:3091:18
data_graphic@http://localhost:9000/vendor/metrics-graphics/dist/metricsgraphics.js:222:24
...

From a quick look the fix you've applied would help at line 1673, too.

@reppners
Copy link
Author

I can definitely confirm that using the same options object multiple times is no longer an issue.

almossawi added a commit that referenced this issue Mar 31, 2015
@almossawi
Copy link
Contributor

If you wouldn't mind verifying that the latest commit fixes your last exception.

@almossawi almossawi changed the title 'xax_start_at_min' on true breaks chart drawing Exception when same params object is used to call MG.data_graphic multiple times Mar 31, 2015
@reppners
Copy link
Author

I use bower and reference the master branch to pull in the latest changes - in your latest commit the bower dist js-files are completely emptied - was this by accident?

@almossawi
Copy link
Contributor

Aah, my bad. Committed, before it finished building.

@reppners
Copy link
Author

All working fine now :)

@almossawi
Copy link
Contributor

Great :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants