Skip to content

Commit

Permalink
Merge pull request #13 from fehmisener/feature/fehmise-frontend
Browse files Browse the repository at this point in the history
Feature/fehmise frontend
  • Loading branch information
fehmisener authored May 8, 2024
2 parents 568c290 + 1235ec2 commit a09bdd5
Show file tree
Hide file tree
Showing 11 changed files with 152 additions and 207 deletions.
4 changes: 4 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Chilanka&family=Inter:wght@100..900&display=swap"
rel="stylesheet">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Dataviz Explorer</title>
</head>
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
"chart.js": "^4.4.2",
"chartjs-plugin-zoom": "^2.0.1",
"downloadjs": "^1.4.7",
"highcharts-react-official": "^3.2.1",
"papaparse": "^5.4.1",
"react": "^18.2.0",
"react-chartjs-2": "^5.2.0",
"react-dom": "^18.2.0"
Expand Down
8 changes: 8 additions & 0 deletions src/components/Charts/AnimatedChart.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import React, { useEffect, useState } from 'react';
import { Line } from 'react-chartjs-2';
import {
Chart as ChartJS,
LinearScale,
PointElement,
LineElement,
} from 'chart.js';

import Box from '@mui/material/Box';
import Paper from '@mui/material/Paper';
import { alpha } from '@mui/material';

ChartJS.register(LinearScale, PointElement, LineElement);

