Skip to content

Commit

Permalink
✨ (static-map) increase stroke width on mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiamersmann committed Dec 15, 2023
1 parent c24739c commit c5152ba
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
31 changes: 24 additions & 7 deletions packages/@ourworldindata/grapher/src/mapCharts/MapChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,10 @@ export class MapChart
return 0
}

@computed get strokeWidth(): number | undefined {
return this.manager.isStaticAndSmall ? 2 : undefined
}

renderMapLegend(): JSX.Element {
const { numericLegend, categoryLegend } = this

Expand Down Expand Up @@ -629,7 +633,9 @@ export class MapChart
declare type SVGMouseEvent = React.MouseEvent<SVGElement>

@observer
class ChoroplethMap extends React.Component<{ manager: ChoroplethMapManager }> {
class ChoroplethMap extends React.Component<{
manager: ChoroplethMapManager
}> {
base: React.RefObject<SVGGElement> = React.createRef()

@computed private get uid(): number {
Expand All @@ -640,6 +646,10 @@ class ChoroplethMap extends React.Component<{ manager: ChoroplethMapManager }> {
return this.props.manager
}

@computed private get strokeWidth(): number {
return this.manager.strokeWidth ?? 1
}

@computed.struct private get bounds(): Bounds {
return this.manager.choroplethMapBounds
}
Expand Down Expand Up @@ -843,8 +853,10 @@ class ChoroplethMap extends React.Component<{ manager: ChoroplethMapManager }> {
featuresWithData,
} = this
const focusStrokeColor = "#111"
const focusStrokeWidth = 1.5
const selectedStrokeWidth = 1
const defaultStrokeWidth = this.strokeWidth * 0.3
const focusStrokeWidth = this.strokeWidth * 1.5
const selectedStrokeWidth = this.strokeWidth * 1
const patternStrokeWidth = this.strokeWidth * 0.7
const blurFillOpacity = 0.2
const blurStrokeOpacity = 0.5

Expand Down Expand Up @@ -883,7 +895,9 @@ class ChoroplethMap extends React.Component<{ manager: ChoroplethMapManager }> {
<path
key={feature.id}
d={feature.path}
strokeWidth={0.3 / viewportScale}
strokeWidth={
defaultStrokeWidth / viewportScale
}
stroke={"#aaa"}
fill={"#fff"}
/>
Expand Down Expand Up @@ -912,7 +926,7 @@ class ChoroplethMap extends React.Component<{ manager: ChoroplethMapManager }> {
<path
d="M -1,2 l 6,0"
stroke="#ccc"
strokeWidth="0.7"
strokeWidth={patternStrokeWidth}
/>
</pattern>
</defs>
Expand All @@ -935,7 +949,9 @@ class ChoroplethMap extends React.Component<{ manager: ChoroplethMapManager }> {
key={feature.id}
d={feature.path}
strokeWidth={
(isFocus ? focusStrokeWidth : 0.3) /
(isFocus
? focusStrokeWidth
: defaultStrokeWidth) /
viewportScale
}
stroke={stroke}
Expand Down Expand Up @@ -991,7 +1007,8 @@ class ChoroplethMap extends React.Component<{ manager: ChoroplethMapManager }> {
? focusStrokeWidth
: showSelectedStyle
? selectedStrokeWidth
: 0.3) / viewportScale
: defaultStrokeWidth) /
viewportScale
}
stroke={stroke}
strokeOpacity={strokeOpacity}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export interface ChoroplethMapManager {
onClick: (d: GeoFeature, ev: React.MouseEvent<SVGElement>) => void
onMapMouseOver: (d: GeoFeature) => void
onMapMouseLeave: () => void
strokeWidth?: number
}

export interface RenderFeature {
Expand Down

0 comments on commit c5152ba

Please sign in to comment.