Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues/KUI 1196 show barchart labels #356

Merged
merged 3 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions public/js/app/components/statistics/AnalysesSummary.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,35 @@ function addAllSchoolsData({ totalCourses, totalUniqPublishedAnalyses }) {
return allSchools
}

function Captions({ year, seasons }) {
const { translation, languageIndex } = useLanguage()
function Captions({ school, year, seasons }) {
const {
languageIndex,
translation: {
statisticsLabels,
statisticsLabels: {
formLabels: { formSubHeaders },
},
},
} = useLanguage()

function getSchoolName(schoolName) {
if (schoolName === 'allSchools') return statisticsLabels[schoolName]
return schoolName
}

const seasonsStr = seasons.map(season => seasonLib.labelSeason(season, languageIndex)).join(', ')
return (
<Row>
<Col xs="4" style={{ flex: 'none', width: 'auto', paddingBottom: '20px' }}>
<label>{translation.statisticsLabels.formLabels.formSubHeaders.year}</label>
<label>{formSubHeaders.school}</label>
{`: ${getSchoolName(school)}`}
</Col>
<Col xs="4" style={{ flex: 'none', width: 'auto', paddingBottom: '20px' }}>
<label>{formSubHeaders.year}</label>
{`: ${year}`}
</Col>
<Col xs="4" style={{ flex: 'none', width: 'auto', paddingBottom: '20px' }}>
<label>{translation.statisticsLabels.formLabels.formSubHeaders.seasons}</label>
<label>{formSubHeaders.seasons}</label>
{`: ${seasonsStr}`}
</Col>
</Row>
Expand All @@ -46,12 +63,12 @@ function Captions({ year, seasons }) {
function AnalysesNumbersTable({ statisticsResult }) {
const { translation } = useLanguage()
const { analysesNumbersTable } = translation.statisticsLabels.summaryLabels
const { combinedAnalysesPerSchool, year, seasons } = statisticsResult
const { combinedAnalysesPerSchool, year, seasons, school } = statisticsResult
const cellNames = ['totalCourses', 'totalUniqPublishedAnalyses']

return (
<>
<Captions year={year} seasons={seasons} />
<Captions school={school} year={year} seasons={seasons} />

<TableSummary
docsPerSchool={combinedAnalysesPerSchool}
Expand All @@ -74,7 +91,7 @@ function AnalysesNumbersCharts({ statisticsResult }) {

return (
<>
<Captions year={year} seasons={seasons} />
<Captions school={school} year={year} seasons={seasons} />

<Charts chartNames={chartNames} schools={schools} />
</>
Expand Down
23 changes: 11 additions & 12 deletions public/js/app/components/statistics/Chart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ function splitIntoLines(label) {
}

function getChartData(numberName, schools, allSchoolsLabels) {
const schoolCodes = Object.keys(schools)
const orderedSchools = schoolsLib.orderedSchoolsFormOptions()

let schoolCodes = Object.keys(schools)

schoolCodes = schoolCodes.sort((a, b) => orderedSchools.indexOf(a) - orderedSchools.indexOf(b))

return schoolCodes.map(school => {
const schoolNumbers = schools[school]
Expand Down Expand Up @@ -62,21 +66,16 @@ function Charts({ chartNames = [], schools = {} }) {

function Chart({ data = [], label = '' }) {
const styles = {
font: { fontFamily: 'Open Sans', fontSize: '16px' },
font: { fontFamily: 'Open Sans', fontSize: 'font-heading-xs' },
}
return (
<VictoryChart height={405} width={405} theme={VictoryTheme.material} domainPadding={20} style={styles.font}>
<VictoryLabel x={4} y={24} text={label} style={styles.font} />
{data.length > 1 ? (
<VictoryAxis
tickValues={schoolsLib.orderedSchoolsFormOptions}
style={{
tickLabels: styles.font,
}}
/>
) : (
<VictoryAxis />
)}
<VictoryAxis
style={{
tickLabels: styles.font,
}}
/>
<VictoryAxis
dependentAxis
tickValues={[0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]}
Expand Down
28 changes: 20 additions & 8 deletions public/js/app/components/statistics/MemosSummary.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,25 +58,37 @@ function addAllSchoolsData({
return allSchools
}

function Captions({ year, periods }) {
function Captions({ school, year, periods }) {
const {
translation: {
statisticsLabels: { formLabels },
statisticsLabels,
statisticsLabels: {
formLabels: { formSubHeaders },
},
},
languageIndex,
} = useLanguage()

function getSchoolName(schoolName) {
if (schoolName === 'allSchools') return statisticsLabels[schoolName]
return schoolName
}

const periodsLabels = periods.map(period => periodsLib.labelPeriod(period, languageIndex, false))
const uniqquePeriodsLabels = [...new Set(periodsLabels)]
const periodsStr = uniqquePeriodsLabels.join(', ')
return (
<Row>
<Col xs="2" style={{ flex: 'none', width: 'auto', paddingBottom: '20px' }}>
<label>{formLabels.formSubHeaders.year}</label>
<Col xs="4" style={{ flex: 'none', width: 'auto', paddingBottom: '20px' }}>
<label>{formSubHeaders.school}</label>
{`: ${getSchoolName(school)}`}
</Col>
<Col xs="4" style={{ flex: 'none', width: 'auto', paddingBottom: '20px' }}>
<label>{formSubHeaders.year}</label>
{`: ${year}`}
</Col>
<Col xs="4" style={{ flex: 'none', width: 'auto', paddingBottom: '20px' }}>
<label>{formLabels.formSubHeaders.periods}</label>
<label>{formSubHeaders.periods}</label>
{`: ${periodsStr}`}
</Col>
</Row>
Expand All @@ -90,12 +102,12 @@ function MemosNumbersTable({ statisticsResult }) {
},
} = useLanguage()
const { memosNumbersTable } = summaryLabels
const { combinedMemosPerSchool, year, periods } = statisticsResult
const { combinedMemosPerSchool, year, periods, school } = statisticsResult
const cellNames = getCellNames()

return (
<>
<Captions year={year} periods={periods} />
<Captions school={school} year={year} periods={periods} />

<TableSummary
docsPerSchool={combinedMemosPerSchool}
Expand Down Expand Up @@ -123,7 +135,7 @@ function MemosNumbersCharts({ statisticsResult }) {

return (
<>
<Captions year={year} periods={periods} languageIndex={languageIndex} />
<Captions school={school} year={year} periods={periods} languageIndex={languageIndex} />

<Charts chartNames={chartNames} schools={schools} languageIndex={languageIndex} />
</>
Expand Down
Loading