@cryptotaxi247 / netdata-1 / commits / 2eae13f3e

d3pie cleanup

Costa Tsaousis (ktsaou) committed Feb 1, 2018 at 02:52 UTC 2eae13f3ef3b2b61aecd26e5d65f930c0f64f68c
1 file changed +38 -91
web/lib/d3pie-0.2.1-netdata-1.js
+38 -91
@@ -272,47 +272,6 @@ var helpers = {
272 return svg;
273 },
274
275 -/*
276 - whenIdExists: function(id, callback) {
277 - var inc = 1;
278 - var giveupIterationCount = 1000;
279 -
280 - var interval = setInterval(function() {
281 - if (document.getElementById(id)) {
282 - clearInterval(interval);
283 - callback();
284 - }
285 - if (inc > giveupIterationCount) {
286 - clearInterval(interval);
287 - }
288 - inc++;
289 - }, 1);
290 - },
291 -
292 - whenElementsExist: function(els, callback) {
293 - var inc = 1;
294 - var giveupIterationCount = 1000;
295 -
296 - var interval = setInterval(function() {
297 - var allExist = true;
298 - for (var i=0; i<els.length; i++) {
299 - if (!document.getElementById(els[i])) {
300 - allExist = false;
301 - break;
302 - }
303 - }
304 - if (allExist) {
305 - clearInterval(interval);
306 - callback();
307 - }
308 - if (inc > giveupIterationCount) {
309 - clearInterval(interval);
310 - }
311 - inc++;
312 - }, 1);
313 - },
314 -*/
315 -
275 shuffleArray: function(array) {
276 var currentIndex = array.length, tmpVal, randomIndex;
277
@@ -1600,9 +1559,7 @@ var text = {
1559 offscreenCoord: -10000,
1560
1561 addTitle: function(pie) {
1603 -
1604 -
1605 - var title = pie.svg.selectAll("." + pie.cssPrefix + "title")
1562 + pie.__title = pie.svg.selectAll("." + pie.cssPrefix + "title")
1563 .data([pie.options.header.title])
1564 .enter()
1565 .append("text")
@@ -1640,8 +1597,8 @@ var text = {
1597 x = ((canvasWidth - canvasPadding.right) / 2) + canvasPadding.left;
1598 }
1599
1643 - // add whatever offset has been added by user
1644 - x += pie.options.misc.pieCenterOffset.x;
1600 + // add whatever offset has been added by user
1601 + x += pie.options.misc.pieCenterOffset.x;
1602
1603 var y = canvasPadding.top + textComponents.title.h;
1604
@@ -1657,7 +1614,7 @@ var text = {
1614 }
1615 }
1616
1660 - pie.svg.select("#" + pie.cssPrefix + "title")
1617 + pie.__title
1618 .attr("x", x)
1619 .attr("y", y);
1620 },
@@ -1665,7 +1622,7 @@ var text = {
1622 addSubtitle: function(pie) {
1623 var headerLocation = pie.options.header.location;
1624
1668 - pie.svg.selectAll("." + pie.cssPrefix + "subtitle")
1625 + pie.__subtitle = pie.svg.selectAll("." + pie.cssPrefix + "subtitle")
1626 .data([pie.options.header.subtitle])
1627 .enter()
1628 .append("text")
@@ -1700,17 +1657,18 @@ var text = {
1657 x = ((canvasWidth - canvasPadding.right) / 2) + canvasPadding.left;
1658 }
1659
1703 - // add whatever offset has been added by user
1704 - x += pie.options.misc.pieCenterOffset.x;
1660 + // add whatever offset has been added by user
1661 + x += pie.options.misc.pieCenterOffset.x;
1662
1663 var y = text.getHeaderHeight(pie);
1707 - pie.svg.select("#" + pie.cssPrefix + "subtitle")
1664 +
1665 + pie.__subtitle
1666 .attr("x", x)
1667 .attr("y", y);
1668 },
1669
1670 addFooter: function(pie) {
1713 - pie.svg.selectAll("." + pie.cssPrefix + "footer")
1671 + pie.__footer = pie.svg.selectAll("." + pie.cssPrefix + "footer")
1672 .data([pie.options.footer])
1673 .enter()
1674 .append("text")
@@ -1750,7 +1708,7 @@ var text = {
1708 x = canvasWidth / 2; // TODO - shouldn't this also take into account padding?
1709 }
1710
1753 - pie.svg.select("#" + pie.cssPrefix + "footer")
1711 + pie.__footer
1712 .attr("x", x)
1713 .attr("y", canvasHeight - canvasPadding.bottom);
1714 },
@@ -2092,54 +2050,43 @@ var tt = {
2050 this.outerLabelGroupData = [];
2051
2052 // add the key text components offscreen (title, subtitle, footer). We need to know their widths/heights for later computation
2095 - if (this.textComponents.title.exists) {
2096 - text.addTitle(this);
2097 - }
2098 - if (this.textComponents.subtitle.exists) {
2099 - text.addSubtitle(this);
2100 - }
2053 + if (this.textComponents.title.exists) text.addTitle(this);
2054 + if (this.textComponents.subtitle.exists) text.addSubtitle(this);
2055 text.addFooter(this);
2056
2057 // the footer never moves. Put it in place now
2058 var self = this;
2105 - //helpers.whenIdExists(this.cssPrefix + "footer", function() {
2106 - text.positionFooter(self);
2107 - var d3 = helpers.getDimensions(self.cssPrefix + "footer");
2108 - self.textComponents.footer.h = d3.h;
2109 - self.textComponents.footer.w = d3.w;
2110 - //});
2059 + text.positionFooter(self);
2060 + var d3 = helpers.getDimensions(self.cssPrefix + "footer");
2061 + self.textComponents.footer.h = d3.h;
2062 + self.textComponents.footer.w = d3.w;
2063 +
2064 + if (self.textComponents.title.exists) {
2065 + var d1 = helpers.getDimensions(self.cssPrefix + "title");
2066 + self.textComponents.title.h = d1.h;
2067 + self.textComponents.title.w = d1.w;
2068 + }
2069
2112 - // now create the pie chart and position everything accordingly
2113 - var reqEls = [];
2114 - if (this.textComponents.title.exists) { reqEls.push(this.cssPrefix + "title"); }
2115 - if (this.textComponents.subtitle.exists) { reqEls.push(this.cssPrefix + "subtitle"); }
2116 - if (this.textComponents.footer.exists) { reqEls.push(this.cssPrefix + "footer"); }
2070 + if (self.textComponents.subtitle.exists) {
2071 + var d2 = helpers.getDimensions(self.cssPrefix + "subtitle");
2072 + self.textComponents.subtitle.h = d2.h;
2073 + self.textComponents.subtitle.w = d2.w;
2074 + }
2075
2118 - //helpers.whenElementsExist(reqEls, function() {
2076 + // now compute the full header height
2077 + if (self.textComponents.title.exists || self.textComponents.subtitle.exists) {
2078 + var headerHeight = 0;
2079 if (self.textComponents.title.exists) {
2120 - var d1 = helpers.getDimensions(self.cssPrefix + "title");
2121 - self.textComponents.title.h = d1.h;
2122 - self.textComponents.title.w = d1.w;
2123 - }
2124 - if (self.textComponents.subtitle.exists) {
2125 - var d2 = helpers.getDimensions(self.cssPrefix + "subtitle");
2126 - self.textComponents.subtitle.h = d2.h;
2127 - self.textComponents.subtitle.w = d2.w;
2128 - }
2129 - // now compute the full header height
2130 - if (self.textComponents.title.exists || self.textComponents.subtitle.exists) {
2131 - var headerHeight = 0;
2132 - if (self.textComponents.title.exists) {
2133 - headerHeight += self.textComponents.title.h;
2134 - if (self.textComponents.subtitle.exists) {
2135 - headerHeight += self.options.header.titleSubtitlePadding;
2136 - }
2137 - }
2080 + headerHeight += self.textComponents.title.h;
2081 if (self.textComponents.subtitle.exists) {
2139 - headerHeight += self.textComponents.subtitle.h;
2082 + headerHeight += self.options.header.titleSubtitlePadding;
2083 }
2141 - self.textComponents.headerHeight = headerHeight;
2084 }
2085 + if (self.textComponents.subtitle.exists) {
2086 + headerHeight += self.textComponents.subtitle.h;
2087 + }
2088 + self.textComponents.headerHeight = headerHeight;
2089 + }
2090
2091 // at this point, all main text component dimensions have been calculated
2092 math.computePieRadius(self);