Skip to main content

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:

AttributeTypeRequiredDescription
typestringYesSpecifies the type of object to be drawn. (e.g., .class, .frame, int, str). See Entity Type for more details.
idnumber or nullYesA unique identifier for the object. May be null anywhere to render a blank ID box.
valueanyYesThe content of the object to be drawn. Format depends on the entity type.
x, ynumberNoThe x and y coordinates for the object on the canvas. Required only if the automation parameter of draw is false.
styleobject or arrayNoCustom visual styling. See Style API for more details.
width, heightnumberNoThe height and width for the object. If defined height and width is smaller than the automatically calculated, then it will be overwritten.

Entity Type

Type ValueDescription
int, float, str, bool, NonePrimitives
list, tupleSequences
setSets
dictDictionaries
.classClasses
.frameStack Frames
.blank .blank-frameBlank Objects

Primitives

AttributeTypeRequiredDescription
typestringYesMust be set to one of int, str, bool, float, or None to indicate a primitive object.
idnumberYesUnique identifier for the primitive object.
valueanyNoThe actual value represented by the primitive object. To render an empty box, set the value as null or don't define it.
x, ynumberNoOptional manual coordinates. Required only if automation is disabled.
styleobject or arrayNoCustom visual styling.
width, heightnumberNoThe height and width for the primitive object.

Examples

Integer
[
{
"type": "int",
"id": 19,
"value": 124
}
]
Example IntegerExample Integer
Blank integer
[
{
"type": "int",
"id": 19,
"value": ""
}
]
Example Blank IntegerExample Blank Integer
String
[
{
"type": "str",
"id": 43,
"value": "David is cool"
}
]
Example StringExample String
Boolean
[
{
"type": "bool",
"id": 32,
"value": true
}
]
Example BooleanExample Boolean
Float
[
{
"type": "float",
"id": 76,
"value": 3.14
}
]
Example FloatExample Float
Blank float
[
{
"type": "float",
"id": 76,
"value": ""
}
]
Example Blank FloatExample Blank Float
None
[
{
"type": "None",
"id": 0,
"value": "None"
}
]
Example NoneExample None
Empty Box
[
{
"type": "bool",
"id": 0,
"value": null
}
]
Example Empty BoxExample Empty Box

Sequences

AttributeTypeRequiredDescription
typestringYesMust be set to list to indicate a list object, or tuple to indicate a tuple object.
idnumberYesUnique identifier for the sequence.
valuearrayYesList of object ids. Values can be made null to draw blank boxes.
show_indexesbooleanNoIndicates whether to show indices in the memory box. Defaults to false.
x, ynumberNoOptional manual coordinates. Required only if automation is disabled.
styleobject or arrayNoCustom visual styling.
width, heightnumberNoThe height and width for the sequence.

Examples

List with blank boxes
[
{
"type": "list",
"id": 82,
"value": [19, 43, null, 49]
}
]
Example ListExample List
List with indices shown
[
{
"type": "list",
"id": 84,
"value": [32, 10, 90, 57],
"show_indexes": true
}
]
Example List with IndicesExample List with Indices
Tuple with blank boxes
[
{
"type": "tuple",
"id": 11,
"value": [82, 76, null]
}
]
Example TupleExample Tuple
Tuple with indices shown
[
{
"type": "tuple",
"id": 11,
"value": [82, 76, null],
"show_indexes": true
}
]
Example Tuple with IndicesExample Tuple with Indices

Sets

AttributeTypeRequiredDescription
typestringYesMust be set to set to indicate a set object.
idnumberYesUnique identifier for the set.
valuearrayYesList of object ids. Values can be made null to draw blank boxes.
x, ynumberNoOptional manual coordinates. Required only if automation is disabled.
styleobject or arrayNoCustom visual styling.
width, heightnumberNoThe height and width for the set.

Examples

Set with blank boxes
[
{
"type": "set",
"id": 90,
"value": [36, 49, null, 64]
}
]
Example SetExample Set
Set with large width
[
{
"type": "set",
"id": 32,
"value": [10, 11, 12],
"width": 500
}
]
Example SetExample Set

Dictionaries

AttributeTypeRequiredDescription
typestringYesMust be set to dict to indicate a dictionary object.
idnumberYesUnique identifier for the dictionary.
valuedictYesDictionary of string object id keys to int object id value pairs. Keys can be made empty or all-whitespace strings and values can be made null to draw blank boxes.
x, ynumberNoOptional manual coordinates. Required only if automation is disabled.
styleobject or arrayNoCustom visual styling.
width, heightnumberNoThe height and width for the dictionary.

Examples

Dictionary with blank boxes
[
{
"type": "dict",
"id": 10,
"value": {
"": 81,
"1": null,
" ": 12
}
}
]
Example DictionaryExample Dictionary
Dictionary with large height
[
{
"type": "dict",
"id": 10,
"value": { "x": 81, "y": 100, "z": 121 },
"height": 600
}
]
Example DictionaryExample Dictionary

Classes

AttributeTypeRequiredDescription
typestringYesMust be set to .class to indicate a class object.
idnumberYesUnique identifier for the class object.
namestringYesThe name of the class being drawn.
valueobjectYesA mapping of attribute names (as keys) to object IDs (as values). Attribute names may be empty or all-whitespace strings and attribute values may be null to render blank boxes, respectively.
x, ynumberNoOptional manual coordinates. Required only if automation is disabled.
styleobject or arrayNoCustom visual styling.
width, heightnumberNoThe height and width for the class.

Examples

Class with blank boxes
[
{
"type": ".class",
"id": 82,
"name": "Person",
"value": {
"age": 12,
"name": 17,
"": null
}
}
]
Example ClassExample Class

Stack Frames

AttributeTypeRequiredDescription
typestringYesMust be .frame to indicate a stack frame.
idnullNoIgnored for stack frames and not rendered regardless of value.
namestringYesThe name of the stack frame (e.g., __main__, foo)
valueobjectYesA mapping of variable names (as keys) to object IDs (as values). 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.
x, ynumberNoOptional manual coordinates. Required only if automation is disabled.
styleobject or arrayNoCustom visual styling.
width, heightnumberNoThe height and width for the class.

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
}
]
Example Main Stack FrameExample Main Stack Frame
Function stack frame with blank boxes
[
{
"type": ".frame",
"name": "func",
"value": {
"age": 12,
"name": 17,
"": null
}
},
{
"type": ".blank",
"width": 200,
"height": 100
}
]
Example Function Stack FrameExample Function Stack Frame

Blank Objects

AttributeTypeRequiredDescription
typestringYesMust be set to .blank to indicate a blank object, or .blank-frame to indicate a blank frame.
widthnumberYesThe width of the blank object/frame.
heightnumberYesThe height of the blank object/frame.

Examples

Blank object
{
"type": ".blank",
"width": 200,
"height": 100
}
Blank frame
{
"type": ".blank-frame",
"width": 200,
"height": 100
}