मैं डी 3 और कोणीय 2 अल्फा 37 को एकीकृत करने की कोशिश कर रहा हूं (here से शुरू हुआ)। वर्तमान में जो समस्या है, वह यह है कि जेनरेट किए गए डीओएम तत्वों को नकली स्टाइल दृश्य encapsulation में उपयोग की जाने वाली विशेषताओं को प्राप्त नहीं होता है, और इसलिए मैं तत्व के लिए दृश्य encapsulation को सेट किए बिना उन्हें स्टाइल नहीं कर सकता (या मूल, लेकिन मैं बल्कि नकली का उपयोग करेंगे)।जेनरेट किए गए डीओएम तत्वों में होस्ट विशेषता जोड़ना
मैं प्रोग्राम के रूप में [1] घटक के अंदर एक तत्व से आवश्यक विशेषता निकालने, और उसके बाद जो काम करता है उत्पन्न तत्वों [2], में जोड़ने में कामयाब रहे, लेकिन यह स्पष्ट रूप से अविश्वसनीय रूप से hacky है:
import {Component, View, Attribute, ElementRef, LifecycleEvent} from 'angular2/angular2';
import d3 from 'd3';
@Component({
selector: 'bar-graph',
properties: [ 'data' ]
})
@View({
template: '<div class="chart"></div>',
styles: [`.chart {
background: #eee;
padding: 3px;
}
div.bar {
width: 0;
transition: all 1s ease-out;
-moz-transition: all 1s ease-out;
-webkit-transition: all 1s ease-out;
}
div.bar {
font: 10px sans-serif;
background-color: steelblue;
text-align: right;
padding: 3px;
margin: 5px;
color: white;
box-shadow: 2px 2px 2px #666;
}`]
})
export class BarGraph implements LifecycleEvent.OnChanges {
data: Array<number>;
divs: any;
constructor(elementRef: ElementRef, @Attribute('width') width: string, @Attribute('height') height: string) {
var el:any = elementRef.nativeElement;
var graph:any = d3.select(el);
this.hostAttr = graph[0][0].children[0].attributes[1].name; //hack here [1]
this.divs = graph.
select('div.chart').
style({
'width': width + 'px',
'height': height + 'px',
}).
selectAll('div.bar');
}
render(newValue) {
if (!newValue) return;
this.divs.data(newValue)
.enter().append('div')
.classed('bar', true)
.attr(this.hostAttr, true) //add the attribute here [2]
.style('width', d => d + '%')
.text(d => d + '%');
}
onChanges() {
this.render(this.data);
}
}
क्या इस तरह की चीज़ से निपटने के लिए एक अनुशंसित तरीका है (या क्या मुझे कोणीय 2 के बाहर डीओएम के साथ टंकण करना बंद कर देना चाहिए)?
यदि आप कोई उत्तर चाहते हैं, तो कम से कम आप beta.0 में अपग्रेड करना होगा। –
@EricMartinez बीटा 7 पर एक ही समस्या है। –