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

Clean up factor range and add factor method #14037

Merged
merged 15 commits into from
Aug 27, 2024
Prev Previous commit
Next Next commit
use switch for range.levels
  • Loading branch information
bryevdv committed Aug 23, 2024
commit 59216a86292a856621804fc39391d090a3ac0284
39 changes: 23 additions & 16 deletions bokehjs/src/lib/models/axes/categorical_axis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,22 +109,29 @@ export class CategoricalAxisView extends AxisView {
return map(this.model.formatter.doFormat(ticks, this))
}

if (range.levels == 1) {
const major = ticks.major as L1Factor[]
const labels = format(major)
info.push([labels, coords.major, this.model.major_label_orientation, this.visuals.major_label_text])
} else if (range.levels == 2) {
const major = (ticks.major as L2Factor[]).map((x) => x[1])
const labels = format(major)
info.push([labels, coords.major, this.model.major_label_orientation, this.visuals.major_label_text])
info.push([map(ticks.tops as string[]), coords.tops, this.model.group_label_orientation, this.visuals.group_text])
} else if (range.levels == 3) {
const major = (ticks.major as L3Factor[]).map((x) => x[2])
const labels = format(major)
const mid_labels = ticks.mids.map((x) => x[1])
info.push([labels, coords.major, this.model.major_label_orientation, this.visuals.major_label_text])
info.push([map(mid_labels), coords.mids, this.model.subgroup_label_orientation, this.visuals.subgroup_text])
info.push([map(ticks.tops as string[]), coords.tops, this.model.group_label_orientation, this.visuals.group_text])
switch (range.levels) {
case 1: {
const major = ticks.major as L1Factor[]
const labels = format(major)
info.push([labels, coords.major, this.model.major_label_orientation, this.visuals.major_label_text])
break
}
case 2: {
const major = (ticks.major as L2Factor[]).map((x) => x[1])
const labels = format(major)
info.push([labels, coords.major, this.model.major_label_orientation, this.visuals.major_label_text])
info.push([map(ticks.tops as L1Factor[]), coords.tops, this.model.group_label_orientation, this.visuals.group_text])
break
}
case 3: {
const major = (ticks.major as L3Factor[]).map((x) => x[2])
const labels = format(major)
const mid_labels = ticks.mids.map((x) => x[1])
info.push([labels, coords.major, this.model.major_label_orientation, this.visuals.major_label_text])
info.push([map(mid_labels), coords.mids, this.model.subgroup_label_orientation, this.visuals.subgroup_text])
info.push([map(ticks.tops as L1Factor[]), coords.tops, this.model.group_label_orientation, this.visuals.group_text])
break
}
}

return info
Expand Down
Loading