Entity Specification
The draw function has an objects argument which is used to define the array of entities (type DrawnEntity) to be rendered on the canvas.
This page documents the attributes of the DrawnEntity object type and provides examples for the different kinds of entities supported by MemoryViz.
Core Attributes
All supported entities include the following core attributes, unless explicitly stated otherwise:
| Attribute | Type | Description |
|---|---|---|
type | string | Specifies the type of object to be drawn. (e.g., .class, .frame, int, str). See Entity Type for more details. |
id | number or null | A unique identifier for the object (duplicate IDs will emit a warning). May be null anywhere to render a blank ID box. |
value | Varies | The content of the object to be drawn. Format and type depends on the entity type. |
x, y | number | The x and y coordinates for the object on the canvas. Will be automatically calculated if not provided. |
width, height | number | The height and width for the object. Will be automatically calculated if not provided. If defined height and/or width is smaller than the minimum required for the object, then they will be overwritten. |
style | object or array | Custom visual styling. See Style API for more details. |
Entity Type
| Type Value | Description |
|---|---|
int, float, str, bool, None, complex, bytes, range, datetime.date | Primitives |
list, tuple | Sequences |
set, frozenset | Sets |
dict | Dictionaries |
.class | Classes |
.frame | Stack Frames |
.blank .blank-frame | Blank Objects |
Primitives
| Attribute | Type | Default | Description |
|---|---|---|---|
type | string | -- | Must be set to one of int, str, bool, float, or None to indicate a primitive object. |
value | See below | null | The actual value represented by the primitive object. To render an empty box, set the value as null or don't define it. |
type | type of value |
|---|---|
int, float | number |
str | string |
bool | boolean |
None, complex, bytes, range, datetime.date | string |
Examples
Integer
[
{
"type": "int",
"id": 19,
"value": 124
}
]
Blank integer
[
{
"type": "int",
"id": 19,
"value": ""
}
]
String
[
{
"type": "str",
"id": 43,
"value": "David is cool"
}
]
Boolean
[
{
"type": "bool",
"id": 32,
"value": true
}
]
Float
[
{
"type": "float",
"id": 76,
"value": 3.14
}
]
Blank float
[
{
"type": "float",
"id": 76,
"value": ""
}
]
None
[
{
"type": "None",
"id": 0,
"value": "None"
}
]
Complex
[
{
"type": "complex",
"id": 76,
"value": "(4+2j)"
}
]
Range
[
{
"type": "range",
"id": 76,
"value": "range(0, 5)"
}
]
Bytes
[
{
"type": "bytes",
"id": 76,
"value": "b'\\x00\\x00'"
}
]
Date
[
{
"type": "date",
"id": 76,
"value": "2019-12-04"
}
]
Empty Box
[
{
"type": "bool",
"id": 0,
"value": null
}
]
Sequences
| Attribute | Type | Default | Description |
|---|---|---|---|
type | string | -- | Must be set to list to indicate a list object, or tuple to indicate a tuple object. |
value | array of number or null | [] | List of object ids (unresolved IDs will emit a warning). Values can be made null to draw blank boxes. |
show_indexes | boolean | false | Indicates whether to show indices in the memory box. |
Examples
List with blank boxes
[
{
"type": "list",
"id": 82,
"value": [19, 43, null, 49]
}
]
List with indices shown
[
{
"type": "list",
"id": 84,
"value": [32, 10, 90, 57],
"show_indexes": true
}
]
Tuple with blank boxes
[
{
"type": "tuple",
"id": 11,
"value": [82, 76, null]
}
]
Tuple with indices shown
[
{
"type": "tuple",
"id": 11,
"value": [82, 76, null],
"show_indexes": true
}
]
Sets
| Attribute | Type | Default | Description |
|---|---|---|---|
type | string | -- | Must be set to set to indicate a set object. |
value | array of number or null | [] | List of object ids (unresolved IDs will emit a warning). Values can be made null to draw blank boxes. |
Examples
Set with blank boxes
[
{
"type": "set",
"id": 90,
"value": [36, 49, null, 64]
}
]
Set with large width
[
{
"type": "set",
"id": 32,
"value": [10, 11, 12],
"width": 500
}
]
Frozenset
[
{
"type": "frozenset",
"id": 90,
"value": [36, 49, 72, 64]
}
]
Frozenset with blank boxes
[
{
"type": "frozenset",
"id": 90,
"value": [null, 16, null, 84]
}
]
Dictionaries
| Attribute | Type | Default | Description |
|---|---|---|---|
type | string | -- | Must be set to dict to indicate a dictionary object. |
value | dict or array of number or null | {} | Dictionary of string object id keys to int object id value pairs or a list of two-element lists, where each inner list is in the form [key id, value id] (unresolved IDs will emit a warning). Keys can be made empty or all-whitespace strings and values can be made null to draw blank boxes. |
Examples
Dictionary with blank boxes
[
{
"type": "dict",
"id": 10,
"value": {
"": 81,
"1": null,
" ": 12
}
}
]
Dictionary with large height
[
{
"type": "dict",
"id": 10,
"value": { "x": 81, "y": 100, "z": 121 },
"height": 600
}
]
Dictionary with value specified using a list
[
{
"type": "dict",
"id": 10,
"value": [
["", 81],
["1", null],
["", 12]
]
}
]
Classes
| Attribute | Type | Default | Description |
|---|---|---|---|
type | string | -- | Must be set to .class to indicate a class object. |
name | string | "" | The name of the class being drawn. |
value | dict of string to number or null | {} | A mapping of attribute names (as keys) to object IDs (as values). Unresolved IDs will emit a warning. Attribute names may be empty or all-whitespace strings and attribute values may be null to render blank boxes, respectively. |
Examples
Class with blank boxes
[
{
"type": ".class",
"id": 82,
"name": "Person",
"value": {
"age": 12,
"name": 17,
"": null
}
}
]
Stack Frames
| Attribute | Type | Default | Description |
|---|---|---|---|
type | string | -- | Must be .frame to indicate a stack frame. |
name | string | "" | The name of the stack frame (e.g., __main__, foo) |
value | dict of string to number or null | {} | A mapping of variable names (as keys) to object IDs (as values). Unresolved IDs will emit a warning. These represent the local variables in the scope of the frame. Variable names may be empty or all-whitespace strings and attribute values may be null to render blank boxes, respectively. |
Note: Stack frames do not have an id field.
Examples
Main stack frame
[
{
"type": ".frame",
"name": "__main__",
"value": {
"lst1": 82,
"lst2": 84,
"p": 99,
"d": 10,
"t": 11
}
},
{
"type": ".blank",
"width": 200,
"height": 100
}
]
Function stack frame with blank boxes
[
{
"type": ".frame",
"name": "func",
"value": {
"age": 12,
"name": 17,
"": null
}
},
{
"type": ".blank",
"width": 200,
"height": 100
}
]
Blank Objects
| Attribute | Type | Default | Description |
|---|---|---|---|
type | string | -- | Must be set to .blank to indicate a blank object, or .blank-frame to indicate a blank frame. |
width | number | 0 | The width of the blank object/frame. |
height | number | 0 | The height of the blank object/frame. |
Examples
Blank object
{
"type": ".blank",
"width": 200,
"height": 100
}
Blank frame
{
"type": ".blank-frame",
"width": 200,
"height": 100
}