Added min width to missing graphs (#176)
continuous-integration/drone/push Build is passing Details

Closes #129
Closes #120

Co-authored-by: shahanneda <shahan.neda@gmail.com>
Reviewed-on: #176
Reviewed-by: Mark Chiu <e26chiu@csclub.uwaterloo.ca>
This commit is contained in:
Shahan Nedadahandeh 2023-02-13 18:58:06 -05:00
parent 3958120bc1
commit 1a98bea483
4 changed files with 34 additions and 0 deletions

View File

@ -69,6 +69,8 @@ export type StatsPlotProps = {
boxPlotLeftOffset?: number; boxPlotLeftOffset?: number;
/** Boxplot padding */ /** Boxplot padding */
boxPlotPadding?: number; boxPlotPadding?: number;
/** Minimum width of the graph. */
minWidth?: number;
}; };
export const BoxPlot = withTooltip<StatsPlotProps, TooltipData>( export const BoxPlot = withTooltip<StatsPlotProps, TooltipData>(
@ -96,7 +98,12 @@ export const BoxPlot = withTooltip<StatsPlotProps, TooltipData>(
boxPlotWidthFactor = 0.4, boxPlotWidthFactor = 0.4,
boxPlotLeftOffset = 0.3, boxPlotLeftOffset = 0.3,
boxPlotPadding = 0.3, boxPlotPadding = 0.3,
minWidth = 500,
}: StatsPlotProps & WithTooltipProvidedProps<TooltipData>) => { }: StatsPlotProps & WithTooltipProvidedProps<TooltipData>) => {
if (width < minWidth) {
width = minWidth;
}
// bounds // bounds
const xMax = width; const xMax = width;
const yMax = height - 120; const yMax = height - 120;

View File

@ -22,4 +22,12 @@
display: flex; display: flex;
margin: calc(16rem / 8); margin: calc(16rem / 8);
justify-content: center; justify-content: center;
}
@media screen and (max-width: 900px) {
/* To fix legend being cut off on mobile */
.legend {
justify-content: start;
}
} }

View File

@ -50,6 +50,8 @@ interface LineGraphProps {
yTickLabelSize?: number; yTickLabelSize?: number;
/** Margin for each item in the legend */ /** Margin for each item in the legend */
itemMargin?: string; itemMargin?: string;
/** Minimum width of the graph. */
minWidth?: number;
} }
const DEFAULT_LABEL_SIZE = 16; const DEFAULT_LABEL_SIZE = 16;
@ -72,7 +74,12 @@ export const LineGraph = withTooltip<LineGraphProps, TooltipData>(
hideTooltip, hideTooltip,
showTooltip, showTooltip,
itemMargin = "0 0 0 15px", itemMargin = "0 0 0 15px",
minWidth = 500,
}) => { }) => {
if (width < minWidth) {
width = minWidth;
}
const xLength = data.xValues.length; const xLength = data.xValues.length;
if (data.lines.length != colorRange.length) { if (data.lines.length != colorRange.length) {

View File

@ -61,6 +61,8 @@ export type StackedBarProps = {
tooltipBottomLabel?: string; tooltipBottomLabel?: string;
//** Display percentage */ //** Display percentage */
displayPercentage?: boolean; displayPercentage?: boolean;
/** Minimum width of the graph. */
minWidth?: number;
}; };
let tooltipTimeout: number; let tooltipTimeout: number;
@ -91,7 +93,12 @@ export const StackedBarGraphVertical = withTooltip<
tooltipBottomLabel = "", tooltipBottomLabel = "",
tooltipTopLabel = "", tooltipTopLabel = "",
displayPercentage, displayPercentage,
minWidth = 500,
}: StackedBarProps & WithTooltipProvidedProps<TooltipData>) => { }: StackedBarProps & WithTooltipProvidedProps<TooltipData>) => {
if (width < minWidth) {
width = minWidth;
}
const yTotals = data.reduce((allTotals, currCategory) => { const yTotals = data.reduce((allTotals, currCategory) => {
const yTotal = keys.reduce((categoryTotal, k) => { const yTotal = keys.reduce((categoryTotal, k) => {
categoryTotal += currCategory[k] as number; categoryTotal += currCategory[k] as number;
@ -284,7 +291,12 @@ export const StackedBarGraphHorizontal = withTooltip<
tooltipBottomLabel = "", tooltipBottomLabel = "",
tooltipTopLabel = "", tooltipTopLabel = "",
displayPercentage, displayPercentage,
minWidth = 500,
}: StackedBarProps & WithTooltipProvidedProps<TooltipData>) => { }: StackedBarProps & WithTooltipProvidedProps<TooltipData>) => {
if (width < minWidth) {
width = minWidth;
}
const yTotals = data.reduce((allTotals, currCategory) => { const yTotals = data.reduce((allTotals, currCategory) => {
const yTotal = keys.reduce((categoryTotal, k) => { const yTotal = keys.reduce((categoryTotal, k) => {
categoryTotal += currCategory[k] as number; categoryTotal += currCategory[k] as number;