Files
edx-platform/lms/static/js/learner_analytics_dashboard/CircleChartLegend.jsx
Syed Ali Abbas Zaidi f1fb38ed83 fix: multi lines and spaces issues (#31885)
* fix: multi lines and spaces issues

* fix: eslint operator-linebreak issue

* fix: eslint quotes issue

* fix: remaining quotes issues

* fix: eslint object curly newline issue

* fix: eslint object curly spacing issue

* fix: eslint brace-style issues

* fix: react jsx indent and props issues

* fix: eslint trailing spaces issues

* fix: eslint linbreak style issue

* fix: eslint space unary operator issue

* fix: eslint line around directives issue

* fix: void and typeof space unary ops issue
2023-05-03 12:22:46 +05:00

56 lines
1.3 KiB
JavaScript

import React from 'react';
import classNames from 'classnames';
import PropTypes from 'prop-types';
class CircleChartLegend extends React.Component {
constructor(props) {
super(props);
}
getList() {
const {data} = this.props;
return data.map(({value, label, sliceIndex}, index) => {
const swatchClass = `swatch-${sliceIndex}`;
return (
<li className="legend-item" key={index}>
<div
className={classNames('color-swatch', swatchClass)}
aria-hidden="true"
/>
<span className="label">{label}</span>
<span className="percentage">{this.getPercentage(value)}</span>
</li>
);
});
}
getPercentage(value) {
const num = value * 100;
return `${num}%`;
}
renderList() {
return (
<ul className="legend-list">
{this.getList()}
</ul>
);
}
render() {
return (
<div className="legend">
{this.renderList()}
</div>
);
}
}
CircleChartLegend.propTypes = {
data: PropTypes.array.isRequired
}
export default CircleChartLegend;