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

Feat vertical page layout #44

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
src="https://cloud.umami.is/script.js"
data-website-id="c86a6222-5be7-4d14-a055-6d1b84baae27"
></script>
<style>
:root, body {
overscroll-behavior: none;
}
</style>
</head>
<body>
<div id="root"></div>
Expand Down
12 changes: 8 additions & 4 deletions src/factories/charts/ChartsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { FactoriesGraphSettingsModal } from './graph/settings/FactoriesGraphSett
import { FactoriesSankeyChart } from './sankey/FactoriesSankeyChart';
import { useChartsView } from './store/chartsSlice';

import { FullHeightContainer } from '@/layout/FullHeightContainer';

export interface IChartsTabProps {}

export function ChartsTab(_props: IChartsTabProps) {
Expand All @@ -30,7 +32,7 @@ export function ChartsTab(_props: IChartsTabProps) {
}

return (
<div>
<>
<AfterHeaderSticky>
<Group gap="xs">
<SegmentedControl
Expand All @@ -44,8 +46,10 @@ export function ChartsTab(_props: IChartsTabProps) {
{view === 'graph' && <FactoriesGraphSettingsModal />}
</Group>
</AfterHeaderSticky>
{view === 'graph' && <FactoriesGraphContainer />}
{view === 'sankey' && <FactoriesSankeyChart />}
</div>
<FullHeightContainer>
{view === 'graph' && <FactoriesGraphContainer />}
{view === 'sankey' && <FactoriesSankeyChart />}
</FullHeightContainer>
</>
);
}
11 changes: 3 additions & 8 deletions src/factories/charts/graph/FactoriesGraphContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,8 @@ export interface IFactoriesGraphContainer {}
export function FactoriesGraphContainer(props: IFactoriesGraphContainer) {
const { nodes, edges } = useFactoriesGraph();
return (
<Stack gap="md">
<ReactFlowProvider>
<FactoriesGraphLayout
nodes={nodes}
edges={edges}
></FactoriesGraphLayout>
</ReactFlowProvider>
</Stack>
<ReactFlowProvider>
<FactoriesGraphLayout nodes={nodes} edges={edges}></FactoriesGraphLayout>
</ReactFlowProvider>
);
}
116 changes: 54 additions & 62 deletions src/factories/charts/graph/FactoriesGraphLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,67 +95,59 @@ export const FactoriesGraphLayout = (props: FactoriesGraphLayoutProps) => {
const ref = useRef<HTMLDivElement>(null);

return (
<Box w={'100%'} h={'80vh'} opacity={opacity}>
<ReactFlow
ref={ref}
minZoom={0.2}
nodes={nodes}
edges={edges}
nodeTypes={nodeTypes}
edgeTypes={edgeTypes}
onNodesChange={onNodesChange}
onEdgesChange={onEdgesChange}
connectionLineType={ConnectionLineType.SmoothStep}
fitView
snapToGrid
colorMode="dark"
proOptions={{
hideAttribution: true,
}}
snapGrid={[10, 10]}
>
<Controls showFitView />
<MiniMap pannable={true} nodeStrokeWidth={3} />

<svg>
<defs>
<linearGradient id="edge-gradient">
<stop offset="0%" stopColor="var(--mantine-color-gray-7)" />
<stop offset="100%" stopColor="var(--mantine-color-gray-4)" />
</linearGradient>
<linearGradient id="edge-gradient-reverse">
<stop offset="0%" stopColor="var(--mantine-color-gray-4)" />
<stop offset="100%" stopColor="var(--mantine-color-gray-7)" />
</linearGradient>

<marker
id="edge-circle"
viewBox="-5 -5 10 10"
refX="0"
refY="0"
markerUnits="strokeWidth"
markerWidth="10"
markerHeight="10"
orient="auto"
>
<circle
stroke="#2a8af6"
strokeOpacity="0.75"
r="2"
cx="0"
cy="0"
/>
</marker>
</defs>
</svg>
<Background
bgColor="var(--mantine-color-dark-7)"
color="var(--mantine-color-dark-4)"
variant={BackgroundVariant.Dots}
gap={[10, 10]}
/>
{props.children}
</ReactFlow>
</Box>
<ReactFlow
ref={ref}
minZoom={0.2}
nodes={nodes}
edges={edges}
nodeTypes={nodeTypes}
edgeTypes={edgeTypes}
onNodesChange={onNodesChange}
onEdgesChange={onEdgesChange}
connectionLineType={ConnectionLineType.SmoothStep}
fitView
snapToGrid
colorMode="dark"
proOptions={{
hideAttribution: true,
}}
snapGrid={[10, 10]}
>
<Controls showFitView />
<MiniMap pannable={true} nodeStrokeWidth={3} />

<svg>
<defs>
<linearGradient id="edge-gradient">
<stop offset="0%" stopColor="var(--mantine-color-gray-7)" />
<stop offset="100%" stopColor="var(--mantine-color-gray-4)" />
</linearGradient>
<linearGradient id="edge-gradient-reverse">
<stop offset="0%" stopColor="var(--mantine-color-gray-4)" />
<stop offset="100%" stopColor="var(--mantine-color-gray-7)" />
</linearGradient>

<marker
id="edge-circle"
viewBox="-5 -5 10 10"
refX="0"
refY="0"
markerUnits="strokeWidth"
markerWidth="10"
markerHeight="10"
orient="auto"
>
<circle stroke="#2a8af6" strokeOpacity="0.75" r="2" cx="0" cy="0" />
</marker>
</defs>
</svg>
<Background
bgColor="var(--mantine-color-dark-7)"
color="var(--mantine-color-dark-4)"
variant={BackgroundVariant.Dots}
gap={[10, 10]}
/>
{props.children}
</ReactFlow>
);
};
64 changes: 33 additions & 31 deletions src/factories/charts/sankey/FactoriesSankeyChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,36 +73,38 @@ export function FactoriesSankeyChart(props: IFactoriesSankeyChartProps) {
}

return (
<Container size="lg" mt="lg" mb={100}>
<ErrorBoundary
fallback={
<Alert
title="An error occurred while rendering chart"
color="red"
icon={<IconAlertCircle />}
variant="light"
>
Make sure to avoid circular paths in your logistics chain.
</Alert>
}
showDialog
>
<Box h={400}>
<ResponsiveSankey
data={data}
linkTooltip={info => {
return (
<Paper shadow="sm" radius="sm" p="md">
<Text size="md">
{info.link.source.id} → {info.link.target.id}:{' '}
{info.link.resourceLabel} ({info.link.value})
</Text>
</Paper>
);
}}
/>
</Box>
</ErrorBoundary>
</Container>
<ErrorBoundary
fallback={
<Alert
title="An error occurred while rendering chart"
color="red"
icon={<IconAlertCircle />}
variant="light"
>
Make sure to avoid circular paths in your logistics chain.
</Alert>
}
showDialog
>
<ResponsiveSankey
data={data}
margin={{
top: 32,
bottom: 32,
left: 32,
right: 32,
}}
linkTooltip={info => {
return (
<Paper shadow="sm" radius="sm" p="md">
<Text size="md">
{info.link.source.id} → {info.link.target.id}:{' '}
{info.link.resourceLabel} ({info.link.value})
</Text>
</Paper>
);
}}
/>
</ErrorBoundary>
);
}
4 changes: 2 additions & 2 deletions src/factories/details/FactoryGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const FactoryGraph = ({ id }: { id: string }) => {
useSolverSolution(id, 'game');

return (
<Box h="80vh" pos={'relative'}>
<>
<Box pos={'absolute'} right={0} top={0} style={{ zIndex: 99 }} p="md">
<SolverRequestDrawer
factoryId={id}
Expand All @@ -24,6 +24,6 @@ export const FactoryGraph = ({ id }: { id: string }) => {
instance={instance}
/>
)}
</Box>
</>
);
};
7 changes: 6 additions & 1 deletion src/factories/details/FactoryPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { AfterHeaderSticky } from '@/layout/AfterHeaderSticky';
import { FactoryDeleteButton } from '@/factories/details/FactoryDeleteButton';
import { ProductionView } from '@/factories/details/ProductionView';
import { FactoryGraph } from '@/factories/details/FactoryGraph';
import { FullHeightContainer } from '@/layout/FullHeightContainer';

