mirror of https://gitlab.com/ecentrics/concordia
Ezerous
4 years ago
7 changed files with 175 additions and 69 deletions
@ -0,0 +1,56 @@ |
|||||
|
import React, { useMemo } from 'react'; |
||||
|
import Chart from 'react-apexcharts'; |
||||
|
import PropTypes from 'prop-types'; |
||||
|
import { CHART_TYPE_BAR } from '../../../../constants/polls/PollGraph'; |
||||
|
|
||||
|
const PollChartBar = (props) => { |
||||
|
const { pollOptions, voteCounts } = props; |
||||
|
|
||||
|
const chartOptions = useMemo(() => ({ |
||||
|
chart: { |
||||
|
id: 'chart-bar', |
||||
|
}, |
||||
|
theme: { |
||||
|
palette: 'palette8', |
||||
|
}, |
||||
|
plotOptions: { |
||||
|
bar: { |
||||
|
horizontal: true, |
||||
|
distributed: true, |
||||
|
}, |
||||
|
}, |
||||
|
xaxis: { |
||||
|
categories: pollOptions, |
||||
|
tickAmount: 1, |
||||
|
labels: { |
||||
|
formatter(val) { |
||||
|
if (val.toFixed) return val.toFixed(0); |
||||
|
return val; |
||||
|
}, |
||||
|
}, |
||||
|
}, |
||||
|
tooltip: { |
||||
|
enabled: false, |
||||
|
}, |
||||
|
}), [pollOptions]); |
||||
|
|
||||
|
const chartSeries = useMemo(() => [{ |
||||
|
name: 'Votes', |
||||
|
data: voteCounts, |
||||
|
}], [voteCounts]); |
||||
|
|
||||
|
return ( |
||||
|
<Chart |
||||
|
options={chartOptions} |
||||
|
series={chartSeries} |
||||
|
type={CHART_TYPE_BAR} |
||||
|
/> |
||||
|
); |
||||
|
}; |
||||
|
|
||||
|
PollChartBar.propTypes = { |
||||
|
pollOptions: PropTypes.arrayOf(PropTypes.string).isRequired, |
||||
|
voteCounts: PropTypes.arrayOf(PropTypes.number).isRequired, |
||||
|
}; |
||||
|
|
||||
|
export default PollChartBar; |
@ -0,0 +1,49 @@ |
|||||
|
import React, { useMemo } from 'react'; |
||||
|
import Chart from 'react-apexcharts'; |
||||
|
import PropTypes from 'prop-types'; |
||||
|
import { CHART_TYPE_DONUT } from '../../../../constants/polls/PollGraph'; |
||||
|
|
||||
|
const PollChartDonut = (props) => { |
||||
|
const { pollOptions, voteCounts } = props; |
||||
|
|
||||
|
const chartOptions = useMemo(() => ({ |
||||
|
chart: { |
||||
|
id: 'chart-donut', |
||||
|
}, |
||||
|
theme: { |
||||
|
palette: 'palette8', |
||||
|
}, |
||||
|
plotOptions: { |
||||
|
pie: { |
||||
|
donut: { |
||||
|
labels: { |
||||
|
show: true, |
||||
|
total: { |
||||
|
show: true, |
||||
|
label: 'Total Votes', |
||||
|
}, |
||||
|
}, |
||||
|
}, |
||||
|
}, |
||||
|
}, |
||||
|
labels: pollOptions, |
||||
|
tooltip: { |
||||
|
enabled: false, |
||||
|
}, |
||||
|
}), [pollOptions]); |
||||
|
|
||||
|
return ( |
||||
|
<Chart |
||||
|
options={chartOptions} |
||||
|
series={voteCounts} |
||||
|
type={CHART_TYPE_DONUT} |
||||
|
/> |
||||
|
); |
||||
|
}; |
||||
|
|
||||
|
PollChartDonut.propTypes = { |
||||
|
pollOptions: PropTypes.arrayOf(PropTypes.string).isRequired, |
||||
|
voteCounts: PropTypes.arrayOf(PropTypes.number).isRequired, |
||||
|
}; |
||||
|
|
||||
|
export default PollChartDonut; |
@ -0,0 +1,4 @@ |
|||||
|
#topic-poll-container .ui.segment.tab { |
||||
|
box-shadow: none; |
||||
|
border: none; |
||||
|
} |
@ -1,2 +1,2 @@ |
|||||
export const DEFAULT_OPTION_COLOR = '#3B5066'; |
export const CHART_TYPE_BAR = 'bar'; |
||||
export const CASTED_OPTION_COLOR = '#0b2540'; |
export const CHART_TYPE_DONUT = 'donut'; |
||||
|
Loading…
Reference in new issue