6
d3とangular2 alpha.37(hereから開始)を統合しようとしています。私が現在持っている問題は、生成されたDOM要素がエミュレートされたスタイリングビューのカプセル化で使用される属性を取得しないため、要素のビューカプセル化をNone(またはNative)に設定せずにスタイルを設定できないことですむしろエミュレートされたものを使うだろう)。生成されたDOM要素にホスト属性を追加する
私は仕事をしている、プログラム[2] [1]成分内側要素から必要な属性を抽出し、その後、生成された要素に追加するために管理、これは明らかに非常にハックである:
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);
}
}
このようなことに対処するための推奨される方法はありますか(または、Angular2以外のDOMを使っていなくてもよいですか)。
回答が必要な場合は、少なくともベータ版にアップグレードする必要があります。 –
@EricMartinez beta.7でも同じ問題があります。 –