Skip to content

Commit

Permalink
✨ (slope) add entity annotation to tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiamersmann committed Nov 29, 2024
1 parent 8482c7e commit 2c40d5c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
14 changes: 10 additions & 4 deletions packages/@ourworldindata/grapher/src/slopeCharts/SlopeChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -583,22 +583,25 @@ export class SlopeChart
return !!this.manager.isSemiNarrow
}

@computed private get showValueLabelsInline(): boolean {
return this.useCompactLineLegend
}

// used by LineLegend
@computed get focusedSeriesNames(): SeriesName[] {
return this.hoveredSeriesName ? [this.hoveredSeriesName] : []
}

@computed get lineLegendSeriesLeft(): LineLabelSeries[] {
return this.series.map((series) => {
const { seriesName, color, start, annotation } = series
const { seriesName, color, start } = series
const formattedValue = this.formatColumn.formatValueShort(
start.value
)
return {
color,
seriesName,
label: formattedValue,
annotation,
yValue: start.value,
}
})
Expand Down Expand Up @@ -755,6 +758,9 @@ export class SlopeChart
const title = isRelativeMode
? `${series.seriesName}, ${formatColumn.formatTime(endTime)}`
: series.seriesName
const titleAnnotation = !this.showValueLabelsInline
? series.annotation
: undefined

const isStartValueOriginal = series.start.originalTime === startTime
const isEndValueOriginal = series.end.originalTime === endTime
Expand Down Expand Up @@ -830,6 +836,7 @@ export class SlopeChart
offsetY={-16}
style={{ maxWidth: "250px" }}
title={title}
titleAnnotation={titleAnnotation}
subtitle={timeLabel}
subtitleFormat={targetYear ? "notice" : undefined}
dissolve={fading}
Expand Down Expand Up @@ -1004,7 +1011,7 @@ export class SlopeChart
yRange={[this.bounds.top, this.bounds.bottom]}
maxWidth={this.maxLineLegendWidth}
lineLegendAnchorX="start"
showValueLabelsInline={!this.useCompactLineLegend}
showValueLabelsInline={this.showValueLabelsInline}
connectorLineWidth={this.lineLegendConnectorLinesWidth}
fontSize={this.fontSize}
fontWeight={700}
Expand Down Expand Up @@ -1040,7 +1047,6 @@ export class SlopeChart
yRange={[this.bounds.top, this.bounds.bottom]}
maxWidth={this.maxLineLegendWidth}
lineLegendAnchorX="end"
showValueLabelsInline={!this.useCompactLineLegend}
connectorLineWidth={this.lineLegendConnectorLinesWidth}
fontSize={this.fontSize}
isStatic={this.manager.isStatic}
Expand Down
7 changes: 7 additions & 0 deletions packages/@ourworldindata/grapher/src/tooltip/Tooltip.scss
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@
font-size: 14px;
font-weight: $bold;
letter-spacing: 0;

.annotation {
margin-left: 4px;
font-weight: normal;
color: $grey;
font-size: 0.9em;
}
}
.subtitle {
margin: 4px 0 2px 0;
Expand Down
10 changes: 9 additions & 1 deletion packages/@ourworldindata/grapher/src/tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class TooltipCard extends React.Component<
let {
id,
title,
titleAnnotation,
subtitle,
subtitleFormat,
footer,
Expand Down Expand Up @@ -189,7 +190,14 @@ class TooltipCard extends React.Component<
>
{hasHeader && (
<div className="frontmatter">
{title && <div className="title">{title}</div>}
{title && (
<div className="title">
{title}{" "}
<span className="annotation">
{titleAnnotation}
</span>
</div>
)}
{subtitle && (
<div className="subtitle">
{timeNotice && TOOLTIP_ICON.notice}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface TooltipProps {
offsetXDirection?: "left" | "right"
offsetYDirection?: "upward" | "downward"
title?: string | number // header text
titleAnnotation?: string // rendered next to the title, but muted
subtitle?: string | number // header deck
subtitleFormat?: "notice" | "unit" // optional postprocessing for subtitle
footer?: { icon: TooltipFooterIcon; text: string }[]
Expand Down

0 comments on commit 2c40d5c

Please sign in to comment.