Skip to content

Commit

Permalink
Calculate plot size based on the number of categories. If a plot thic…
Browse files Browse the repository at this point in the history
…kness is specified use it instead
  • Loading branch information
airenzp authored and xzhou82 committed Feb 25, 2025
1 parent 721df00 commit 1a612f6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
1 change: 0 additions & 1 deletion client/plots/singleCellPlot.js
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,6 @@ class singleCellPlot {
plots: [
{
chartType: 'violin',
settings: { violin: { plotThickness: 90 } },
term: {
$id: await digestMessage(`${gene}-${this.state.config.sample}-${this.state.config.experimentID}`),
term: {
Expand Down
5 changes: 2 additions & 3 deletions client/plots/violin.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,12 @@ class ViolinPlot {
},
{
label: 'Plot thickness',
title: 'Thickness of plots, can be between 40 and 200',
title: 'If not specified, the plot thickness is calculated based on the number of categories',
type: 'number',
chartType: 'violin',
settingsKey: 'plotThickness',
step: 10,
max: 500,
max: 200,
min: 40,
debounceInterval: 1000
},
Expand Down Expand Up @@ -389,7 +389,6 @@ export function getDefaultViolinSettings(app, overrides = {}) {
lines: [],
unit: 'abs', // abs: absolute scale, log: log scale
rowSpace: 10,
plotThickness: 130,
medianLength: 7,
medianThickness: 3,
ticks: 20,
Expand Down
12 changes: 9 additions & 3 deletions client/plots/violin.renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ export default function setViolinRenderer(self) {
const svgData = renderSvg(t1, self, isH, settings)
renderScale(t1, t2, settings, isH, svgData, self)
let y = self.settings.rowSpace
const thickness = self.settings.plotThickness || self.getAutoThickness()
for (const [plotIdx, plot] of self.data.plots.entries()) {
const plotThickness = self.settings.plotThickness
// The scale uses half of the plotThickness as the maximum value as the image is symmetrical
// Only one half of the image is computed and the other half is mirrored
const wScale = scaleLinear()
.domain([plot.density.densityMax, plot.density.densityMin])
.range([plotThickness / 2, 0])
.range([thickness / 2, 0])
let areaBuilder
//when doing this interpolation, the violin plot will be smoother and some padding may be added
//between the plot and the axis
Expand Down Expand Up @@ -109,9 +109,15 @@ export default function setViolinRenderer(self) {
td2.style('text-align', 'center').text(stat.value ?? 0)
}
}
self.getAutoThickness = function () {
if (self.data.plots.length === 1) return 150
const count = self.data.plots.length
return Math.min(130, Math.max(60, 600 / count)) //clamp between 60 and 130
}

self.getPlotThicknessWithPadding = function () {
return self.settings.plotThickness + self.settings.rowSpace
const plotThickness = self.settings.plotThickness || self.getAutoThickness()
return plotThickness + self.settings.rowSpace
}

self.renderPvalueTable = function () {
Expand Down

0 comments on commit 1a612f6

Please sign in to comment.