A Python library for creating smooth, animated bar chart visualizations using Pygame. This project allows you to create dynamic racing bar charts with customizable colors, animations, and recording capabilities.
- Smooth bar animations with multiple animation styles
- Customizable colors, fonts, and dimensions
- Support for different animation types (bottom-up, top-down, simultaneous)
- Video recording capabilities
- Header and value label customization
- Support for image integration with dominant color extraction
- Flexible configuration options
- Clone the repository:
git clone https://github.com/sanskar-mk2/animated-graphs.git
cd animated-graphs
- Install required packages:
pip install -r requirements.txt
- Ensure you have the required assets:
- Fonts in
./assets/fonts/
- Data files in appropriate directories
- Fonts in
Here's a basic example of how to use the library:
from src.color import Color
from projects.PYPL.pypl_data_loader import load_data
from src.animated_graph import PygameExtended
from src.graph import GraphConfig
from src.animated_graph import BarChartAnimation
# Load your data
visualization_data = load_data("./ODE/All.json")
# Configure window
WINDOW_SIZE = (1920, 1080)
app = PygameExtended(WINDOW_SIZE)
# Set up configuration
chart_config = GraphConfig(
header_font="./assets/fonts/Arial.ttf",
header_font_size=69,
header_text="Online IDE Popularity (Global)",
bar_height=40,
width_multiplier=100,
colors=[
Color("#f98284"), # Red
Color("#ffc384"), # Orange
# ... add more colors as needed
],
left_gap=250,
text_bar_distance=30,
small_text_size=30,
to_show=10,
fps=60,
animation_speed=0.1,
bg_color=Color("#28282e"),
header_bg_color=Color("#6c5671"),
header_text_color=Color("#ffffff"),
value_gap=10,
record_path="outputs/animation.mp4",
wait_time_after_completion=3,
value_prepost=("~", "%"),
)
# Create and run visualization
chart = BarChartAnimation(
pygame_app=app,
chart_data=visualization_data,
header_height=100,
chart_config=chart_config,
)
chart.run()
Here are some example animations created with this library:
steam_most_positive_reviews.mp4
pypl_pypl_all_graph.mp4
header_font
: Path to font file for header textheader_font_size
: Font size for header textheader_text
: Text to display in headerbar_height
: Height of each bar in pixelswidth_multiplier
: Scale factor for bar widthscolors
: List of Color objects for barsleft_gap
: Space between left edge and barstext_bar_distance
: Space between text and barssmall_text_size
: Font size for bar labelsto_show
: Number of bars to displayfps
: Frames per second for animationanimation_speed
: Time in seconds for each bar's growthbg_color
: Background colorheader_bg_color
: Header background colorheader_text_color
: Header text colorvalue_gap
: Gap between value text and bar edgerecord_path
: Path to save the recordingwait_time_after_completion
: Time to wait after completionvalue_prepost
: Tuple of (prefix, suffix) for values