|
1 | | -<p> |
2 | | - <img width="100%" src="https://assets.solidjs.com/banner?type=Ecosystem&background=tiles&project=library-name" alt="solid-create-script"> |
| 1 | +<p align="center"> |
| 2 | + <img width="100%" src="https://assets.solidjs.com/banner?type=Ecosystem&background=tiles&project=solid-highcharts" alt="solid-highcharts"> |
3 | 3 | </p> |
4 | 4 |
|
5 | | -# Template: SolidJS Library |
| 5 | +# @dschz/solid-highcharts |
6 | 6 |
|
7 | | -Template for [SolidJS](https://www.solidjs.com/) library package. Bundling of the library is managed by [tsup](https://tsup.egoist.dev/). |
| 7 | +[](LICENSE) |
| 8 | +[](https://github.com/highcharts/highcharts) |
| 9 | +[](https://www.npmjs.com/package/@dschz/solid-highcharts) |
| 10 | +[](https://bundlephobia.com/package/@dschz/solid-highcharts) |
| 11 | +[](https://github.com/dsnchz/solid-highcharts/actions/workflows/ci.yaml) |
| 12 | +[](https://discord.gg/yVBGJfTfQy) |
8 | 13 |
|
9 | | -Other things configured include: |
| 14 | +A comprehensive SolidJS wrapper for [Highcharts](https://www.highcharts.com/) that provides type-safe, reactive chart components with proper lifecycle management. |
10 | 15 |
|
11 | | -- Bun (for dependency management and running scripts) |
12 | | -- TypeScript |
13 | | -- ESLint / Prettier |
14 | | -- Solid Testing Library + Vitest (for testing) |
15 | | -- Playground app using library |
16 | | -- Simple Bun server scaffolding for playground app |
17 | | -- Support for publishing to NPM and JSR |
18 | | -- GitHub Actions (for all CI/CD) |
| 16 | +## ✨ Features |
19 | 17 |
|
20 | | -## Getting Started |
| 18 | +- 🎯 **Type-Safe**: Full TypeScript support with proper type inference |
| 19 | +- ⚡ **Reactive**: Seamless integration with SolidJS reactivity system |
| 20 | +- 🏗️ **Modular**: Support for all Highcharts variants (Core, Stock, Maps, Gantt) |
| 21 | +- 🧹 **Clean**: Automatic cleanup and memory management |
| 22 | +- 📱 **Responsive**: Built-in responsive chart behavior |
| 23 | +- 🎨 **Customizable**: Full access to Highcharts configuration options |
21 | 24 |
|
22 | | -Some pre-requisites before install dependencies: |
| 25 | +## ⚖️ Licensing |
23 | 26 |
|
24 | | -- Install Node Version Manager (NVM) |
25 | | - ```bash |
26 | | - curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash |
27 | | - ``` |
28 | | -- Install Bun |
29 | | - ```bash |
30 | | - curl -fsSL https://bun.sh/install | bash |
31 | | - ``` |
| 27 | +**Important**: This wrapper library (`@dschz/solid-highcharts`) is MIT licensed, but **Highcharts itself is a commercial product** that requires a license for most use cases. |
32 | 28 |
|
33 | | -### Installing Dependencies |
| 29 | +### Highcharts Licensing |
| 30 | + |
| 31 | +- 🏢 **Commercial Use**: Requires a [Highcharts license](https://shop.highcharts.com/) for commercial projects |
| 32 | +- 🎓 **Non-Commercial**: Free for personal projects, school websites, and non-profit organizations |
| 33 | +- 🧪 **Evaluation**: Free for testing and evaluation purposes |
| 34 | + |
| 35 | +### License Requirements by Use Case |
| 36 | + |
| 37 | +| Use Case | Highcharts License Required | |
| 38 | +| -------------------------------- | --------------------------- | |
| 39 | +| Personal/hobby projects | ❌ **Free** | |
| 40 | +| Educational/school websites | ❌ **Free** | |
| 41 | +| Non-profit organizations | ❌ **Free** | |
| 42 | +| Commercial websites/applications | ✅ **License Required** | |
| 43 | +| SaaS products | ✅ **License Required** | |
| 44 | +| Products for sale | ✅ **License Required** | |
| 45 | + |
| 46 | +📋 **Before using Highcharts in your project**, please review the [official Highcharts license terms](https://www.highcharts.com/products/highcharts/#non-commercial) to determine if you need to purchase a license. |
| 47 | + |
| 48 | +This wrapper library simply provides SolidJS integration - all Highcharts licensing terms apply to your usage of the underlying Highcharts library. |
| 49 | + |
| 50 | +## 📦 Installation |
34 | 51 |
|
35 | 52 | ```bash |
36 | | -nvm use |
37 | | -bun install |
| 53 | +# Using npm |
| 54 | +npm install highcharts @dschz/solid-highcharts |
| 55 | + |
| 56 | +# Using yarn |
| 57 | +yarn install highcharts @dschz/solid-highcharts |
| 58 | + |
| 59 | +# Using pnpm |
| 60 | +pnpm install highcharts @dschz/solid-highcharts |
| 61 | + |
| 62 | +# Using bun |
| 63 | +bun install highcharts @dschz/solid-highcharts |
38 | 64 | ``` |
39 | 65 |
|
40 | | -### Local Development Build |
| 66 | +### Highcharts Module Usage |
41 | 67 |
|
42 | | -```bash |
43 | | -bun start |
44 | | -bun start:server # entirely optional to use |
| 68 | +All Highcharts functionality is available from the single `highcharts` package via different import paths. |
| 69 | + |
| 70 | +**⚠️ Important: Import order matters!** Highcharts modules must be imported after the core module. |
| 71 | + |
| 72 | +**📦 Highcharts v12+**: As of Highcharts version 12, you should use ESM import paths for better compatibility and tree-shaking. The examples below show the recommended ESM imports. |
| 73 | + |
| 74 | +```tsx |
| 75 | +// Core Highcharts (standard charts) - ESM import |
| 76 | +import Highcharts from "highcharts/esm/highcharts"; |
| 77 | + |
| 78 | +// Stock Charts (financial/time-series data) - ESM import |
| 79 | +import HighchartsStock from "highcharts/esm/highstock"; |
| 80 | + |
| 81 | +// Maps (geographical data) - ESM import |
| 82 | +import HighchartsMaps from "highcharts/esm/highmaps"; |
| 83 | + |
| 84 | +// Gantt Charts (project timelines) - ESM import |
| 85 | +import HighchartsGantt from "highcharts/esm/highcharts-gantt"; |
| 86 | + |
| 87 | +// Additional modules (optional) -- ORDER MATTERS! MUST BE IMPORTED AFTER Highcharts IMPORT! |
| 88 | +import "highcharts/esm/modules/accessibility"; |
| 89 | +import "highcharts/esm/modules/exporting"; |
| 90 | +import "highcharts/esm/modules/export-data"; |
45 | 91 | ``` |
46 | 92 |
|
47 | | -### Linting & Formatting |
| 93 | +See this [post](https://www.highcharts.com/docs/getting-started/version-12) for more details. |
48 | 94 |
|
49 | | -```bash |
50 | | -bun run lint # checks source for lint violations |
51 | | -bun run format # checks source for format violations |
| 95 | +**Legacy UMD imports** (pre-v12) are still supported but ESM is recommended: |
52 | 96 |
|
53 | | -bun run lint:fix # fixes lint violations |
54 | | -bun run format:fix # fixes format violations |
| 97 | +```tsx |
| 98 | +// Legacy UMD imports (still works but not recommended) |
| 99 | +import Highcharts from "highcharts"; |
| 100 | +import HighchartsStock from "highcharts/highstock"; |
| 101 | +import HighchartsMaps from "highcharts/highmaps"; |
| 102 | +import HighchartsGantt from "highcharts/highcharts-gantt"; |
| 103 | + |
| 104 | +// Additional modules (optional) -- ORDER MATTERS! MUST BE IMPORTED AFTER Highcharts IMPORT! |
| 105 | +import "highcharts/modules/accessibility"; |
| 106 | +import "highcharts/modules/exporting"; |
| 107 | +import "highcharts/modules/export-data"; |
55 | 108 | ``` |
56 | 109 |
|
57 | | -### Building the Library |
| 110 | +### API Quick Start |
58 | 111 |
|
59 | | -This template uses [tsup-preset-solid](https://github.com/solidjs-community/tsup-preset-solid) to build and bundle the library |
| 112 | +This library exposes four factory functions that create the Highcharts components to use in your Solid application. |
60 | 113 |
|
61 | | -```bash |
62 | | -bun run build |
| 114 | +#### Basic Chart |
| 115 | + |
| 116 | +```tsx |
| 117 | +import Highcharts from "highcharts/esm/highcharts"; |
| 118 | +import { createChart } from "@dschz/solid-highcharts"; |
| 119 | + |
| 120 | +// Highcharts Chart component |
| 121 | +const Chart = createChart(Highcharts); |
63 | 122 | ``` |
64 | 123 |
|
65 | | -### Publishing the Library |
| 124 | +#### Stock Chart |
66 | 125 |
|
67 | | -This template also comes with Changeset pre-configured and three utility scripts. You must have Changeset installed to leverage them. |
| 126 | +```tsx |
| 127 | +// To create a StockChart |
| 128 | +import Highcharts from "highcharts/esm/highstock"; |
| 129 | +import { createStockChart } from "@dschz/solid-highcharts"; |
68 | 130 |
|
69 | | -```bash |
70 | | -bun pkg:changeset # run Changeset CLI |
71 | | -bun pkg:version # consume any changeset to produce package manifest updates |
72 | | -bun pkg:publish # git tag and publish the package to NPM via Changeset |
| 131 | +// Highcharts StockChart component |
| 132 | +const StockChart = createStockChart(Highcharts); |
73 | 133 | ``` |
74 | 134 |
|
75 | | -Another thing to note is the template includes a `jsr.json` config to support publishing to JSR alongside NPM if interested. To publish to JSR, you can run: |
| 135 | +#### Map Chart |
76 | 136 |
|
77 | | -```bash |
78 | | -bunx jsr publish # publishes to JSR |
79 | | -bunx jsr publish --dry-run # checks if library is publishable |
| 137 | +```tsx |
| 138 | +// To create a MapChart |
| 139 | +import Highcharts from "highcharts/esm/highmaps"; |
| 140 | +import { createMapChart } from "@dschz/solid-highcharts"; |
| 141 | + |
| 142 | +// Highcharts MapChart component |
| 143 | +const MapChart = createMapChart(Highcharts); |
| 144 | +``` |
| 145 | + |
| 146 | +#### Gantt Chart |
| 147 | + |
| 148 | +```tsx |
| 149 | +// To create a GanttChart |
| 150 | +import Highcharts from "highcharts/esm/highcharts-gantt"; |
| 151 | +import { createGanttChart } from "@dschz/solid-highcharts"; |
| 152 | + |
| 153 | +// Highcharts GanttChart component |
| 154 | +const GanttChart = createGanttChart(Highcharts); |
| 155 | +``` |
| 156 | + |
| 157 | +#### Accessibility / Exporting Modules |
| 158 | + |
| 159 | +For additional modules like `exporting` and `accessibility`, you simply import them to register with Highcharts: |
| 160 | + |
| 161 | +```tsx |
| 162 | +import Highcharts from "highcharts/esm/highcharts"; |
| 163 | +import "highcharts/esm/modules/accessibility"; |
| 164 | +import "highcharts/esm/modules/exporting"; |
| 165 | +import "highcharts/esm/modules/export-data"; |
| 166 | + |
| 167 | +import { createChart } from "@dschz/solid-highcharts"; |
| 168 | + |
| 169 | +const Chart = createChart(Highcharts); |
| 170 | +``` |
| 171 | + |
| 172 | +**Note**: You may need to disable import sorting rules (like `simple-import-sort` or Prettier) for these imports to prevent automatic reordering that would break functionality as the additional modules must be imported **AFTER** the target Highcharts module import. |
| 173 | + |
| 174 | +## 🔧 Component Props |
| 175 | + |
| 176 | +All chart components returned from the factory functions accept the same props interface: |
| 177 | + |
| 178 | +```tsx |
| 179 | +type HighchartOptions = Highcharts.Options & { |
| 180 | + animation?: boolean | Partial<AnimationOptionsObject>; |
| 181 | +}; |
| 182 | + |
| 183 | +type HighchartsComponentProps = HighchartOptions & { |
| 184 | + /** CSS class for container */ |
| 185 | + class?: string; |
| 186 | + |
| 187 | + /** CSS styles for container */ |
| 188 | + style?: JSX.CSSProperties; |
| 189 | + |
| 190 | + /** Access to container element */ |
| 191 | + ref?: (container: HTMLDivElement) => void; |
| 192 | + |
| 193 | + /** Callback when chart is created */ |
| 194 | + onCreateChart?: (chart: Highcharts.Chart) => void; |
| 195 | +}; |
| 196 | +``` |
| 197 | + |
| 198 | +### Props Examples |
| 199 | + |
| 200 | +```tsx |
| 201 | +// Basic styling |
| 202 | +<Chart |
| 203 | + class="my-chart" |
| 204 | + style={{ height: '400px', border: '1px solid #ccc' }} |
| 205 | + title={{ text: 'Styled Chart' }} |
| 206 | + series={[{ type: 'line', data: [1, 2, 3] }]} |
| 207 | +/> |
| 208 | + |
| 209 | +// Chart reference and callbacks |
| 210 | +<Chart |
| 211 | + ref={(container) => console.log('Container:', container)} |
| 212 | + onCreateChart={(chart) => { |
| 213 | + // Access chart instance |
| 214 | + chart.setTitle({ text: 'Updated Title' }); |
| 215 | + |
| 216 | + // Add custom event listeners |
| 217 | + chart.container.addEventListener('click', () => { |
| 218 | + console.log('Chart clicked!'); |
| 219 | + }); |
| 220 | + }} |
| 221 | + series={[{ type: 'line', data: [1, 2, 3] }]} |
| 222 | +/> |
| 223 | +``` |
| 224 | + |
| 225 | +## 🎨 Styling and Theming |
| 226 | + |
| 227 | +### CSS Styling |
| 228 | + |
| 229 | +```css |
| 230 | +/* Global chart container styles */ |
| 231 | +.highcharts-container { |
| 232 | + border-radius: 8px; |
| 233 | + box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); |
| 234 | +} |
| 235 | + |
| 236 | +/* Custom chart class */ |
| 237 | +.my-chart { |
| 238 | + background: #f5f5f5; |
| 239 | + padding: 16px; |
| 240 | +} |
| 241 | + |
| 242 | +/* Responsive behavior */ |
| 243 | +.chart-responsive { |
| 244 | + width: 100%; |
| 245 | + height: 400px; |
| 246 | + min-height: 300px; |
| 247 | +} |
| 248 | + |
| 249 | +@media (max-width: 768px) { |
| 250 | + .chart-responsive { |
| 251 | + height: 300px; |
| 252 | + } |
| 253 | +} |
| 254 | +``` |
| 255 | + |
| 256 | +### Highcharts Theming |
| 257 | + |
| 258 | +```tsx |
| 259 | +import Highcharts from "highcharts/esm/highcharts"; |
| 260 | +import { createChart } from "@dschz/solid-highcharts"; |
| 261 | + |
| 262 | +// Apply global theme |
| 263 | +Highcharts.setOptions({ |
| 264 | + colors: ["#058DC7", "#50B432", "#ED561B", "#DDDF00"], |
| 265 | + chart: { |
| 266 | + backgroundColor: "#f9f9f9", |
| 267 | + style: { |
| 268 | + fontFamily: "Inter, sans-serif", |
| 269 | + }, |
| 270 | + }, |
| 271 | + title: { |
| 272 | + style: { |
| 273 | + color: "#333", |
| 274 | + fontSize: "18px", |
| 275 | + }, |
| 276 | + }, |
| 277 | +}); |
| 278 | + |
| 279 | +const Chart = createChart(Highcharts); |
| 280 | +``` |
| 281 | + |
| 282 | +## 📈 Performance Tips |
| 283 | + |
| 284 | +### 1. Use Chart Boost for Large Datasets |
| 285 | + |
| 286 | +```tsx |
| 287 | +import Highcharts from "highcharts/esm/highcharts"; |
| 288 | +import "highcharts/esm/modules/boost"; |
| 289 | + |
| 290 | +<Chart |
| 291 | + boost={{ |
| 292 | + useGPUTranslations: true, |
| 293 | + seriesThreshold: 50, |
| 294 | + }} |
| 295 | + series={[ |
| 296 | + { |
| 297 | + type: "line", |
| 298 | + data: largeDataset, // 1000+ points |
| 299 | + boostThreshold: 100, |
| 300 | + }, |
| 301 | + ]} |
| 302 | +/>; |
80 | 303 | ``` |
81 | 304 |
|
82 | | -> Note: For JSR publishing, Changeset does not update the jsr.json file after running `bun pkg:publish` so you have to manually update the version by hand after changeset has run. |
| 305 | +## 🤝 Contributing |
| 306 | + |
| 307 | +All contributions are welcome! Please see our [Contributing Guide](CONTRIBUTING.md) for details. |
83 | 308 |
|
84 | | -### Contributing |
| 309 | +### Development Setup |
| 310 | + |
| 311 | +```bash |
| 312 | +# Clone the repository |
| 313 | +git clone https://github.com/dsnchz/solid-highcharts.git |
| 314 | +cd solid-highcharts |
| 315 | + |
| 316 | +# Install dependencies |
| 317 | +bun install |
| 318 | + |
| 319 | +# Run tests |
| 320 | +bun test |
| 321 | + |
| 322 | +# Build the library |
| 323 | +bun run build |
| 324 | + |
| 325 | +# Start development server |
| 326 | +bun start |
| 327 | +``` |
85 | 328 |
|
86 | | -The only requirements when contributing are: |
| 329 | +## 📄 License |
87 | 330 |
|
88 | | -- You keep a clean git history in your branch |
89 | | - - rebasing `main` instead of making merge commits. |
90 | | -- Using proper commit message formats that adhere to [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/) |
91 | | - - Additionally, squashing (via rebase) commits that are not [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/) |
92 | | -- CI checks pass before merging into `main` |
| 331 | +MIT © [David Sanchez](https://github.com/dsnchz) |
0 commit comments