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) prevent infinite loop #3694

Merged
merged 1 commit into from
Jun 6, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -905,19 +905,28 @@ export class DiscreteBarChart
const barHeight = this.approximateBarHeight

return this.series.map((series) => {
// make sure we're dealing with a single-line text fragment
const seriesName = series.seriesName.replace(/\n/g, " ").trim()

let label = new TextWrap({
text: series.seriesName,
text: seriesName,
maxWidth: this.boundsWithoutColorLegend.width * 0.3,
...this.legendLabelStyle,
})

// prevent labels from being taller than the bar
while (label.height > barHeight && label.lines.length > 1) {
let step = 0
while (
label.height > barHeight &&
label.lines.length > 1 &&
step < 10 // safety net
) {
label = new TextWrap({
text: series.seriesName,
text: seriesName,
maxWidth: label.maxWidth + 20,
...this.legendLabelStyle,
})
step += 1
}

return { ...series, label }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,19 +332,28 @@ export class StackedDiscreteBarChart
const barHeight = this.approximateBarHeight

return this.items.map((item) => {
// make sure we're dealing with a single-line text fragment
const entityName = item.entityName.replace(/\n/g, " ").trim()

let label = new TextWrap({
text: item.entityName,
text: entityName,
maxWidth: this.boundsWithoutLegend.width * 0.3,
...this.labelStyle,
})

// prevent labels from being taller than the bar
while (label.height > barHeight && label.lines.length > 1) {
let step = 0
while (
label.height > barHeight &&
label.lines.length > 1 &&
step < 10 // safety net
) {
label = new TextWrap({
text: item.entityName,
text: entityName,
maxWidth: label.maxWidth + 20,
...this.labelStyle,
})
step += 1
}

return { ...item, label }
Expand Down