Coder Social home page Coder Social logo

Comments (2)

krispo avatar krispo commented on August 17, 2024

First, it should be noted that angular couldn't $watch the function directly while the function definition is changing. So if you use json-tree for changing the options (means, function definitions) you need to subscribe to 'onFunctionChanged' event from json-tree. And then manually refresh the directive. (This is needed only for changing function definition, the others options are $watched by angular).

Second, you can use functions only for those options that can be represented by the functions correctly in the nvd3 core. Say, 'height' is always a number (or null), but 'x' is always a function, 'color' can be both. The common right function definition is:

function(a,b,c,...){ /* do smth */ }

but it should be matched to the correct core definition. Say,

{
    ...,
    x: function(d){ return d[0]; }, /* or d.x, or else. It relies on your data json */
    tooltipContent: function (key, x, y, e, graph) { /* do smth, return html */ },
    color: function (d, i) { /* do smth */ },
    dispatch: { /* events */
        tooltipShow: function (e){ /* event handler */ }
    } 
}

Sometimes you can see something like:

xScale: function i(n){return o(n)}

It is default function definition for some d3 scale, i.e., d3.scale.linear() - this is definitely a function, but this is not a common definition. So, in directive it is can be used something like:

xScale: function(){ return d3.scale.linear();}()

from angular-nvd3.

fernoftheandes avatar fernoftheandes commented on August 17, 2024

@krispo

Here is the only way I have found so far to use a JSON object WITH FUNCTIONS to set the options in the angular directive. First the piece of the JSON object with the necessary functions:

... ,
  "x": { 
    "args": "d",
    "body": "return d[0]"
  },
  "y": { 
    "args": "d",
    "body": "return d[1]"
  },...

And then, inside the directive, I do this:

$scope.options = options;
$scope.options.chart.x = new Function(options.chart.x.args,options.chart.x.body);
$scope.options.chart.y = new Function(options.chart.y.args,options.chart.y.body);

With options being a JSON object that I fetch from the server.

This all seem like the hard way to go about this. Do you have any alternatives to this?

Thanks!

from angular-nvd3.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.