Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 4 additions & 48 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,64 +1,20 @@
cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.5...3.29)

set(TARGET_NAME miniplot)

find_package(OpenSSL REQUIRED)

set(EXTENSION_NAME ${TARGET_NAME}_extension)
set(LOADABLE_EXTENSION_NAME ${TARGET_NAME}_loadable_extension)

project(${TARGET_NAME})
include_directories(src/include)

set(EXTENSION_SOURCES src/miniplot_extension.cpp)

# Rust静的ライブラリのパス
set(CHART_VIEWER_DIR ${CMAKE_CURRENT_SOURCE_DIR}/chart_viewer)
set(RUST_LIB ${CHART_VIEWER_DIR}/target/release/libchart_viewer.a)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

# Rustライブラリを自動ビルド
add_custom_command(
OUTPUT ${RUST_LIB}
COMMAND cargo build --release --lib
WORKING_DIRECTORY ${CHART_VIEWER_DIR}
COMMENT "Building Rust chart_viewer library..."
VERBATIM
)
set(EXTENSION_SOURCES src/miniplot_extension.cpp)

add_custom_target(rust_chart_viewer ALL
DEPENDS ${RUST_LIB}
)
include_directories(src/include)

# DuckDBエクステンションをビルド
build_static_extension(${TARGET_NAME} ${EXTENSION_SOURCES})
build_loadable_extension(${TARGET_NAME} " " ${EXTENSION_SOURCES})

# 依存関係を追加
add_dependencies(${EXTENSION_NAME} rust_chart_viewer)
add_dependencies(${LOADABLE_EXTENSION_NAME} rust_chart_viewer)

# OpenSSLリンク
target_link_libraries(${EXTENSION_NAME} OpenSSL::SSL OpenSSL::Crypto)
target_link_libraries(${LOADABLE_EXTENSION_NAME} OpenSSL::SSL OpenSSL::Crypto)

# Rust静的ライブラリをリンク(重要!)
target_link_libraries(${EXTENSION_NAME} ${RUST_LIB})
target_link_libraries(${LOADABLE_EXTENSION_NAME} ${RUST_LIB})

# macOS用のシステムライブラリ
if(APPLE)
target_link_libraries(${EXTENSION_NAME}
"-framework Foundation"
"-framework Security"
resolv
)
target_link_libraries(${LOADABLE_EXTENSION_NAME}
"-framework Foundation"
"-framework Security"
resolv
)
endif()

