Skip to main content

A Python package for frontend-related functionality with chart visualization tools

Project description

webengage-frontend

A Python package for frontend-related functionality.

Description

webengage-frontend is a Python package designed to provide frontend-related utilities and tools for WebEngage projects. It includes chart visualization capabilities for creating bar charts from pandas DataFrames.

Installation

From Source

# Clone the repository
git clone https://repo.webengage.com/data-consultancy/data-science-consulting-master-repo.git
cd data-science-consulting-master-repo/webengage-fe

# Install in development mode
pip install -e .

# Or install with development dependencies
pip install -e ".[dev]"

Using pip

pip install webengage-frontend

Requirements

  • Python >= 3.8

Development Setup

  1. Clone the repository:
git clone https://repo.webengage.com/data-consultancy/data-science-consulting-master-repo.git
cd data-science-consulting-master-repo/webengage-fe
  1. Create a virtual environment:
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install dependencies:
pip install -r requirements-dev.txt
  1. Install the package in development mode:
pip install -e .

Usage

Chart Visualization

Create professional, interactive HTML-based bar charts from pandas DataFrames with optimal aspect ratios:

import pandas as pd
from webengage_frontend import ChartVisualizer

# Create sample DataFrame
df = pd.DataFrame({
    'category': ['Q1', 'Q2', 'Q3', 'Q4'],
    'sales': [100000, 150000, 120000, 180000],
    'profit': [20000, 30000, 25000, 40000],
    'expenses': [80000, 120000, 95000, 140000]
})

# Initialize ChartVisualizer
visualizer = ChartVisualizer(df)

# Create bar chart with single y-axis column (optimal aspect ratio)
# Matches reference style: clean, minimal, no value labels by default
fig = visualizer.bar_chart(
    x='category',
    y=['sales'],
    title='Sales by Category',
    xlabel='Category',
    ylabel='Sales ($)',
    show_values=False,  # No value labels (matching reference style)
    aspect_ratio=1.8    # Optimal width-to-height ratio
)
fig.show()  # Display interactive HTML chart

# Create grouped bar chart with multiple y-axis columns
# Clean style with horizontal grid lines only
fig = visualizer.bar_chart(
    x='category',
    y=['sales', 'profit', 'expenses'],
    title='Financial Overview by Quarter',
    xlabel='Quarter',
    ylabel='Amount ($)',
    width=1200,         # Custom width in pixels
    height=600,         # Custom height in pixels
    show_values=False,  # Clean look without value labels
    show_legend=True,
    y_format='k'        # Format y-axis as thousands (1.0k, 2.5k)
)
fig.show()

# Export to HTML file
html_str = visualizer.to_html(fig, filename='chart.html')
print("Chart saved to chart.html")

# Custom color palette
custom_colors = ['#1E40AF', '#059669', '#DC2626']
fig = visualizer.bar_chart(
    x='category',
    y=['sales', 'profit'],
    title='Sales vs Profit',
    color_palette=custom_colors,
    style='modern',
    aspect_ratio=2.0  # Wider chart
)
fig.show()

# For Jupyter Notebooks or Streamlit
# fig.show() works directly
# For web applications, use: visualizer.to_html(fig)

Bar Chart Features

  • Reference-Style Design: Clean, minimal bar charts matching professional reference style
  • HTML/JavaScript Based: Interactive charts using Plotly.js for web compatibility
  • Optimal Aspect Ratios: Automatic calculation of width-to-height ratios (default 1.8:1)
  • Clean Styling:
    • White background (no grey backgrounds)
    • Horizontal grid lines only (no vertical grid lines)
    • Thin bars with clear spacing between groups
    • No value labels by default (clean, minimal look)
  • Interactive: Hover tooltips, zoom, pan, and export capabilities
  • Professional Design: Modern, crisp visualization with clean styling
  • Value Labels: Optional value labels (disabled by default to match reference)
  • Custom Dimensions: Specify exact width/height in pixels or use aspect ratios
  • Custom Colors: Use your own color palette or choose from the default professional palette
  • Multiple Series: Support for grouped bar charts with multiple data series
  • Y-Axis Formatting: Format y-axis labels (thousands, currency, etc.)
  • Flexible Styling: Choose between 'modern' and 'minimal' styles
  • Web Ready: Perfect for dashboards, web applications, and HTML reports
  • Export Options: Save charts as standalone HTML files or embed in web pages

Development

Running Tests

pytest

Code Formatting

black src/

Linting

flake8 src/

Type Checking

mypy src/

Project Structure

webengage-fe/
├── src/
│   └── webengage_frontend/     # Main package directory
│       ├── __init__.py
│       ├── charts.py           # Chart visualization classes
│       └── utils.py            # Utility functions
├── tests/                      # Test files
│   ├── __init__.py
│   └── test_utils.py
├── setup.py                    # Setup script
├── pyproject.toml             # Modern Python packaging configuration
├── requirements.txt           # Production dependencies
├── requirements-dev.txt       # Development dependencies
├── MANIFEST.in                # Package manifest
├── LICENSE                    # MIT License
├── .gitignore                 # Git ignore rules
└── README.md                  # This file

Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Merge Request

License

This project is licensed under the MIT License.

Authors

  • WebEngage

Project Status

Active development.

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

webengage_frontend-0.1.1.tar.gz (12.6 kB view details)

Uploaded Source

Built Distribution

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

webengage_frontend-0.1.1-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file webengage_frontend-0.1.1.tar.gz.

File metadata

  • Download URL: webengage_frontend-0.1.1.tar.gz
  • Upload date:
  • Size: 12.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for webengage_frontend-0.1.1.tar.gz
Algorithm Hash digest
SHA256 5121ff4a0e344e3a81ff63e12e99ce99669e71c01d2702e5324494135433f0d3
MD5 856533473dddd410df41fb1aa398ceb6
BLAKE2b-256 d39eed65ac0e09a12ff3315264397767e523cd6dcc708b3928a7b37ac3e09942

See more details on using hashes here.

File details

Details for the file webengage_frontend-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for webengage_frontend-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 43b98c32f032e49117eddc5498c98a225b920a7f86b0c0904b699fb2c1b64fa1
MD5 18d18486708bf60704352fe52c83a5c2
BLAKE2b-256 f4995c43ef3d7046e03ae0c7d66b775465d674f914fe4e54b00cf3418eca6181

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