(()=>{function t(m){var w="<svg></svg>";return{restrict:"EA",template:w,scope:{measurements:"=",dps:"=",options:"="},link:function(r,o){var a,i,s,u,l=r.options;function n(){var t=(()=>{var t=nv.models.pieChart().x(c).y(d).color(p).tooltipContent(h);return l&&(t.showLabels(r.options.showLabels||!1),t.showLegend(r.options.showLegend||!1),t.options({tooltips:r.options.showTooltips||!1}),l.showLegend||t.margin({top:0})),t.pie.pieLabelsOutside(!1).labelType("percent"),t})(),e=d3.select(o[0]).select("svg"),n=o.children().first(),e=_.debounce(function(t,e,n){(t=>{t&&t.update&&t.update()})(t);var o,a=r.measurements,i=e.datum()||r.dps;a&&i&&((i.length!==r.dps.length||0<_.differenceBy(i,r.dps,"_id").length)&&(i=r.dps),n=n[0].querySelector(".nv-pieWrap"),((o=a.some(function(t){return 0<t.value}))?(i=_.map(i,function(t,e){return{_id:t._id,label:t.label,value:a[e].value,color:t.color,unit:t.unit,disabled:t.disabled}}),e.datum(i)):(t.noData(m.getString("No data to display.")),e.datum([]))).transition().duration(500).call(t),n)&&(n.style.display=o?"":"none")}.bind(void 0,t,e,n),500,{trailing:!0});return a=r.$watch("measurements",e),i=r.$watch("dps",e),s=r.$watch(v,e),u=r.$watch(f,e),o.onresize=g,t}function c(t){return t.label}function d(t){return t.value}function p(t){return t.data.color}function h(t,e,n){return _.escape("".concat(t,": ").concat(e," ").concat(n.point.unit||""))}function v(){return o.parent().width()}function f(){return o.parent().height()}function g(){r.$apply()}nv.addGraph(n),r.$watch("options",function(t,e){t&&!_.isEqual(t,e)&&(l=t,o.html(w),a(),i(),s(),u(),nv.addGraph(n))})}}}t.$inject=["gettextCatalog"],angular.module("c8y.ui").directive("c8yPieChart",t)})();