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

Changing data in a graph after initial creation #23

Closed
filtoid opened this issue Jul 15, 2014 · 5 comments
Closed

Changing data in a graph after initial creation #23

filtoid opened this issue Jul 15, 2014 · 5 comments

Comments

@filtoid
Copy link

filtoid commented Jul 15, 2014

It's not clear from the documentation how to update an existing graph. I've tried simply assigning a new set of data to the scope variable but this seems to add data and then draw new data over the top - creating new Y axes as well. Is this even possible or is it a 'write once' object with updates requiring a page refresh.

@nikolaswise
Copy link
Contributor

The examples are all pulling in external JSON, so we haven't really spent a lot of time working with live updates yet. We've structured the directives so they should be taking advantage of Angulars $scope bindings, and if the scope changes it should just redraw the chart.

Do you have some sample code I can take a look at that demonstrates the problem?

@filtoid
Copy link
Author

filtoid commented Jul 30, 2014

Index.html

<!DOCTYPE html>
<html>
    <head>
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.8/angular.min.js"></script>
        <script src="http://d3js.org/d3.v3.min.js"></script>
        <script src="http://dimplejs.org/dist/dimple.v2.0.0.js"></script>
        <script src="http://code.jquery.com/ui/1.10.4/jquery-ui.min.js"></script>
        <script src="angular-dimple.js"></script>
        <script src="app.js"></script>
    </head>
    <body ng-app="myApp">
        <div ng-controller="myController">
            <graph data="graphData">
                <x field="Month" order-by="Date"></x>
                <y field="Unit Sales"></y>
                <line field="Owner" value="Aperture"></line>
            </graph>
            <button id="update_data" ng-click="update_data()">Change Data</button>
        </div>
    </body>
</html>

app.js

angular.module('myApp', [
  'angular-dimple'
])

.controller('myController', ['$scope',  function($scope) {

        $scope.generate_data = function () {
            var retary = [];
            for (var i = 0; i < 5; i++) {
                var date = new Date(Date.now() + i * 86400000);
                var obj = {
                    'Date': date,
                    'Month': date.getMonth() + '-' + date.getDate(),
                    'Owner': 'Aperture',
                    'Unit Sales': (Math.random() * 1000) + 1000
                };
                retary[retary.length] = obj;
            }
            return {'data': retary};
        };

        $scope.update_data = function () {
            $scope.graphData = $scope.generate_data().data;
        };

        $scope.update_data();

    }]);

The problem is exhibited on my machine (MacOS running Chrome) - basically the data draws as expected but it doesn't remove the old stuff and generates new axes on the wrong side of the graph (subsequent data draws the axes over the second axes location).

I looked through the code and it seems to be simply reassigning the data object internally so I don't understand why it isn't working (as doing this in vanilla dimple appears to work).

Thanks for looking into this.

@nikolaswise
Copy link
Contributor

Thanks @filtoid. @paulcpederson and figured out what was going on. Right now we're binding data to the series rather than the graph - so calling chart.draw() just redraws the entire chart (including axis and legend) with the new data in the series, rather than redrawing the chart with all existing bits and pieces with new data.

We're going to re-architect the directive to make the charts behave as expected - what you want it to be doing is exactly what we would expect it to do. So uh ... thanks for the heads up that it don't.

We'll try to get it today or tomorrow - but PR's welcome if you want to crack into it yourself.

@nikolaswise
Copy link
Contributor

Okay! This is fixed in #26. I used your random data controller (which is awesome) and built a demo.

http://nikolaswise.github.io/angular-dimple/examples/#/animation-test

@filtoid filtoid closed this as completed Jul 31, 2014
@filtoid
Copy link
Author

filtoid commented Jul 31, 2014

Perfect thanks for that :)

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

No branches or pull requests

2 participants