const AnimatedChart = () => {
const [phase, setPhase] = useState(0);

Expand Down
33 changes: 0 additions & 33 deletions src/components/Charts/ChartBox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import { alpha } from '@mui/material';
import ClearOutlinedIcon from '@mui/icons-material/ClearOutlined';
import ShowChartOutlinedIcon from '@mui/icons-material/ShowChartOutlined';
import ScatterPlotOutlinedIcon from '@mui/icons-material/ScatterPlotOutlined';
import ZoomOutMapOutlinedIcon from '@mui/icons-material/ZoomOutMapOutlined';
import FileDownloadOutlinedIcon from '@mui/icons-material/FileDownloadOutlined';

import { processHeaderName } from '../../utils/data';

Expand All @@ -29,22 +27,6 @@ export default function ChartBox({
onChartTypeChange,
onRemoveChart,
}) {
const [loading, setLoading] = React.useState(false);

function _resetChartZoom(chartId) {
const chart = Chart.getChart(`chart-${chartId}`);
chart.resetZoom();
}

function _downloadChart(chartId) {
setLoading(true);

const chart = Chart.getChart(`chart-${chartId}`);

download(chart.toBase64Image(), 'chart.png', 'image/png');
setLoading(false);
}

const _handleChartTypeChange = (event, index, newType) => {
if (newType !== null) {
onChartTypeChange(newType);
Expand Down Expand Up @@ -142,27 +124,12 @@ export default function ChartBox({
height: '100%',
}}
>
<Button
startIcon={<ZoomOutMapOutlinedIcon />}
onClick={() => _resetChartZoom(index)}
>
Reset Zoom
</Button>
<Button
startIcon={<ClearOutlinedIcon />}
onClick={() => onRemoveChart()}
>
Remove Chart
</Button>

<LoadingButton
variant="outlined"
startIcon={<FileDownloadOutlinedIcon />}
onClick={() => _downloadChart(index)}
loading={loading}
>
Download Chart
</LoadingButton>
</ButtonGroup>
</Grid>
</Grid>
Expand Down
24 changes: 13 additions & 11 deletions src/components/Charts/ChartPopup.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ export default function ChartPopup({
});

const onChartCreate = async () => {
if (xAxis && yAxis1) {
if (
xAxis &&
yAxis1 &&
yAxis1 !== yAxis2 &&
xAxis !== yAxis1 &&
xAxis !== yAxis2
) {
const selectedYAxes = [yAxis1];
if (showSecondYAxis && yAxis2) {
selectedYAxes.push(yAxis2);
Expand All @@ -51,7 +57,9 @@ export default function ChartPopup({
await handleChartCreate(xAxis, selectedYAxes);
setLoading(false);
} else {
alert('Please select both X-axis and Y-axis.');
alert(
'Please select both X-axis and Y-axis, and ensure Y-axis values are different.'
);
}
};

Expand Down Expand Up @@ -94,9 +102,7 @@ export default function ChartPopup({
},
}}
>
<MenuItem value="" disabled>
Select X-axis
</MenuItem>
<MenuItem value="">Select X-axis</MenuItem>
{columns.map((column) => (
<MenuItem key={column.field} value={column.field}>
{column.headerName}
Expand All @@ -118,9 +124,7 @@ export default function ChartPopup({
},
}}
>
<MenuItem value="" disabled>
Select Y-axis
</MenuItem>
<MenuItem value="">Select Y-axis</MenuItem>
{columns.map((column) => (
<MenuItem key={column.field} value={column.field}>
{column.headerName}
Expand All @@ -143,9 +147,7 @@ export default function ChartPopup({
},
}}
>
<MenuItem value="" disabled>
Select Other Value (Optional)
</MenuItem>
<MenuItem value="">Select Other Value (Optional)</MenuItem>
{columns.map((column) => (
<MenuItem key={column.field} value={column.field}>
{column.headerName}
Expand Down
113 changes: 52 additions & 61 deletions src/components/Charts/LineChart.jsx
Original file line number Diff line number Diff line change
@@ -1,76 +1,67 @@
import React from 'react';
import {
Chart as ChartJS,
CategoryScale,
LinearScale,
PointElement,
LineElement,
Title,
Tooltip,
Legend,
Colors,
} from 'chart.js';
import { Line } from 'react-chartjs-2';
import zoomPlugin from 'chartjs-plugin-zoom';

ChartJS.register(
CategoryScale,
LinearScale,
PointElement,
LineElement,
Colors,
Title,
Tooltip,
Legend,
zoomPlugin
);
import Highcharts from 'highcharts';
import DarkUnica from 'highcharts/themes/brand-dark';
import HighchartsExporting from 'highcharts/modules/exporting';
import HighchartsReact from 'highcharts-react-official';
import HighchartsBoost from 'highcharts/modules/boost';

DarkUnica(Highcharts);

HighchartsBoost(Highcharts);
HighchartsExporting(Highcharts);

export default function LineChart({ chartName, data, xAxis }) {
const options = {
responsive: true,
datasets: {
line: {
pointRadius: 0,
const optionsHighChart = {
boost: {
enabled: true,
seriesThreshold: 1,
debug: {
timeRendering: true,
},
},
scales: {
x: {
title: {
display: true,
text: xAxis,
},
},
y: {
title: {
display: true,
text: 'Value',
},
},
exporting: {
enabled: true,
},
plugins: {
colors: {
forceOverride: true,
chart: {
type: 'line',
zooming: {
type: 'xy',
},
legend: {
position: 'top',
panning: {
enabled: true,
type: 'xy',
},
panKey: 'shift',
},
legend: {
align: 'center',
verticalAlign: 'top',
},
title: {
text: 'Line Chart',
},
xAxis: {
title: {
display: true,
text: `Line Chart`,
text: xAxis,
},
zoom: {
pan: {
enabled: true,
mode: 'xy',
},
zoom: {
wheel: {
enabled: true,
modifierKey: 'ctrl',
},
},
},
yAxis: {
title: {
text: 'Value',
},
},
series: data.datasets.map((dataset) => ({
name: dataset.label,
data: dataset.data,
})),
};
return <Line id={chartName} options={options} data={data} height={110} />;

return (
<HighchartsReact
id={chartName}
highcharts={Highcharts}
options={optionsHighChart}
/>
);
}
Loading

0 comments on commit a09bdd5

Please sign in to comment.