Nicholas Ortenzio
D3.js is a JavaScript library for manipulating documents based on data. D3 helps you bring data to life using HTML, SVG and CSS. D3’s emphasis on web standards gives you the full capabilities of modern browsers without tying yourself to a proprietary framework, combining powerful visualization components and a data-driven approach to DOM manipulation
AngularJS is what HTML would have been, had it been designed for building web-apps. Declarative templates with data-binding, MVW, MVVM, MVC, dependency injection and great testability story all implemented with pure client-side JavaScript
Put your D3 stuff inside a controller and call it a day.
Axes are a problem
Creating an axis returns a function that gets called directly from a selection.
1. My initial approach was to create and Angular directive
1. Create an Angular directive
2. Alternative approach to rendering axes - Cheat
<g transform="translate(20,20)">
<g class="x axis" ng-attr-transform="translate(0, {{ height }})"></g>
<g class="y axis">
<text transform="rotate(-90)" y="6" dy=".71em" style="text-anchor:end;">Price</text>
</g>
</g>
$scope.xAxis = d3.svg.axis().scale($scope.x).orient("bottom");
$scope.yAxis = d3.svg.axis().scale($scope.y).orient("left");
$scope.xAxis(d3.select('.x.axis'));
$scope.yAxis(d3.select('.y.axis'));
Okay so barcharts and scatter plots are easy, but what about
charts that arent a 1:1 representation of data?
Many chart types work by accepting data and returning a path
area
area = d3.svg.area()
.x(function(d) { return $scope.x(d.date); })
.y0($scope.height)
.y1(function(d) { return $scope.y(d.close); });
$scope.areaPath = area($scope.data);
geopath = d3.geo.path().projection(projection);
$scope.ocean.path = path($scope.ocean.data);
<path d="{{ path }}" />
Hexbin
$scope.hexbin = d3.hexbin()
.size([width, height])
.radius(10);
<path ng-repeat="(i, hex) in hexs"
ng-attr-d="{{ hexbin.hexagon() }}"
ng-attr-transform="translate({{ hex.x }}, {{ hex.y}})"
ng-attr-style="fill: {{ color(hex.length) }}"
class="hexagon" />
Basically, having a deep understanding of how all
the D3 chart types work
is key to using them without D3
Slides
https://slides.com/nonononono/using-d3-with-angular-js/
Examples
Source