keystone_ui 0.96.0 → 0.97.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7f8538f59f354ba28a22af1978d841fa009a30c8303082fbaeaab72fe5b26aed
4
- data.tar.gz: 4c175286b7c9d777579c37c505d86701dc6866b900f317ecbdfc5cafa2c284b1
3
+ metadata.gz: 7a6d1b9a708eca00e9bbc2d350357bbc6e143412e710d28e5aa0839c3b9e3b25
4
+ data.tar.gz: c16b15329182ef72fcfee00f5f93c7c0627e57900d49e7c793ea6c2fe40212af
5
5
  SHA512:
6
- metadata.gz: ffe084ecc25acc64e9f21ba09714e9ccfef06861a77eaababf7705753a442a10aafa5ad6a42aad96ab3e61b68b4dc71770213d75a473971a6aeabf7a46348c0d
7
- data.tar.gz: 661ad787b150952dfb6646eb4e7e1430aabf63334442ce47bed952d538a1dfd270d33e77f7bc463bdef9716f972a4d9753c71d35ed0f0da8244f2929441777b2
6
+ metadata.gz: 03e29e1487956c4e3fa22f3446aff808adf896c0f743e76f92d00159825e0323de173afa73d300f453774c59fd8594ffaecb2e4941d9123930b6c45e54beb005
7
+ data.tar.gz: b62f7a4d3a0c19f10e9d61801d0d3d77143de191ab5b01791316c6ba87f39717c7a81697bee2456c9039a51a830b17f3cc1e0afd4f802a79eb715295b7f34ee1
@@ -1,13 +1,15 @@
1
- <div class="<%= Keystone::Ui::BarChartComponent::FRAME_CLASSES %>" role="img">
1
+ <div class="<%= frame_classes %>" role="img">
2
2
  <div class="<%= Keystone::Ui::BarChartComponent::PLOT_ROW_CLASSES %>">
3
- <svg class="<%= Keystone::Ui::BarChartComponent::AXIS_CLASSES %>">
4
- <% ticks.each do |tick| %>
5
- <text class="ks-bar-chart-text" data-axis-tick x="100%" dx="-6" y="<%= tick[:y].round(2) %>%" dominant-baseline="middle" text-anchor="end"><%= tick[:label] %></text>
6
- <% end %>
7
- </svg>
3
+ <% unless strip? %>
4
+ <svg class="<%= Keystone::Ui::BarChartComponent::AXIS_CLASSES %>">
5
+ <% ticks.each do |tick| %>
6
+ <text class="ks-bar-chart-text" data-axis-tick x="100%" dx="-6" y="<%= tick[:y].round(2) %>%" dominant-baseline="middle" text-anchor="end"><%= tick[:label] %></text>
7
+ <% end %>
8
+ </svg>
9
+ <% end %>
8
10
  <div class="<%= Keystone::Ui::BarChartComponent::PLOT_CLASSES %>">
9
11
  <svg class="<%= Keystone::Ui::BarChartComponent::LAYER_CLASSES %>" viewBox="0 0 100 100" preserveAspectRatio="none">
10
- <% ticks.each do |tick| %>
12
+ <% grid_lines.each do |tick| %>
11
13
  <line class="ks-bar-chart-grid" x1="0" x2="100" y1="<%= tick[:y].round(2) %>" y2="<%= tick[:y].round(2) %>" vector-effect="non-scaling-stroke"></line>
12
14
  <% end %>
13
15
  <% drawn_bars.each do |bar| %>
@@ -24,10 +26,12 @@
24
26
  </div>
25
27
  </div>
26
28
  <div class="<%= Keystone::Ui::BarChartComponent::LABEL_ROW_CLASSES %>">
27
- <span class="<%= Keystone::Ui::BarChartComponent::LABEL_SPACER_CLASSES %>"></span>
29
+ <% unless strip? %>
30
+ <span class="<%= Keystone::Ui::BarChartComponent::LABEL_SPACER_CLASSES %>"></span>
31
+ <% end %>
28
32
  <svg class="<%= Keystone::Ui::BarChartComponent::LABELS_CLASSES %>">
29
- <% drawn_bars.each do |bar| %>
30
- <text class="ks-bar-chart-text" data-bar-label x="<%= bar[:center].round(2) %>%" y="100%" dy="-6" text-anchor="middle"><%= bar[:label] %></text>
33
+ <% labelled_bars.each do |bar| %>
34
+ <text class="ks-bar-chart-text" data-bar-label x="<%= bar[:label_x].round(2) %>%" y="100%" dy="-6" text-anchor="<%= bar[:label_anchor] %>"><%= bar[:label] %></text>
31
35
  <% end %>
32
36
  </svg>
