railsui_charts 0.2.2 → 0.2.3
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 +4 -4
- data/CHANGELOG.md +56 -1
- data/README.md +42 -2
- data/app/assets/stylesheets/railsui_charts.css +45 -0
- data/lib/generators/railsui_charts/install/install_generator.rb +59 -13
- data/lib/railsui_charts/chart_helper.rb +7 -3
- data/lib/railsui_charts/version.rb +1 -1
- data/package.json +4 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: edb2d338949929fa733699ed8c06cc91edd16c4e5bf9621db0e1db0fa019b245
|
|
4
|
+
data.tar.gz: dfb7e2e6dabeb591d544fdcf68070ea997451bd7f1fb19bb36a5f793a9160bbd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 40dc738c972145c4b092a9802f77ea3a406b97305cf2c9355f209ac3bdd97612982fc6fea6c62b83e6ba20686fc67313b04bb1a18152685a68f11724df2bbe40
|
|
7
|
+
data.tar.gz: 04a089986c882997b1b297ed048495facf4a6da6761b9bafdfc4c5fb80a1d094cffe544fd30670469736d46c3ca497f9ffd6b3345a65663ff72e57e84a5a7bcb
|
data/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,41 @@ public API may change between minor versions.
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.2.3]
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
|
|
13
|
+
- The installer no longer writes a stylesheet import that cannot resolve. From
|
|
14
|
+
0.1.0 through 0.2.2 it appended `@import "../../stylesheets/railsui_charts";`
|
|
15
|
+
to `app/assets/tailwind/application.css`. Relative to that file the path names
|
|
16
|
+
`app/stylesheets` — not the application's own `app/assets/stylesheets`, and not
|
|
17
|
+
the gem's copy, which lives outside the application where no relative path can
|
|
18
|
+
reach it. Tailwind does not quietly skip an import it cannot resolve; it fails
|
|
19
|
+
the build. So an application that ran the installer and used Tailwind did not
|
|
20
|
+
get unstyled charts, it got no stylesheet build at all, and one that did not
|
|
21
|
+
use Tailwind never received the CSS by any route.
|
|
22
|
+
|
|
23
|
+
The stylesheet is now served from the gem through the asset pipeline, which
|
|
24
|
+
already carried it, and the installer links it in the application layout.
|
|
25
|
+
Nothing is copied, so `bundle update` moves the CSS the way it already moves
|
|
26
|
+
the Ruby and the JavaScript. Running `rails g railsui_charts:install` again
|
|
27
|
+
takes the old import back out.
|
|
28
|
+
|
|
29
|
+
- Chart data tables are hidden by the gem's own `.railsui-chart-data-table`
|
|
30
|
+
rather than by the host application's `sr-only`. An application not running
|
|
31
|
+
Tailwind has no such class, and rendered the table at full size in the middle
|
|
32
|
+
of the page. Even where it exists it does not hide a table: `width: 1px` is a
|
|
33
|
+
suggestion a table box ignores, because CSS never sizes one below its
|
|
34
|
+
min-content width. The table laid out at full width and, being positioned,
|
|
35
|
+
pushed the page's scroll width past the viewport — which on a phone reads as
|
|
36
|
+
the whole page sliding sideways. `table-layout: fixed` is what makes the width
|
|
37
|
+
stick. `sr-only` rides along for applications that already style it.
|
|
38
|
+
|
|
39
|
+
### Added
|
|
40
|
+
|
|
41
|
+
- `@getrailsui/charts/styles.css`, for an application that would rather pull the
|
|
42
|
+
stylesheet into its own Tailwind build than link it separately.
|
|
43
|
+
|
|
9
44
|
## [0.2.2]
|
|
10
45
|
|
|
11
46
|
### Added
|
|
@@ -19,6 +54,23 @@ public API may change between minor versions.
|
|
|
19
54
|
|
|
20
55
|
### Fixed
|
|
21
56
|
|
|
57
|
+
- Series that do not share an x-axis now align to the union of their labels, or
|
|
58
|
+
to an explicit `categories:` when one is given, since series order is not
|
|
59
|
+
always reading order. Categories were read off the first series alone and
|
|
60
|
+
every later series was flattened to bare values from position zero, so a
|
|
61
|
+
projection labelled November landed on January, on top of the history it was
|
|
62
|
+
meant to continue. Apex draws the resulting gaps as gaps.
|
|
63
|
+
- A complex combo keeps a `categories:` it was given. Derived lists are still
|
|
64
|
+
stripped, because one alongside numeric pair data makes Apex plot nothing, but
|
|
65
|
+
Apex reads `xaxis.categories` ahead of everything else and without one sets the
|
|
66
|
+
axis from the first series alone. For a forecast that was ruinous: the band is
|
|
67
|
+
drawn first so it sits behind the lines, so the projection's months became the
|
|
68
|
+
whole axis and the earlier history disappeared.
|
|
69
|
+
|
|
70
|
+
## [0.2.1]
|
|
71
|
+
|
|
72
|
+
### Fixed
|
|
73
|
+
|
|
22
74
|
- Sparkline charts now use the Rails UI tooltip renderer, so hovered points show
|
|
23
75
|
their label and formatted value instead of an empty tooltip.
|
|
24
76
|
- Range-bar and labelled-point tooltips now read the hovered point from the
|
|
@@ -134,7 +186,10 @@ First release.
|
|
|
134
186
|
reachable only by hovering a mark
|
|
135
187
|
- Animation stops when the reader has asked for reduced motion
|
|
136
188
|
|
|
137
|
-
[Unreleased]: https://github.com/getrailsui/railsui_charts/compare/v0.2.
|
|
189
|
+
[Unreleased]: https://github.com/getrailsui/railsui_charts/compare/v0.2.3...HEAD
|
|
190
|
+
[0.2.3]: https://github.com/getrailsui/railsui_charts/compare/v0.2.2...v0.2.3
|
|
191
|
+
[0.2.2]: https://github.com/getrailsui/railsui_charts/compare/v0.2.1...v0.2.2
|
|
192
|
+
[0.2.1]: https://github.com/getrailsui/railsui_charts/compare/v0.2.0...v0.2.1
|
|
138
193
|
[0.2.0]: https://github.com/getrailsui/railsui_charts/compare/v0.1.2...v0.2.0
|
|
139
194
|
[0.1.2]: https://github.com/getrailsui/railsui_charts/compare/v0.1.1...v0.1.2
|
|
140
195
|
[0.1.1]: https://github.com/getrailsui/railsui_charts/compare/v0.1.0...v0.1.1
|
data/README.md
CHANGED
|
@@ -42,8 +42,31 @@ bundle install
|
|
|
42
42
|
rails g railsui_charts:install
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
-
The generator
|
|
46
|
-
rather than copied into your app, so
|
|
45
|
+
The generator links the stylesheet in your layout. Both the CSS and the
|
|
46
|
+
JavaScript are served from the gem rather than copied into your app, so
|
|
47
|
+
`bundle update` moves all of it.
|
|
48
|
+
|
|
49
|
+
### Stylesheet
|
|
50
|
+
|
|
51
|
+
The generator adds this to your layout's `<head>`:
|
|
52
|
+
|
|
53
|
+
```erb
|
|
54
|
+
<%= stylesheet_link_tag "railsui_charts" %>
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
The engine puts the file on the asset path and precompiles it, so this works on
|
|
58
|
+
Propshaft and on Sprockets without anything further.
|
|
59
|
+
|
|
60
|
+
If you would rather the CSS went through your own Tailwind build — to control
|
|
61
|
+
where it lands in the cascade, say — install the npm package below and import it
|
|
62
|
+
instead of linking it:
|
|
63
|
+
|
|
64
|
+
```css
|
|
65
|
+
/* app/assets/tailwind/application.css */
|
|
66
|
+
@import "@getrailsui/charts/styles.css";
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Do one or the other, not both.
|
|
47
70
|
|
|
48
71
|
### Bundled apps (esbuild, bun, rollup, webpack)
|
|
49
72
|
|
|
@@ -75,6 +98,23 @@ import { registerRailsuiCharts } from "@getrailsui/charts"
|
|
|
75
98
|
registerRailsuiCharts(application)
|
|
76
99
|
```
|
|
77
100
|
|
|
101
|
+
### Upgrading from 0.2.2 and earlier
|
|
102
|
+
|
|
103
|
+
Those versions' installer wrote an `@import` into `app/assets/tailwind/application.css`
|
|
104
|
+
that could never resolve — it named `app/stylesheets`, which is neither your app's
|
|
105
|
+
stylesheets nor the gem's. Tailwind fails the build on an import it cannot find, so
|
|
106
|
+
if you have this line, your CSS build is broken:
|
|
107
|
+
|
|
108
|
+
```css
|
|
109
|
+
@import "../../stylesheets/railsui_charts";
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Running the installer again removes it and links the stylesheet properly:
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
rails g railsui_charts:install
|
|
116
|
+
```
|
|
117
|
+
|
|
78
118
|
### Upgrading from 0.1.x
|
|
79
119
|
|
|
80
120
|
0.1.x copied the controllers into `app/javascript/controllers`. Those copies are
|
|
@@ -110,6 +110,51 @@
|
|
|
110
110
|
width: 100%;
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
+
/* ------------------------------------------------------------- chart data */
|
|
114
|
+
|
|
115
|
+
/* The table behind every chart: out of sight, still in the accessibility tree,
|
|
116
|
+
so no value is reachable only by hovering a mark.
|
|
117
|
+
*
|
|
118
|
+
* Hidden here rather than by borrowing the host's `sr-only`, for two reasons.
|
|
119
|
+
* An app that is not running Tailwind has no such class, and the table renders
|
|
120
|
+
* at full size in the middle of the page. And even where it exists, `sr-only`
|
|
121
|
+
* does not hide a table: it shrinks an element to 1px and clips the rest, but
|
|
122
|
+
* width is only a suggestion to a table box, which CSS never sizes below its
|
|
123
|
+
* min-content width. The hidden table lays out at its full width, and since it
|
|
124
|
+
* is positioned, it pushes the page's scroll width past the viewport — which
|
|
125
|
+
* on a phone reads as the whole page sliding sideways.
|
|
126
|
+
*
|
|
127
|
+
* Fixed layout is what makes the 1px stick. The caption needs the same
|
|
128
|
+
* treatment for the same reason: left in flow, its own min-content width holds
|
|
129
|
+
* the table open on its own. Neither is removed from the accessibility tree.
|
|
130
|
+
*
|
|
131
|
+
* The height stays at the table's own — that one is a minimum a table will not
|
|
132
|
+
* go under either, and `contain` does not apply to a table box. It costs
|
|
133
|
+
* nothing: the element is out of flow, and a page carrying a chart is taller
|
|
134
|
+
* than the table under it. Collapsing it would take `display: block`, which
|
|
135
|
+
* throws away the table semantics this element exists for. */
|
|
136
|
+
.railsui-chart-data-table {
|
|
137
|
+
position: absolute;
|
|
138
|
+
width: 1px;
|
|
139
|
+
height: 1px;
|
|
140
|
+
padding: 0;
|
|
141
|
+
margin: -1px;
|
|
142
|
+
border: 0;
|
|
143
|
+
overflow: hidden;
|
|
144
|
+
white-space: nowrap;
|
|
145
|
+
clip-path: inset(50%);
|
|
146
|
+
table-layout: fixed;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
.railsui-chart-data-table > caption {
|
|
150
|
+
position: absolute;
|
|
151
|
+
width: 1px;
|
|
152
|
+
height: 1px;
|
|
153
|
+
overflow: hidden;
|
|
154
|
+
white-space: nowrap;
|
|
155
|
+
clip-path: inset(50%);
|
|
156
|
+
}
|
|
157
|
+
|
|
113
158
|
/* -------------------------------------------------------- small multiples */
|
|
114
159
|
|
|
115
160
|
.railsui-small-multiples {
|
|
@@ -8,23 +8,62 @@ module RailsuiCharts
|
|
|
8
8
|
# version was installed — a fix could ship and reach nobody. Bundled apps
|
|
9
9
|
# take it from npm, importmap apps from the pin this engine adds, and both
|
|
10
10
|
# follow the gem from then on.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
#
|
|
12
|
+
# The stylesheet now follows the same rule, for the same reason and after
|
|
13
|
+
# the same mistake. See remove_broken_css_import.
|
|
14
|
+
|
|
15
|
+
LAYOUT = "app/views/layouts/application.html.erb"
|
|
16
|
+
TAILWIND_ENTRY = "app/assets/tailwind/application.css"
|
|
17
|
+
STYLESHEET_TAG = %q(<%= stylesheet_link_tag "railsui_charts" %>).freeze
|
|
18
|
+
|
|
19
|
+
# What 0.1.0 through 0.2.2 wrote into the Tailwind entry. It never worked.
|
|
20
|
+
# Relative to app/assets/tailwind it names app/stylesheets — not the
|
|
21
|
+
# application's own app/assets/stylesheets, and certainly not the file it
|
|
22
|
+
# was after, which lives inside the gem where no relative path from the
|
|
23
|
+
# application can reach it. Tailwind does not quietly skip an import it
|
|
24
|
+
# cannot resolve; it fails the build. So this is removed rather than
|
|
25
|
+
# corrected, from anyone who ran the old generator.
|
|
26
|
+
BROKEN_IMPORT = %r{^@import\s+"\.\./\.\./stylesheets/railsui_charts";?[ \t]*\r?\n}.freeze
|
|
27
|
+
|
|
28
|
+
def remove_broken_css_import
|
|
29
|
+
path = File.join(destination_root, TAILWIND_ENTRY)
|
|
30
|
+
return unless File.exist?(path)
|
|
31
|
+
|
|
32
|
+
contents = File.read(path)
|
|
33
|
+
return unless contents.match?(BROKEN_IMPORT)
|
|
34
|
+
|
|
35
|
+
File.write(path, contents.sub(BROKEN_IMPORT, ""))
|
|
36
|
+
say "✓ Removed the unresolvable @import from #{TAILWIND_ENTRY}", :green
|
|
37
|
+
say " It named a path that does not exist and failed the Tailwind build.", :yellow
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Served from the gem through the asset pipeline, which already carries it:
|
|
41
|
+
# the engine puts app/assets/stylesheets on the load path and precompiles
|
|
42
|
+
# the file. Nothing is copied, so `bundle update` moves the CSS too.
|
|
43
|
+
def add_stylesheet_link
|
|
44
|
+
path = File.join(destination_root, LAYOUT)
|
|
45
|
+
|
|
46
|
+
unless File.exist?(path)
|
|
47
|
+
say "⚠️ #{LAYOUT} not found. Add this to your layout's <head>:", :yellow
|
|
48
|
+
say " #{STYLESHEET_TAG}"
|
|
19
49
|
return
|
|
20
50
|
end
|
|
21
51
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
52
|
+
contents = File.read(path)
|
|
53
|
+
|
|
54
|
+
if contents.include?(%("railsui_charts"))
|
|
55
|
+
say "✓ Rails UI Charts stylesheet already linked", :green
|
|
56
|
+
return
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
unless contents.match?(%r{</head>})
|
|
60
|
+
say "⚠️ No </head> found in #{LAYOUT}. Add this to your layout's <head>:", :yellow
|
|
61
|
+
say " #{STYLESHEET_TAG}"
|
|
62
|
+
return
|
|
27
63
|
end
|
|
64
|
+
|
|
65
|
+
inject_into_file LAYOUT, " #{STYLESHEET_TAG}\n", before: %r{^[ \t]*</head>}
|
|
66
|
+
say "✓ Linked the Rails UI Charts stylesheet in #{LAYOUT}", :green
|
|
28
67
|
end
|
|
29
68
|
|
|
30
69
|
def print_next_steps
|
|
@@ -51,6 +90,13 @@ module RailsuiCharts
|
|
|
51
90
|
say "ApexCharts is a peer dependency; pin it too:", :cyan
|
|
52
91
|
say ' pin "apexcharts", to: "https://esm.sh/apexcharts@3.45.2"', :cyan
|
|
53
92
|
say ""
|
|
93
|
+
elsif File.exist?(File.join(destination_root, TAILWIND_ENTRY))
|
|
94
|
+
say "Prefer the CSS inside your Tailwind build? Once the package is", :cyan
|
|
95
|
+
say "installed you can drop the stylesheet_link_tag and import it:", :cyan
|
|
96
|
+
say ""
|
|
97
|
+
say " /* #{TAILWIND_ENTRY} */", :cyan
|
|
98
|
+
say ' @import "@getrailsui/charts/styles.css";', :cyan
|
|
99
|
+
say ""
|
|
54
100
|
end
|
|
55
101
|
|
|
56
102
|
say "Then use <%= railsui_chart data, type: :area %> in your views.", :cyan
|
|
@@ -163,7 +163,11 @@ module RailsuiCharts
|
|
|
163
163
|
end
|
|
164
164
|
|
|
165
165
|
# Every chart ships a visually hidden table so no value is reachable only by
|
|
166
|
-
# hovering a mark.
|
|
166
|
+
# hovering a mark. The hiding is the gem's own — `sr-only` rides along for
|
|
167
|
+
# apps that already style it, but a host utility cannot be relied on to
|
|
168
|
+
# exist, and Tailwind's does not actually hide a table. See
|
|
169
|
+
# railsui-chart-data-table in the stylesheet.
|
|
170
|
+
#
|
|
167
171
|
# The table a caller supplied, rather than one derived from the series.
|
|
168
172
|
#
|
|
169
173
|
# This is the accessible half of an extension point: a downstream helper
|
|
@@ -176,7 +180,7 @@ module RailsuiCharts
|
|
|
176
180
|
rows = Array(table[:rows] || table["rows"])
|
|
177
181
|
return if rows.blank?
|
|
178
182
|
|
|
179
|
-
content_tag(:table, class: "sr-only", aria: { label: "Chart data" }) do
|
|
183
|
+
content_tag(:table, class: "railsui-chart-data-table sr-only", aria: { label: "Chart data" }) do
|
|
180
184
|
safe_join([
|
|
181
185
|
content_tag(:caption, "Data for chart #{id}"),
|
|
182
186
|
content_tag(:thead) do
|
|
@@ -220,7 +224,7 @@ module RailsuiCharts
|
|
|
220
224
|
rows = columns.first&.dig(:data)
|
|
221
225
|
return if rows.blank?
|
|
222
226
|
|
|
223
|
-
content_tag(:table, class: "sr-only", aria: { label: "Chart data" }) do
|
|
227
|
+
content_tag(:table, class: "railsui-chart-data-table sr-only", aria: { label: "Chart data" }) do
|
|
224
228
|
safe_join([
|
|
225
229
|
content_tag(:caption, "Data for chart #{id}"),
|
|
226
230
|
content_tag(:thead) do
|
data/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getrailsui/charts",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "Rails-native chart components built on ApexCharts. Stimulus controllers for the railsui_charts gem.",
|
|
5
5
|
"author": "Andy Leverenz <railsui@justalever.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -14,15 +14,18 @@
|
|
|
14
14
|
"module": "app/javascript/railsui_charts/index.js",
|
|
15
15
|
"exports": {
|
|
16
16
|
".": "./app/javascript/railsui_charts/index.js",
|
|
17
|
+
"./styles.css": "./app/assets/stylesheets/railsui_charts.css",
|
|
17
18
|
"./controllers/*": "./app/javascript/controllers/*"
|
|
18
19
|
},
|
|
19
20
|
"files": [
|
|
20
21
|
"app/javascript",
|
|
21
22
|
"app/assets/javascripts",
|
|
23
|
+
"app/assets/stylesheets",
|
|
22
24
|
"README.md",
|
|
23
25
|
"LICENSE.md",
|
|
24
26
|
"CHANGELOG.md"
|
|
25
27
|
],
|
|
28
|
+
"packageManager": "yarn@4.11.0",
|
|
26
29
|
"scripts": {
|
|
27
30
|
"build": "esbuild app/javascript/railsui_charts/index.js --bundle --format=esm --external:@hotwired/stimulus --external:apexcharts --outfile=app/assets/javascripts/railsui_charts.js"
|
|
28
31
|
},
|