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:

AttributeTypeDescription
typestringSpecifies the type of object to be drawn. (e.g., .class, .frame, int, str). See Entity Type for more details.
idnumber or nullA unique identifier for the object (duplicate IDs will emit a warning). May be null anywhere to render a blank ID box.
valueVariesThe content of the object to be drawn. Format and type depends on the entity type.
x, ynumberThe x and y coordinates for the object on the canvas. Will be automatically calculated if not provided.
width, heightnumberThe 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.
styleobject or arrayCustom visual styling. See Style API for more details.

Entity Type

Type ValueDescription
int, float, str, bool, None, complex, bytes, range, datetime.datePrimitives
list, tupleSequences
set, frozensetSets
dictDictionaries
.classClasses
.frameStack Frames
.blank .blank-frameBlank Objects

Primitives

AttributeTypeDefaultDescription
typestring--Must be set to one of int, str, bool, float, or None to indicate a primitive object.
valueSee belownullThe actual value represented by the primitive object. To render an empty box, set the value as null or don't define it.
typetype of value
int, floatnumber
strstring
boolboolean
None, complex, bytes, range, datetime.datestring

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
Complex
[
{
"type": "complex",
"id": 76,
"value": "(4+2j)"
}
]
Example ComplexExample Complex
Range
[
{
"type": "range",
"id": 76,
"value": "range(0, 5)"
}
]
RangeRange
Bytes
[
{
"type": "bytes",
"id": 76,
"value": "b'\\x00\\x00'"
}
]
BytesBytes
Date
[
{
"type": "date",
"id": 76,
"value": "2019-12-04"
}
]
BytesBytes
Empty Box
[
{
"type": "bool",
"id": 0,
"value": null
}
]
Example Empty BoxExample Empty Box

Sequences

AttributeTypeDefaultDescription
typestring--Must be set to list to indicate a list object, or tuple to indicate a tuple object.
valuearray of number or null[]List of object ids (unresolved IDs will emit a warning). Values can be made null to draw blank boxes.
show_indexesbooleanfalseIndicates whether to show indices in the memory box.

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

AttributeTypeDefaultDescription
typestring--Must be set to set to indicate a set object.
valuearray 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]
}
]
Example SetExample Set
Set with large width
[
{
"type": "set",
"id": 32,
"value": [10, 11, 12],
"width": 500
}
]
Example SetExample Set
Frozenset
[
{
"type": "frozenset",
"id": 90,
"value": [36, 49, 72, 64]
}
]
Example FrozensetExample Frozenset
Frozenset with blank boxes
[
{
"type": "frozenset",
"id": 90,
"value": [null, 16, null, 84]
}
]
Example FrozensetExample Frozenset

Dictionaries

AttributeTypeDefaultDescription
typestring--Must be set to dict to indicate a dictionary object.
valuedict 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
}
}
]
Example DictionaryExample Dictionary
Dictionary with large height
[
{
"type": "dict",
"id": 10,
"value": { "x": 81, "y": 100, "z": 121 },
"height": 600
}
]
Example DictionaryExample Dictionary
Dictionary with value specified using a list
[
{
"type": "dict",
"id": 10,
"value": [
["", 81],
["1", null],
["", 12]
]
}
]
Example DictionaryExample Dictionary

Classes

AttributeTypeDefaultDescription
typestring--Must be set to .class to indicate a class object.
namestring""The name of the class being drawn.
valuedict 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
}
}
]
Example ClassExample Class

Stack Frames

AttributeTypeDefaultDescription
typestring--Must be .frame to indicate a stack frame.
namestring""The name of the stack frame (e.g., __main__, foo)
valuedict 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
}
]
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

AttributeTypeDefaultDescription
typestring--Must be set to .blank to indicate a blank object, or .blank-frame to indicate a blank frame.
widthnumber0The width of the blank object/frame.
heightnumber0The height of the blank object/frame.

Examples

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