Skip to main content

Gradio implementation for the vis.js Timeline visualization library

Project description

Gradio vis.js Timeline

Static Badge Static Badge

A Gradio component that implements the vis.js Timeline visualization library, allowing you to create interactive timelines in your Gradio apps.

Resources:

Installation

pip install gradio_vistimeline

Usage

import gradio as gr
from gradio_vistimeline import VisTimeline

demo = gr.Interface(
    lambda x: x,
    VisTimeline(
        value={
            "items": [
                {"content": "Item 1", "start": "2024-12-2", "end": "2024-12-10"},
                {"content": "Item 2", "start": "2024-12-14"}
            ]
        },
        options={
            "start": "2024-12-1",
            "end": "2024-12-15",
            "editable": True
        }
    ),
    "json"
)

if __name__ == "__main__":
    demo.launch()

VisTimeline

Features

  • Interactive timeline visualization
  • Integration of vis.js Timeline includes:
    • Items
    • Ranges
    • Points
    • Background items
    • Groups
    • Subgroups
  • Pass options object during instantiation
  • Styled with the gradio style variables
  • Gradio events for editing data and selecting items

Value Data Format

The timeline accepts a value in the following format:

{
    "groups": [
        {
            "id": "group_id", 
            "content": "Group Name" # Optional
        }
    ],
    "items": [
        {
            "content": "Item content",
            "start": "2024-01-01",  # ISO date string or Unix timestamp
            "end": "2024-01-05",    # Optional
            "group": "group_id",    # Optional
        }
    ]
}

Or as a VisTimelineData object:

from gradio_vistimeline import VisTimelineGroup, VisTimelineItem, VisTimelineData

value = VisTimelineData(
    groups=[
        VisTimelineGroup(
            id="group_id", 
            content="Group Name"   # Optional
        )
    ],
    items=[
        VisTimelineItem(
            content="Item content",
            start="2024-01-01",    # ISO date string or Unix timestamp
            end="2024-01-05",      # Optional
            group="group_id"       # Optional
        )
    ]
)

Events

name description
load Triggered when the component is mounted for the first time
change Triggered when the timeline value changes through any means
input Triggered when a user directly modifies timeline items (add/remove/update)
select Triggered when clicking the timeline
item_select Triggered when items are selected or unselected

Configuration

vis.js Timeline Options

The component accepts all configuration options supported by vis.js Timeline. Some commonly used options:

options = {
    "editable": True,             # Enable item editing
    "multiselect": True,          # Allow selecting multiple items
    "showCurrentTime": True,      # Show a marker for current time
    "stack": True,                # Stack overlapping items
    "zoomable": True              # Allow zooming the timeline
}

For a complete list of options, see the vis.js Timeline documentation.

Component-Specific Options

Data Synchronization

VisTimeline(
    value=value,
    preserve_old_content_on_value_change=True  # Default: False
)

Controls how the timeline updates their groups and items DataSets when the component value changes:

  • False: Clears and reinitializes all DataSets to ensure perfect sync with the Gradio component value
  • True: Merges new data with existing content (updates existing items, adds new ones, removes missing ones)

Defaulted to false to ensure the value matches the visualization on the timeline.

Changing it to true reduces visual flicker when dragging items around. Desync is only a real risk in this mode when you edit item ID's or add/remove item properties of existing items.

JavaScript Integration

VisTimeline(
    value=value,
    elem_id="my-timeline"  # Optional
)

When elem_id is set, the timeline instance becomes available in JavaScript as window.visTimelineInstances["my-timeline"], allowing easy access through custom scripts.

Styling Items The component provides pre-defined color classes matching Gradio's theme colors. Apply them by setting an item's className:

item = {
    "content": "Colored item",
    "start": "2024-01-01",
    "className": "color-primary-500"  # Uses Gradio's primary-500 color
}

Available color classes follow the pattern:

  • color-primary-[50-950]
  • color-secondary-[50-950]
  • color-neutral-[50-950]

Custom styles can be applied by defining your own CSS classes.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gradio_vistimeline-1.0.1.tar.gz (1.7 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gradio_vistimeline-1.0.1-py3-none-any.whl (1.3 MB view details)

Uploaded Python 3

File details

Details for the file gradio_vistimeline-1.0.1.tar.gz.

File metadata

  • Download URL: gradio_vistimeline-1.0.1.tar.gz
  • Upload date:
  • Size: 1.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.0

File hashes

Hashes for gradio_vistimeline-1.0.1.tar.gz
Algorithm Hash digest
SHA256 d3b0f3a03dc196acbf0a13aa466325e977ed3f3921a3d3f448613be0590481af
MD5 534c578369a5a4de362fa2d9a3dad64c
BLAKE2b-256 c7b826d32c32b5136d448f03133eaa7462bbcb4825c2b6ff20f64d9fdbf8a057

See more details on using hashes here.

File details

Details for the file gradio_vistimeline-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for gradio_vistimeline-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6a176edae1251aef64cc9601e601f3d7432e5c735bf5f413d5b1a0b5d4869ab0
MD5 b08d80639340f7e01958d3598010affd
BLAKE2b-256 8d6f9a5bc7d457d3258570c5780753c9670ff8d79c46d06a8aca49d57095f51a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page