janela 0.16.0 → 0.16.2

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: 83aee3a06740005fd9bf9e81ddc12c6de350ea4b8f6fce34899a94869e0f2615
4
- data.tar.gz: cd6d59364454c17e80302de50377a5ca2ca3f2db2ceb2bd58be8ca6a29d6b878
3
+ metadata.gz: f90ccaae7d4191d3b5bfa3db12db772656808a9b15908d73bef299beda109eef
4
+ data.tar.gz: a3cd040d84114900904349d9bde09ad89fb264624a7997c3a9961e9947f8b266
5
5
  SHA512:
6
- metadata.gz: 670dcac643875f4723159a3f8ecc4429d9feb115dcf58c7336fc823f8290eff4bb3c25316893dc382958753d43e689c4572416d9371b7fa36e0e23447640052c
7
- data.tar.gz: 6c423db2685c60bb12a6f3878ea956fe926dfde507a9a373d71be3f42092322a22a6958ecf6cc54aee68e6535fd8690e9d4320a0a55da2aa6eed4e40074b0734
6
+ metadata.gz: 6cdcc597e34ed611a8c9c2f448875ca9e5cd487f888b5bed8fe0c1e9f5e22728ad6f3b743da7c3b868b80b85a0c6565630e6604629fbe7d316c5d00a338213cb
7
+ data.tar.gz: 0a96deb8421cc49ce7048cfe148ef2516fd2edd4bb91b24635ec172935db2d728ae4e3be871abfb346a6870b577b854505057909d35cabdfed7737e49ad722c4
data/CHANGELOG.md CHANGED
@@ -5,6 +5,20 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.16.2] - 2026-11-23
9
+
10
+ ### Fixed
11
+
12
+ - **A value-labelled ratio's axis ends where the data does, not at 120%.** `value_labels` made room for the label above the tallest bar by adding 10% of grace to the value axis, so a ratio whose largest group was 95% drew an axis to 120%, a share no bar can reach. A ratio's labels now get their room from padding above the plot, so the axis ends at 100% (or wherever the data does). Every other measure keeps the grace, which also leaves room under a negative bar, and draws what it did (#96, ADR 054).
13
+ - **A pane is narrowed by a click on a dimension whose name starts with its own.** A pane sets aside the reader's filter on its own dimension, so the pane you clicked shows the alternatives. It recognised that filter by prefix, so a pane by `store` also set aside `store_type_in` and drew every store, unfiltered, after a click on a store type. Pairs like `category` and `category_group`, or `region` and `region_manager`, met the same thing. Only a key that is exactly the pane's own dimension and a Ransack predicate is set aside now. One visible difference: a misspelt predicate on the pane's own dimension (`store_inn` on a pane by store), which was quietly set aside with it, is now refused like a typo on any other key (#103, ADR 003, ADR 025).
14
+ - **A misspelt predicate on a key reached through an association is refused, not dropped, on a pane that ignores unknown filters.** On a pane with `ignore_unknown_filters`, `customer_region_inn` (a typo for `customer_region_in`) was dropped as if it belonged to another model, and the pane drew an unfiltered number with no error. A plain column with the same typo (`status_inn`) was already refused. A key reached through an association is now held to the same rule: refused with its reason when it starts with a dimension the model declares and ends with no predicate Ransack knows. Another model's key that only shares the prefix, such as `customer_region_code_in`, is still dropped (#94, ADR 063).
15
+
16
+ ## [0.16.1] - 2026-11-02
17
+
18
+ ### Added
19
+
20
+ - **A Charts guide, `docs/charts.md`.** The pane options were documented only in the README, so the demo's Documentation page had nowhere to say how to choose a renderer or how to build a chart with a running total and more series on two axes. The guide covers the renderers, the options that shape one chart, `cumulative:` and `series:` with the combined chart as a worked example, and the colours. It ships in the gem and is listed under Documentation on the demo (ADR 062).
21
+
8
22
  ## [0.16.0] - 2026-10-29
9
23
 
10
24
  ### Added
@@ -320,6 +334,8 @@ First alpha, installed from GitHub for testing in a single host application.
320
334
  - Only models that declare a `janela` block are addressable over HTTP.
321
335
  - ADRs 001 to 004 in `docs/decisions/`, shipped inside the gem.
322
336
 
337
+ [0.16.2]: https://github.com/retail-tasker/janela/releases/tag/v0.16.2
338
+ [0.16.1]: https://github.com/retail-tasker/janela/releases/tag/v0.16.1
323
339
  [0.16.0]: https://github.com/retail-tasker/janela/releases/tag/v0.16.0
324
340
  [0.15.0]: https://github.com/retail-tasker/janela/releases/tag/v0.15.0
325
341
  [0.14.0]: https://github.com/retail-tasker/janela/releases/tag/v0.14.0
data/README.md CHANGED
@@ -390,7 +390,7 @@ A host with no tenancy defines nothing, gets a nil owner, and is correct: nothin
390
390
 
391
391
  The dashboard's filters live in the page URL as the same `q[...]` parameters, so a reload keeps them and a filtered dashboard is a link you can send: `/reports/orders?q[status_in][]=paid` renders filtered before any JavaScript runs. A pane ignores filters on its own dimension, so clicking a value re-scopes the rest of the dashboard rather than collapsing the pane you clicked. Clicking a bucket on a time pane filters the others to the range it covers. Every selected value is marked `aria-pressed="true"` on tables and drawn solid against faded siblings on charts, so it can be styled and read.
392
392
 
393
- **A frame over two models.** Every pane is handed the frame's filters, and a pane refuses a key its model does not declare, because Ransack would otherwise drop it and show an unfiltered number (ADR 025). On a frame that holds panes over two models that refusal reaches a click it should not: `paid` clicked on an orders pane is `q[status_in][]=paid` to a page views pane, which has no status and would answer "That request is not allowed on this pane" where its number was. A pane can say it ignores what it cannot apply: `janela_pane PageView, :views, by: :page, ignore_unknown_filters: true`, or the checkbox on the pane form, or `?ignore_unknown_filters=1` in the pane URL. The keys Ransack would drop are dropped before the query, a key the model does declare is applied as on any pane, a declared key with a predicate the dimension does not allow is still refused, and a host's `where:` and a frame's `default_where` are still refused when wrong. Unset, a pane is what it always was, so a typo on a pane that never meets another model still fails loudly. Two models share a click only when they spell the key the same, which for a dimension reached through an association is `<association>_<column>` (ADR 063).
393
+ **A frame over two models.** Every pane is handed the frame's filters, and a pane refuses a key its model does not declare, because Ransack would otherwise drop it and show an unfiltered number (ADR 025). On a frame that holds panes over two models that refusal reaches a click it should not: `paid` clicked on an orders pane is `q[status_in][]=paid` to a page views pane, which has no status and would answer "That request is not allowed on this pane" where its number was. A pane can say it ignores what it cannot apply: `janela_pane PageView, :views, by: :page, ignore_unknown_filters: true`, or the checkbox on the pane form, or `?ignore_unknown_filters=1` in the pane URL. The keys Ransack would drop are dropped before the query, a key the model does declare is applied as on any pane, a declared key with a predicate the dimension does not allow is still refused, including one reached through an association, and a host's `where:` and a frame's `default_where` are still refused when wrong. Unset, a pane is what it always was, so a typo on a pane that never meets another model still fails loudly. Two models share a click only when they spell the key the same, which for a dimension reached through an association is `<association>_<column>` (ADR 063).
394
394
 
395
395
  **Selecting more than one.** Ctrl or Cmd click adds a value to the selection and takes it out again, leaving the rest alone, which is how every list in every operating system already behaves. A plain click selects one value and replaces whatever was selected, or clears the dimension if that value was the only one. It works the same on a chart. The (none) group, the rows that have nothing there, is a member of the selection like any value: Ctrl or Cmd click it beside a value and the panes show the rows that have that value or nothing (`q[channel_in][]=web&q[channel_null]=1`), where `not_in` and `not_null` together still mean neither (ADR 049). All of it works from the keyboard too: a value is a real `<button>`, so Enter is a click and Ctrl or Cmd with Enter adds. `Escape` clears the frame's filters, and those are the only two keys Janela binds, both only while focus is inside the frame, because a single letter belongs to your application and to any text field on the page (ADR 024). A pane with no matching rows renders a `.janela-empty` paragraph. A group whose dimension is null is labelled `(none)` and filters with Ransack's null predicate rather than an empty string. Only models that declare a `janela` block can be requested over HTTP.
396
396
 
@@ -581,7 +581,7 @@ Deliberately out of scope: natural-language query, a separate data warehouse, a
581
581
 
582
582
  ## Status
583
583
 
584
- **v0.16.0 alpha.** The measures/dimensions DSL, time dimensions, cross-filtering with multi-selection, bar, line, doughnut and pie charts, pane URLs, shareable dashboard URLs, snapshots, database-backed frames found by owner and key, panes that hold words or a host partial as well as a query, a host-fixed filter no click can remove and a frame's own permanent one beside it, STI subclasses, the engine's own pages for reading and editing them, bar charts that read in their measure's format and can show each bar's value, category panes that can be ordered either way by their measure or by their label, tools an agent can use to read and arrange a dashboard, and the optional vitral theme work and are covered by unit and real-browser tests, with the classes a theme may target documented in [Theming Janela](docs/theming.md). Not yet built: a visual editor, and narrowing a time pane's own granularity by clicking one of its buckets (a click on a bucket does filter the others). [Vista](docs/roadmap.md), the roadmap, says what 1.0 means and which of these are in it; open work is in [GitHub Issues](https://github.com/retail-tasker/janela/issues).
584
+ **v0.16.2 alpha.** The measures/dimensions DSL, time dimensions, cross-filtering with multi-selection, bar, line, doughnut and pie charts, pane URLs, shareable dashboard URLs, snapshots, database-backed frames found by owner and key, panes that hold words or a host partial as well as a query, a host-fixed filter no click can remove and a frame's own permanent one beside it, STI subclasses, the engine's own pages for reading and editing them, bar charts that read in their measure's format and can show each bar's value, category panes that can be ordered either way by their measure or by their label, tools an agent can use to read and arrange a dashboard, and the optional vitral theme work and are covered by unit and real-browser tests, with the classes a theme may target documented in [Theming Janela](docs/theming.md). Not yet built: a visual editor, and narrowing a time pane's own granularity by clicking one of its buckets (a click on a bucket does filter the others). [Vista](docs/roadmap.md), the roadmap, says what 1.0 means and which of these are in it; open work is in [GitHub Issues](https://github.com/retail-tasker/janela/issues).
585
585
 
586
586
  ## Development
587
587
 
@@ -35,6 +35,7 @@ export default class extends Controller {
35
35
  // is decided here, when the chart is made: patched onto a chart built
36
36
  // with it on, it draws at the wrong size.
37
37
  maintainAspectRatio: !this.fixedHeightValue,
38
+ layout: this.labelRoomAbove() ? { padding: { top: Chart.defaults.font.size + 8 } } : undefined,
38
39
  scales: this.scales(),
39
40
  // A line is clicked anywhere along its x position rather than on
40
41
  // the exact pixel of a point, which on a dense series is a few
@@ -125,7 +126,7 @@ export default class extends Controller {
125
126
  const scales = { y: {
126
127
  beginAtZero: true,
127
128
  // Room above the tallest bar, and below the lowest, for its label (ADR 054).
128
- grace: this.valueLabelsValue ? "10%" : undefined,
129
+ grace: this.valueLabelsValue && !this.labelRoomAbove() ? "10%" : undefined,
129
130
  title: this.axisTitle(this.axesValue.left),
130
131
  ticks
131
132
  } }
@@ -146,6 +147,14 @@ export default class extends Controller {
146
147
  return scales
147
148
  }
148
149
 
150
+ // A ratio's labels get their room from padding above the plot rather than
151
+ // from grace on the scale, which took a share of 95% to an axis of 120%
152
+ // (#96). A ratio is never negative, so nothing is needed below. Other
153
+ // measures keep the grace, which also leaves room under a negative bar.
154
+ labelRoomAbove() {
155
+ return this.valueLabelsValue && this.tickFormatValue.ratio === true
156
+ }
157
+
149
158
  axisTitle(text) {
150
159
  return text ? { display: true, text } : undefined
151
160
  }
@@ -657,7 +657,7 @@ module Janela
657
657
  def applicable_filters
658
658
  @applicable_filters ||= begin
659
659
  given = ignore_unknown_filters ? definition.applicable(filters) : filters
660
- single_value? ? given : given.reject { |key, _| key.to_s.start_with?(ransack_name) }
660
+ single_value? ? given : given.reject { |key, _| dimension_definition.key?(key) }
661
661
  end
662
662
  end
663
663
  end
data/docs/charts.md ADDED
@@ -0,0 +1,148 @@
1
+ ---
2
+ Topics: charts, renderers, panes, time, series, cumulative
3
+ ---
4
+
5
+ # Charts and Their Options
6
+
7
+ A pane is a measure, sometimes over a dimension, drawn one way. This page
8
+ is the reference for the drawing: which renderer suits which question, the
9
+ options that change how it reads, and how to put more than one measure on
10
+ a chart. Each option is written the same three ways, in `janela_pane`, as a
11
+ column on a stored pane, and in the pane's URL, so a hand written page, an
12
+ analyst's row and a link all say the same thing.
13
+
14
+ The short version: pick the renderer from the shape of the question, pass
15
+ the option you need, and let the others stay unset. Every option is off
16
+ until a pane asks for it, and a pane that sets none is drawn as it always
17
+ was.
18
+
19
+ ## Choosing a renderer
20
+
21
+ `as:` is `:table` unless the pane says otherwise.
22
+
23
+ | Renderer | The question it answers | Needs |
24
+ | --- | --- | --- |
25
+ | `:table` | what are the exact numbers | anything |
26
+ | `:bar` | how do the values of a category compare | a category dimension |
27
+ | `:line` | how does a measure move over time | a time dimension |
28
+ | `:doughnut`, `:pie` | how is a whole split between a handful of values | a category dimension, no negatives |
29
+ | none, with no `by:` | what is the single figure | a measure alone |
30
+
31
+ ```erb
32
+ <%= janela_pane Order, :revenue %>
33
+ <%= janela_pane Order, :revenue, by: :status, as: :bar %>
34
+ <%= janela_pane Order, :revenue, by: :placed_on, as: :line, granularity: :week %>
35
+ <%= janela_pane Order, :orders, by: :region, as: :doughnut, limit: 8 %>
36
+ ```
37
+
38
+ A table is also what any chart becomes where there is no chart runtime, so
39
+ the numbers are always readable. Bars and lines are drawn in the browser
40
+ with Chart.js. A doughnut or a pie is drawn on the server as SVG with a
41
+ legend of buttons beside it, so it is in the page before any JavaScript
42
+ runs and can be operated from the keyboard. A ring cannot show a negative
43
+ value, so a pane with one is drawn as a table and says so.
44
+
45
+ Clicking a bar, a slice or a table value narrows the other panes on the
46
+ frame. A click on a line's bucket narrows them to that range.
47
+
48
+ ## Shaping one chart
49
+
50
+ These options apply to a single measure over a single dimension.
51
+
52
+ | Option | Does | Applies to |
53
+ | --- | --- | --- |
54
+ | `limit:` | keeps the top rows or bars | table, bar, ring |
55
+ | `sort:` | `:asc`, `:label`, `:label_desc`; the default is largest first | a category pane |
56
+ | `granularity:` | `:hour` to `:year`; the bucket size | a time pane |
57
+ | `height:` | `1` to `5`, from about 96px to about 448px | bar, line |
58
+ | `prominence:` | `1` to `3`, the size of a single figure | a single value |
59
+ | `value_labels:` | writes the value on the chart | bar, line |
60
+ | `companions:` | up to three more columns | table |
61
+
62
+ A bar or line chart is drawn at twice its width, up to 20rem, unless it
63
+ is given a height. Heights and prominences are steps rather than lengths,
64
+ so a stored pane takes them from its form. `value_labels` on a bar is all
65
+ or none: if any label is wider than its bar's share of the chart, none is
66
+ drawn. The README has the detail of each; ADRs 046, 047, 050, 051, 054
67
+ and 055 have the reasons.
68
+
69
+ ## A running total
70
+
71
+ A time pane reads per period by default: orders placed each month.
72
+ `cumulative: true` reads the same buckets as a total to date.
73
+
74
+ ```erb
75
+ <%= janela_pane Order, :orders, by: :placed_on, as: :line, granularity: :month, cumulative: true %>
76
+ ```
77
+
78
+ The total is summed after the read, so the buckets, the filters and a
79
+ click on a bucket are exactly what they were. It is refused, with its
80
+ reason, on a category pane, on a single value, and on a measure that does
81
+ not add up: an average, a minimum, a maximum or a ratio. A running sum of
82
+ averages would be a number, but not the average to date. Per period and to
83
+ date are two different answers that can share a page, so a pane that sets
84
+ `cumulative` has its own frame id.
85
+
86
+ ## More than one series
87
+
88
+ A time pane can carry up to three more measures over the same buckets.
89
+ Each is a hash led by its measure.
90
+
91
+ ```erb
92
+ <%= janela_pane Order, :orders, by: :placed_on, as: :line, granularity: :month, cumulative: true,
93
+ series: [
94
+ { measure: :orders, by: :shipped_on, cumulative: true, title: "Orders shipped to date" },
95
+ { measure: :orders, as: :bar, axis: :right, title: "Orders per month" }
96
+ ] %>
97
+ ```
98
+
99
+ That is orders placed and orders shipped, both to date, as two lines on
100
+ the left axis, with orders per month as bars on a right one.
101
+
102
+ | Key | Means | Left out |
103
+ | --- | --- | --- |
104
+ | `measure` | a measure the model declares | required |
105
+ | `by` | a time dimension of the same model | the pane's own |
106
+ | `cumulative` | a running total | per period |
107
+ | `as` | `line` or `bar` | the pane's renderer if it is one of those, else `line` |
108
+ | `axis` | `left` or `right` | `left` |
109
+ | `title` | the legend's name for it | one Janela writes, such as `Orders shipped to date` |
110
+
111
+ **What the chart does.** Every series' buckets are joined into one axis,
112
+ from the first bucket any series has to the last. A series with no row in
113
+ a bucket reads zero there, so a total to date is flat across a month
114
+ nothing shipped. For a measure that has no value in an empty bucket (an
115
+ average, a minimum, a maximum or a ratio) the bucket is a gap instead. A
116
+ chart with series shows a legend and colours by series rather than by
117
+ category: `--janela-series-1` for the pane's own, the rest in order. Bars
118
+ are drawn behind lines. A right axis exists only when a series asks for
119
+ one, and then both axes are titled with the series on them. A right axis
120
+ that holds only bars is scaled so the tallest reaches about a third of the
121
+ plot, which keeps them from covering the lines.
122
+
123
+ **What it does not do.** Series belong to a time pane. A category pane,
124
+ a ring and a single value refuse them or ignore them, and a stored
125
+ snapshot holds none. A series cannot have its own granularity or filter,
126
+ or come from another model, and nothing stacks. With `value_labels`, each
127
+ line writes its latest value at its end and a bar writes nothing.
128
+
129
+ **Where to set it.** The same keys are rows on the pane form, `cumulative`
130
+ and `series` in `Janela::Tools`, and `?cumulative=1&series[][measure]=orders&series[][by]=shipped_on`
131
+ in the pane URL. Put `measure` first in a series in a URL, because that is
132
+ what starts a new one. A table draws each series as a column after the
133
+ measure's, which is also what a page with no chart runtime shows.
134
+
135
+ ## Colours
136
+
137
+ Bars, slices and series are drawn from eight colours by position, and every
138
+ position after the eighth in one neutral. They are `--janela-series-1` to
139
+ `--janela-series-8` and `--janela-series-other`, and [Theming
140
+ Janela](theming) says how to change them.
141
+
142
+ ## What this page is not
143
+
144
+ It is not the list of what can be asked of a model; that is the model's
145
+ own `janela` block, and `Janela::Definition` answers it. It is not the
146
+ layout around a pane either, which is [Composing a Page Around
147
+ Panes](composing). The decisions behind the options are the ADRs: 062 for
148
+ running totals and series, and the README for the rest.
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  Date: 2026-10-29
3
- Status: Proposed
3
+ Status: Accepted
4
4
  Related: ADR 002, ADR 005, ADR 006, ADR 007, ADR 009, ADR 018, ADR 020, ADR 029, ADR 037, ADR 045, ADR 046, ADR 047, ADR 051, ADR 054, ADR 055
5
5
  Triggers:
6
6
  - a running total, a cumulative line, a to-date figure over time
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  Date: 2026-10-29
3
- Status: Proposed
3
+ Status: Accepted
4
4
  Related: ADR 003, ADR 005, ADR 008, ADR 012, ADR 025, ADR 035, ADR 037, ADR 040, ADR 043, ADR 053
5
5
  Triggers:
6
6
  - a frame holding panes over more than one model
@@ -0,0 +1,146 @@
1
+ ---
2
+ Date: 2026-11-20
3
+ Status: Proposed
4
+ Related: ADR 002, ADR 007, ADR 009, ADR 020, ADR 038, ADR 054, ADR 055, ADR 062
5
+ Triggers:
6
+ - adding a measure kind, or a sixth aggregate to the DSL
7
+ - counting distinct values rather than rows
8
+ - dividing one sum by another, or a rate against a target
9
+ - hiding or dashing a value worked out from too few rows
10
+ - a ratio that can be above 100%
11
+ Topics: DSL, query layer, measures, formatting, ordering
12
+ ---
13
+
14
+ # ADR 064: A Measure Can Count Distinct Values, Divide Two Sums, and Require a Minimum of Rows
15
+
16
+ ## Context
17
+
18
+ #97, from a host building reporting frames over fact views. A measure
19
+ today is one of five aggregates, or `ratio:` of one boolean column
20
+ (ADR 038). Three things a reporting page needs cannot be declared:
21
+
22
+ - **A count of distinct values.** "Stores visited" is not "visits".
23
+ - **One sum over another.** Visits against target, or ranged lines against
24
+ lines expected. It reads as a percentage, and it can rightly be above
25
+ 100%: a store that beat its target did not make an error.
26
+ - **A minimum sample.** A ratio over three rows is noise that looks like a
27
+ finding. The host's own rule is fifty observations before a rate is
28
+ shown.
29
+
30
+ Measured against the demo on `3a41a64` (Rails main, SQLite), with
31
+ `Order` grouped by `status`:
32
+
33
+ - `relation.distinct.count(:customer_id)` answers a hash per group,
34
+ through Groupdate per month too, and its grouped alias is
35
+ `count_customer_id`, the same alias ADR 007 already orders a count by.
36
+ Nothing new is needed for grouping, ordering or gap filling.
37
+ - A ratio of two sums cannot be one `relation.<aggregate>(expression)`
38
+ call: `SUM(a) / SUM(b)` is not an argument to any one aggregate, and
39
+ wrapping it nests aggregates. Two sums read separately and divided per
40
+ key are right, and Groupdate fills both with zero, so an empty bucket is
41
+ `0 / 0`, which has to be no value rather than an error. Ordering by the
42
+ expression itself, `SUM(a) * 1.0 / NULLIF(SUM(b), 0)`, works in an
43
+ `ORDER BY` beside a `GROUP BY`, which is how ADR 038 already orders a
44
+ ratio.
45
+ - `HAVING COUNT(*) >= 2` on a category pane returns only the groups that
46
+ qualify, before `limit`. On a time pane the same `HAVING` through
47
+ Groupdate returned `{}` where every day had one row: Groupdate fills
48
+ between the first and last bucket it is given, so with none it draws
49
+ nothing, and with some it draws a shorter axis. A minimum on a time
50
+ pane cannot be a `HAVING`.
51
+
52
+ ### What was considered
53
+
54
+ **A free SQL expression measure** (`measure :x, sql: "..."`) would cover
55
+ all three and every future ask. Rejected: it is a second query language
56
+ beside Ransack (ADR 001, ADR 002), it cannot be checked at declaration,
57
+ and a forker reading it learns nothing about what it means.
58
+
59
+ **A ratio of sums as a new key, `divide: [:a, :b]`.** Rejected for the
60
+ name. A boolean ratio already is a division, the true rows over the known
61
+ rows, and reading the two as one idea with one name is simpler than two
62
+ words for it.
63
+
64
+ **`min_rows` drawing a dash in a category pane.** A table row reading
65
+ "–" was the first shape asked for. Rejected for how it meets `limit` and
66
+ `sort`: on `sort: :asc, limit: 10`, the bottom ten would be chosen from
67
+ groups that include the suppressed ones, so either the dashes take the
68
+ places of real values or they are sorted out of the limit and never seen
69
+ anyway. Leaving them out before the limit is the version that answers the
70
+ question a bottom ten asks.
71
+
72
+ **Clamping a ratio of sums at 100%.** Rejected. Over 100% is a real
73
+ answer, and a clamped one is a wrong number that looks right.
74
+
75
+ ## Decision
76
+
77
+ **A measure can be `count_distinct:` a column, `ratio:` one column `over:`
78
+ another, and any measure that does not add up can require `min_rows:`.**
79
+
80
+ ```ruby
81
+ janela do
82
+ measure :visits, count: true
83
+ measure :stores_visited, count_distinct: :place_id
84
+ measure :to_target, ratio: :visits, over: :target
85
+ measure :in_stock_rate, ratio: :in_stock, min_rows: 50
86
+ end
87
+ ```
88
+
89
+ **`count_distinct:`** is `COUNT(DISTINCT column)`, a sixth aggregate. It
90
+ reads as a count (no decimal places, ADR 020) and orders by its count
91
+ alias. It is not additive: two months' distinct stores do not sum to the
92
+ quarter's, so `cumulative` refuses it as it refuses an average (ADR 062),
93
+ and a bucket with no rows is zero.
94
+
95
+ **`ratio: :a, over: :b`** is `SUM(a) / SUM(b)`, read by two sums and
96
+ divided per group. Both columns must be numeric, checked at declaration
97
+ the way ADR 038 checks a boolean. Without `over:`, `ratio:` is what it
98
+ is today. It is stored as the fraction and read as a percentage, exactly
99
+ as ADR 038 says, and is never clamped: 1.25 reads `125.0%`, and the
100
+ axis follows the data (#96). A group whose denominator sums to zero has
101
+ no value, as an empty bucket of a boolean ratio has none today. It
102
+ orders by the expression. It does not add up, so `cumulative` refuses it.
103
+
104
+ **`min_rows:`** is a whole number of rows a group needs before its value
105
+ is shown. It is allowed on an average, a minimum, a maximum and either
106
+ ratio, and refused on a sum, a count or a count distinct, which are
107
+ true however few rows they are over. Rows are the group's rows after
108
+ every filter, `COUNT(*)`.
109
+
110
+ - On a category pane a group under the minimum is **left out before**
111
+ `sort` and `limit`, as `HAVING COUNT(*) >= n`, so a bottom ten is ten
112
+ groups that qualified.
113
+ - On a time pane, a series (ADR 062) and a single value, a bucket under
114
+ the minimum **has no value**: read beside a count of its rows and set to
115
+ none after the read, so the axis is the same with or without it. It is
116
+ a gap on a line, no bar, and `–` in a table or a single value.
117
+ - A snapshot stores what the query returned, so a frozen value under the
118
+ minimum stays without one (ADR 009).
119
+
120
+ **No pane or URL changes.** All three are declarations on the model, the
121
+ same way every measure option is (ADR 020). A stored pane names the
122
+ measure and gets them.
123
+
124
+ ## Consequences
125
+
126
+ - A reporting host can declare the three it asked for without a view per
127
+ question or a second model.
128
+ - `Measure` grows from five aggregates and a ratio to six and a ratio
129
+ with an optional denominator, plus one option. `Definition#query` reads
130
+ a ratio of sums in two queries, and a time pane with `min_rows` in two.
131
+ Both are bounded: the second query has the same `GROUP BY` as the first.
132
+ - A category pane with `min_rows` can show fewer rows than its `limit`
133
+ with nothing on the page saying why. That is the honest cost of leaving
134
+ groups out. A note under the pane saying how many were left out is a
135
+ later question, not decided here.
136
+ - **`–` for no value.** Today an empty bucket of a ratio formats as an
137
+ empty string. A suppressed value and an empty one should read the same,
138
+ so both become `–`. That is a visible change to every host with a ratio
139
+ over empty buckets, small, and listed in the changelog.
140
+ - `Janela::Tools` and `describe_vocabulary` need nothing new: they list
141
+ measures by name (ADR 053).
142
+ - What would change this decision: a host needing a running ratio of
143
+ sums, which is meaningful (the running numerator over the running
144
+ denominator) and could be allowed later without changing these names;
145
+ or one needing the left-out groups listed, which would argue for the
146
+ dash again.
@@ -0,0 +1,123 @@
1
+ ---
2
+ Date: 2026-11-20
3
+ Status: Proposed
4
+ Related: ADR 002, ADR 003, ADR 020, ADR 025, ADR 040, ADR 043, ADR 051, ADR 062, ADR 064
5
+ Triggers:
6
+ - narrowing one pane without narrowing the frame around it
7
+ - two panes over the same model where only one is filtered
8
+ - a measure of only some rows, such as new products or one channel
9
+ - adding a where to a pane, or a filter column to janela_panes
10
+ Topics: DSL, query layer, measures, cross-filtering, frames
11
+ ---
12
+
13
+ # ADR 065: A Measure Can Carry Its Own Condition, So One Pane Is Narrowed and Not the Frame
14
+
15
+ ## Context
16
+
17
+ #98. Every narrowing a host can apply today is frame-wide. A host's
18
+ `where:` (ADR 040) narrows every pane a `janela_frame` draws, and a
19
+ frame's `default_where` (ADR 043) narrows every pane over its model. A
20
+ frame cannot hold "sales" beside "sales of new products" over the same
21
+ model. The only way today is a second model or a second database view per
22
+ condition, which turns a one-word difference into a schema change.
23
+
24
+ Read against the code on `ced8ea9`: `Definition#query` and
25
+ `Definition#series` both start from `filter(on || model.all, where)`, and
26
+ `Definition#narrow` already applies a fixed set of Ransack conditions
27
+ under ADR 025's bounds (declared dimensions, allowed predicates, the value
28
+ limit), raising with its reason. A condition has one obvious place to go
29
+ in: the relation, before the grouping, in the two methods every pane
30
+ passes through.
31
+
32
+ ### What was considered
33
+
34
+ **A `where:` on the pane.** The obvious reading of "fix a filter on one
35
+ pane". Rejected for its cost and for what it says. It is a new column on
36
+ `janela_panes`, a new parameter in the pane URL (ADR 037 counts both as
37
+ public surface), a field on the pane form and an attribute in
38
+ `Janela::Tools`, and it has to be told how it composes with the reader's
39
+ `q[...]` on the same key. And it puts the meaning in the wrong place:
40
+ "sales of new products" is a thing being measured, which a host names once
41
+ on the model, not a property of where a pane happens to sit. Two pages
42
+ wanting it would each write it again.
43
+
44
+ **A `filter:` beside the frame's `where:` that names a pane.** Rejected:
45
+ a hand-written frame has no pane identities to name, and a stored one
46
+ would need its own column anyway.
47
+
48
+ **A conditional aggregate in SQL**, `SUM(CASE WHEN ... THEN x END)`.
49
+ Rejected: Ransack builds `WHERE` conditions, not `CASE` expressions, so
50
+ this would be a second condition language beside Ransack's, which ADR 002
51
+ exists to avoid. It would also keep every group in a category pane with a
52
+ zero where it has no matching rows, which reads as a measured zero rather
53
+ than an absence.
54
+
55
+ ## Decision
56
+
57
+ **A measure may carry `where:`, a hash of Ransack conditions on the
58
+ model's declared dimensions, and it measures only the rows that meet
59
+ them.**
60
+
61
+ ```ruby
62
+ janela do
63
+ measure :sales, sum: :amount
64
+ measure :new_product_sales, sum: :amount, where: { new_product_eq: true }
65
+ measure :online_orders, count: true, where: { channel_in: %w[web app] }
66
+
67
+ dimension :new_product
68
+ dimension :channel
69
+ end
70
+ ```
71
+
72
+ ```erb
73
+ <%= janela_frame do %>
74
+ <%= janela_pane Sale, :sales, by: :region, as: :bar %>
75
+ <%= janela_pane Sale, :new_product_sales, by: :region, as: :bar %>
76
+ <% end %>
77
+ ```
78
+
79
+ **It is applied as one more narrowing, before the grouping,** through
80
+ `Definition#narrow`, in `query` and `series`. So it composes with every
81
+ other narrowing the same way they compose with each other: a frame's
82
+ default, a host's `where:`, the reader's selection and the measure's own
83
+ condition are all ANDed. A reader's click that contradicts it (`no` on
84
+ `new_product` for a pane of new product sales) leaves that pane empty,
85
+ which is the true answer to the question asked.
86
+
87
+ **It is checked when the `janela` block ends,** against the dimensions the
88
+ block declared and ADR 025's predicate bounds, and a wrong condition raises
89
+ at boot with the same sentence a bad request would get. The check waits for
90
+ the end of the block because a measure is usually declared before the
91
+ dimensions it names.
92
+
93
+ **It travels with the measure.** A pane, a series (ADR 062), a stored
94
+ pane, a snapshot, a companion column's facts (ADR 051) and
95
+ `Janela::Tools` name the measure and get its condition. Nothing about a
96
+ pane, its URL or its form changes.
97
+
98
+ **A pane's own dimension is not exempt.** A measure narrowed to two
99
+ channels drawn `by: :channel` shows those two. The cross-filtering rule
100
+ (ADR 003) sets aside the reader's selection on a pane's own dimension;
101
+ the measure's condition is part of what the pane measures, not a
102
+ selection.
103
+
104
+ ## Consequences
105
+
106
+ - A frame can hold a measure and a narrowed version of it side by side
107
+ with no new model, view or pane setting.
108
+ - A category pane of a narrowed measure shows only groups that have
109
+ matching rows, not every group with a zero. A host wanting every group
110
+ listed puts the unnarrowed measure beside it.
111
+ - The condition is the host's own code, read at boot, so it is not part
112
+ of ADR 025's request bounds in the sense of arriving over HTTP. It is
113
+ still held to them, because a typo in it would otherwise be a silently
114
+ unfiltered measure, the failure this library is built to refuse.
115
+ - The measure's name is the only label a reader sees, so it has to say
116
+ what is narrowed ("New product sales", not "Sales 2"). That is the
117
+ host's naming, as it is for every measure (ADR 020).
118
+ - Works with ADR 064's measures unchanged: a ratio over a condition is a
119
+ ratio of the rows that meet it, and `min_rows` counts those rows.
120
+ - What would change this decision: a host needing the narrowing chosen
121
+ per page rather than per measure, such as an analyst picking a filter
122
+ for one stored pane at run time. That is a pane-level `where:`, and it
123
+ would need its own ADR on the URL and the form.
@@ -22,12 +22,12 @@ them when in doubt: `grep -l "Triggers:.*fork" docs/decisions/*.md`.
22
22
  |-------|------|
23
23
  | **Vision, scope, forkability** | 001, 010, 012, 037, 052 |
24
24
  | **Open-source & host-decoupling** | 001, 022, 036, 041, 052, 060, 061 |
25
- | **DSL & query layer** | 002, 006, 007, 020, 025, 038, 044, 049, 051, 055, 062 |
25
+ | **DSL & query layer** | 002, 006, 007, 020, 025, 038, 044, 049, 051, 055, 062, 064, 065 |
26
26
  | **Dependencies** | 002, 003, 004, 006, 017, 025, 053 |
27
27
  | **Authorisation** | 002, 003, 004, 009, 017, 019, 022, 032, 033, 034, 035, 039, 040, 048, 053 |
28
28
  | **Performance & storage** | 007, 017, 025, 048, 051 |
29
- | **Ordering & formatting** | 007, 020, 038, 054, 055, 061, 062 |
30
- | **Cross-filtering & Hotwire** | 003, 004, 005, 008, 024, 025, 040, 043, 044, 045, 048, 049, 063 |
29
+ | **Ordering & formatting** | 007, 020, 038, 054, 055, 061, 062, 064 |
30
+ | **Cross-filtering & Hotwire** | 003, 004, 005, 008, 024, 025, 040, 043, 044, 045, 048, 049, 063, 065 |
31
31
  | **Layouts & views** | 011, 012, 016, 018, 020, 027, 039, 047, 050, 059 |
32
32
  | **CSS & styling** | 016, 018, 023, 026, 027, 036, 042, 046, 047, 050, 062 |
33
33
  | **Frames, panes & persistence** | 012, 013, 014, 019, 029, 030, 033, 039, 040, 041, 043, 044, 047, 048, 050, 051, 053, 054, 055, 062, 063 |
@@ -109,9 +109,11 @@ them when in doubt: `grep -l "Triggers:.*fork" docs/decisions/*.md`.
109
109
  | 059 | A Host Can Tell Janela's Own Pages That Its Layout Draws Charts | 2026-10-14 | Proposed |
110
110
  | 060 | The Demo Tells Search Engines What It Is, and Shows Its Own Adoption | 2026-10-14 | Proposed |
111
111
  | 061 | The Demo Speaks Brazilian Portuguese Under a Prefix, and the Gem Stays English | 2026-10-14 | Proposed |
112
- | 062 | A Time Pane Can Accumulate, and Carry More Series on Two Axes | 2026-10-29 | Proposed |
113
- | 063 | A Pane Can Ignore a Filter Its Model Cannot Apply | 2026-10-29 | Proposed |
112
+ | 062 | A Time Pane Can Accumulate, and Carry More Series on Two Axes | 2026-10-29 | Accepted |
113
+ | 063 | A Pane Can Ignore a Filter Its Model Cannot Apply | 2026-10-29 | Accepted |
114
+ | 064 | A Measure Can Count Distinct Values, Divide Two Sums, and Require a Minimum of Rows | 2026-11-20 | Proposed |
115
+ | 065 | A Measure Can Carry Its Own Condition, So One Pane Is Narrowed and Not the Frame | 2026-11-20 | Proposed |
114
116
 
115
117
  ## Next number
116
118
 
117
- Next ADR: 064
119
+ Next ADR: 066
@@ -272,9 +272,11 @@ module Janela
272
272
 
273
273
  # A key Ransack did not apply that is a declared dimension and a suffix
274
274
  # that is not another attribute with a known predicate on it: path_inn is
275
- # path with a typo, status_code_in is a different attribute entirely.
275
+ # path with a typo, status_code_in is a different attribute entirely. A
276
+ # dimension through an association is spelt <association>_<column> here as
277
+ # everywhere else, so it is held to the same rule (#94).
276
278
  def misspelt_declared_key?(key)
277
- dimensions.values.reject(&:through).any? do |dimension|
279
+ dimensions.values.any? do |dimension|
278
280
  rest = key.to_s.delete_prefix("#{dimension.ransack_name}_")
279
281
  rest != key.to_s && Ransack.predicates.keys.none? { |predicate| rest.end_with?("_#{predicate}") }
280
282
  end
@@ -110,6 +110,14 @@ module Janela
110
110
  through ? "#{through}_#{column}" : column.to_s
111
111
  end
112
112
 
113
+ # Whether a filter key is this dimension's: its Ransack name and then a
114
+ # predicate Ransack knows, exactly. A prefix alone is not enough, since
115
+ # store_type_in starts with store and is another dimension's (#103).
116
+ def key?(key)
117
+ prefix = "#{ransack_name}_"
118
+ key.to_s.start_with?(prefix) && Ransack.predicates.has_key?(key.to_s.delete_prefix(prefix))
119
+ end
120
+
113
121
  def label(bucket, granularity = self.granularity)
114
122
  LABELS.fetch(granularity).call(bucket)
115
123
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Janela
4
- VERSION = "0.16.0"
4
+ VERSION = "0.16.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: janela
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.0
4
+ version: 0.16.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jay Killeen
@@ -151,6 +151,7 @@ files:
151
151
  - db/migrate/20261029000001_add_series_to_janela_panes.rb
152
152
  - db/migrate/20261029000003_add_ignore_unknown_filters_to_janela_panes.rb
153
153
  - docs/agents.md
154
+ - docs/charts.md
154
155
  - docs/composing.md
155
156
  - docs/decisions/001-built-to-be-forked.md
156
157
  - docs/decisions/002-measures-and-dimensions-over-ransack.md
@@ -215,6 +216,8 @@ files:
215
216
  - docs/decisions/061-the-demo-speaks-brazilian-portuguese-under-a-prefix-and-the-gem-stays-english.md
216
217
  - docs/decisions/062-a-time-pane-can-accumulate-and-carry-more-series-on-two-axes.md
217
218
  - docs/decisions/063-a-pane-can-ignore-a-filter-its-model-cannot-apply.md
219
+ - docs/decisions/064-a-measure-can-count-distinct-values-divide-two-sums-and-require-a-minimum-of-rows.md
220
+ - docs/decisions/065-a-measure-can-carry-its-own-condition-so-one-pane-is-narrowed-and-not-the-frame.md
218
221
  - docs/decisions/INDEX.md
219
222
  - docs/multi-tenancy.md
220
223
  - docs/naming.md
@@ -242,23 +245,6 @@ metadata:
242
245
  changelog_uri: https://github.com/retail-tasker/janela/blob/main/CHANGELOG.md
243
246
  bug_tracker_uri: https://github.com/retail-tasker/janela/issues
244
247
  rubygems_mfa_required: 'true'
245
- post_install_message: |
246
- Janela 0.16.0: one migration, if you use stored frames.
247
-
248
- A time pane can now be a running total and carry more series on two
249
- axes (ADR 062), and a pane can ignore a filter its model cannot apply
250
- (ADR 063). That adds nullable cumulative, series and
251
- ignore_unknown_filters columns to janela_panes. Run
252
- bin/rails janela:install:migrations and then bin/rails db:migrate. If
253
- you never use stored frames there is nothing to do.
254
-
255
- Also: a line chart with value_labels now writes its latest value at
256
- its end.
257
-
258
- Steps: UPGRADING.md in this gem, or
259
- https://github.com/retail-tasker/janela/blob/main/UPGRADING.md
260
-
261
- Then run: bin/rails janela:doctor
262
248
  rdoc_options: []
263
249
  require_paths:
264
250
  - lib