Concept map - faw

Skip to content

# Concept map

Concept Map Widget for Marimo

## `ConceptMapWidget`

Bases: `AnyWidget`

A concept mapping widget where students draw labeled directed edges between concepts.

Students select a relationship term then click two concept nodes to connect them. Concept nodes can be dragged to rearrange the layout.

Attributes:

Name | Type | Description
--- | --- | ---
`question` | `str` | The question or prompt shown above the map
`concepts` | `list` | List of concept names (nodes)
`terms` | `list` | List of relationship terms that can label edges
`correct_edges` | `list` | List of dicts with 'from', 'to', 'label' keys
`value` | `dict` | State with 'edges', 'score', 'total', and 'correct' keys

Source code in `src/faw/concept_map.py`

     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    class ConceptMapWidget(anywidget.AnyWidget):
        """
        A concept mapping widget where students draw labeled directed edges between concepts.

        Students select a relationship term then click two concept nodes to connect them.
        Concept nodes can be dragged to rearrange the layout.

        Attributes:
            question (str): The question or prompt shown above the map
            concepts (list): List of concept names (nodes)
            terms (list): List of relationship terms that can label edges
            correct_edges (list): List of dicts with 'from', 'to', 'label' keys
            value (dict): State with 'edges', 'score', 'total', and 'correct' keys
        """

        _esm = Path(__file__).parent / "static" / "concept-map.js"

        question = traitlets.Unicode("").tag(sync=True)
        concepts = traitlets.List(trait=traitlets.Unicode()).tag(sync=True)
        terms = traitlets.List(trait=traitlets.Unicode()).tag(sync=True)
        correct_edges = traitlets.List().tag(sync=True)
        value = traitlets.Dict(default_value=None, allow_none=True).tag(sync=True)

        def __init__(self, question: str, concepts: list[str], terms: list[str], correct_edges: list[dict], **kwargs):
            super().__init__(**kwargs)
            self.question = question
            self.concepts = concepts
            self.terms = terms
            self.correct_edges = correct_edges

## Example