Skip to content
Snippets Groups Projects
Commit d4f16ca2 authored by Bjarke Madsen's avatar Bjarke Madsen
Browse files

Remove font config and add todo to fix broken x-axis on FundingSource page

parent bcf3897a
No related branches found
No related tags found
1 merge request!34Rework to use a common font config across graphs and add x-axis and legends on top and bottom of graphs
import React, { useEffect, useMemo, useState } from 'react'; import React, { useEffect, useMemo, useState } from 'react';
import { Bar } from 'react-chartjs-2'; import { Bar } from 'react-chartjs-2';
import { Col, Container, Row, Table } from "react-bootstrap"; import { Col, Container, Row } from "react-bootstrap";
import { Chart as ChartJS, CategoryScale, LinearScale, BarElement, Title, Tooltip, Legend, Chart } from 'chart.js'; import { Chart as ChartJS, CategoryScale, LinearScale, BarElement, Title, Tooltip, Legend } from 'chart.js';
import { FundingSource, FilterSelection } from "../Schema"; import { FundingSource, FilterSelection } from "../Schema";
import { createFundingSourceDataset, getYearsAndNrens, loadDataWithFilterSelectionFallback } from "../helpers/dataconversion"; import { createFundingSourceDataset, getYearsAndNrens, loadDataWithFilterSelectionFallback } from "../helpers/dataconversion";
...@@ -10,9 +10,6 @@ import Filter from "../components/graphing/Filter" ...@@ -10,9 +10,6 @@ import Filter from "../components/graphing/Filter"
import { Sections } from '../helpers/constants'; import { Sections } from '../helpers/constants';
import ColorBadge from '../components/ColorBadge'; import ColorBadge from '../components/ColorBadge';
ChartJS.defaults.font.size = 16;
ChartJS.register( ChartJS.register(
CategoryScale, CategoryScale,
LinearScale, LinearScale,
...@@ -22,7 +19,6 @@ ChartJS.register( ...@@ -22,7 +19,6 @@ ChartJS.register(
Legend Legend
); );
export const chartOptions = { export const chartOptions = {
maintainAspectRatio: false, maintainAspectRatio: false,
animation: { animation: {
...@@ -31,26 +27,13 @@ export const chartOptions = { ...@@ -31,26 +27,13 @@ export const chartOptions = {
plugins: { plugins: {
legend: { legend: {
display: false, display: false,
labels: { }
boxWidth: 20, },
boxHeight: 30,
pointStyle: "rectRounded",
borderRadius: 6,
useBorderRadius: true,
},
},
},
scales: { scales: {
x: { x: {
position: 'top' as const, position: 'top' as const,
stacked: true, stacked: true,
ticks: { ticks: {
font:{
size: 20,
family: 'Open Sans, sans-serif',
weight: 'bold',
},
callback: (value: string | number) => { callback: (value: string | number) => {
if (typeof value === 'number') { if (typeof value === 'number') {
return `${value}%`; return `${value}%`;
...@@ -58,41 +41,25 @@ export const chartOptions = { ...@@ -58,41 +41,25 @@ export const chartOptions = {
return value; return value;
}, },
}, },
}, },
// TODO: The ticks given here are not based on the dataset (chartJS bug?), find a fix or remove the axis
x2: { x2: {
stacked: true,
ticks: { ticks: {
callback: (value: string | number) => { callback: (value: string | number) => {
if (typeof value === 'number') { if (typeof value === 'number') {
return `${value}%`; return `${value * 100}%`;
} }
return value; return value;
}, },
font: {
size: 20,
family: 'Open Sans, sans-serif',
weight: 'bold',
}
}, },
grid: { grid: {
display: false, drawOnChartArea: false
drawTicks: false, }
drawBorder: false,
},
min : 0,
max : 100
}, },
y: { y: {
stacked: true, stacked: true,
ticks: { ticks: {
autoSkip: false, autoSkip: false
font: {
size: 20,
family: 'Open Sans, sans-serif',
weight: 'bold',
}
}, },
}, },
}, },
...@@ -100,28 +67,28 @@ export const chartOptions = { ...@@ -100,28 +67,28 @@ export const chartOptions = {
}; };
function FundingSourceLegend() { function FundingSourceLegend() {
return ( return (
<Container className="border rounded-3 border-1 funding-chart-Legend"> <Container className="border rounded-3 border-1 funding-chart-Legend">
<Row fluid className="justify-content-center " <Row fluid='true' className="justify-content-center "
style={{paddingLeft:'7vw'}}> style={{ paddingLeft: '7vw' }}>
<Col className="d-flex align-items-center"> <Col className="d-flex align-items-center">
<ColorBadge key={0} index={0}/> <ColorBadge key={0} index={0} />
<span className='bold-14pt'>Client Institutions</span></Col> <span className='bold-14pt'>Client Institutions</span></Col>
<Col className="d-flex align-items-center" > <Col className="d-flex align-items-center" >
<ColorBadge key={1} index={1}/> <ColorBadge key={1} index={1} />
<span className='bold-14pt'>Commercial</span></Col> <span className='bold-14pt'>Commercial</span></Col>
<Col className="d-flex align-items-center" > <Col className="d-flex align-items-center" >
<ColorBadge key={2} index={2}/> <ColorBadge key={2} index={2} />
<span className='bold-14pt'>European Funding</span></Col> <span className='bold-14pt'>European Funding</span></Col>
<Col className="d-flex align-items-center" > <Col className="d-flex align-items-center" >
<ColorBadge key={3} index={3}/> <ColorBadge key={3} index={3} />
<span className='bold-14pt'>Gov/Public Bodies</span></Col> <span className='bold-14pt'>Gov/Public Bodies</span></Col>
<Col className="d-flex align-items-center" > <Col className="d-flex align-items-center" >
<ColorBadge key={4} index={4}/> <ColorBadge key={4} index={4} />
<span className='bold-14pt'>Other</span></Col> <span className='bold-14pt'>Other</span></Col>
</Row> </Row>
</Container> </Container>
); );
} }
...@@ -165,25 +132,25 @@ function FundingSourcePage({ filterSelection, setFilterSelection }: inputProps) ...@@ -165,25 +132,25 @@ function FundingSourcePage({ filterSelection, setFilterSelection }: inputProps)
const numNrens = filterSelection.selectedNrens.length; const numNrens = filterSelection.selectedNrens.length;
const numYears = filterSelection.selectedYears.length; const numYears = filterSelection.selectedYears.length;
let heightPerBar = 4; // every added bar should give this much additional height const heightPerBar = 4; // every added bar should give this much additional height
// set a minimum height of 20rem, additional years need some more space // set a minimum height of 20rem, additional years need some more space
const height = Math.max(numNrens * heightPerBar + (numYears * 2 * heightPerBar), 20); const height = Math.max(numNrens * heightPerBar + (numYears * 2 * heightPerBar), 20);
return ( return (
<DataPage title="Income Source Of NRENs per Year" <DataPage title="Income Source Of NRENs per Year"
description='The graph shows the percentage share of their income that individual NRENs derived from different sources. description='The graph shows the percentage share of their income that individual NRENs derived from different sources.
On hovering over the graphs will give income share in that year. This can be used to compare selecting multiple years to see how the On hovering over the graphs will give income share in that year. This can be used to compare selecting multiple years to see how the
share has changed between the years.' share has changed between the years.'
category={Sections.Organisation} filter={filterNode}> category={Sections.Organisation} filter={filterNode}>
<div> <div>
<FundingSourceLegend/> <FundingSourceLegend />
<div className="chart-container" style={{ 'height': `${height}rem` }}> <div className="chart-container" style={{ 'height': `${height}rem` }}>
<Bar <Bar
data={fundingSourceDataset} data={fundingSourceDataset}
options={chartOptions} options={chartOptions}
/> />
</div> </div>
<FundingSourceLegend/> <FundingSourceLegend />
</div> </div>
</DataPage> </DataPage>
); );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment