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

Make isClass optional #35

Merged
merged 8 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ and adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
- Added data type and manual layout tests for the `draw` function.
- Updated file paths for example files under docs to import the correct file.
- Added style and automatic layout tests for the `draw` function.
- Updated documentation, tests, and examples to reflect the `isClass` attribute being optional and set to `false` by default.

## [0.1.0] - 2024-04-16

Expand Down
2 changes: 0 additions & 2 deletions demo/src/__tests__/SvgDisplay.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,12 @@ describe("SvgDisplay", () => {
stack_frame: true,
},
{
isClass: false,
name: "str",
id: 19,
value: "David is cool!",
style: ["highlight"],
},
{
isClass: false,
name: "int",
id: 13,
value: 7,
Expand Down
3 changes: 1 addition & 2 deletions demo/src/sample/automated-layout/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
"stack_frame": true
},
{
"isClass": false,
"name": "list",
"id": 84,
"value": [32, 10, 90, 57],
"show_indexes": true
},
{ "isClass": false, "name": "None", "id": 13, "value": "None" }
{ "name": "None", "id": 13, "value": "None" }
]
6 changes: 0 additions & 6 deletions demo/src/sample/blanks/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,17 @@
"stack_frame": true
},
{
"isClass": false,
"name": "list",
"id": 82,
"value": [19, 43, 28, 49]
},
{
"isClass": false,
"name": "list",
"id": 84,
"value": [32, 10, 90, 57],
"show_indexes": true
},
{
"isClass": false,
"name": "int",
"id": 19,
"value": 1969
Expand All @@ -44,13 +41,11 @@
"height": 200
},
{
"isClass": false,
"name": "bool",
"id": 32,
"value": true
},
{
"isClass": false,
"name": "str",
"id": 43,
"value": "David is cool"
Expand All @@ -61,7 +56,6 @@
"height": 150
},
{
"isClass": false,
"name": "tuple",
"id": 11,
"value": [82, 76]
Expand Down
3 changes: 0 additions & 3 deletions demo/src/sample/manual-layout/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,20 @@
"stack_frame": true
},
{
"isClass": false,
"x": 1050,
"y": 500,
"name": "dict",
"id": 10,
"value": { "x": 81, "y": 100, "z": 121 }
},
{
"isClass": false,
"x": 1050,
"y": 40,
"name": "tuple",
"id": 11,
"value": [82, 76]
},
{
"isClass": false,
"x": 750,
"y": 250,
"name": "bool",
Expand Down
2 changes: 0 additions & 2 deletions demo/src/sample/simple/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@
"stack_frame": true
},
{
"isClass": false,
"name": "str",
"id": 19,
"value": "David is cool!",
"style": ["highlight"]
},
{
"isClass": false,
"name": "int",
"id": 13,
"value": 7
Expand Down
5 changes: 0 additions & 5 deletions demo/src/sample/styling/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"style": ["highlight"]
},
{
"isClass": false,
"x": 350,
"y": 350,
"name": "list",
Expand All @@ -21,7 +20,6 @@
}
},
{
"isClass": false,
"x": 750,
"y": 500,
"name": "str",
Expand All @@ -30,15 +28,13 @@
"style": "highlight"
},
{
"isClass": false,
"x": 1050,
"y": 260,
"name": "set",
"id": 90,
"value": [36, 49, 64]
},
{
"isClass": false,
"x": 1050,
"y": 500,
"name": "dict",
Expand All @@ -47,7 +43,6 @@
"style": { "text_id": { "font-style": "italic" } }
},
{
"isClass": false,
"x": 750,
"y": 750,
"name": "None",
Expand Down
54 changes: 33 additions & 21 deletions docs/docs/02-object_structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ the array of objects to be drawn.
To be successfully rendered, the array must contain objects that strictly follow a specific structure. Every object
must contain the following attributes:

- `isClass` - `boolean`: denotes whether the object to be drawn is a user-defined class (or a stack-frame) or a built-in
object. Pass true to draw a class or a stack-frame, and false to draw any built-in types.
- `isClass` - `boolean`: denotes whether the object to be drawn is a user-defined class (or a stack frame) or a built-in
object. This has a default value of `false` and should be manually set to `true` only when drawing a class or stack frame.
- `name` - `string`: denotes the type of the object to draw (if `isClass===true`, then this is the name of the
corresponding class or stackframe).
- If the user want to hardcode the coordinates (implying the `automation` parameter of `draw` is false), each object
corresponding class or stack frame).
- If the user wants to hardcode the coordinates (implying the `automation` parameter of `draw` is false), each object
must include `x` and `y` attributes (for x-y coordinates).
- `id` - `string`|`number`: denotes the id value of this object. If we are to draw a StackFrame, then this MUST be `null`.
- `id` - `string`|`number`: denotes the id value of this object. If we are to draw a stack frame, then this MUST be `null`.
- `value` - `*`: denotes the value of the object. This could be anything, from an empty string to a JS object,
which would be passed for the purpose of drawing a user-defined class object, a
stackframe, or a dictionary.
**Note that in such cases where we want to do draw a 'container'
stack frame, or a dictionary.
**Note that in such cases where we want to draw a 'container'
object (an object that contains other objects), we pass a _JS object_ where the keys are the
attributes/variables and the values are the id's of the corresponding objects (not the
objects themselves)**.
- `stack_frame` - `boolean`: denotes whether a stack frame will be drawn or not. NOTE that this is only
applicable if the object's `isClass` attribute is true (since the
`MemoryModel.drawClass` covers both classes and stack-frames). By default,
applicable if the object's `isClass` attribute is `true` (since the
`MemoryModel.drawClass` covers both classes and stack frames). By default,
`stack_frame` is set to null (_which is false_).
- `show_indexes` - `boolean`: This is applicable only when drawing tuples or lists (when drawSequence
method will be used). It denotes whether the memory box of the underlying
Expand All @@ -40,31 +40,43 @@ must contain the following attributes:
### Examples

```javascript
{"isClass": true, "name": "__main__", "id": null, "value": {"lst1": 82, "lst2": 84, "p": 99, "d": 10, "t": 11}, "stack_frame": true},
{"name": "BLANK", "width": 100, "height": 200, "stack_frame" : true},
{"isClass": true, "name": "func", "id": null, "value": {"age": 12, "name": 17}, "stack_frame": true},
{
"isClass": true,
"name": "__main__",
"id": null,
"value": {"lst1": 82, "lst2": 84, "p": 99, "d": 10, "t": 11},
"stack_frame": true
}

{
"isClass": true,
"name": "func",
"id": null,
"value": {"age": 12, "name": 17},
"stack_frame": true
}

{"name": "BLANK", "width": 100, "height": 200, "stack_frame" : true}

{"isClass": false, "name": "list", "id": 82, "value": [19, 43, 28, 49]}
{"name": "list", "id": 82, "value": [19, 43, 28, 49]}

{"isClass": false, "name": "list", "id": 84, "value": [32, 10, 90, 57], "show_indexes": true}
{"name": "list", "id": 84, "value": [32, 10, 90, 57], "show_indexes": true}

{"isClass": false, "name": "int", "id": 19, "value": 1969}
{"name": "int", "id": 19, "value": 1969}

{"isClass": false, "name": "bool", "id": 32, "value": true}
{"name": "bool", "id": 32, "value": true}

{"name": "BLANK", "width": 200, "height": 100}

{"isClass": false, "name": "str", "id": 43, "value": "David is cool"}
{"name": "str", "id": 43, "value": "David is cool"}

{"isClass": false, "name": "tuple", "id": 11, "value": [82, 76]}
{"name": "tuple", "id": 11, "value": [82, 76]}

{"isClass": false, "name": "set", "id": 90, "value": [36, 49, 64]}
{"name": "set", "id": 90, "value": [36, 49, 64]}

{"isClass": false, "name": "dict", "id": 10, "value": {"x": 81, "y": 100, "z": 121}}
{"name": "dict", "id": 10, "value": {"x": 81, "y": 100, "z": 121}}

{"isClass": false, "name": "None", "id": 13, "value": "None",
{"name": "None", "id": 13, "value": "None",
"style": {
"text_value" : {"font-style": "italic"},
"box_id": {"fill": "red", "fillStyle": "dots"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
"stack_frame": true
},
{
"isClass": false,
"name": "list",
"id": 84,
"value": [32, 10, 90, 57],
"show_indexes": true
},
{ "isClass": false, "name": "None", "id": 13, "value": "None" }
{ "name": "None", "id": 13, "value": "None" }
]
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ const listOfObjs = [
value: { age: 12, name: 17 },
stack_frame: false,
},
{ isClass: false, name: "list", id: 82, value: [19, 43, 28, 49] },
{ isClass: false, name: "int", id: 19, value: 1969 },
{ name: "list", id: 82, value: [19, 43, 28, 49] },
{ name: "int", id: 19, value: 1969 },
];

const { objs, canvas_height, canvas_width } = drawAutomatedOtherItems(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,7 @@
* - ~/examples/automation_demo/more_specific_demos/draw_automated.svg
*/

const {
sarahsonder marked this conversation as resolved.
Show resolved Hide resolved
drawAutomated,
separateJSON,
getSize,
drawAutomatedOtherItems,
MemoryModel,
} = require("memory-viz");
const { drawAutomated } = require("memory-viz");
const fs = require("fs");

const WIDTH = 1300;
Expand Down
11 changes: 5 additions & 6 deletions docs/docs/99-api/examples/blankspaces_demo/blankspaces_demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,19 @@ const listOfObjs = [
value: { age: 12, name: 17 },
stack_frame: true,
},
{ isClass: false, name: "list", id: 82, value: [19, 43, 28, 49] },
{ name: "list", id: 82, value: [19, 43, 28, 49] },
{
isClass: false,
name: "list",
id: 84,
value: [32, 10, 90, 57],
show_indexes: true,
},
{ isClass: false, name: "int", id: 19, value: 1969 },
{ name: "int", id: 19, value: 1969 },
{ name: "BLANK", width: 100, height: 200 },
{ isClass: false, name: "bool", id: 32, value: true },
{ isClass: false, name: "str", id: 43, value: "David is cool" },
{ name: "bool", id: 32, value: true },
{ name: "str", id: 43, value: "David is cool" },
{ name: "BLANK", width: 200, height: 150 },
{ isClass: false, name: "tuple", id: 11, value: [82, 76] },
{ name: "tuple", id: 11, value: [82, 76] },
];

const configuration = {
Expand Down
3 changes: 0 additions & 3 deletions docs/docs/99-api/examples/manual_demo/manual_demo.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,20 @@
"stack_frame": true
},
{
"isClass": false,
"x": 1050,
"y": 500,
"name": "dict",
"id": 10,
"value": { "x": 81, "y": 100, "z": 121 }
},
{
"isClass": false,
"x": 1050,
"y": 40,
"name": "tuple",
"id": 11,
"value": [82, 76]
},
{
"isClass": false,
"x": 750,
"y": 250,
"name": "bool",
Expand Down
3 changes: 1 addition & 2 deletions docs/docs/99-api/examples/simple_demo/simple_demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ const objects = [
stack_frame: true,
},
{
isClass: false,
name: "str",
id: 19,
value: "David is cool!",
style: ["highlight"],
},
{ isClass: false, name: "int", id: 13, value: 7 },
{ name: "int", id: 13, value: 7 },
];

const m = draw(objects, true, { width: 1300 });
Expand Down
6 changes: 1 addition & 5 deletions docs/docs/99-api/examples/style_demo/nostyle_demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,38 +30,34 @@ const objs = [
stack_frame: true,
},
{
isClass: false,
x: 350,
y: 350,
name: "list",
id: 54,
value: [19, 43, 28, 49],
},
{
isClass: false,
x: 750,
y: 500,
name: "str",
id: 43,
value: "David is cool",
},
{
isClass: false,
x: 1050,
y: 260,
name: "set",
id: 90,
value: [36, 49, 64],
},
{
isClass: false,
x: 1050,
y: 500,
name: "dict",
id: 10,
value: { x: 81, y: 100, z: 121 },
},
{ isClass: false, x: 750, y: 750, name: "None", id: 13, value: "None" },
{ x: 750, y: 750, name: "None", id: 13, value: "None" },
];

const m = draw(objs, true, configuration);
Expand Down
Loading
Loading