Skip to content

Commit cc85915

Browse files
committed
feat: improve accessibility, add missing chart options and view component libraries support
1 parent abd0eae commit cc85915

21 files changed

Lines changed: 1959 additions & 79 deletions

File tree

CHANGELOG.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [0.2.0] - Unreleased
9+
10+
### Added
11+
- **Accessibility (ARIA + keyboard)**: `title:` and `description:` options on charts, `role="img"` and `aria-label` on SVG elements, `aria-hidden` on decorative elements (grid, crosshair, reference lines), `aria-label` on data points
12+
- **Empty state**: Centered "No data available" message (customizable via `empty_message:`) when data array is empty, with placeholder icon
13+
- **Data labels**: `c.data_label format: :currency, position: :top` to render formatted values directly on bars, lines, scatter dots, and pie slices
14+
- **Sparklines**: `trackplot_sparkline @data, key: :revenue` helper for inline mini-charts (line, bar, area) via `<trackplot-sparkline>` custom element
15+
- **Stacked bars**: `c.bar :revenue, stack: "main"` now renders stacked bars using `d3.stack()`, matching the existing stacked area pattern
16+
- **Dual Y-axis**: `c.axis :y, axis_id: :right` creates a right-side axis; series bind via `y_axis: :right`
17+
- **Export to PNG/SVG**: `element.exportPNG()` and `element.exportSVG()` methods on `<trackplot-chart>` for downloading charts
18+
- **ViewComponent support**: `Trackplot::Component` (optional, requires `view_component` gem)
19+
- **Phlex support**: `Trackplot::PhlexComponent` (optional, requires `phlex` gem)
20+
- **Brush/zoom**: `c.brush(axis: :x)` for interactive range selection on cartesian charts with mini preview
21+
- **Real-time data append**: `element.appendData(newPoints, { maxPoints: 50 })` for live dashboard updates with `trackplot:data-update` event
22+
- **Heatmap chart type**: `c.heatmap(x_key: :day, y_key: :hour, value_key: :count)` for density/intensity visualization
23+
- **Treemap chart type**: `c.treemap(value_key: :size, label_key: :name)` for hierarchical data with optional `parent_key` grouping
24+
25+
## [0.1.0] - 2025-01-01
26+
27+
### Added
28+
- Initial release with 10 chart types: Line, Bar, Area (with stacking), Scatter, Pie/Donut, Radar, Horizontal Bar, Candlestick, Funnel
29+
- Declarative Ruby DSL via `trackplot_chart` helper with block syntax
30+
- D3.js rendering via `<trackplot-chart>` custom element
31+
- Theming system with 4 presets (default, dark, vibrant, minimal) and custom hash support
32+
- Tooltip with crosshair for cartesian charts, hover tooltips for pie/radar/funnel
33+
- Legend component with configurable position
34+
- Grid lines (horizontal/vertical)
35+
- Reference lines (horizontal/vertical) with labels, colors, and dash styles
36+
- Format helpers (`:currency`, `:percent`, `:compact`, `:decimal`, `:integer`) for axes and tooltips
37+
- Click events via `trackplot:click` custom event with datum detail
38+
- Turbo support: stable `id:` option, `turbo:before-cache` cleanup, `updateData()` / `updateConfig()` public API
39+
- ResizeObserver for responsive re-rendering
40+
- Importmap integration via Rails engine
41+
- Animated transitions with configurable `animate:` option
42+
- DataAdapter: normalizes Hash, Array, ActiveRecord::Relation inputs to string-keyed hashes

CONTRIBUTING.md

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# Contributing to Trackplot
2+
3+
Thank you for considering contributing to Trackplot! This guide will help you get started.
4+
5+
## Development Setup
6+
7+
1. **Clone the repository**
8+
9+
```bash
10+
git clone https://github.com/eagerworks/trackplot.git
11+
cd trackplot
12+
```
13+
14+
2. **Install dependencies**
15+
16+
```bash
17+
bundle install
18+
```
19+
20+
3. **Run the test suite**
21+
22+
```bash
23+
bundle exec rake
24+
```
25+
26+
Or run tests directly:
27+
28+
```bash
29+
ruby -Ilib -Itest -e "Dir['test/**/*_test.rb'].each { |f| require File.expand_path(f) }"
30+
```
31+
32+
4. **Run the dummy Rails app** (for visual testing)
33+
34+
```bash
35+
cd test/dummy
36+
bin/rails server
37+
```
38+
39+
Then open `http://localhost:3000/charts` in your browser.
40+
41+
## Running the Linter
42+
43+
We use [Standard Ruby](https://github.com/standardrb/standard) for code formatting:
44+
45+
```bash
46+
bundle exec standardrb
47+
```
48+
49+
To auto-fix violations:
50+
51+
```bash
52+
bundle exec standardrb --fix
53+
```
54+
55+
## Project Structure
56+
57+
```
58+
lib/trackplot/
59+
chart_builder.rb # Main DSL builder
60+
sparkline_builder.rb # Sparkline mini-chart builder
61+
data_adapter.rb # Normalizes input data
62+
theme.rb # Theme presets and resolution
63+
engine.rb # Rails engine setup
64+
components/ # One file per chart/component type
65+
base.rb, line.rb, bar.rb, area.rb, pie.rb, ...
66+
67+
app/
68+
assets/javascripts/trackplot/
69+
index.js # Complete JS engine (D3 rendering)
70+
helpers/trackplot/
71+
chart_helper.rb # View helpers
72+
73+
test/
74+
trackplot/
75+
chart_builder_test.rb # Ruby DSL tests
76+
dummy/ # Rails dummy app for integration testing
77+
```
78+
79+
## How to Contribute
80+
81+
### Reporting Bugs
82+
83+
- Open an issue at https://github.com/eagerworks/trackplot/issues
84+
- Include: Ruby/Rails version, browser, minimal reproduction steps, expected vs actual behavior
85+
86+
### Submitting Changes
87+
88+
1. Fork the repository
89+
2. Create a feature branch (`git checkout -b feature/my-feature`)
90+
3. Make your changes
91+
4. Add tests for new functionality
92+
5. Run the full test suite (`bundle exec rake`)
93+
6. Run the linter (`bundle exec standardrb`)
94+
7. Commit with a descriptive message
95+
8. Push to your fork and open a Pull Request
96+
97+
### Coding Conventions
98+
99+
- Follow Standard Ruby style
100+
- Ruby components follow the existing pattern: inherit from `Components::Base`, implement `to_config`
101+
- JS renderers follow the pattern: `renderXxx(g, data, ..., theme, chartElement)` function
102+
- Keep the JS in a single `index.js` file (no build step)
103+
- Test Ruby DSL output (config hashes), not HTML rendering
104+
- Use `transform_keys` (stdlib) instead of `symbolize_keys` (ActiveSupport) in gem code
105+
106+
### Adding a New Chart Type
107+
108+
1. Create `lib/trackplot/components/my_chart.rb` inheriting from `Base`
109+
2. Add autoload in `lib/trackplot.rb`
110+
3. Add DSL method in `chart_builder.rb`
111+
4. Add renderer function in `index.js`
112+
5. Register the type in `ALL_SERIES_TYPES` constant
113+
6. Add tooltip support if applicable
114+
7. Add tests in `chart_builder_test.rb`
115+
8. Add demo in `test/dummy/app/views/charts/index.html.erb`

0 commit comments

Comments
 (0)