mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-10-07 22:58:12 +08:00
tweak truncation method
This commit is contained in:
@@ -43,7 +43,7 @@ export default class Truncate extends Component {
|
|||||||
const shortenedString =
|
const shortenedString =
|
||||||
length === str.length - 1
|
length === str.length - 1
|
||||||
? str
|
? str
|
||||||
: `${str.slice(0, length)}…${str.slice(-length / 2)}`;
|
: `${str.slice(0, length)}…${str.slice(-length)}`;
|
||||||
// Measure the size of that string
|
// Measure the size of that string
|
||||||
const renderedSize = pixelWidth(shortenedString, params);
|
const renderedSize = pixelWidth(shortenedString, params);
|
||||||
|
|
||||||
@@ -53,13 +53,13 @@ export default class Truncate extends Component {
|
|||||||
}
|
}
|
||||||
// Base case: If we've narrowed down to a length, return the closest string
|
// Base case: If we've narrowed down to a length, return the closest string
|
||||||
if (length === lastLength) {
|
if (length === lastLength) {
|
||||||
return `${str.slice(0, close)}…${str.slice(-close / 2)}`;
|
return `${str.slice(0, close)}…${str.slice(-close)}`;
|
||||||
}
|
}
|
||||||
// If the current size is longer than max
|
// If the current size is longer than max
|
||||||
if (renderedSize > maxSize) {
|
if (renderedSize > maxSize) {
|
||||||
// If we're only one off from the closest string so far, just return the closest string
|
// If we're only one off from the closest string so far, just return the closest string
|
||||||
if (length - close === 1) {
|
if (length - close === 1) {
|
||||||
return `${str.slice(0, close)}…${str.slice(-close / 2)}`;
|
return `${str.slice(0, close)}…${str.slice(-close)}`;
|
||||||
}
|
}
|
||||||
// Otherwise recursively call with half the current length
|
// Otherwise recursively call with half the current length
|
||||||
return this.computeLargestTruncatedString(
|
return this.computeLargestTruncatedString(
|
||||||
|
|||||||
Reference in New Issue
Block a user