Skip to content

Instantly share code, notes, and snippets.

@ygaller
Last active April 21, 2017 11:01
Show Gist options
  • Save ygaller/c33469cb3118d43a0213812358e19262 to your computer and use it in GitHub Desktop.
Save ygaller/c33469cb3118d43a0213812358e19262 to your computer and use it in GitHub Desktop.
@Component({
selector: 'd3-circle-packing-all-in-one',
templateUrl: './d3-circle-packing-all-in-one.component.html',
styleUrls: ['./d3-circle-packing-all-in-one.component.css'],
})
export class D3CirclePackingAllInOneComponent implements OnInit, OnDestroy {
@Input() url: string;
private d3: D3;
private parentNativeElement: any;
private d3Svg: Selection<SVGSVGElement, any, null, undefined>;
constructor(private http: Http, element: ElementRef, d3Service: D3Service) {
this.d3 = d3Service.getD3();
this.parentNativeElement = element.nativeElement;
}
ngOnInit() {
const d3 = this.d3;
if (this.parentNativeElement == null) {
return;
}
const stratify = d3.stratify()
.id((d: HierarchyPointNode<any>) => (<any>d).name)
.parentId((d: HierarchyPointNode<any>) => (<any>d).name.substring(0, (<any>d).name.lastIndexOf(".")));
const processData = function (root: HierarchyNode<any>) {
//This is where we render the canvas
};
this.http.get('./assets/' + this.url).map(res => {
const rawData = res['_body'] || '';
const data = this.d3.csvParse(rawData);
return stratify(data)
.sum((d: HierarchyPointNode<any>) => d.value)
.sort((a, b) => b.value - a.value);
}).subscribe(root => processData(root));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment