From 28adf502caa80efc3845cf070a0f8fc861e288b8 Mon Sep 17 00:00:00 2001 From: yoonie-jang Date: Sat, 29 Jun 2024 20:54:43 -0400 Subject: [PATCH] Add review changes --- memory-viz/src/automate.ts | 9 +++++---- memory-viz/src/tests/draw.spec.tsx | 10 +++++++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/memory-viz/src/automate.ts b/memory-viz/src/automate.ts index bdf9b273..3e3e295b 100644 --- a/memory-viz/src/automate.ts +++ b/memory-viz/src/automate.ts @@ -31,9 +31,9 @@ function drawAutomated(objects: DrawnEntity[], width, configuration) { min_width += requiredWidth + 2 * configuration.padding + 1; if (width < min_width) { - console.log( - `WARNING: provided width (${width}) is smaller than the minimum width` + - ` of the canvas (${min_width}). The provided width has been overwritten` + + console.warn( + `WARNING: provided width (${width}) is smaller than the required width` + + ` (${min_width}). The provided width has been overwritten` + ` in the generated diagram.` ); width = min_width; @@ -119,7 +119,7 @@ function drawAutomatedStackFrames(stack_frames: DrawnEntity[], configuration) { min_required_height = height + min_required_height; } - required_width += configuration.left_margin; + required_width += configuration.padding; return { StackFrames: draw_stack_frames, @@ -209,6 +209,7 @@ function drawAutomatedOtherItems( let curr_row_objects = []; for (const item of objs) { let hor_reach = x_coord + item.width + PADDING; + if (hor_reach < max_width) { item.x = x_coord; item.y = y_coord; diff --git a/memory-viz/src/tests/draw.spec.tsx b/memory-viz/src/tests/draw.spec.tsx index 7c413db0..141c5a71 100644 --- a/memory-viz/src/tests/draw.spec.tsx +++ b/memory-viz/src/tests/draw.spec.tsx @@ -775,12 +775,20 @@ describe("draw function", () => { style: ["highlight"], }, ]; - const spy = jest.spyOn(global.console, "log"); + const spy = jest.spyOn(global.console, "warn"); draw(objects, true, { width: 13, roughjs_config: { options: { seed: 12345 } }, }); expect(spy).toHaveBeenCalledTimes(1); + console.log(spy.mock.calls[0][0]); + + const message = new RegExp( + "^WARNING: provided width \\(\\d+\\) is smaller than " + + "the required width \\(\\d+\\). The provided width has been overwritten " + + "in the generated diagram.$" + ); + expect(message.test(spy.mock.calls[0][0])).toBe(true); spy.mockRestore(); });