install(
TARGETS ${EXTENSION_NAME}
EXPORT "${DUCKDB_EXPORT_SET}"
Expand Down
74 changes: 39 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ No more switching between pandas and matplotlib for data visualization.

## ✨ What's New in v0.0.2

- 🔄 **Complete rewrite** using Plotly.js for better compatibility
- 🔄 **Complete C++-only rewrite** - Removed Rust dependency for better compatibility
- 🌐 **Browser-based rendering** - Charts open in your default browser
- 📦 **Fully offline** - Plotly.js embedded (3.4MB), no internet required
- 📦 **Lightweight build** - Uses Plotly.js CDN (no large embedded libraries)
- 🎨 **Interactive features** - Zoom, pan, hover tooltips, export to PNG
- 🚀 **Simpler architecture** - No external binaries or process management
- ⚡ **Single file** - Just 9.2MB, install and use immediately
- 🚀 **Worker thread compatible** - Works in DuckDB Community Extensions
- ⚡ **Single binary** - No external dependencies at runtime

## Features

- 📊 **Multiple chart types**: Bar, Line, Scatter, and Area charts
- 🖥️ **Browser-based rendering**: Charts open in your default web browser
- 🚀 **Simple SQL interface**: Visualize data directly from SQL queries
- 💻 **Cross-platform**: Works on macOS, Linux, and Windows
- 🔒 **Fully offline**: No internet connection required
- 🌐 **Internet required**: Initial chart rendering requires internet connection (Plotly.js loads from CDN, then cached by browser)
- ✨ **Interactive**: Zoom, pan, hover, and export capabilities

## Installation
Expand All @@ -35,8 +35,6 @@ INSTALL miniplot FROM community;
LOAD miniplot;
```

````

That's it! No additional setup required.

## Usage
Expand Down Expand Up @@ -100,6 +98,22 @@ SELECT bar_chart(
) FROM sales;
```

### Working with CSV Files

```sql
-- Load CSV data
CREATE TABLE stocks AS
SELECT * FROM read_csv_auto('stocks.csv');

-- Visualize stock prices
SELECT line_chart(
list(CAST(date AS VARCHAR) ORDER BY date),
list(price ORDER BY date),
'Stock Price Trend'
)
FROM stocks;
```

## How It Works

```
Expand All @@ -108,30 +122,11 @@ SQL Query → Data Extraction → HTML Generation → Browser Opens → Interact

1. **SQL Query** → Execute chart function with your data
2. **Data Extraction** → Extension processes your data
3. **HTML Generation** → Creates HTML with embedded Plotly.js
3. **HTML Generation** → Creates HTML with Plotly.js CDN link
4. **Browser Opens** → Opens in your default browser
5. **Interactive Chart** → Zoom, pan, hover, export

## Why Miniplot?

### vs pandas + matplotlib

| Feature | miniplot | pandas + matplotlib |
| --------------------- | ------------- | --------------------- |
| **Language** | SQL only | Python required |
| **Setup** | 1 SQL command | pip install × 2 |
| **Context Switching** | None | Query → Python → Plot |
| **Interactive** | ✅ Full | ❌ Static images |
| **Data Size** | Unlimited | Memory limited |

### vs Jupyter + Plotly

| Feature | miniplot | Jupyter + Plotly |
| ---------------- | -------------- | ----------------- |
| **Environment** | Any SQL client | Browser + Server |
| **Deployment** | Single binary | Python + packages |
| **Startup Time** | Instant | Notebook loading |
| **Sharing** | SQL query | Notebook file |
**Note**: Charts require internet connection on first use. After initial load, Plotly.js is cached by your browser and works offline.

## Architecture

Expand All @@ -144,16 +139,17 @@ SQL Query → Data Extraction → HTML Generation → Browser Opens → Interact
└────────────┬────────────────────┘
┌─────────────────────────────────┐
│ Extension (9.2MB)
│ - C++ interface
│ - Rust HTML generator
│ - Plotly.js embedded
│ Extension (C++)
│ - Data extraction
│ - HTML generation
│ - Plotly.js CDN link
└────────────┬────────────────────┘
┌─────────────────────────────────┐
│ Browser Opens │
│ - Loads Plotly.js from CDN │
│ - Interactive chart │
│ - No internet needed
│ - Caches for offline use
└─────────────────────────────────┘
```

Expand All @@ -178,6 +174,12 @@ All charts include:
- 💾 **Export** - Download as PNG image
- 🔄 **Reset** - Double-click to reset view

## Requirements

- **Internet connection**: Required for first-time chart rendering (Plotly.js loads from CDN)
- **Browser**: Any modern web browser (Chrome, Firefox, Safari, Edge)
- After initial use, charts work offline (browser caches Plotly.js)

## License

MIT License - see [LICENSE](LICENSE) file
Expand All @@ -186,12 +188,14 @@ MIT License - see [LICENSE](LICENSE) file

- Built with [DuckDB](https://duckdb.org/)
- Powered by [Plotly.js](https://plotly.com/javascript/)
- Written in [Rust](https://www.rust-lang.org/) and C++
- Written in C++

## Links

- [Community Extensions](https://github.com/duckdb/community-extensions)
- [Issue Tracker](https://github.com/nkwork9999/miniplot/issues)
- [DuckDB Documentation](https://duckdb.org/docs/)

````
```

```
28 changes: 11 additions & 17 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,29 +1,23 @@
#!/bin/bash
set -e

echo "=== Building Miniplot Extension (Offline Plotly.js) ==="
echo "=== Building Miniplot Extension (100% Offline) ==="

# Plotly.jsの存在確認
if [ ! -f "chart_viewer/assets/plotly.min.js" ]; then
echo "Error: plotly.min.js not found!"
echo "Please download it first:"
echo " mkdir -p chart_viewer/assets"
echo " curl -o chart_viewer/assets/plotly.min.js https://cdn.plot.ly/plotly-2.27.0.min.js"
exit 1
fi

echo "Step 1: Building Rust library..."
cd chart_viewer
cargo build --release --lib
cd ..
# Step 1: Plotly.jsを埋め込み
echo ""
echo "Step 1: Embedding Plotly.js..."
bash scripts/embed_plotly.sh # chmod不要で直接bashで実行

# Step 2: DuckDBエクステンションをビルド
echo ""
echo "Step 2: Building DuckDB extension..."
make release

echo ""
echo "=== Build Complete ==="
echo "Extension: build/release/extension/miniplot/miniplot.duckdb_extension"
echo ""
ls -lh build/release/extension/miniplot/miniplot.duckdb_extension

echo ""
echo "Plotly.js embedded: $(ls -lh chart_viewer/assets/plotly.min.js | awk '{print $5}')"
echo "✓ Extension built successfully"
echo "✓ 100% offline (no CDN dependencies)"
echo "✓ Plotly.js embedded (~3MB)"
7 changes: 0 additions & 7 deletions chart_viewer/Cargo.lock

This file was deleted.

11 changes: 0 additions & 11 deletions chart_viewer/Cargo.toml

This file was deleted.

8 changes: 0 additions & 8 deletions chart_viewer/assets/plotly.min.js

This file was deleted.

Loading
Loading