現在、Angular でカスタム ディレクティブを使用して、親 div のサイズ変更を監視して angular-nvd3 チャートのサイズを変更しています。これは機能しますが、サイズが変更されている単一のグラフでも、すべてのグラフを再描画する必要があります。
派生したカスタム ディレクティブで updateHeight および updateWidth 関数をオーバーライドして、個々のチャートを更新することは可能ですか?個別のディレクティブを作成してコードを複製する必要はありません。
angular.module('app.graphs').directive('flexibleDiv', function () {
return {
scope: {
opts: '='
},
link: function (scope, element, attr) {
// Watching height of parent div
scope.$watch(function () {
return element.parent(0).height();
}, updateHeight);
// Watching width of parent div
scope.$watch(function () {
return element.parent(0).width();
}, updateWidth);
function updateHeight() {
scope.$parent.scatter_api.refresh();
scope.$parent.focus_api.refresh();
scope.$parent.scatter_twoaxis_api.refresh();
}
function updateWidth() {
scope.$parent.scatter_api.refresh();
scope.$parent.focus_api.refresh();
scope.$parent.scatter_twoaxis_api.refresh();
}
}
}
<div class="widget-body no-padding" flexible-div>
<nvd3-scatter-chart data="scatter_data" api="scatter_api"></nvd3-scatter-chart>
</div>
</div>