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

Grapher redesign updates (iii) #2712

Merged
merged 2 commits into from
Oct 8, 2023
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
36 changes: 34 additions & 2 deletions packages/@ourworldindata/grapher/src/controls/Controls.scss
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,33 @@ nav.controlsRow .controls {

//
// Make buttons narrower by omitting their text labels as the viewport gets narrower
// TODO: move the logic to js to calculate actual widths for different entity name lengths
// and the variable number of buttons present in the content switcher block
// use the .GrapherComponentSemiNarrow if necessary but allow container queries to
// collapse labels in two steps on browsers that support them
//
// TODO: the measurement and label-hiding logic will have to move to js anyway once the
// number of chart buttons becomes variable and the settings button can be replaced
// by a single control widget ‘promoted’ from within the drawer
//
@at-root {
// collapse both the settings and entity selector labels down at the semi-narrow breakpoint
.GrapherComponentSemiNarrow {
nav.controlsRow .settings-menu button.menu-toggle {
min-height: $control-row-height;
svg {
margin: 0 2px;
}
.label {
display: none;
}
}
nav.controlsRow .entity-selection-menu button.menu-toggle {
label span {
display: none;
}
}
}
}

@container grapher (max-width:550px) {
// collapse the Settings toggle down to just an icon on small screens
nav.controlsRow .settings-menu button.menu-toggle {
Expand All @@ -77,7 +101,15 @@ nav.controlsRow .controls {
display: none;
}
}

// undo the .GrapherComponentSemiNarrow hiding until next container query
nav.controlsRow .entity-selection-menu button.menu-toggle {
label span {
display: inline;
}
}
}

@container grapher (max-width:475px) {
// hide the entity name in the Edit/Select/Switch button
nav.controlsRow .entity-selection-menu button.menu-toggle {
Expand Down
7 changes: 7 additions & 0 deletions packages/@ourworldindata/grapher/src/core/Grapher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2312,6 +2312,7 @@ export class Grapher
isExportingToSvgOrPng: this.isExportingtoSvgOrPng,
optimizeForHorizontalSpace: this.optimizeForHorizontalSpace,
GrapherComponentNarrow: this.isNarrow,
GrapherComponentSemiNarrow: this.isSemiNarrow,
GrapherComponentSmall: this.isSmall,
GrapherComponentMedium: this.isMedium,
})
Expand Down Expand Up @@ -2416,6 +2417,12 @@ export class Grapher
return this.renderWidth <= 400
}

// SemiNarrow charts shorten their button labels to fit within the controls row
@computed get isSemiNarrow(): boolean {
if (this.isExportingtoSvgOrPng) return false
return this.renderWidth <= 550
}

// Small charts are rendered into 6 or 7 columns in a 12-column grid layout
// (e.g. side-by-side charts or charts in the All Charts block)
@computed get isSmall(): boolean {
Expand Down
12 changes: 8 additions & 4 deletions packages/@ourworldindata/grapher/src/lineCharts/LineChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ export class LineChart

@action.bound private onCursorLeave(): void {
this.tooltipState.target = null
this.hoveredSeriesName = undefined
this.clearHighlightedSeries()
}

@computed private get allValues(): LinePoint[] {
Expand Down Expand Up @@ -375,6 +375,7 @@ export class LineChart
hoverX = closestValue?.x
}

// be sure all lines are un-dimmed if the cursor is above the graph itself
if (this.dualAxis.innerBounds.contains(mouse)) {
this.hoveredSeriesName = undefined
}
Expand Down Expand Up @@ -611,13 +612,16 @@ export class LineChart
this.hoveredSeriesName = seriesName
}

@action.bound onLineLegendMouseLeave(): void {
@action.bound clearHighlightedSeries(): void {
clearTimeout(this.hoverTimer)

this.hoverTimer = setTimeout(() => {
// wait before clearing selection in case the mouse is moving quickly over neighboring labels
this.hoveredSeriesName = undefined
}, 100)
}, 200)
}

@action.bound onLineLegendMouseLeave(): void {
this.clearHighlightedSeries()
}

@computed get focusedSeriesNames(): string[] {
Expand Down
Loading