-
Notifications
You must be signed in to change notification settings - Fork 1
SettingsStateMap
Bote Wang edited this page Nov 15, 2024
·
2 revisions
The SettingsStateMap component provides an interactive map interface for state selection in the settings panel, featuring zoom, pan, and click-based selection capabilities.
interface MapState {
dimensions: {
width: number;
height: number;
};
zoomLevel: number;
initialTransform: d3.ZoomTransform | null;
}
interface SettingsStateMapProps {
containerRef: React.RefObject<HTMLDivElement>;
svgRef: React.RefObject<SVGSVGElement>;
gRef: React.RefObject<SVGGElement>;
}
const initializeZoom = useCallback(() => {
// Zoom behavior configuration
zoomBehaviorRef.current = zoom<SVGSVGElement, unknown>()
.scaleExtent([1, 8])
.on("zoom", (event) => {
g.attr("transform", event.transform);
});
});
const renderMap = useCallback(() => {
// Map projection setup
const projection = d3.geoAlbersUsa()
.fitSize([dimensions.width, dimensions.height],
{type: "Sphere"});
// Path generator
const path = d3.geoPath().projection(projection);
// State rendering
states.selectAll("path")
.data(topojson.feature(us, us.objects.states).features)
.join("path")
.attr("fill", "#252a33")
.attr("stroke", "#5c636b");
});
interface MapEventHandlers {
handleClick: (event: any, d: any, path: any) => void;
handleReset: () => void;
updateDimensions: () => void;
detectZoomLevel: () => void;
}
- Smooth zoom transitions
- Pan constraints
- Zoom level limits
- Auto-reset functionality
- Click to zoom
- Visual feedback
- Auto-zoom out
- State highlighting
- Dynamic sizing
- Window resize handling
- Device pixel ratio detection
- Viewport adaptation
.state-path {
transition: fill 0.3s ease;
cursor: pointer;
}
.selected-state {
fill: white;
}
const containerStyles = {
minHeight: '240px',
maxHeight: '360px',
position: 'relative'
};
function StateSelector() {
return (
<div className="state-selector-container">
<SettingsStateMap />
<button className="reset-button">
Reset View
</button>
</div>
);
}
- Memoized callbacks
- Efficient zoom handling
- Optimized state updates
- Controlled re-renders
Main Pages
Data Pipeline
- Data Pipeline
- Data Transformation Script
- Custom data interface for wrapping processed csv into React Components
- Data Fetching API
Static Components
Visualizations
-
- WIP
Styling