Skip to main content

A lightweight Python library for rendering Vega-Lite JSON charts in Jupyter/Colab.

Project description

ChartSpan

ChartSpan is a Python library for crafting and transforming Vega-Lite chart specifications with ease. It provides utilities to clean, modify, and create charts programmatically using Altair, a powerful declarative visualization library.

Features

  • Clean and Transform Vega-Lite Specifications: Simplify and customize your chart specifications by removing unnecessary keys and adjusting configurations.
  • File-based Workflow: Load and save specifications directly from and to JSON files.
  • Customizable Dimensions: Easily modify chart dimensions and adapt them to your needs.
  • Altair Integration: Build and render charts seamlessly using the Altair library.

Installation

You can install ChartSpan via pip:

pip install chartspan

Getting Started

Example Usage

from chartspan import ChartSpan

# Example Vega-Lite specification
spec = {
    "data": {
        "values": [
            {"x": 1, "y": 2},
            {"x": 2, "y": 3},
            {"x": 3, "y": 5}
        ]
    },
    "mark": "line",
    "encoding": {
        "x": {"field": "x", "type": "quantitative"},
        "y": {"field": "y", "type": "quantitative"}
    }
}

# Initialize ChartSpan
span = ChartSpan(width=500, height=400)

# Transform the specification
cleaned_chart = span.span(spec)

# Display the chart
cleaned_chart.display()

File-based Workflow

Load a specification from a file and create a chart:

from chartspan import ChartSpan, load_spec

# Load Vega-Lite spec from file
spec = load_spec("example_spec.json")

# Span the chart
span = ChartSpan()
chart = span.span(spec)

# Display the chart
chart.display()

Save a transformed specification to a file:

from chartspan.utils import save_spec

# Save the cleaned specification
save_spec(chart.to_dict(), "cleaned_spec.json")

API Reference

ChartSpan

Methods

  • __init__(width=800, height=600, remove_keys=None)

    • Initialize ChartSpan with custom dimensions and keys to remove.
  • clean_spec(obj)

    • Recursively cleans the Vega-Lite specification.
  • span(spec)

    • Transforms a Vega-Lite specification into an Altair chart object.
  • from_file(filepath, **kwargs)

    • Create a ChartSpan instance and load a specification from a JSON file.

Utilities

  • load_spec(filepath)

    • Load a Vega-Lite specification from a JSON file.
  • save_spec(spec, filepath)

    • Save a Vega-Lite specification to a JSON file.

Requirements

  • Python 3.8 or higher
  • Altair >= 5.0.0
  • pandas >= 1.0.0

Installation for Development

Clone the repository:

git clone https://github.com/yourusername/chartspan.git
cd chartspan

Install dependencies:

pip install -e .

Run tests:

pytest

License

ChartSpan is licensed under the MIT License. See the LICENSE file for details.

Contributing

We welcome contributions! Please open an issue or submit a pull request for any enhancements or bug fixes.

Contact

For inquiries or support, contact Your Name.

Acknowledgments

This project is built on top of the amazing Altair library. Special thanks to the open-source community for making tools like this possible.

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

chartspan-0.1.0.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

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

chartspan-0.1.0-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file chartspan-0.1.0.tar.gz.

File metadata

  • Download URL: chartspan-0.1.0.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.6

File hashes

Hashes for chartspan-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3237ef3cb8a445c839165b8cfc6e807c88bc3943e8878798e2a87cdde3dcf627
MD5 d4cfd3bbaf03c13502ecab9de2ac5040
BLAKE2b-256 6ef35d50b68c9fd57240e687822434cbbf12b25ed2bccaf75a028528357a7fdc

See more details on using hashes here.

File details

Details for the file chartspan-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: chartspan-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.6

File hashes

Hashes for chartspan-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c0c121cce46c38fac1e7aa1efc3a8ac094091ce2e0934a45c64bfd51c1a1071c
MD5 cec7801ac014b805375a5f9dc978e716
BLAKE2b-256 372211257d2471d8e8ae7090d882c8dede03d5eaa783333a78bff014cfbe1b11

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