Skip to content

Commit

Permalink
Clean up and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
leowrites committed Oct 9, 2024
1 parent 4ba787b commit 64c23a5
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 62 deletions.
6 changes: 3 additions & 3 deletions memory-viz/src/automate.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MemoryModel } from "./memory_model";
import { config } from "./config";
import { DisplaySettings, DrawnEntity, SortOptions } from "./types";
import { DisplaySettings, DrawnEntity, Size, SortOptions } from "./types";

/**
* Draws the objects given in the path in an automated fashion.
Expand Down Expand Up @@ -216,7 +216,7 @@ function drawAutomatedOtherItems(
let y_coord = config_aut.top_margin;

// Once a row is occupied, we must establish its height to determine the y-coordinate of the next row's boxes.
let row_height;
let row_height: number;
let curr_row_objects = [];
for (const item of objs) {
let hor_reach = x_coord + item.width + PADDING;
Expand Down Expand Up @@ -318,7 +318,7 @@ function separateObjects(objects: DrawnEntity[]): {
* @param {DrawnEntity} obj - an object as specified in MemoryModel.drawAll, except that coordinates are missing.
* @returns {object} the width and the height the drawn object would have.
*/
function getSize(obj: DrawnEntity): { height: number; width: number } {
function getSize(obj: DrawnEntity): Size {
// The x and y values here are unimportant; 'obj' must simply have these properties for processing by 'drawAll'.
obj.x = obj.x || 10;
obj.y = obj.y || 10;
Expand Down
4 changes: 2 additions & 2 deletions memory-viz/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { VizualizationOptions } from "./types";
import { VisualizationConfig } from "./types";

export const config: Partial<VizualizationOptions> = {
export const config: Partial<VisualizationConfig> = {
rect_style: { stroke: "rgb(0, 0, 0)" },
text_color: "rgb(0, 0, 0)", // Default text color
value_color: "rgb(27, 14, 139)", // Text color for primitive values
Expand Down
23 changes: 14 additions & 9 deletions memory-viz/src/memory_model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { config } from "./config";
import { DOMImplementation, XMLSerializer } from "@xmldom/xmldom";
import {
DrawnEntity,
VizualizationOptions,
VisualizationConfig,
Rect,
Primitive,
Style,
Expand Down Expand Up @@ -59,9 +59,9 @@ export class MemoryModel {
list_index_sep: number; // Vertical offset for list index labels
font_size: number; // Font size, in px
browser: boolean; // Whether this library is being used in a browser context
roughjs_config?: Config; // Configuration object used to pass in options to rough.js
roughjs_config: Config; // Configuration object used to pass in options to rough.js

constructor(options: Partial<VizualizationOptions>) {
constructor(options: Partial<VisualizationConfig>) {
if (options.browser) {
this.document = document;
} else {
Expand Down Expand Up @@ -232,7 +232,7 @@ export class MemoryModel {
style.box_container
);

let size = {
let size: Rect = {
width: box_width,
height: this.obj_min_height,
x: x,
Expand Down Expand Up @@ -390,7 +390,7 @@ export class MemoryModel {

this.drawRect(x, y, box_width, box_height, style.box_container);

const size = { width: box_width, height: box_height, x: x, y: y };
const size: Rect = { width: box_width, height: box_height, x: x, y: y };

if (immutable.includes(type)) {
this.drawRect(
Expand Down Expand Up @@ -493,7 +493,12 @@ export class MemoryModel {
style.box_container
);

const SIZE = { x, y, width: box_width, height: this.obj_min_height };
const SIZE: Rect = {
x,
y,
width: box_width,
height: this.obj_min_height,
};

let curr_x = x + this.item_min_width / 2;
let item_y =
Expand Down Expand Up @@ -615,7 +620,7 @@ export class MemoryModel {
}

this.drawRect(x, y, box_width, box_height, style.box_container);
const SIZE = { x, y, width: box_width, height: box_height };
const SIZE: Rect = { x, y, width: box_width, height: box_height };

// A second loop, so that we can position the colon and value boxes correctly.
curr_y = y + this.prop_min_height + this.item_min_height / 2;
Expand Down Expand Up @@ -706,7 +711,7 @@ export class MemoryModel {
}
this.drawRect(x, y, box_width, box_height, style.box_container);

const SIZE = { x, y, width: box_width, height: box_height };
const SIZE: Rect = { x, y, width: box_width, height: box_height };

// Draw element boxes.
let curr_y = y + this.prop_min_height + this.item_min_height / 2;
Expand Down Expand Up @@ -907,7 +912,7 @@ export class MemoryModel {
obj.x,
obj.y,
obj.name,
obj.id && obj.id.toString(),
String(obj.id),
obj.value,
is_frame,
obj.style
Expand Down
Loading

0 comments on commit 64c23a5

Please sign in to comment.