export const FactoryPage = ({
currentView,
Expand Down Expand Up @@ -60,7 +61,11 @@ export const FactoryPage = ({
</Group>
</AfterHeaderSticky>
{currentView === 'overview' && <ProductionView id={id} />}
{currentView === 'calculator' && <FactoryGraph id={id} />}
{currentView === 'calculator' && (
<FullHeightContainer>
<FactoryGraph id={id} />
</FullHeightContainer>
)}
</>
);
};
4 changes: 2 additions & 2 deletions src/layout/AfterHeaderSticky.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ function useHeaderTop() {
export function AfterHeaderSticky(
props: React.PropsWithChildren<IAfterHeaderStickyProps>,
) {
const headerTop = useHeaderTop();
// const headerTop = useHeaderTop();
return (
<Box
bg="dark.7"
w="100%"
style={{
position: 'sticky',
top: headerTop,
top: 0,
zIndex: 10,
boxShadow: '0 4px 4px rgba(0, 0, 0, 0.1)',
}}
Expand Down
16 changes: 16 additions & 0 deletions src/layout/AppContainer.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.appContainer {
height: 100vh;

display: flex;
flex-direction: column;

overscroll-behavior: none;
}

.appContainerPageContent {
flex-grow: 1;
display: flex;

flex-direction: column;
align-items: stretch;
}
22 changes: 22 additions & 0 deletions src/layout/AppContainer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { ReactNode } from 'react';
import styles from './AppContainer.module.css';

interface IAppContainerProps {
header: ReactNode;
footer: ReactNode;
children: ReactNode;
}

export const AppContainer = ({
footer,
header,
children,
}: IAppContainerProps) => {
return (
<div className={styles.appContainer}>
{header}
<div className={styles.appContainerPageContent}>{children}</div>
{footer}
</div>
);
};
8 changes: 8 additions & 0 deletions src/layout/FullHeightContainer.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.fullHeightContainer {
position: relative;
height: 0;

flex-grow: 1;

overflow-y: scroll;
}
6 changes: 6 additions & 0 deletions src/layout/FullHeightContainer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { ReactNode } from 'react';
import styles from '@/layout/FullHeightContainer.module.css';

export const FullHeightContainer = ({ children }: { children: ReactNode }) => {
return <div className={styles.fullHeightContainer}>{children}</div>;
};
4 changes: 2 additions & 2 deletions src/layout/Header.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
);
border-bottom: rem(1px) solid
light-dark(var(--mantine-color-gray-2), transparent);
position: sticky;
top: 0;
/*position: sticky;*/
/*top: 0;*/
z-index: 10;
}

Expand Down
Loading
Loading