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

Text Updates #211

Merged
merged 4 commits into from
Nov 22, 2024
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
12 changes: 8 additions & 4 deletions app/src/app/components/sidebar/Evaluation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
P4ZoneSummaryStats,
P4ZoneSummaryStatsKeys,
} from '@/app/utils/api/apiHandlers';
import {Button, CheckboxGroup} from '@radix-ui/themes';
import {Button, CheckboxGroup, Heading} from '@radix-ui/themes';
import {Flex, Spinner, Text} from '@radix-ui/themes';
import {queryClient} from '@utils/api/queryClient';
import {formatNumber, NumberFormats} from '@/app/utils/numbers';
Expand Down Expand Up @@ -100,7 +100,6 @@ const Evaluation: React.FC = () => {
const totPop = useMapStore(state => state.summaryStats.totpop?.data);
const mapDocument = useMapStore(state => state.mapDocument);
const assignmentsHash = useMapStore(state => state.assignmentsHash);

const columnConfig = useMemo(() => {
const summaryType = mapDocument?.available_summary_stats?.[0];

Expand Down Expand Up @@ -139,6 +138,7 @@ const Evaluation: React.FC = () => {
queryClient
);


const {
unassigned,
maxValues,
Expand All @@ -155,6 +155,7 @@ const Evaluation: React.FC = () => {
zone: -999,
total: getEntryTotal(totPop),
};

ZoneSummaryStatsKeys.forEach(key => {
let total = unassigned[key];
maxValues[key] = -Math.pow(10, 12);
Expand All @@ -164,7 +165,7 @@ const Evaluation: React.FC = () => {
// @ts-ignore
maxValues[key] = Math.max(row[key], maxValues[key]);
});
unassigned[`${key}_pct`] = total / unassigned[key];
unassigned[`${key}_pct`] = total / unassigned['total'];
unassigned[key] = total;
});

Expand All @@ -189,7 +190,10 @@ const Evaluation: React.FC = () => {
const rows = unassigned && showUnassigned ? [...data.results, unassigned] : data.results;
return (
<div className="w-full">
<Flex align="center" gap="3" mt="1">
<Heading as="h3" size="3">
Voting age population
</Heading>
<Flex align="center" gap="3" my="2">
{modeButtonConfig.map((mode, i) => (
<Button
key={i}
Expand Down
2 changes: 1 addition & 1 deletion app/src/app/components/sidebar/MapModeSelector.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function MapModeSelector() {
if (!activeTool) return null;
const activeTools = [
{mode: 'pan', disabled: false, label: 'Pan', icon: <HandIcon />},
{mode: 'brush', disabled: false, label: 'Brush', icon: <Pencil2Icon />},
{mode: 'brush', disabled: false, label: 'Paint', icon: <Pencil2Icon />},
{mode: 'eraser', disabled: false, label: 'Erase', icon: <EraserIcon />},
{
mode: 'shatter',
Expand Down
3 changes: 0 additions & 3 deletions app/src/app/components/sidebar/PaintByCounty.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ export default function PaintByCounty() {
Paint by County
</Flex>
</Text>
<Text size="1" color="gray">
Paint-by-county feature is still experimental.
</Text>
</Box>
);
}
55 changes: 33 additions & 22 deletions app/src/app/components/sidebar/charts/HorizontalBarChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from 'recharts';
import {colorScheme} from '@/app/constants/colors';
import {useState, useMemo} from 'react';
import { formatNumber } from '@/app/utils/numbers';
import {formatNumber} from '@/app/utils/numbers';

type TooltipInput = {
active?: boolean;
Expand All @@ -25,7 +25,7 @@ const calculateMinMaxRange = (data: Array<{zone: number; total_pop: number}>) =>
const min = Math.min(...totalPops);
const max = Math.max(...totalPops);
const range = Math.abs(max - min);
return { min, max, range };
return {min, max, range};
};

const numberFormat = new Intl.NumberFormat('en-US');
Expand All @@ -47,7 +47,7 @@ export const HorizontalBar = () => {
const summaryStats = useMapStore(state => state.summaryStats);
const numDistricts = useMapStore(state => state.mapDocument?.num_districts);
const idealPopulation = summaryStats?.idealpop?.data;
const lockPaintedAreas = useMapStore(state => state.mapOptions.lockPaintedAreas)
const lockPaintedAreas = useMapStore(state => state.mapOptions.lockPaintedAreas);
const maxNumberOrderedBars = 40; // max number of zones to consider while keeping blank spaces for missing zones
const [totalExpectedBars, setTotalExpectedBars] = useState<
Array<{zone: number; total_pop: number}>
Expand All @@ -74,10 +74,10 @@ export const HorizontalBar = () => {
const stats = useMemo(() => {
if (mapMetrics) {
const chartObject = calculateChartObject();
const allAreNonZero = chartObject.every(entry => entry.total_pop > 0)
const stats = allAreNonZero ? calculateMinMaxRange(chartObject) : undefined
const allAreNonZero = chartObject.every(entry => entry.total_pop > 0);
const stats = allAreNonZero ? calculateMinMaxRange(chartObject) : undefined;
setTotalExpectedBars(chartObject);
return stats
return stats;
}
}, [mapMetrics]);

Expand All @@ -100,7 +100,7 @@ export const HorizontalBar = () => {
return (
<Flex gap="3" direction="column">
<Heading as="h3" size="3">
Population by district
Total population by district
</Heading>
<ResponsiveContainer width="100%" minHeight="350px">
<BarChart
Expand Down Expand Up @@ -134,7 +134,7 @@ export const HorizontalBar = () => {
))}
</Bar>
<ReferenceLine x={idealPopulation ?? 0} stroke="black" strokeDasharray="3 3">
<Label
<Label
value={`Ideal: ${new Intl.NumberFormat('en-US').format(
Math.round(idealPopulation ?? 0) ?? 0
)}`}
Expand All @@ -146,24 +146,35 @@ export const HorizontalBar = () => {
</ReferenceLine>
</BarChart>
</ResponsiveContainer>
{stats?.range !== undefined && <Text>
Top-to-bottom deviation: {formatNumber(stats.range || 0, 'string')}
</Text>}
<Text>
{stats?.range !== undefined
? `Top-to-bottom deviation: ${formatNumber(stats.range || 0, 'string')}`
: 'Top-to-bottom population deviation will appear when all districts are started'}
</Text>
</Flex>
);
};

const getRenderCustomBarLabel: (
lockPaintedAreas: MapStore['mapOptions']['lockPaintedAreas']
) => React.FC<any> = lockPaintedAreas => {
const InnerComponent: React.FC<any> = ({y, height, index, value}) => {
const entryIsLocked =
Array.isArray(lockPaintedAreas) && lockPaintedAreas.indexOf(index + 1) !== -1;

const getRenderCustomBarLabel: (lockPaintedAreas: MapStore['mapOptions']['lockPaintedAreas']) => React.FC<any> = (lockPaintedAreas) => {
const InnerComponent: React.FC<any> = ({ y, height, index, value }) => {
const entryIsLocked = Array.isArray(lockPaintedAreas) && lockPaintedAreas.indexOf(index+1) !== -1

if (!entryIsLocked || !value) {
return null
return null;
}
return <g transform={`translate(${10}, ${y+height/2-9}), scale(1.25)`}>
<path d="M5 4.63601C5 3.76031 5.24219 3.1054 5.64323 2.67357C6.03934 2.24705 6.64582 1.9783 7.5014 1.9783C8.35745 1.9783 8.96306 2.24652 9.35823 2.67208C9.75838 3.10299 10 3.75708 10 4.63325V5.99999H5V4.63601ZM4 5.99999V4.63601C4 3.58148 4.29339 2.65754 4.91049 1.99307C5.53252 1.32329 6.42675 0.978302 7.5014 0.978302C8.57583 0.978302 9.46952 1.32233 10.091 1.99162C10.7076 2.65557 11 3.57896 11 4.63325V5.99999H12C12.5523 5.99999 13 6.44771 13 6.99999V13C13 13.5523 12.5523 14 12 14H3C2.44772 14 2 13.5523 2 13V6.99999C2 6.44771 2.44772 5.99999 3 5.99999H4ZM3 6.99999H12V13H3V6.99999Z" fill="currentColor" fill-rule="evenodd" clip-rule="evenodd"></path>
</g>;
}
return InnerComponent
}
return (
<g transform={`translate(${10}, ${y + height / 2 - 9}), scale(1.25)`}>
<path
d="M5 4.63601C5 3.76031 5.24219 3.1054 5.64323 2.67357C6.03934 2.24705 6.64582 1.9783 7.5014 1.9783C8.35745 1.9783 8.96306 2.24652 9.35823 2.67208C9.75838 3.10299 10 3.75708 10 4.63325V5.99999H5V4.63601ZM4 5.99999V4.63601C4 3.58148 4.29339 2.65754 4.91049 1.99307C5.53252 1.32329 6.42675 0.978302 7.5014 0.978302C8.57583 0.978302 9.46952 1.32233 10.091 1.99162C10.7076 2.65557 11 3.57896 11 4.63325V5.99999H12C12.5523 5.99999 13 6.44771 13 6.99999V13C13 13.5523 12.5523 14 12 14H3C2.44772 14 2 13.5523 2 13V6.99999C2 6.44771 2.44772 5.99999 3 5.99999H4ZM3 6.99999H12V13H3V6.99999Z"
fill="currentColor"
fill-rule="evenodd"
clip-rule="evenodd"
></path>
</g>
);
};
return InnerComponent;
};
Loading