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

Ft add geography chart scene #69

Merged
merged 5 commits into from
Nov 23, 2023
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
4 changes: 2 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Form from './scenes/Form';
import Line from './scenes/Line';
import Pie from './scenes/Pie';
import FAQ from './scenes/FAQ';
// import Geograph from './scenes/Geograph';
import Geography from './scenes/Geography';
import Calendar from './scenes/Calendar';

function App() {
Expand All @@ -35,7 +35,7 @@ function App() {
<Route path="/bar" element={<Bar />} />
<Route path="/pie" element={<Pie />} />
<Route path="/line" element={<Line />} />
{/* <Route path="/geograph" element={<Geograph />} /> */}
<Route path="/geography" element={<Geography />} />
<Route path="/faq" element={<FAQ />} />
<Route path="/calendar" element={<Calendar />} />
</Routes>
Expand Down
97 changes: 97 additions & 0 deletions src/components/Shared/Geography/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import { useTheme } from '@mui/material';
import { ResponsiveChoropleth } from '@nivo/geo';
import PropTypes from 'prop-types';
import { geoFeatures } from '../../../data/mockGeoFeatures';
import { tokens } from '../../../theme';

const GeographyChart = ({ data, isDashboard = false }) => {
const theme = useTheme();
const colors = tokens(theme.palette.mode);
return (
<ResponsiveChoropleth
data={data}
theme={{
axis: {
domain: {
line: {
stroke: colors.grey[100],
},
},
legend: {
text: {
fill: colors.grey[100],
},
},
ticks: {
line: {
stroke: colors.grey[100],
strokeWidth: 1,
},
text: {
fill: colors.grey[100],
},
},
},
legends: {
text: {
fill: colors.grey[100],
},
},
tooltip: {
container: {
color: colors.primary[500],
},
},
}}
features={geoFeatures.features}
margin={{
top: 0, right: 0, bottom: 0, left: 0,
}}
domain={[0, 1000000]}
unknownColor="#666666"
label="properties.name"
valueFormat=".2s"
projectionScale={isDashboard ? 40 : 150}
projectionTranslation={isDashboard ? [0.49, 0.6] : [0.5, 0.5]}
projectionRotation={[0, 0, 0]}
borderWidth={1.5}
borderColor="#ffffff"
legends={
!isDashboard
? [
{
anchor: 'bottom-left',
direction: 'column',
justify: true,
translateX: 20,
translateY: -100,
itemsSpacing: 0,
itemWidth: 94,
itemHeight: 18,
itemDirection: 'left-to-right',
itemTextColor: colors.grey[100],
itemOpacity: 0.85,
symbolSize: 18,
effects: [
{
on: 'hover',
style: {
itemTextColor: '#ffffff',
itemOpacity: 1,
},
},
],
},
]
: undefined
}
/>
);
};

GeographyChart.propTypes = {
data: PropTypes.oneOfType(['object']).isRequired,
isDashboard: PropTypes.bool.isRequired,
};

export default GeographyChart;
10 changes: 5 additions & 5 deletions src/components/Shared/LineChart/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import { useTheme } from '@mui/material';
import { tokens } from '../../../theme';

const LineChart = ({ data, isDashbord = false }) => {
const LineChart = ({ data, isDashboard = false }) => {
const theme = useTheme();
const colors = tokens(theme.palette.mode);

Expand Down Expand Up @@ -43,7 +43,7 @@ const LineChart = ({ data, isDashbord = false }) => {
},
},
}}
colors={isDashbord ? { datum: 'color' } : { scheme: 'nivo' }}
colors={isDashboard ? { datum: 'color' } : { scheme: 'nivo' }}
margin={{
top: 50, right: 110, bottom: 50, left: 60,
}}
Expand All @@ -63,15 +63,15 @@ const LineChart = ({ data, isDashbord = false }) => {
tickSize: 5,
tickPadding: 5,
tickRotation: 0,
legend: isDashbord ? undefined : 'transportation',
legend: isDashboard ? undefined : 'transportation',
legendOffset: 36,
legendPosition: 'middle',
}}
axisLeft={{
tickSize: 5,
tickPadding: 5,
tickRotation: 0,
legend: isDashbord ? undefined : 'count',
legend: isDashboard ? undefined : 'count',
legendOffset: -40,
legendPosition: 'middle',
}}
Expand Down Expand Up @@ -116,7 +116,7 @@ const LineChart = ({ data, isDashbord = false }) => {

LineChart.propTypes = {
data: PropTypes.oneOfType(['object']).isRequired,
isDashbord: PropTypes.bool.isRequired,
isDashboard: PropTypes.bool.isRequired,
};

export default LineChart;
5 changes: 5 additions & 0 deletions src/components/Shared/PieChart/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ const PieChart = ({ data }) => {
fill: colors.grey[100],
},
},
tooltip: {
container: {
color: colors.primary[500],
},
},
}}
margin={{
top: 40, right: 80, bottom: 80, left: 80,
Expand Down
22 changes: 22 additions & 0 deletions src/scenes/Geography/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Box, useTheme } from '@mui/material';
import GeographyChart from '../../components/Shared/Geography';
import Header from '../../components/Shared/Header/Header';
import { mockGeographyData as data } from '../../data/mockData';
import { tokens } from '../../theme';

console.log(GeographyChart);
const Geography = () => {
const theme = useTheme();
const colors = tokens(theme.palette.mode);

return (
<Box m="20px">
<Header title="Geography Chart" subTitle="Customized Simple Geography Chart" />
<Box height="75vh" border={`1px solid ${colors.grey[100]}`}>
<GeographyChart data={data} />
</Box>
</Box>
);
};

export default Geography;