This PR creates a new util file `DefaultProp` that provides default prop values for graph/chart components. More values could be added in the future as the pages are developed. staging: (shahan: sorry, due to a unlucky naming this branch name doesnt work with staging ) Co-authored-by: e26chiu <e26chiu@csc.uwaterloo.ca> Reviewed-on: #87 Reviewed-by: Shahan Nedadahandeh <snedadah@csclub.uwaterloo.ca>new-branch-test
parent
97aa2261f2
commit
1c0191facc
@ -0,0 +1,58 @@ |
||||
// Only static number props are included for this list
|
||||
const propNames = ["graphHeight", "labelSize", "labelWidth"] as const; |
||||
|
||||
// This type is needed for smart autocomplete
|
||||
type PropName = typeof propNames[number]; |
||||
|
||||
const mobileBarGraphFactor = 1.25; |
||||
const desktopBarGraphFactor = 2; |
||||
|
||||
const mobilePieChartFactor = 1.25; |
||||
const desktopPieChartFactor = 3; |
||||
|
||||
const graphWidth = ( |
||||
isMobile: boolean, |
||||
pageWidth: number, |
||||
isPieChart: boolean |
||||
): number => { |
||||
const mobileFactor = isPieChart ? mobilePieChartFactor : mobileBarGraphFactor; |
||||
const desktopFactor = isPieChart |
||||
? desktopPieChartFactor |
||||
: desktopBarGraphFactor; |
||||
return isMobile ? pageWidth / mobileFactor : pageWidth / desktopFactor; |
||||
}; |
||||
|
||||
export const barGraphWidth = (isMobile: boolean, width: number) => |
||||
graphWidth(isMobile, width, false); |
||||
|
||||
export const pieChartWidth = (isMobile: boolean, width: number) => |
||||
graphWidth(isMobile, width, true); |
||||
|
||||
export const barGraphMargin = { |
||||
top: 20, |
||||
bottom: 80, |
||||
left: 60, |
||||
right: 20, |
||||
}; |
||||
|
||||
export const DefaultProp: { [key in PropName]: number } = { |
||||
graphHeight: 500, |
||||
labelSize: 24, |
||||
labelWidth: 100, |
||||
}; |
||||
|
||||
export const barGraphProps = (isMobile: boolean, pageWidth: number) => { |
||||
return { |
||||
width: barGraphWidth(isMobile, pageWidth), |
||||
height: DefaultProp.graphHeight, |
||||
margin: barGraphMargin, |
||||
}; |
||||
}; |
||||
|
||||
export const pieChartProps = (isMobile: boolean, pageWidth: number) => { |
||||
return { |
||||
width: pieChartWidth(isMobile, pageWidth), |
||||
labelWidth: DefaultProp.labelWidth, |
||||
labelTextSize: DefaultProp.labelSize, |
||||
}; |
||||
}; |
Loading…
Reference in new issue