-
Notifications
You must be signed in to change notification settings - Fork 49
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
Feature/map tooltip #662
base: staging
Are you sure you want to change the base?
Feature/map tooltip #662
Changes from 2 commits
ff59a0e
8985432
02a3c3f
caf001b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ const INITIAL_VIEW_STATE = { | |
const TOOLTIP_COMMON_STYLE = { | ||
backgroundColor: colorTheme.newColors.black3, | ||
borderRadius: '5px', | ||
fontSize: '0.7em', | ||
fontSize: '14px', | ||
color: colorTheme.newColors.white, | ||
} | ||
|
||
|
@@ -98,6 +98,38 @@ const getColor = ( | |
return colors[5] | ||
} | ||
|
||
const getColorFromDataPoint = (dataPoint: number | string): string => { | ||
let value: number; | ||
|
||
if (typeof dataPoint === 'string') { | ||
const standardizedDataPoint = dataPoint.trim().replace('−', '-').replace(',', '.'); | ||
value = parseFloat(standardizedDataPoint); | ||
} else { | ||
value = dataPoint; | ||
} | ||
|
||
if (value >= 0) { | ||
return mapColors[0]; // 0%+ | ||
} | ||
if (value < 0 && value >= -3) { | ||
return mapColors[1]; // 0–3% | ||
} | ||
if (value < -3 && value >= -5) { | ||
return mapColors[2]; // 3–5% | ||
} | ||
if (value < -5 && value >= -7) { | ||
return mapColors[3]; // 5–7% | ||
} | ||
if (value < -7 && value >= -10) { | ||
return mapColors[4]; // 7–10% | ||
} | ||
if (value < -10 && value >= -15) { | ||
return mapColors[5]; // 10–15% | ||
} | ||
|
||
return mapColors[6]; | ||
}; | ||
|
||
// Use when viewState is reimplemented | ||
/* const MAP_RANGE = { | ||
lon: [8.107180004121693, 26.099158344940808], | ||
|
@@ -117,6 +149,8 @@ export function isMunicipalityData( | |
} | ||
|
||
function MobileTooltip({ tInfo }: { tInfo: MunicipalityTapInfo }) { | ||
const dataPointColor = getColorFromDataPoint(tInfo.mData.dataPoint); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO this would be more readable inlined |
||
|
||
return ( | ||
<Link | ||
href={`/kommun/${tInfo.mData.name.toLowerCase()}`} | ||
|
@@ -134,8 +168,8 @@ function MobileTooltip({ tInfo }: { tInfo: MunicipalityTapInfo }) { | |
color: colorTheme.newColors.white, height: 14, width: 14, marginRight: 4, | ||
}} | ||
/> | ||
<span style={{ textDecoration: 'underline' }}>{`${tInfo.mData.name}`}</span> | ||
{`: ${tInfo.mData.formattedDataPoint}`} | ||
<span style={{ textDecoration: 'underline' }}>{`${tInfo.mData.name}`}:</span> | ||
<span style={{ color: dataPointColor, fontWeight: 'bold' }}>{`${tInfo.mData.formattedDataPoint}%`}</span> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please run "npm run lint" to get a list of small nitpicks that will need to be addressed. |
||
</Link> | ||
) | ||
} | ||
|
@@ -146,7 +180,7 @@ function Map({ | |
const [municipalityFeatureCollection, setMunicipalityFeatureCollection] = useState<any>({}) | ||
// "tapped" municipality tooltips are only to be used on touch devices. | ||
const [lastTapInfo, setLastTapInfo] = useState<MunicipalityTapInfo | null>(null) | ||
const wrapperRef = useRef<HTMLDivElement|null>(null) | ||
const wrapperRef = useRef<HTMLDivElement | null>(null) | ||
|
||
const router = useRouter() | ||
|
||
|
@@ -264,11 +298,19 @@ function Map({ | |
if (!isMunicipalityData(mData) || onTouchDevice()) { | ||
return null // tooltips on touch devices are handled separately | ||
} | ||
return { | ||
|
||
const dataPointColor = getColorFromDataPoint(mData.dataPoint); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it makes sense to inline this variable |
||
|
||
return ({ | ||
html: ` | ||
<p>${mData.name}: ${(mData).formattedDataPoint}</p>`, | ||
<p> | ||
${mData.name}: | ||
<span style="color: ${dataPointColor}; font-weight: bold;"> | ||
${(mData).formattedDataPoint}% | ||
</span> | ||
</p>`, | ||
style: TOOLTIP_COMMON_STYLE, | ||
} | ||
}) | ||
}} | ||
onClick={({ object: mData, x, y }) => { | ||
if (!isMunicipalityData(mData)) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This gets the job done, but would mean we have two independent definitions of the boundaries. I see there's a "boundaries" array as well. Could that be something to use?