Last active
April 22, 2017 11:41
-
-
Save ygaller/936fbcf2b8205e864f07a7ed8355cb3c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component({ | |
selector: 'd3-circle-packing-renderer', | |
templateUrl: './d3-circle-packing-renderer.component.html', | |
styleUrls: ['./d3-circle-packing-renderer.component.css'], | |
}) | |
export class D3CirclePackingRendererComponent implements OnInit, OnDestroy { | |
private d3: D3; | |
private parentNativeElement: any; | |
private d3Svg: Selection<SVGSVGElement, any, null, undefined>; | |
@Input() root: Observable<HierarchyNode<any>>; | |
constructor(element: ElementRef, d3Service: D3Service) { | |
this.d3 = d3Service.getD3(); | |
this.parentNativeElement = element.nativeElement; | |
} | |
ngOnInit() { | |
const d3 = this.d3; | |
if (this.parentNativeElement == null) { | |
return; | |
} | |
const processData = function (root: HierarchyNode<any>) { | |
//Render the canvas | |
}; | |
this.root.subscribe(root => processData(root)); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Injectable() | |
export class FlareCsvService implements HierarchicalData { | |
private d3: D3; | |
private stratify; | |
constructor(private http: Http, d3Service: D3Service, private url: string) { | |
this.d3 = d3Service.getD3(); | |
this.stratify = this.d3.stratify() | |
.id((d: HierarchyPointNode<any>) => (<any>d).name) | |
.parentId((d: HierarchyPointNode<any>) => (<any>d).name.substring(0, (<any>d).name.lastIndexOf("."))); | |
} | |
getRoot(): Observable<HierarchyNode<any>> { | |
return this.http.get('./assets/' + this.url).map(res => { | |
const rawData = res['_body'] || ''; | |
const data = this.d3.csvParse(rawData); | |
return this.stratify(data) | |
.sum((d: HierarchyPointNode<any>) => d.value) | |
.sort((a, b) => b.value - a.value); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment