fulgur_chart 0.3.0-x64-mingw-ucrt
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.md +112 -0
- data/lib/fulgur_chart/3.1/fulgur_chart.so +0 -0
- data/lib/fulgur_chart/3.2/fulgur_chart.so +0 -0
- data/lib/fulgur_chart/3.3/fulgur_chart.so +0 -0
- data/lib/fulgur_chart/3.4/fulgur_chart.so +0 -0
- data/lib/fulgur_chart.rb +89 -0
- metadata +54 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: ca7f8ec21da9a8ef7e14212aeb4421e1dce3d4b4d9c547dfe85358540335c4d9
|
|
4
|
+
data.tar.gz: eecbfd75a3c06baaf2df0612d2f321626840c3cc3ff2541e77bdda5c5509a016
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 0f151dbad7b4a94f3979a78aef5c1497154f8a8d70e143b014fa3380b88f35f26c8bd68c1218a0190ffad1384ac0f66d930eb4567838db21966f1402c7f1f806
|
|
7
|
+
data.tar.gz: 31b7bb3706cc5e10f9c4ea0d1dabdf6ac8d76d4f56a1db998d5f5c8f4e45e5603cf92c3e67add6f0b8eeb75aba5dfcd2d435efc1f4dbe8a7245f15ec318d466d
|
data/README.md
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# fulgur_chart (Ruby)
|
|
2
|
+
|
|
3
|
+
Ruby binding for [fulgur-chart](https://github.com/fulgur-rs/fulgur-chart) — render
|
|
4
|
+
chart.js v4 / Vega-Lite JSON specs to deterministic SVG/PNG via a Rust native extension
|
|
5
|
+
([magnus](https://github.com/matsadler/magnus) / [rb-sys](https://github.com/oxidize-rb/rb-sys)).
|
|
6
|
+
|
|
7
|
+
## Requirements
|
|
8
|
+
|
|
9
|
+
- Ruby >= 3.0
|
|
10
|
+
- A Rust toolchain (`cargo`) — the gem builds a native extension at install time.
|
|
11
|
+
|
|
12
|
+
## Build / test from source
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
cd crates/bindings/ruby
|
|
16
|
+
bundle install
|
|
17
|
+
bundle exec rake # compile the native extension + run the test suite
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
`bundle exec rake` runs the `compile` task (which builds the Rust extension) followed by
|
|
21
|
+
the minitest suite.
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
The API is a fluent **builder**: `FulgurChart.build(spec)` returns a builder you configure with
|
|
26
|
+
chainable setters and finish with `render(:svg)` / `render(:png)`.
|
|
27
|
+
|
|
28
|
+
```ruby
|
|
29
|
+
require "fulgur_chart"
|
|
30
|
+
|
|
31
|
+
spec = <<~JSON
|
|
32
|
+
{
|
|
33
|
+
"type": "bar",
|
|
34
|
+
"data": {
|
|
35
|
+
"labels": ["a", "b", "c"],
|
|
36
|
+
"datasets": [{ "data": [1, 3, 2] }]
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
JSON
|
|
40
|
+
|
|
41
|
+
# SVG (UTF-8 String)
|
|
42
|
+
svg = FulgurChart.build(spec).render(:svg)
|
|
43
|
+
File.write("chart.svg", svg)
|
|
44
|
+
|
|
45
|
+
# PNG (binary / ASCII-8BIT String) — write with binwrite to avoid encoding mangling
|
|
46
|
+
png = FulgurChart.build(spec).width(800).height(600).scale(2.0).render(:png)
|
|
47
|
+
File.binwrite("chart.png", png)
|
|
48
|
+
|
|
49
|
+
# Set a default format with .format, then call render with no argument
|
|
50
|
+
png2 = FulgurChart.build(spec).format(:png).render
|
|
51
|
+
|
|
52
|
+
# The builder is reusable and reconfigurable between renders
|
|
53
|
+
chart = FulgurChart.build(spec).dsl(:chartjs)
|
|
54
|
+
a = chart.width(400).render(:svg)
|
|
55
|
+
b = chart.width(1234).render(:svg)
|
|
56
|
+
|
|
57
|
+
# JSON Schema for a DSL (compact JSON String)
|
|
58
|
+
chartjs_schema = FulgurChart.schema(:chartjs)
|
|
59
|
+
vegalite_schema = FulgurChart.schema("vegalite")
|
|
60
|
+
|
|
61
|
+
# Library version (String, e.g. "0.1.0")
|
|
62
|
+
FulgurChart.version
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
The DSL is auto-detected from the spec: a top-level `mark` key selects Vega-Lite, a
|
|
66
|
+
top-level `type` key selects chart.js. Use `.dsl(:chartjs)` / `.dsl(:vegalite)` to override.
|
|
67
|
+
Options accept either a Symbol or a String (`.dsl(:chartjs)` == `.dsl("chartjs")`).
|
|
68
|
+
|
|
69
|
+
### API
|
|
70
|
+
|
|
71
|
+
| Method | Returns |
|
|
72
|
+
| --- | --- |
|
|
73
|
+
| `FulgurChart.build(spec_json)` | a `FulgurChart::Builder` |
|
|
74
|
+
| `builder.render(format = nil)` | `String` — `:svg` → UTF-8, `:png` → binary (ASCII-8BIT). Format precedence: argument > `.format()` > default `:svg` |
|
|
75
|
+
| `FulgurChart.render(spec_json, format, **opts)` | low-level primitive the builder calls; same return contract |
|
|
76
|
+
| `FulgurChart.schema(dsl)` | JSON Schema `String` for `:chartjs` or `:vegalite` |
|
|
77
|
+
| `FulgurChart.version` | version `String` |
|
|
78
|
+
|
|
79
|
+
### Builder setters
|
|
80
|
+
|
|
81
|
+
Each setter returns the builder for chaining; all are optional.
|
|
82
|
+
|
|
83
|
+
| Setter | Type | Notes |
|
|
84
|
+
| --- | --- | --- |
|
|
85
|
+
| `.width(w)` / `.height(h)` | Float | Canvas size override (applied before input-limit validation). |
|
|
86
|
+
| `.scale(s)` | Float | Raster scale factor; raster output only (ignored when rendering `:svg`). Default `1.0`. |
|
|
87
|
+
| `.strict` / `.strict(bool)` | Bool | Reject unknown keys (raises `StrictError`). `.strict` ⇒ `true`. Default `false`. |
|
|
88
|
+
| `.dsl(d)` | `:chartjs` \| `:vegalite` (Symbol/String) | Override DSL auto-detection. |
|
|
89
|
+
| `.font(bytes)` | binary `String` | A TTF/OTF font to use instead of the bundled default (Noto Sans JP). |
|
|
90
|
+
| `.format(f)` | `:svg` \| `:png` (Symbol/String) | Default format for a terminal `render` with no argument. |
|
|
91
|
+
|
|
92
|
+
### Errors
|
|
93
|
+
|
|
94
|
+
The error hierarchy lives in the native extension under the `FulgurChart` module
|
|
95
|
+
(the module is `FulgurChart`, not `Fulgur`, to avoid a top-level collision with the
|
|
96
|
+
Fulgur PDF library when both gems are loaded in the same process):
|
|
97
|
+
|
|
98
|
+
- `FulgurChart::ParseError < StandardError` — invalid JSON, undetectable DSL, unknown format,
|
|
99
|
+
input-limit violations.
|
|
100
|
+
- `FulgurChart::StrictError < FulgurChart::ParseError` — unknown key encountered under `.strict`.
|
|
101
|
+
- `FulgurChart::RenderError < StandardError` — raster rendering failure.
|
|
102
|
+
|
|
103
|
+
Note the font-error asymmetry: an invalid font raises `FulgurChart::ParseError` when rendering
|
|
104
|
+
`:svg` but `FulgurChart::RenderError` when rendering `:png`, because the two outputs go through
|
|
105
|
+
different render pipelines.
|
|
106
|
+
|
|
107
|
+
## Note: packaging
|
|
108
|
+
|
|
109
|
+
The published-gem story — source-installing the path-dependent Rust core and shipping
|
|
110
|
+
cross-platform prebuilt gems — is tracked as a follow-up. Today the gem builds against the
|
|
111
|
+
in-repo core via a Cargo path dependency, so it is intended for use from within this
|
|
112
|
+
repository (build from source as shown above).
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
data/lib/fulgur_chart.rb
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Native extension. Defines the FulgurChart module with:
|
|
4
|
+
# - FulgurChart.schema(dsl), FulgurChart.version
|
|
5
|
+
# - FulgurChart.render(spec_json, format, **opts) (low-level render primitive; the builder
|
|
6
|
+
# below is the intended API, but render is also callable directly)
|
|
7
|
+
# - errors: FulgurChart::ParseError / StrictError / RenderError
|
|
8
|
+
# Module name is `FulgurChart` (NOT `Fulgur`) to avoid a top-level collision with the
|
|
9
|
+
# Fulgur (PDF) library when both gems are loaded in the same process.
|
|
10
|
+
require_relative "fulgur_chart/fulgur_chart"
|
|
11
|
+
|
|
12
|
+
module FulgurChart
|
|
13
|
+
# Entry point for the builder API:
|
|
14
|
+
#
|
|
15
|
+
# FulgurChart.build(spec_json).width(800).dsl(:chartjs).render(:svg) # => String
|
|
16
|
+
# FulgurChart.build(spec_json).format(:png).render # => binary String
|
|
17
|
+
#
|
|
18
|
+
# `spec_json` is a chart.js v4 / Vega-Lite DSL JSON string. The behavior (DSL auto-detect,
|
|
19
|
+
# options, error classes, determinism) follows docs/binding-api-contract.md.
|
|
20
|
+
def self.build(spec_json)
|
|
21
|
+
Builder.new(spec_json)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Fluent, reusable builder. Setters mutate and return self; `render` may be called multiple
|
|
25
|
+
# times and the builder may be reconfigured between calls.
|
|
26
|
+
class Builder
|
|
27
|
+
def initialize(spec_json)
|
|
28
|
+
@spec = spec_json
|
|
29
|
+
@opts = {}
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Override the chart width / height (px). Applied before input-limit validation.
|
|
33
|
+
def width(value)
|
|
34
|
+
set(:width, value)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def height(value)
|
|
38
|
+
set(:height, value)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Raster scale factor (ignored when rendering SVG).
|
|
42
|
+
def scale(value)
|
|
43
|
+
set(:scale, value)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Force the input DSL ("chartjs"/"vegalite" or the matching Symbol). Omit to auto-detect.
|
|
47
|
+
def dsl(value)
|
|
48
|
+
set(:dsl, value)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# TrueType/OpenType font bytes (binary String). Omit to use the bundled Noto Sans JP.
|
|
52
|
+
def font(bytes)
|
|
53
|
+
set(:font, bytes)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Reject unknown keys. `strict` => true; `strict(false)` => false.
|
|
57
|
+
def strict(value = true)
|
|
58
|
+
set(:strict, value)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Default output format for a terminal `render` with no argument (Symbol/String).
|
|
62
|
+
def format(value)
|
|
63
|
+
set(:format, value)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# Render to the given format ("svg"/"png" or the matching Symbol). Format precedence:
|
|
67
|
+
# explicit argument > `.format()` setter > default :svg. Returns a UTF-8 String for svg
|
|
68
|
+
# and a binary (ASCII-8BIT) String for png.
|
|
69
|
+
def render(fmt = nil)
|
|
70
|
+
# Distinguish "no explicit format" (nil) from a falsy-but-explicit one (e.g. false).
|
|
71
|
+
# An explicit argument always wins per the documented precedence; an invalid value is
|
|
72
|
+
# forwarded to the native layer to raise ParseError rather than silently falling back.
|
|
73
|
+
resolved =
|
|
74
|
+
if fmt.nil?
|
|
75
|
+
@opts.key?(:format) ? @opts[:format] : :svg
|
|
76
|
+
else
|
|
77
|
+
fmt
|
|
78
|
+
end
|
|
79
|
+
FulgurChart.render(@spec, resolved, **@opts.reject { |key, _| key == :format })
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
private
|
|
83
|
+
|
|
84
|
+
def set(key, value)
|
|
85
|
+
@opts[key] = value
|
|
86
|
+
self
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: fulgur_chart
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.3.0
|
|
5
|
+
platform: x64-mingw-ucrt
|
|
6
|
+
authors:
|
|
7
|
+
- Fulgur
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2026-06-21 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Render chart.js / Vega-Lite specs to deterministic SVG/PNG (Rust core)
|
|
14
|
+
email:
|
|
15
|
+
executables: []
|
|
16
|
+
extensions: []
|
|
17
|
+
extra_rdoc_files: []
|
|
18
|
+
files:
|
|
19
|
+
- README.md
|
|
20
|
+
- lib/fulgur_chart.rb
|
|
21
|
+
- lib/fulgur_chart/3.1/fulgur_chart.so
|
|
22
|
+
- lib/fulgur_chart/3.2/fulgur_chart.so
|
|
23
|
+
- lib/fulgur_chart/3.3/fulgur_chart.so
|
|
24
|
+
- lib/fulgur_chart/3.4/fulgur_chart.so
|
|
25
|
+
homepage: https://github.com/fulgur-rs/fulgur-chart
|
|
26
|
+
licenses:
|
|
27
|
+
- MIT OR Apache-2.0
|
|
28
|
+
metadata:
|
|
29
|
+
homepage_uri: https://github.com/fulgur-rs/fulgur-chart
|
|
30
|
+
source_code_uri: https://github.com/fulgur-rs/fulgur-chart
|
|
31
|
+
changelog_uri: https://github.com/fulgur-rs/fulgur-chart/blob/main/crates/fulgur-chart/CHANGELOG.md
|
|
32
|
+
post_install_message:
|
|
33
|
+
rdoc_options: []
|
|
34
|
+
require_paths:
|
|
35
|
+
- lib
|
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '3.1'
|
|
41
|
+
- - "<"
|
|
42
|
+
- !ruby/object:Gem::Version
|
|
43
|
+
version: 3.5.dev
|
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
45
|
+
requirements:
|
|
46
|
+
- - ">="
|
|
47
|
+
- !ruby/object:Gem::Version
|
|
48
|
+
version: '0'
|
|
49
|
+
requirements: []
|
|
50
|
+
rubygems_version: 3.5.23
|
|
51
|
+
signing_key:
|
|
52
|
+
specification_version: 4
|
|
53
|
+
summary: Render chart.js / Vega-Lite specs to deterministic SVG/PNG (Rust core)
|
|
54
|
+
test_files: []
|