From b8fcd3d9626df2a74da8868f1b032f42ec966072 Mon Sep 17 00:00:00 2001 From: corpglory-dev Date: Fri, 8 Mar 2019 15:17:04 +0300 Subject: [PATCH] Improve rendering --- .../src/components/PieChart/PieChart.tsx | 35 ++++++++-------- public/sass/components/_panel_piechart.scss | 41 +++++++++++-------- 2 files changed, 43 insertions(+), 33 deletions(-) diff --git a/packages/grafana-ui/src/components/PieChart/PieChart.tsx b/packages/grafana-ui/src/components/PieChart/PieChart.tsx index 4686063d186..fa8810335d8 100644 --- a/packages/grafana-ui/src/components/PieChart/PieChart.tsx +++ b/packages/grafana-ui/src/components/PieChart/PieChart.tsx @@ -27,6 +27,9 @@ export interface Props extends Themeable { export class PieChart extends PureComponent { containerElement: any; + svgElement: any; + tooltipElement: any; + tooltipValueElement: any; static defaultProps = { pieType: 'pie', @@ -58,12 +61,10 @@ export class PieChart extends PureComponent { const outerRadius = radius - radius / 10; const innerRadius = pieType === PieChartType.PIE ? 0 : radius - radius / 3; - select('.piechart-container svg').remove(); - const svg = select('.piechart-container') - .append('svg') + const svg = select(this.svgElement) + .html('') .attr('width', width) .attr('height', height) - .attr('class', 'shadow') .append('g') .attr('transform', `translate(${width / 2},${height / 2})`); @@ -85,20 +86,18 @@ export class PieChart extends PureComponent { .style('stroke', (d: any, idx: number) => colors[idx]) .style('stroke-width', `${strokeWidth}px`) .on('mouseover', (d: any, idx: any) => { - select('#tooltip') - .style('opacity', 1) - .select('#tooltip-value') - // TODO: show percents - .text(`${names[idx]} (${data[idx]})`); + select(this.tooltipElement).style('opacity', 1); + // TODO: show percents + select(this.tooltipValueElement).text(`${names[idx]} (${data[idx]})`); }) .on('mousemove', () => { - select('#tooltip') + select(this.tooltipElement) // TODO: right position .style('top', `${event.pageY}px`) .style('left', `${event.pageX}px`); }) .on('mouseout', () => { - select('#tooltip').style('opacity', 0); + select(this.tooltipElement).style('opacity', 0); }); } @@ -113,13 +112,17 @@ export class PieChart extends PureComponent { style={{ height: `${height * 0.9}px`, width: `${Math.min(width, height * 1.3)}px`, - top: '10px', - margin: 'auto', }} - /> -
+ > + (this.svgElement = element)} /> +
+
(this.tooltipElement = element)}>
-
+
(this.tooltipValueElement = element)} + />
diff --git a/public/sass/components/_panel_piechart.scss b/public/sass/components/_panel_piechart.scss index a762e7b6257..8f98f60658b 100644 --- a/public/sass/components/_panel_piechart.scss +++ b/public/sass/components/_panel_piechart.scss @@ -4,9 +4,14 @@ width: 100%; height: 100%; - svg { - width: 100%; - height: 100%; + .piechart-container { + top: 10px; + margin: auto; + + svg { + width: 100%; + height: 100%; + } } .piechart-tooltip { @@ -15,21 +20,23 @@ background-color: #141414; color: #d8d9da; opacity: 0; - } + position: absolute; + width: 300px; - .piechart-tooltip .piechart-tooltip-time { - text-align: center; - position: relative; - top: -3px; - padding: 0.2rem; - font-weight: bold; - color: #d8d9da; - } + .piechart-tooltip-time { + text-align: center; + position: relative; + top: -3px; + padding: 0.2rem; + font-weight: bold; + color: #d8d9da; - .piechart-tooltip .piechart-tooltip-value { - display: table-cell; - font-weight: bold; - padding-left: 15px; - text-align: right; + .piechart-tooltip-value { + display: table-cell; + font-weight: bold; + padding-left: 15px; + text-align: right; + } + } } }