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 (vi) #2732

Merged
merged 4 commits into from
Oct 11, 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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
"googleapis": "^108.0.0",
"handsontable": "^12.3.3",
"html-to-text": "^8.2.0",
"indefinite": "^2.4.3",
"instantsearch.js": "^4.56.9",
"js-base64": "^3.7.2",
"js-cookie": "^3.0.1",
Expand Down
1 change: 0 additions & 1 deletion packages/@ourworldindata/grapher/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"decko": "^1.2.0",
"expr-eval": "^2.0.2",
"fuzzysort": "^1.1.4",
"indefinite": "^2.4.3",
"js-cookie": "^3.0.1",
"mobx": "^5.15.7",
"mobx-formatters": "^1.0.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

svg {
font-size: 10px;
padding-left: 1px;
padding-left: 0.75px;
color: $active-text;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export class EntitySelectionToggle extends React.Component<{
onClick={(): void => {
this.props.manager.isSelectingData = !active
}}
data-track-note="chart_add_entity"
>
{label.icon}
<label>
Expand Down
98 changes: 98 additions & 0 deletions packages/@ourworldindata/grapher/src/controls/LabeledSwitch.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
$light-fill: #dadada;
$active-fill: #dbe5f0;

$light-text: #858585;
$dark-text: #5b5b5b;

$info-icon: #a1a1a1;
$active-switch: #6e87a2;

$medium: 400;
$lato: $sans-serif-font-stack;

@at-root {
// placed either directly in controls row or in settings menu
.controlsRow .controls,
.settings-menu-contents {
// on/off switch with label written to the right
.labeled-switch {
display: flex;
color: $light-text;
font: $medium 13px/16px $lato;
letter-spacing: 0.01em;

position: relative;
margin: 8px 0;
-webkit-user-select: none;
user-select: none;

label {
color: $dark-text;
padding-left: 35px;
white-space: nowrap;

&:hover {
cursor: pointer;
}

svg {
color: $info-icon;
height: 13px;
padding: 0 0.333em;
}
}

.labeled-switch-subtitle {
// only show subtitle in settings menu, otherwise use icon + tooltip
display: none;
}

input {
position: absolute;
opacity: 0;
left: 0;
}

.outer {
position: absolute;
left: 0;
top: 0;
content: " ";
width: 29px;
height: 16px;
background: $light-fill;
border-radius: 8px;
pointer-events: none;
.inner {
position: relative;
content: " ";
width: 10px;
height: 10px;
background: $light-text;
border-radius: 5px;
top: 3px;
left: 3px;
pointer-events: none;
transition: transform 333ms;
}
}

&:hover {
.outer .inner {
background: $dark-text;
}
}

input:checked + .outer {
background: $active-fill;
.inner {
background: $active-switch;
transform: translate(13px, 0);
}
}
&:hover input:checked + .outer .inner {
background: darken($active-switch, 13%);
}
}
}
}
12 changes: 8 additions & 4 deletions packages/@ourworldindata/grapher/src/controls/LabeledSwitch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,22 @@ export class LabeledSwitch extends React.Component<{
value?: boolean
label?: string
tooltip?: string
tracking?: string
onToggle: () => any
}> {
render(): JSX.Element {
const { label, value, tooltip } = this.props
const { label, value, tooltip, tracking } = this.props

return (
<div className="config-switch">
<div className="labeled-switch">
<label>
<input
type="checkbox"
checked={value}
onChange={this.props.onToggle}
data-track-note={tracking}
/>
<div className="outer">
<div data-track-note="" className="outer">
<div className="inner"></div>
</div>
{label}
Expand All @@ -38,7 +40,9 @@ export class LabeledSwitch extends React.Component<{
</Tippy>
)}
</label>
{tooltip && <div className="config-subtitle">{tooltip}</div>}
{tooltip && (
<div className="labeled-switch-subtitle">{tooltip}</div>
)}
</div>
)
}
Expand Down
76 changes: 5 additions & 71 deletions packages/@ourworldindata/grapher/src/controls/SettingsMenu.scss
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ nav.controlsRow .controls .settings-menu {
z-index: $zindex-controls-backdrop;
}

.config-switch {
.labeled-switch {
label > svg {
display: none;
}

.config-subtitle {
.labeled-switch-subtitle {
display: block;
}
}
Expand Down Expand Up @@ -192,6 +192,7 @@ nav.controlsRow .controls .settings-menu {
}
}

.labeled-switch .labeled-switch-subtitle,
.config-subtitle {
font-size: 13px;
margin: 5px 0;
Expand Down Expand Up @@ -227,76 +228,9 @@ nav.controlsRow .controls .settings-menu {
}

// on/off switch with label written to the right
.config-switch {
position: relative;
.labeled-switch {
margin: 14px 0;
-webkit-user-select: none;
user-select: none;

label {
color: $dark-text;
padding-left: 35px;
&:hover {
cursor: pointer;
}

svg {
color: $info-icon;
height: 13px;
padding: 0 0.333em;
}
}

.config-subtitle {
display: none;
}

input {
position: absolute;
opacity: 0;
left: 0;
}

.outer {
position: absolute;
left: 0;
top: 0;
content: " ";
width: 29px;
height: 16px;
background: $light-fill;
border-radius: 8px;
pointer-events: none;
.inner {
position: relative;
content: " ";
width: 10px;
height: 10px;
background: $light-text;
border-radius: 5px;
top: 3px;
left: 3px;
pointer-events: none;
transition: transform 333ms;
}
}

&:hover {
.outer .inner {
background: $dark-text;
}
}

input:checked + .outer {
background: $active-fill;
.inner {
background: $active-switch;
transform: translate(13px, 0);
}
}
&:hover input:checked + .outer .inner {
background: darken($active-switch, 13%);
}
display: block;
}

// vertical list of options (for selecting faceting mode)
Expand Down
41 changes: 26 additions & 15 deletions packages/@ourworldindata/grapher/src/controls/SettingsMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export interface SettingsMenuManager
FacetStrategySelectionManager {
base?: React.RefObject<SVGGElement | HTMLDivElement> // the root grapher element
showConfigurationDrawer?: boolean
isInIFrame?: boolean

// ArchieML directives
hideFacetControl?: boolean
Expand Down Expand Up @@ -266,8 +265,6 @@ export class SettingsMenu extends React.Component<{
}

@computed get drawer(): Element | null {
// use a drop-down menu when embedded in an iframe
if (this.manager.isInIFrame) return null
// use the drawer `<nav>` element if it exists, otherwise render into a drop-down menu
return this.manager.base?.current?.closest(".related-charts")
? null // also use a drop-down menu within the Related Charts section
Expand Down Expand Up @@ -310,7 +307,6 @@ export class SettingsMenu extends React.Component<{
showFacetControl,
showFacetYDomainToggle,
showAbsRelToggle,
showTableFilterToggle,
} = this

const {
Expand Down Expand Up @@ -381,13 +377,6 @@ export class SettingsMenu extends React.Component<{
)}
{showZoomToggle && <ZoomToggle manager={manager} />}
</SettingsGroup>

<SettingsGroup title="Data rows" active={isOnTableTab}>
{showTableFilterToggle && (
<TableFilterToggle manager={manager} />
)}
</SettingsGroup>

<SettingsGroup
title="Axis scale"
active={
Expand Down Expand Up @@ -417,20 +406,42 @@ export class SettingsMenu extends React.Component<{
)
}

render(): JSX.Element | null {
const { showSettingsMenuToggle, active } = this
return showSettingsMenuToggle ? (
renderChartSettings(): JSX.Element {
const { active } = this
return (
<div className="settings-menu">
<button
className={classnames("menu-toggle", { active })}
onClick={this.toggleVisibility}
data-track-note="chart_settings_menu_toggle"
title="Chart settings"
>
<FontAwesomeIcon icon={faGear} />
<span className="label"> Settings</span>
</button>
{this.menu}
</div>
) : null
)
}

renderTableControls(): JSX.Element {
// Since tables only have a single control, display it inline rather than
// placing it in the settings menu
return <TableFilterToggle manager={this.manager} />
}

render(): JSX.Element | null {
const {
manager: { isOnChartTab, isOnTableTab },
showSettingsMenuToggle,
showTableFilterToggle,
} = this

return isOnTableTab && showTableFilterToggle
? this.renderTableControls()
: isOnChartTab && showSettingsMenuToggle
? this.renderChartSettings()
: null
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export class AbsRelToggle extends React.Component<{
value={this.isRelativeMode}
tooltip={this.tooltip}
onToggle={this.onToggle}
tracking="chart_abs_rel_toggle"
/>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ export class AxisScaleToggle extends React.Component<{
<button
className={classnames({ active: isLinear })}
onClick={(): void => this.setAxisScale(linear)}
data-track-note="chart_toggle_scale"
>
{label}Linear
</button>
<button
className={classnames({ active: !isLinear })}
onClick={(): void => this.setAxisScale(log)}
data-track-note="chart_toggle_scale"
>
{label}Logarithmic
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export class FacetStrategySelector extends React.Component<{
onClick={(): void => {
this.props.manager.facetStrategy = value
}}
data-track-note={`chart_facet_${option}`}
>
<div className="faceting-icon">
{range(value === "none" ? 1 : 6).map(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export class FacetYDomainToggle extends React.Component<{
tooltip="Use the same minimum and maximum values on all charts or scale axes to fit the data in each chart"
value={this.isYDomainShared}
onToggle={this.onToggle}
tracking="chart_facet_ydomain_toggle"
/>
)
}
Expand Down
Loading
Loading