Improve rendering
This commit is contained in:
@@ -27,6 +27,9 @@ export interface Props extends Themeable {
|
|||||||
|
|
||||||
export class PieChart extends PureComponent<Props> {
|
export class PieChart extends PureComponent<Props> {
|
||||||
containerElement: any;
|
containerElement: any;
|
||||||
|
svgElement: any;
|
||||||
|
tooltipElement: any;
|
||||||
|
tooltipValueElement: any;
|
||||||
|
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
pieType: 'pie',
|
pieType: 'pie',
|
||||||
@@ -58,12 +61,10 @@ export class PieChart extends PureComponent<Props> {
|
|||||||
const outerRadius = radius - radius / 10;
|
const outerRadius = radius - radius / 10;
|
||||||
const innerRadius = pieType === PieChartType.PIE ? 0 : radius - radius / 3;
|
const innerRadius = pieType === PieChartType.PIE ? 0 : radius - radius / 3;
|
||||||
|
|
||||||
select('.piechart-container svg').remove();
|
const svg = select(this.svgElement)
|
||||||
const svg = select('.piechart-container')
|
.html('')
|
||||||
.append('svg')
|
|
||||||
.attr('width', width)
|
.attr('width', width)
|
||||||
.attr('height', height)
|
.attr('height', height)
|
||||||
.attr('class', 'shadow')
|
|
||||||
.append('g')
|
.append('g')
|
||||||
.attr('transform', `translate(${width / 2},${height / 2})`);
|
.attr('transform', `translate(${width / 2},${height / 2})`);
|
||||||
|
|
||||||
@@ -85,20 +86,18 @@ export class PieChart extends PureComponent<Props> {
|
|||||||
.style('stroke', (d: any, idx: number) => colors[idx])
|
.style('stroke', (d: any, idx: number) => colors[idx])
|
||||||
.style('stroke-width', `${strokeWidth}px`)
|
.style('stroke-width', `${strokeWidth}px`)
|
||||||
.on('mouseover', (d: any, idx: any) => {
|
.on('mouseover', (d: any, idx: any) => {
|
||||||
select('#tooltip')
|
select(this.tooltipElement).style('opacity', 1);
|
||||||
.style('opacity', 1)
|
// TODO: show percents
|
||||||
.select('#tooltip-value')
|
select(this.tooltipValueElement).text(`${names[idx]} (${data[idx]})`);
|
||||||
// TODO: show percents
|
|
||||||
.text(`${names[idx]} (${data[idx]})`);
|
|
||||||
})
|
})
|
||||||
.on('mousemove', () => {
|
.on('mousemove', () => {
|
||||||
select('#tooltip')
|
select(this.tooltipElement)
|
||||||
// TODO: right position
|
// TODO: right position
|
||||||
.style('top', `${event.pageY}px`)
|
.style('top', `${event.pageY}px`)
|
||||||
.style('left', `${event.pageX}px`);
|
.style('left', `${event.pageX}px`);
|
||||||
})
|
})
|
||||||
.on('mouseout', () => {
|
.on('mouseout', () => {
|
||||||
select('#tooltip').style('opacity', 0);
|
select(this.tooltipElement).style('opacity', 0);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,13 +112,17 @@ export class PieChart extends PureComponent<Props> {
|
|||||||
style={{
|
style={{
|
||||||
height: `${height * 0.9}px`,
|
height: `${height * 0.9}px`,
|
||||||
width: `${Math.min(width, height * 1.3)}px`,
|
width: `${Math.min(width, height * 1.3)}px`,
|
||||||
top: '10px',
|
|
||||||
margin: 'auto',
|
|
||||||
}}
|
}}
|
||||||
/>
|
>
|
||||||
<div id="tooltip" className="piechart-tooltip">
|
<svg ref={element => (this.svgElement = element)} />
|
||||||
|
</div>
|
||||||
|
<div className="piechart-tooltip" ref={element => (this.tooltipElement = element)}>
|
||||||
<div className="piechart-tooltip-time">
|
<div className="piechart-tooltip-time">
|
||||||
<div id="tooltip-value" className="piechart-tooltip-value" />
|
<div
|
||||||
|
id="tooltip-value"
|
||||||
|
className="piechart-tooltip-value"
|
||||||
|
ref={element => (this.tooltipValueElement = element)}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -4,9 +4,14 @@
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
|
||||||
svg {
|
.piechart-container {
|
||||||
width: 100%;
|
top: 10px;
|
||||||
height: 100%;
|
margin: auto;
|
||||||
|
|
||||||
|
svg {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.piechart-tooltip {
|
.piechart-tooltip {
|
||||||
@@ -15,21 +20,23 @@
|
|||||||
background-color: #141414;
|
background-color: #141414;
|
||||||
color: #d8d9da;
|
color: #d8d9da;
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
}
|
position: absolute;
|
||||||
|
width: 300px;
|
||||||
|
|
||||||
.piechart-tooltip .piechart-tooltip-time {
|
.piechart-tooltip-time {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
position: relative;
|
position: relative;
|
||||||
top: -3px;
|
top: -3px;
|
||||||
padding: 0.2rem;
|
padding: 0.2rem;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
color: #d8d9da;
|
color: #d8d9da;
|
||||||
}
|
|
||||||
|
|
||||||
.piechart-tooltip .piechart-tooltip-value {
|
.piechart-tooltip-value {
|
||||||
display: table-cell;
|
display: table-cell;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
padding-left: 15px;
|
padding-left: 15px;
|
||||||
text-align: right;
|
text-align: right;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user