-
-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ (slope) redesign / TAS-722 (#4222)
### Summary - Entity names are usually only shown only on the right side - If it would be otherwise difficult to match a label on the left to the corresponding slope, then the entity name is repeated - The heuristic here uses the number of levels used by the line legend, the actual threshold (4) is arbitrary of course - We prefer to add labels on the left if they're also labelled on the right (this is only important if labels are dropped due to space constraints) - Entity annotations are hidden on smaller screens - Entity annotations are also shown in the tooltip (line charts show entity annotations in the tooltip as well) ### Future improvements - Show hidden line legend labels on hover - Toggling the No Data section is quite disruptive. Once we make changes to the entity selector that account for the No data problem, we should remove the section ### Testing The Multiembedder problem is hot-fixed on [this staging site](http://staging-site-slope-charts) for testing.
- Loading branch information
1 parent
93cd99a
commit e87de50
Showing
25 changed files
with
1,342 additions
and
379 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,3 +44,4 @@ dist/ | |
.dev.vars | ||
**/tsup.config.bundled*.mjs | ||
cfstorage/ | ||
vite.*.mjs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
packages/@ourworldindata/components/src/TextWrap/TextWrapGroup.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
#! /usr/bin/env jest | ||
|
||
import { TextWrap } from "./TextWrap" | ||
import { TextWrapGroup } from "./TextWrapGroup" | ||
|
||
const FONT_SIZE = 14 | ||
const TEXT = "Lower middle-income countries" | ||
const MAX_WIDTH = 150 | ||
|
||
const textWrap = new TextWrap({ | ||
text: TEXT, | ||
maxWidth: MAX_WIDTH, | ||
fontSize: FONT_SIZE, | ||
}) | ||
|
||
it("should work like TextWrap for a single fragment", () => { | ||
const textWrapGroup = new TextWrapGroup({ | ||
fragments: [{ text: TEXT }], | ||
maxWidth: MAX_WIDTH, | ||
fontSize: FONT_SIZE, | ||
}) | ||
|
||
const firstTextWrap = textWrapGroup.textWraps[0] | ||
expect(firstTextWrap.text).toEqual(textWrap.text) | ||
expect(firstTextWrap.width).toEqual(textWrap.width) | ||
expect(firstTextWrap.height).toEqual(textWrap.height) | ||
expect(firstTextWrap.lines).toEqual(textWrap.lines) | ||
}) | ||
|
||
it("should place fragments in-line if there is space", () => { | ||
const textWrapGroup = new TextWrapGroup({ | ||
fragments: [{ text: TEXT }, { text: "30 million" }], | ||
maxWidth: MAX_WIDTH, | ||
fontSize: FONT_SIZE, | ||
}) | ||
|
||
expect(textWrapGroup.text).toEqual([TEXT, "30 million"].join(" ")) | ||
expect(textWrapGroup.height).toEqual(textWrap.height) | ||
}) | ||
|
||
it("should place the second segment in a new line if preferred", () => { | ||
const maxWidth = 250 | ||
const textWrapGroup = new TextWrapGroup({ | ||
fragments: [ | ||
{ text: TEXT }, | ||
{ text: "30 million", newLine: "avoid-wrap" }, | ||
], | ||
maxWidth, | ||
fontSize: FONT_SIZE, | ||
}) | ||
|
||
// 30 million should be placed in a new line, thus the group's height | ||
// should be greater than the textWrap's height | ||
expect(textWrapGroup.height).toBeGreaterThan( | ||
new TextWrap({ | ||
text: TEXT, | ||
maxWidth, | ||
fontSize: FONT_SIZE, | ||
}).height | ||
) | ||
}) | ||
|
||
it("should place the second segment in the same line if possible", () => { | ||
const maxWidth = 1000 | ||
const textWrapGroup = new TextWrapGroup({ | ||
fragments: [ | ||
{ text: TEXT }, | ||
{ text: "30 million", newLine: "avoid-wrap" }, | ||
], | ||
maxWidth, | ||
fontSize: FONT_SIZE, | ||
}) | ||
|
||
// since the max width is large, "30 million" fits into the same line | ||
// as the text of the first fragmemt | ||
expect(textWrapGroup.height).toEqual( | ||
new TextWrap({ | ||
text: TEXT, | ||
maxWidth, | ||
fontSize: FONT_SIZE, | ||
}).height | ||
) | ||
}) | ||
|
||
it("should place the second segment in the same line if specified", () => { | ||
const maxWidth = 1000 | ||
const textWrapGroup = new TextWrapGroup({ | ||
fragments: [{ text: TEXT }, { text: "30 million", newLine: "always" }], | ||
maxWidth, | ||
fontSize: FONT_SIZE, | ||
}) | ||
|
||
// "30 million" should be placed in a new line since newLine is set to 'always' | ||
expect(textWrapGroup.height).toBeGreaterThan( | ||
new TextWrap({ | ||
text: TEXT, | ||
maxWidth, | ||
fontSize: FONT_SIZE, | ||
}).height | ||
) | ||
}) | ||
|
||
it("should use all available space when one fragment exceeds the given max width", () => { | ||
const maxWidth = 150 | ||
const textWrap = new TextWrap({ | ||
text: "Long-word-that-can't-be-broken-up more words", | ||
maxWidth, | ||
fontSize: FONT_SIZE, | ||
}) | ||
const textWrapGroup = new TextWrapGroup({ | ||
fragments: [ | ||
{ text: "Long-word-that-can't-be-broken-up more words" }, | ||
{ text: "30 million" }, | ||
], | ||
maxWidth, | ||
fontSize: FONT_SIZE, | ||
}) | ||
expect(textWrap.width).toBeGreaterThan(maxWidth) | ||
expect(textWrapGroup.maxWidth).toEqual(textWrap.width) | ||
}) | ||
|
||
it("should place very long words in a separate line", () => { | ||
const maxWidth = 150 | ||
const textWrapGroup = new TextWrapGroup({ | ||
fragments: [ | ||
{ text: "30 million" }, | ||
{ text: "Long-word-that-can't-be-broken-up" }, | ||
], | ||
maxWidth, | ||
fontSize: FONT_SIZE, | ||
}) | ||
expect(textWrapGroup.lines.length).toEqual(2) | ||
|
||
const placedTextWrapOffsets = textWrapGroup.placedTextWraps.map( | ||
({ yOffset }) => yOffset | ||
) | ||
const lineOffsets = textWrapGroup.lines.map(({ yOffset }) => yOffset) | ||
expect(placedTextWrapOffsets).toEqual([0, 0]) | ||
expect(lineOffsets).toEqual([0, textWrapGroup.lineHeight * FONT_SIZE]) | ||
}) |
Oops, something went wrong.