33
37
  </div>
@@ -4,6 +4,7 @@ module Keystone
4
4
  module Ui
5
5
  class BarChartComponent < ViewComponent::Base
6
6
  FRAME_CLASSES = "ks-bar-chart flex aspect-[5/2] max-h-80 w-full flex-col"
7
+ STRIP_FRAME_CLASSES = "ks-bar-chart flex h-[114px] w-full flex-col"
7
8
  PLOT_ROW_CLASSES = "flex min-h-0 flex-1"
8
9
  AXIS_CLASSES = "h-full w-10 shrink-0 overflow-visible"
9
10
  PLOT_CLASSES = "relative min-w-0 flex-1"
@@ -14,14 +15,25 @@ module Keystone
14
15
  FULL = 100.0
15
16
  HEADROOM = 8.0
16
17
  BAR_SHARE = 0.7
18
+ STRIP_BAR_SHARE = 0.92
17
19
  TICK_COUNT = 4
18
20
  ROUND_STEPS = [ 1, 2, 2.5, 5, 10 ].freeze
21
+ GROUP_TONES = 5
19
22
 
20
23
  attr_reader :bars
21
24
 
22
- def initialize(bars:, show_values: false)
25
+ def initialize(bars:, show_values: false, strip: false)
23
26
  @bars = bars
24
27
  @show_values = show_values
28
+ @strip = strip
29
+ end
30
+
31
+ def strip?
32
+ @strip
33
+ end
34
+
35
+ def frame_classes
36
+ strip? ? STRIP_FRAME_CLASSES : FRAME_CLASSES
25
37
  end
26
38
 
27
39
  def show_values?
@@ -31,12 +43,26 @@ module Keystone
31
43
  def drawn_bars
32
44
  bars.each_with_index.map do |bar, index|
33
45
  height = bar[:value].to_f / axis_max * (FULL - HEADROOM)
34
- { x: (index * band) + (band * (1 - BAR_SHARE) / 2), y: FULL - height, width: band * BAR_SHARE, height: height,
35
- center: (index * band) + (band / 2), label: bar[:label], value: bar[:value],
36
- classes: [ "ks-bar-chart-bar", ("ks-bar-chart-bar-shaded" if bar[:shaded]) ].compact.join(" ") }
46
+ x = (index * band) + (band * (1 - bar_share) / 2)
47
+ center = (index * band) + (band / 2)
48
+ { x: x, y: FULL - height, width: band * bar_share, height: height, center: center,
49
+ label: bar[:label], label_x: bar.key?(:group) ? x : center, label_anchor: bar.key?(:group) ? "start" : "middle", value: bar[:value],
50
+ classes: [ "ks-bar-chart-bar", ("ks-bar-chart-bar-shaded" if bar[:shaded]), group_class(bar) ].compact.join(" ") }
51
+ end
52
+ end
53
+
54
+ def labelled_bars
55
+ drawn_bars.each_with_index.filter_map do |bar, index|
56
+ next unless starts_group?(index)
57
+
58
+ newest_group_start?(index) ? bar.merge(label_x: FULL, label_anchor: "end") : bar
37
59
  end
38
60
  end
39
61
 
62
+ def grid_lines
63
+ strip? ? [ { y: FULL } ] : ticks
64
+ end
65
+
40
66
  def ticks
41
67
  (0..(axis_max / step).round).map do |position|
42
68
  value = (step * position).round(6)
@@ -46,6 +72,35 @@ module Keystone
46
72
 
47
73
  private
48
74
 
75
+ def bar_share
76
+ strip? ? STRIP_BAR_SHARE : BAR_SHARE
77
+ end
78
+
79
+ def newest_group_start?(index)
80
+ groups.size > 1 && bars[index].key?(:group) && bars[index][:group] == groups.last
81
+ end
82
+
83
+ def starts_group?(index)
84
+ index.zero? || !bars[index].key?(:group) || bars[index][:group] != bars[index - 1][:group]
85
+ end
86
+
87
+ def group_class(bar)
88
+ return unless bar.key?(:group)
89
+
90
+ "ks-bar-chart-bar-group-#{group_tone(groups.index(bar[:group]))}"
91
+ end
92
+
93
+ def group_tone(position)
94
+ return GROUP_TONES if groups.size == 1
95
+ return [ 1, position - groups.size + 1 + GROUP_TONES ].max if groups.size > GROUP_TONES
96
+
97
+ 1 + (position * (GROUP_TONES - 1).to_f / (groups.size - 1)).round
98
+ end
99
+
100
+ def groups
101
+ @groups ||= bars.map { |bar| bar[:group] }.uniq
102
+ end
103
+
49
104
  def axis_max
