fulgur_chart 0.3.0-aarch64-linux

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 239e98d6a8a35abc6ee3c1de4ffc33f2f93787c5a69c8cd3cdb7672ebc4a0f2c
4
+ data.tar.gz: fd107d207f45fa6e25c040ed31cdc5a230c7c7fdcb1262a6b0774aa1802b05e6
5
+ SHA512:
6
+ metadata.gz: 3f5c233d9a5d99d30c16bba26dceb65403538eee37c1decf945344e59e9fc5d11d31e8ca688b8b2dc52b2c23f288550b22154bfc97a3d75f3c6ce07437eb0dd7
7
+ data.tar.gz: 13d0c4ebf2802c391f370218083244f955c0fc8eb1d637de352514f07a5a0cf6e7f7732bb0d60c693681b3f54acdef4af154bc4c030aaefd367fe5d6b6d47133
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).
@@ -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: aarch64-linux
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: []