Skip to content

Commit

Permalink
refactor: simplified plot functions to a single function CountsByYear…
Browse files Browse the repository at this point in the history
…Plot with specification using a type property
  • Loading branch information
gtdang committed Dec 18, 2024
1 parent 8921b68 commit 27c7cbd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 25 deletions.
39 changes: 18 additions & 21 deletions src/components/BarChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -451,27 +451,24 @@ const inputJson = [
{ label: '2024', count: 5 },
];

export function YearBarPlot() {
// Generate the Vega spec
const vegaSpec = generateBarPlot({ data: inputJson, xLabel: 'Year', yLabel: 'Publications' });

return <Vega spec={vegaSpec} />;
}

export function YearLinePlotCumu() {
// Generate the Vega spec
const vegaSpec = generateCumuSumPlot({
data: inputJson,
xLabel: 'Year',
yLabel: 'Cumulative Publications',
});

return <Vega spec={vegaSpec} />;
}

export function YearBarPlotCumu() {
// Generate the Vega spec
const vegaSpec = generateBarPlotWithCumuSum(inputJson, 'Year');
export function CountsByYearPlot({ type }) {
let vegaSpec = {};
const xLabel = 'Year';
if (type === 'bar') {
vegaSpec = generateBarPlot({
data: inputJson,
xLabel: xLabel,
yLabel: 'Publications',
});
} else if (type === 'cumu-line') {
vegaSpec = generateCumuSumPlot({
data: inputJson,
xLabel: xLabel,
yLabel: 'Cumulative Publications',
});
} else if (type === 'bar-cumu-line') {
vegaSpec = generateBarPlotWithCumuSum(inputJson, 'Year');
}

return <Vega spec={vegaSpec} />;
}
8 changes: 4 additions & 4 deletions src/components/ContentPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useSelector } from 'react-redux';
import { selectUser } from '../store/slice/appState';
import { PublicationsTable } from './PublicationsTable.tsx';
import { AddPublicationModal } from './AddPublicationModal.tsx';
import { YearBarPlot, YearBarPlotCumu, YearLinePlotCumu } from './BarChart.js';
import { CountsByYearPlot } from './BarChart.js';

export function ContentPage() {
const user = useSelector(selectUser);
Expand All @@ -30,9 +30,9 @@ export function ContentPage() {
{/*<div className="viz d-flex justify-content-center pt-5">*/}
{/* <WordCloud />*/}
{/*<YearChart />*/}
<YearBarPlot />
<YearLinePlotCumu />
<YearBarPlotCumu />
<CountsByYearPlot type="bar" />
<CountsByYearPlot type="cumu-line" />
<CountsByYearPlot type="bar-cumu-line" />
{/*</div>*/}
</div>
);
Expand Down

0 comments on commit 27c7cbd

Please sign in to comment.