50
105
  step * (largest / step).ceil
51
106
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KeystoneUi
4
- VERSION = "0.96.0"
4
+ VERSION = "0.97.0"
5
5
  end
@@ -98,7 +98,7 @@ not available in the app yet, that is `keystone_ui-install`'s job.
98
98
  - `ui_swipe_deck` — a stack of cards accepted or rejected by button or swipe.
99
99
  - `ui_chart_card` — a titled card holding a chart.
100
100
  - `ui_line_chart` — a line chart with one line per series, over labels or dates.
101
- - `ui_bar_chart` — a bar chart drawn on the server, which needs no JavaScript and prints.
101
+ - `ui_bar_chart` — a bar chart drawn on the server, which needs no JavaScript and prints, with bars optionally grouped into tones from oldest to newest and one label per group, and optionally drawn as a short strip with no value axis.
102
102
  - `ui_funnel` — a conversion funnel drawn as bars or one joined shape.
103
103
  - `ui_bucket` — an upright container filled toward a goal.
104
104
  - `ui_bucket_series` — a wrapping row of buckets.
@@ -843,10 +843,22 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
843
843
 
844
844
  - `ui_chart_card(title:, height: :md)` takes a block holding a chart, with
845
845
  `height:` `:sm` `:md` `:lg`.
846
- - `ui_bar_chart(bars:, show_values: false)` — `bars:` is
847
- `[{ label:, value:, shaded: }, ...]`, where `shaded: true` draws a bar
848
- faded. It is drawn on the server as an SVG, so use it, not
846
+ - `ui_bar_chart(bars:, show_values: false, strip: false)` — `bars:` is
847
+ `[{ label:, value:, shaded:, group: }, ...]`, where `shaded: true` draws
848
+ a bar faded. It is drawn on the server as an SVG, so use it, not
849
849
  `ui_line_chart`, for a chart that must print or show without JavaScript.
850
+ - Give bars `group:`, such as the version that produced each one, to show
851
+ groups of bars. Groups count from oldest to newest in the order their
852
+ values first appear, and run in tones from grey to the accent, with no
853
+ two of five or fewer groups sharing a tone. With more than five, every
854
+ group older than the newest four is grey. Only a group's first bar
855
+ writes its label, starting at its left edge, so pass `""` for the rest,
856
+ such as `{ label: "v21 → 0.80", value: 0.66, group: "v21" }` followed by
857
+ `{ label: "", value: 0.68, group: "v21" }`. The newest group's label
858
+ ends at the chart's right edge. Never colour bars by hand.
859
+ - Pass `strip: true` for a short strip of bars 114px tall with no value
860
+ axis and no grid lines, only a baseline, and the bars nearly touching,
861
+ such as a trend under a page's main content.
850
862
  - `ui_line_chart(series:, labels: nil, dates: nil, height: :md)` —
851
863
  `series:` is `[{ name:, data:, color:, dashed: }, ...]`, where `color:`
852
864
  is a CSS colour and `dashed: true` is optional. Pass exactly one of
@@ -97,6 +97,16 @@ One decision: is keystone_ui set up in the app?
97
97
  to the address of the last entry in that row that has one. An entry can be
98
98
  marked selected, and the row holding it is drawn in the same tint as a data
99
99
  table's current row and announced to screen readers as the current item.
100
+ - **Bar chart groups.** A bar chart's bars can be put in groups, such as one
101
+ group per version of what produced them. Groups count from oldest to newest
102
+ in the order they first appear. Every bar of a group shares one tone, and
103
+ the tones run from grey for the oldest to the accent for the newest, with
104
+ no two of five or fewer groups sharing one. Past five, every group older
105
+ than the newest four is grey. Only the first bar of each group carries a
106
+ label under the axis, starting at that bar's left edge, apart from the
107
+ newest group's label, which ends at the chart's right edge. A bar chart can
108
+ also be drawn as a short strip with no value axis and no grid lines, only a
109
+ baseline, and its bars nearly touching.
100
110
  - **Value lists.** A value list shows labelled values, each a label and a value
101
111
  with an optional note, a fallback shown when the value is empty, a total
102
112
  marking and a check mark for a value that is right. By default each pair is a
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: keystone_ui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.96.0
4
+ version: 0.97.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Schneider
@@ -15,14 +15,14 @@ dependencies:
15
15
  requirements:
16
16
  - - ">="
17
17
  - !ruby/object:Gem::Version
18
- version: 0.37.0
18
+ version: 0.38.0
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - ">="
24
24
  - !ruby/object:Gem::Version
25
- version: 0.37.0
25
+ version: 0.38.0
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: view_component
28
28
  requirement: !ruby/object:Gem::Requirement