Files
edx-platform/lms/static/js/learner_analytics_dashboard/CircleChartLegend.jsx
Syed Ali Abbas Zaidi 5549db4d80 fix: migrate remaining eslint-config-edx (#31760)
* fix: migrate remaining eslint-config-edx

* refactor: updated eslint rules according to eslint-config-edx-es5

* refactor: add custom rules to suppress unnecessary eslint issues

* refactor: add custom rules to internal eslint configs

* fix: fix all indentation issues

* chore: update lock file
2023-03-02 16:16:50 +05:00

55 lines
1.2 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"></div>
<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;