Skip to content

Commit 9bea2e4

Browse files
authored
Resizing plots horizontally (#2747)
* Add resizers to plots grid * Resize plots horizontally * Fix tests * Fix linting issues * Get plot container size correctly * Fix tests * Fix resizing items from postitions other than first * Apply review comments
1 parent c049d6b commit 9bea2e4

25 files changed

+634
-326
lines changed

.eslintrc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ module.exports = {
2828
'@typescript-eslint/no-unsafe-return': 'off',
2929
'no-undef': 'off',
3030
'sonarjs/no-duplicate-string': 'off',
31-
'testing-library/no-render-in-setup': 'off'
31+
'testing-library/no-render-in-setup': 'off',
32+
'testing-library/render-result-naming-convention': 'off'
3233
}
3334
},
3435
{

extension/src/plots/model/index.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,18 @@ export class PlotsModel extends ModelWithPersistence {
287287
}
288288

289289
public getPlotSize(section: Section) {
290-
return this.plotSizes[section] || PlotSizeNumber.REGULAR
290+
if (
291+
this.plotSizes[section] &&
292+
[
293+
PlotSizeNumber.LARGE,
294+
PlotSizeNumber.REGULAR,
295+
PlotSizeNumber.SMALL,
296+
PlotSizeNumber.SMALLER
297+
].includes(this.plotSizes[section])
298+
) {
299+
return this.plotSizes[section]
300+
}
301+
return PlotSizeNumber.REGULAR
291302
}
292303

293304
public setSectionCollapsed(newState: Partial<SectionCollapsed>) {

extension/src/plots/vega/util.test.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ describe('extendVegaSpec', () => {
139139

140140
it('should truncate all titles from the left to 50 characters for large plots', () => {
141141
const spec = withLongTemplatePlotTitle()
142-
const updatedSpec = extendVegaSpec(spec, 500)
142+
const updatedSpec = extendVegaSpec(spec, PlotSizeNumber.LARGE)
143143

144144
const truncatedTitle = '…-many-many-characters-at-least-seventy-characters'
145145
const truncatedHorizontalTitle =
@@ -191,7 +191,7 @@ describe('extendVegaSpec', () => {
191191

192192
it('should truncate all titles from the left to 30 characters for small plots', () => {
193193
const spec = withLongTemplatePlotTitle()
194-
const updatedSpec = extendVegaSpec(spec, 300)
194+
const updatedSpec = extendVegaSpec(spec, PlotSizeNumber.SMALL)
195195

196196
const truncatedTitle = '…s-at-least-seventy-characters'
197197
const truncatedHorizontalTitle = '…at-least-seventy-characters-x'
@@ -221,7 +221,7 @@ describe('extendVegaSpec', () => {
221221
text: repeatedTitle
222222
})
223223

224-
const updatedSpec = extendVegaSpec(spec, 300)
224+
const updatedSpec = extendVegaSpec(spec, PlotSizeNumber.SMALL)
225225

226226
const truncatedTitle = '…ghijklmnopqrstuvwyz1234567890'
227227

@@ -238,7 +238,7 @@ describe('extendVegaSpec', () => {
238238
const repeatedTitle = 'abcdefghijklmnopqrstuvwyz1234567890'
239239
const spec = withLongTemplatePlotTitle([repeatedTitle, repeatedTitle])
240240

241-
const updatedSpec = extendVegaSpec(spec, 300)
241+
const updatedSpec = extendVegaSpec(spec, PlotSizeNumber.SMALL)
242242

243243
const truncatedTitle = '…ghijklmnopqrstuvwyz1234567890'
244244

@@ -258,7 +258,7 @@ describe('extendVegaSpec', () => {
258258
text: [repeatedTitle, repeatedTitle]
259259
})
260260

261-
const updatedSpec = extendVegaSpec(spec, 300)
261+
const updatedSpec = extendVegaSpec(spec, PlotSizeNumber.SMALL)
262262

263263
const truncatedTitle = '…ghijklmnopqrstuvwyz1234567890'
264264

@@ -272,13 +272,17 @@ describe('extendVegaSpec', () => {
272272
})
273273

274274
it('should update the multi-source template to remove erroneous shape encoding from the vertical line displayed on hover', () => {
275-
const updatedSpec = extendVegaSpec(multiSourceTemplate, 500, {
276-
color: { domain: [], range: [] },
277-
shape: {
278-
field: 'field',
279-
scale: { domain: [], range: [] }
275+
const updatedSpec = extendVegaSpec(
276+
multiSourceTemplate,
277+
PlotSizeNumber.LARGE,
278+
{
279+
color: { domain: [], range: [] },
280+
shape: {
281+
field: 'field',
282+
scale: { domain: [], range: [] }
283+
}
280284
}
281-
})
285+
)
282286

283287
expect(updatedSpec.encoding).not.toBeUndefined()
284288
expect(updatedSpec.layer[1].layer[0].encoding.shape).toBeNull()

extension/src/plots/vega/util.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ const truncateTitleAsArrayOrString = (title: Text, size: number) => {
216216
const TitleLimit = {
217217
[PlotSizeNumber.LARGE]: 50,
218218
[PlotSizeNumber.REGULAR]: 50,
219-
[PlotSizeNumber.SMALL]: 30
219+
[PlotSizeNumber.SMALL]: 30,
220+
[PlotSizeNumber.SMALLER]: 30
220221
}
221222

222223
const truncateTitlePart = (

extension/src/plots/webview/contract.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import { VisualizationSpec } from 'react-vega'
22
import { Color } from '../../experiments/model/status/colors'
33

44
export const PlotSizeNumber = {
5-
LARGE: 500,
6-
REGULAR: 400,
7-
SMALL: 300
5+
LARGE: 1,
6+
REGULAR: 2,
7+
SMALL: 3,
8+
SMALLER: 4
89
}
910

1011
export enum Section {

0 commit comments

Comments
 (0)