Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dart js interop with D3

Tags:

dart

d3.js

I am trying to integrate D3 with dart: My code to this point is as follows:

import 'dart:html';
import 'package:js/js.dart' as js;

void main() {
   js.scoped(() {
     var dee3 = js.context.d3; 
     var dataset = js.array([ 5, 10, 15, 20, 25 ]);
     dee3.select("body").selectAll("p")
    .data(dataset)
    .enter()
    .append("p")
    .text(function(d) { return d; });

  });

Whenever I run this in dartium I get the following exception: Exception: A function must be converted to a Callback before it can be serialized. How can I convert the anonymous function(d) to a callback?

like image 989
epocolis Avatar asked Nov 23 '12 17:11

epocolis


1 Answers

As package:js > 0.2.0 Callback and js.scoped are no longer needed.

import 'dart:html';
import 'package:js/js.dart' as js;

void main() {
  var dee3 = js.context.d3; 
  var dataset = js.array([ 5, 10, 15, 20, 25 ]);
  dee3.select("body").selectAll("p")
    .data(dataset)
    .enter()
    .append("p")
    .text((d, i, context) => d);
}
like image 130
Alexandre Ardhuin Avatar answered Nov 11 '22 23:11

Alexandre Ardhuin