reports_kit 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +51 -396
- data/docs/README.md +7 -0
- data/docs/dimensions.md +110 -0
- data/docs/display_options.md +80 -0
- data/docs/filters.md +225 -0
- data/docs/images/demo.gif +0 -0
- data/docs/images/demo_area.png +0 -0
- data/docs/images/demo_dashed_line.png +0 -0
- data/docs/images/demo_horizontal_stacked.png +0 -0
- data/docs/images/demo_legend.png +0 -0
- data/docs/images/demo_multiautocomplete.png +0 -0
- data/docs/images/demo_radar.png +0 -0
- data/docs/images/users_by_created_at_with_filter.png +0 -0
- data/docs/measures.md +12 -0
- data/lib/reports_kit.rb +0 -1
- data/lib/reports_kit/reports/measure.rb +6 -2
- data/lib/reports_kit/reports_controller.rb +0 -6
- data/lib/reports_kit/version.rb +1 -1
- metadata +15 -4
- data/gists/doc.txt +0 -58
- data/lib/reports_kit/rails.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3952d8e13131065be390fe346c8182be221ec6bf
|
4
|
+
data.tar.gz: 411ce357e9e03b3a233cf8f3ce822f05006e7786
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e28f85804d7d648c18899656ccff8b07e3f10beabd11bba19159b193bbd11942e9e33bde4bd7ec04e69cc60b63e80f469cbf117f46dbac39a92620f1d59ac5bb
|
7
|
+
data.tar.gz: 9cef277587fa45fff0691b38f5a67ff7784401f0092eb00eeb735a02bbdea42dae0e9c68252dfa0b3738290abd38677f3177757aba96ee8be2386c19df5a0fc8
|
data/README.md
CHANGED
@@ -1,29 +1,40 @@
|
|
1
1
|
ReportsKit
|
2
2
|
=====
|
3
|
-
|
3
|
+
ReportsKit lets you easily create beautiful charts with customizable, interactive filters.
|
4
4
|
|
5
|
-
|
6
|
-
-----------------
|
5
|
+
Add powerful reporting to your Rails app in minutes, not months!
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
7
|
+
For interactive examples, see [reportskit.co](https://www.reportskit.co/).
|
8
|
+
|
9
|
+
---
|
10
|
+
|
11
|
+
[<img src="docs/images/demo.gif?raw=true" width="500" />](docs/images/demo.gif?raw=true)
|
12
|
+
|
13
|
+
[<img src="docs/images/demo_area.png?raw=true" width="500" />](docs/images/demo_area.png?raw=true)
|
14
|
+
|
15
|
+
[<img src="docs/images/demo_dashed_line.png?raw=true" width="500" />](docs/images/demo_dashed_line.png?raw=true)
|
16
|
+
|
17
|
+
[<img src="docs/images/demo_horizontal_stacked.png?raw=true" width="500" />](docs/images/demo_horizontal_stacked.png?raw=true)
|
18
|
+
|
19
|
+
[<img src="docs/images/demo_legend.png?raw=true" width="500" />](docs/images/demo_legend.png?raw=true)
|
20
|
+
|
21
|
+
[<img src="docs/images/demo_multiautocomplete.png?raw=true" width="500" />](docs/images/demo_multiautocomplete.png?raw=true)
|
21
22
|
|
22
|
-
|
23
|
+
[<img src="docs/images/demo_radar.png?raw=true" width="250" />](docs/images/demo_radar.png?raw=true)
|
23
24
|
|
24
|
-
|
25
|
+
---
|
25
26
|
|
26
|
-
|
27
|
+
1. **Quick setup** - Install ReportsKit and create your first chart in less than one minute using just ~5 lines of code.
|
28
|
+
1. **Simple chart configuration** - Create charts using your existing Rails models. ReportsKit examines the column types and associations to understand how to render the chart.
|
29
|
+
1. **Powerful results** - To see what ReportsKit can create with minimal code, see [reportskit.co](https://www.reportskit.co/).
|
30
|
+
|
31
|
+
Resources
|
32
|
+
---------
|
33
|
+
|
34
|
+
* [Installation](#installation)
|
35
|
+
* [Quick Start](#quick-start)
|
36
|
+
* [Examples](https://www.reportskit.co/)
|
37
|
+
* [Documentation](documentation)
|
27
38
|
|
28
39
|
Installation
|
29
40
|
------------
|
@@ -51,20 +62,23 @@ Rails.application.routes.draw do
|
|
51
62
|
end
|
52
63
|
```
|
53
64
|
|
54
|
-
|
55
|
-
|
56
|
-
### Your First Chart
|
65
|
+
Quick Start
|
66
|
+
-----------
|
57
67
|
|
58
|
-
|
68
|
+
After installation, you can create your first chart with a single line!
|
69
|
+
|
70
|
+
In any view, create a chart that shows the number of records of a model (e.g. `user`) created over time:
|
59
71
|
|
60
72
|
`app/views/users/index.html.haml`
|
61
73
|
```haml
|
62
74
|
= render_report measure: 'user', dimensions: ['created_at']
|
63
75
|
```
|
64
76
|
|
77
|
+
You're done! `render_report` will render the following chart:
|
78
|
+
|
65
79
|
[<img src="docs/images/users_by_created_at.png?raw=true" width="500" />](docs/images/users_by_created_at.png?raw=true)
|
66
80
|
|
67
|
-
|
81
|
+
Instead of passing a hash to `render_report`, you can alternatively configure your charts using YAML and then pass the filename to `render_report`:
|
68
82
|
|
69
83
|
`config/reports_kit/reports/my_users.yml`
|
70
84
|
```yaml
|
@@ -78,389 +92,30 @@ dimensions:
|
|
78
92
|
= render_report 'my_users'
|
79
93
|
```
|
80
94
|
|
81
|
-
|
82
|
-
|
83
|
-
The measure is what is being counted (or aggregated). You can use any model for the measure.
|
84
|
-
|
85
|
-
For example, say we have a `Flight` model with a `flight_at` datetime column. We can chart the number of flights over time:
|
86
|
-
|
87
|
-
```yaml
|
88
|
-
measure: flight
|
89
|
-
dimensions:
|
90
|
-
- flight_at
|
91
|
-
```
|
92
|
-
[<img src="docs/images/flights_by_flight_at.png?raw=true" width="500" />](docs/images/flights_by_flight_at.png?raw=true)
|
93
|
-
|
94
|
-
### Dimensions
|
95
|
-
|
96
|
-
#### Overview
|
97
|
-
|
98
|
-
The dimension is what the measure is being grouped by. You can use datetime columns, integer columns, string columns, associations, or even define custom dimensions.
|
99
|
-
|
100
|
-
For example, the chart below groups by a `carrier` association on `Flight`
|
101
|
-
|
102
|
-
```yaml
|
103
|
-
measure: flight
|
104
|
-
dimensions:
|
105
|
-
- carrier
|
106
|
-
```
|
107
|
-
[<img src="docs/images/flights_by_carrier.png?raw=true" width="500" />](docs/images/flights_by_carrier.png?raw=true)
|
108
|
-
|
109
|
-
You can also use two dimensions:
|
110
|
-
|
111
|
-
```yaml
|
112
|
-
measure: flight
|
113
|
-
dimensions:
|
114
|
-
- carrier
|
115
|
-
- flight_at
|
116
|
-
```
|
117
|
-
[<img src="docs/images/flights_by_carrier_and_flight_at.png?raw=true" width="500" />](docs/images/flights_by_carrier_and_flight_at.png?raw=true)
|
118
|
-
|
119
|
-
Dimensions can be configured using a string:
|
120
|
-
|
121
|
-
```yaml
|
122
|
-
measure: flight
|
123
|
-
dimensions:
|
124
|
-
- carrier
|
125
|
-
```
|
126
|
-
|
127
|
-
Or, if you need to use options, you can configure them using a hash:
|
128
|
-
|
129
|
-
```yaml
|
130
|
-
measure: flight
|
131
|
-
dimensions:
|
132
|
-
- key: carrier
|
133
|
-
limit: 5
|
134
|
-
```
|
135
|
-
#### Types
|
136
|
-
|
137
|
-
##### Association
|
138
|
-
|
139
|
-
```yaml
|
140
|
-
measure: flight
|
141
|
-
dimensions:
|
142
|
-
- carrier
|
143
|
-
```
|
144
|
-
[<img src="docs/images/flights_by_carrier.png?raw=true" width="500" />](docs/images/flights_by_carrier.png?raw=true)
|
145
|
-
|
146
|
-
##### Datetime Column
|
147
|
-
|
148
|
-
```yaml
|
149
|
-
measure: flight
|
150
|
-
dimensions:
|
151
|
-
- flight_at
|
152
|
-
```
|
153
|
-
[<img src="docs/images/flights_by_flight_at.png?raw=true" width="500" />](docs/images/flights_by_flight_at.png?raw=true)
|
154
|
-
|
155
|
-
##### Integer Column
|
156
|
-
|
157
|
-
```yaml
|
158
|
-
measure: flight
|
159
|
-
dimensions:
|
160
|
-
- delay
|
161
|
-
```
|
162
|
-
[<img src="docs/images/flights_by_delay.png?raw=true" width="500" />](docs/images/flights_by_delay.png?raw=true)
|
163
|
-
|
164
|
-
##### Custom
|
165
|
-
|
166
|
-
You can define custom dimensions in your model. For example, if `Flight` has a column named `delay` (in minutes), we can define a `hours_delayed` dimension:
|
167
|
-
|
168
|
-
```ruby
|
169
|
-
class Flight < ApplicationRecord
|
170
|
-
include ReportsKit::Model
|
171
|
-
|
172
|
-
reports_kit do
|
173
|
-
dimension :hours_delayed, group: 'GREATEST(ROUND(flights.delay::float/60), 0)'
|
174
|
-
end
|
175
|
-
end
|
176
|
-
```
|
177
|
-
|
178
|
-
We can then use the `hours_delayed` dimension:
|
179
|
-
|
180
|
-
```yaml
|
181
|
-
measure: flight
|
182
|
-
dimensions:
|
183
|
-
- hours_delayed
|
184
|
-
```
|
185
|
-
[<img src="docs/images/flights_by_hours_delayed.png?raw=true" width="500" />](docs/images/flights_by_hours_delayed.png?raw=true)
|
186
|
-
|
187
|
-
#### Options
|
188
|
-
|
189
|
-
##### `key` *String*
|
190
|
-
|
191
|
-
The dimension's identifier. You can use association names (e.g. `author`), column names (e.g. `created_at`), or the keys of custom dimensions (e.g. `my_dimension`).
|
192
|
-
|
193
|
-
##### `limit` *Integer*
|
194
|
-
|
195
|
-
The maximum number of dimension instances to include.
|
196
|
-
|
197
|
-
### Filters
|
198
|
-
|
199
|
-
#### Overview
|
200
|
-
|
201
|
-
A filter is like a `where`: it filters the results to only include results that match a condition. You can use datetime columns, integer columns, string columns, associations, or even define custom filters.
|
202
|
-
|
203
|
-
For example, if the `Flight` model has a `delay` column that's an integer, the chart below will show only flights that have a delay of greater than 15 minutes:
|
204
|
-
|
205
|
-
```yaml
|
206
|
-
measure:
|
207
|
-
key: flight
|
208
|
-
filters:
|
209
|
-
- key: delay
|
210
|
-
criteria:
|
211
|
-
operator: '>'
|
212
|
-
value: 15
|
213
|
-
dimensions:
|
214
|
-
- carrier
|
215
|
-
```
|
216
|
-
[<img src="docs/images/flights_with_configured_number.png?raw=true" width="500" />](docs/images/flights_with_configured_number.png?raw=true)
|
217
|
-
|
218
|
-
You can also create form controls that the user can use to filter the chart:
|
219
|
-
|
220
|
-
```yaml
|
221
|
-
measure:
|
222
|
-
key: flight
|
223
|
-
filters:
|
224
|
-
- carrier
|
225
|
-
- carrier_name
|
226
|
-
- is_on_time
|
227
|
-
- flight_at
|
228
|
-
dimensions:
|
229
|
-
- flight_at
|
230
|
-
- carrier
|
231
|
-
```
|
232
|
-
|
233
|
-
In `app/views/my_view.html.haml`:
|
234
|
-
```haml
|
235
|
-
= render_report 'filters' do
|
236
|
-
.pull-right
|
237
|
-
= f.date_range :flight_at
|
238
|
-
= f.multi_autocomplete :carrier, scope: 'top', placeholder: 'Carrier...'
|
239
|
-
= f.string_filter :carrier_name, placeholder: 'Carrier name (e.g. Airlines)...', style: 'width: 175px;'
|
240
|
-
.checkbox
|
241
|
-
= label_tag :is_on_time do
|
242
|
-
= f.check_box :is_on_time
|
243
|
-
On time
|
244
|
-
```
|
245
|
-
[<img src="docs/images/flights_with_filters.png?raw=true" width="500" />](docs/images/flights_with_filters.png?raw=true)
|
246
|
-
|
247
|
-
#### Types
|
248
|
-
|
249
|
-
##### Boolean
|
250
|
-
|
251
|
-
```yaml
|
252
|
-
measure:
|
253
|
-
key: flight
|
254
|
-
filters:
|
255
|
-
- key: is_on_time
|
256
|
-
criteria:
|
257
|
-
operator: true
|
258
|
-
value: 15
|
259
|
-
dimensions:
|
260
|
-
- carrier
|
261
|
-
```
|
262
|
-
[<img src="docs/images/flights_with_configured_boolean.png?raw=true" width="500" />](docs/images/flights_with_configured_boolean.png?raw=true)
|
263
|
-
|
264
|
-
##### Datetime
|
95
|
+
The YAML approach is more maintainable and readable, so we'll use it in the rest of the documentation.
|
265
96
|
|
266
|
-
|
267
|
-
measure:
|
268
|
-
key: flight
|
269
|
-
filters:
|
270
|
-
- key: flight_at
|
271
|
-
criteria:
|
272
|
-
operator: between
|
273
|
-
value: Oct 1, 2016 - Jan 1, 2017
|
274
|
-
dimensions:
|
275
|
-
- carrier
|
276
|
-
```
|
277
|
-
[<img src="docs/images/flights_with_configured_datetime.png?raw=true" width="500" />](docs/images/flights_with_configured_datetime.png?raw=true)
|
278
|
-
|
279
|
-
##### Number
|
280
|
-
|
281
|
-
```yaml
|
282
|
-
measure:
|
283
|
-
key: flight
|
284
|
-
filters:
|
285
|
-
- key: delay
|
286
|
-
criteria:
|
287
|
-
operator: '>'
|
288
|
-
value: 15
|
289
|
-
dimensions:
|
290
|
-
- carrier
|
291
|
-
```
|
292
|
-
[<img src="docs/images/flights_with_configured_number.png?raw=true" width="500" />](docs/images/flights_with_configured_number.png?raw=true)
|
293
|
-
|
294
|
-
##### String
|
295
|
-
|
296
|
-
```yaml
|
297
|
-
measure:
|
298
|
-
key: flight
|
299
|
-
filters:
|
300
|
-
- key: carrier_name
|
301
|
-
criteria:
|
302
|
-
operator: contains
|
303
|
-
value: airlines
|
304
|
-
dimensions:
|
305
|
-
- carrier
|
306
|
-
```
|
307
|
-
[<img src="docs/images/flights_with_configured_string.png?raw=true" width="500" />](docs/images/flights_with_configured_string.png?raw=true)
|
308
|
-
|
309
|
-
|
310
|
-
#### Form Controls
|
97
|
+
### Form Controls
|
311
98
|
|
312
|
-
|
99
|
+
You can add a date range form control to the above chart with a single line, using one of ReportsKit's form helpers:
|
313
100
|
|
314
|
-
|
315
|
-
measure:
|
316
|
-
key: flight
|
317
|
-
filters:
|
318
|
-
- is_on_time
|
319
|
-
dimensions:
|
320
|
-
- flight_at
|
321
|
-
- carrier
|
322
|
-
```
|
323
|
-
```haml
|
324
|
-
= render_report 'filter_check_box' do
|
325
|
-
.checkbox
|
326
|
-
= label_tag :is_on_time do
|
327
|
-
= f.check_box :is_on_time
|
328
|
-
On time
|
329
|
-
```
|
330
|
-
[<img src="docs/images/flights_with_check_box.png?raw=true" width="500" />](docs/images/flights_with_check_box.png?raw=true)
|
331
|
-
|
332
|
-
##### Date Range
|
333
|
-
|
334
|
-
```yaml
|
335
|
-
measure:
|
336
|
-
key: flight
|
337
|
-
filters:
|
338
|
-
- flight_at
|
339
|
-
dimensions:
|
340
|
-
- flight_at
|
341
|
-
- carrier
|
342
|
-
```
|
343
|
-
```haml
|
344
|
-
= render_report 'filter_date_range' do
|
345
|
-
= f.date_range :flight_at
|
346
|
-
```
|
347
|
-
[<img src="docs/images/flights_with_date_range.png?raw=true" width="500" />](docs/images/flights_with_date_range.png?raw=true)
|
348
|
-
|
349
|
-
##### Multi-Autocomplete
|
350
|
-
|
351
|
-
```yaml
|
352
|
-
measure:
|
353
|
-
key: flight
|
354
|
-
filters:
|
355
|
-
- carrier
|
356
|
-
dimensions:
|
357
|
-
- flight_at
|
358
|
-
- carrier
|
359
|
-
```
|
360
|
-
```haml
|
361
|
-
= render_report 'filter_multi_autocomplete' do
|
362
|
-
= f.multi_autocomplete :carrier, scope: 'top', placeholder: 'Carrier...'
|
363
|
-
```
|
364
|
-
[<img src="docs/images/flights_with_multi_autocomplete.png?raw=true" width="500" />](docs/images/flights_with_multi_autocomplete.png?raw=true)
|
365
|
-
|
366
|
-
##### String Filter
|
367
|
-
|
368
|
-
```yaml
|
369
|
-
measure:
|
370
|
-
key: flight
|
371
|
-
filters:
|
372
|
-
- carrier_name
|
373
|
-
dimensions:
|
374
|
-
- flight_at
|
375
|
-
- carrier
|
376
|
-
```
|
101
|
+
`app/views/users/index.html.haml`
|
377
102
|
```haml
|
378
|
-
= render_report '
|
379
|
-
= f.
|
103
|
+
= render_report 'my_users' do |f|
|
104
|
+
= f.date_range :created_at
|
380
105
|
```
|
381
|
-
[<img src="docs/images/flights_with_string_filter.png?raw=true" width="500" />](docs/images/flights_with_string_filter.png?raw=true)
|
382
106
|
|
383
|
-
|
107
|
+
[<img src="docs/images/users_by_created_at_with_filter.png?raw=true" width="500" />](docs/images/users_by_created_at_with_filter.png?raw=true)
|
384
108
|
|
385
|
-
|
109
|
+
Many other form controls are available; see [Filters](docs/filters.md) for more.
|
386
110
|
|
387
|
-
|
111
|
+
### How It Works
|
388
112
|
|
389
|
-
|
113
|
+
In the Quick Start chart, `measure: 'user'` tells ReportsKit to count the number of `User` records, and `dimensions: ['created_at']` tells it to group by the week of the `created_at` column. Since `created_at` is a `datetime` column, ReportsKit knows that it should sort the results chronologically.
|
390
114
|
|
391
|
-
|
392
|
-
|
393
|
-
Here's an example of a horizontal bar chart:
|
394
|
-
|
395
|
-
```yaml
|
396
|
-
measure: flight
|
397
|
-
dimensions:
|
398
|
-
- carrier
|
399
|
-
chart:
|
400
|
-
type: horizontalBar
|
401
|
-
options:
|
402
|
-
scales:
|
403
|
-
xAxes:
|
404
|
-
- scaleLabel:
|
405
|
-
display: true
|
406
|
-
labelString: Flights
|
407
|
-
yAxes:
|
408
|
-
- scaleLabel:
|
409
|
-
display: true
|
410
|
-
labelString: Carrier
|
411
|
-
```
|
412
|
-
[<img src="docs/images/horizontal_bar.png?raw=true" width="500" />](docs/images/horizontal_bar.png?raw=true)
|
413
|
-
|
414
|
-
##### `options`
|
415
|
-
|
416
|
-
You can use any `options` that are supported by Chart.js.
|
417
|
-
|
418
|
-
Here's an example of a chart with Chart.js options:
|
419
|
-
|
420
|
-
```yaml
|
421
|
-
measure: flight
|
422
|
-
dimensions:
|
423
|
-
- origin_market
|
424
|
-
- carrier
|
425
|
-
chart:
|
426
|
-
type: horizontalBar
|
427
|
-
options:
|
428
|
-
scales:
|
429
|
-
xAxes:
|
430
|
-
- stacked: true
|
431
|
-
scaleLabel:
|
432
|
-
display: true
|
433
|
-
labelString: Flights
|
434
|
-
yAxes:
|
435
|
-
- stacked: true
|
436
|
-
scaleLabel:
|
437
|
-
display: true
|
438
|
-
labelString: Market
|
439
|
-
```
|
440
|
-
[<img src="docs/images/chart_options.png?raw=true" width="500" />](docs/images/chart_options.png?raw=true)
|
441
|
-
|
442
|
-
##### `datasets`
|
443
|
-
|
444
|
-
You can use any `datasets` options that are supported by Chart.js.
|
445
|
-
|
446
|
-
Here's an example of a chart with `datasets` options:
|
447
|
-
|
448
|
-
```yaml
|
449
|
-
measure: flight
|
450
|
-
dimensions:
|
451
|
-
- flight_at
|
452
|
-
- key: carrier
|
453
|
-
limit: 3
|
454
|
-
chart:
|
455
|
-
type: line
|
456
|
-
datasets:
|
457
|
-
fill: false
|
458
|
-
borderDash:
|
459
|
-
- 5
|
460
|
-
- 5
|
461
|
-
```
|
462
|
-
[<img src="docs/images/dashed_line.png?raw=true" width="500" />](docs/images/dashed_line.png?raw=true)
|
115
|
+
To learn how to use more of ReportsKit's features, check out the following resources:
|
463
116
|
|
117
|
+
* [Examples](https://www.reportskit.co/)
|
118
|
+
* [Documentation](documentation)
|
464
119
|
|
465
120
|
License
|
466
121
|
-------
|
data/docs/README.md
ADDED
data/docs/dimensions.md
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
### Dimensions
|
2
|
+
|
3
|
+
#### Overview
|
4
|
+
|
5
|
+
The dimension is what the measure is being grouped by. You can use datetime columns, integer columns, string columns, associations, or even define custom dimensions.
|
6
|
+
|
7
|
+
For example, say you have a `Flight` model with a `belongs_to :carrier` association:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
class Flight < ActiveRecord::Base
|
11
|
+
belongs_to :carrier
|
12
|
+
end
|
13
|
+
```
|
14
|
+
|
15
|
+
You can then use `dimensions: ['carrier']` to count the number of Flights per Carrier:
|
16
|
+
|
17
|
+
```yaml
|
18
|
+
measure: flight
|
19
|
+
dimensions:
|
20
|
+
- carrier
|
21
|
+
```
|
22
|
+
[<img src="images/flights_by_carrier.png?raw=true" width="500" />](images/flights_by_carrier.png?raw=true)
|
23
|
+
|
24
|
+
You can also use two dimensions:
|
25
|
+
|
26
|
+
```yaml
|
27
|
+
measure: flight
|
28
|
+
dimensions:
|
29
|
+
- carrier
|
30
|
+
- flight_at
|
31
|
+
```
|
32
|
+
[<img src="images/flights_by_carrier_and_flight_at.png?raw=true" width="500" />](images/flights_by_carrier_and_flight_at.png?raw=true)
|
33
|
+
|
34
|
+
Dimensions can be configured using a string (`carrier`):
|
35
|
+
|
36
|
+
```yaml
|
37
|
+
measure: flight
|
38
|
+
dimensions:
|
39
|
+
- carrier
|
40
|
+
```
|
41
|
+
|
42
|
+
Or, if you need to use options, you can configure them using a hash:
|
43
|
+
|
44
|
+
```yaml
|
45
|
+
measure: flight
|
46
|
+
dimensions:
|
47
|
+
- key: carrier
|
48
|
+
limit: 5
|
49
|
+
```
|
50
|
+
#### Types
|
51
|
+
|
52
|
+
##### Association
|
53
|
+
|
54
|
+
```yaml
|
55
|
+
measure: flight
|
56
|
+
dimensions:
|
57
|
+
- carrier
|
58
|
+
```
|
59
|
+
[<img src="images/flights_by_carrier.png?raw=true" width="500" />](images/flights_by_carrier.png?raw=true)
|
60
|
+
|
61
|
+
##### Datetime Column
|
62
|
+
|
63
|
+
```yaml
|
64
|
+
measure: flight
|
65
|
+
dimensions:
|
66
|
+
- flight_at
|
67
|
+
```
|
68
|
+
[<img src="images/flights_by_flight_at.png?raw=true" width="500" />](images/flights_by_flight_at.png?raw=true)
|
69
|
+
|
70
|
+
##### Integer Column
|
71
|
+
|
72
|
+
```yaml
|
73
|
+
measure: flight
|
74
|
+
dimensions:
|
75
|
+
- delay
|
76
|
+
```
|
77
|
+
[<img src="images/flights_by_delay.png?raw=true" width="500" />](images/flights_by_delay.png?raw=true)
|
78
|
+
|
79
|
+
##### Custom Dimensions
|
80
|
+
|
81
|
+
You can define custom dimensions in your model. For example, if `Flight` has a column named `delay` (in minutes), we can define a `hours_delayed` dimension:
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
class Flight < ApplicationRecord
|
85
|
+
include ReportsKit::Model
|
86
|
+
|
87
|
+
reports_kit do
|
88
|
+
dimension :hours_delayed, group: 'GREATEST(ROUND(flights.delay::float/60), 0)'
|
89
|
+
end
|
90
|
+
end
|
91
|
+
```
|
92
|
+
|
93
|
+
We can then use the `hours_delayed` dimension:
|
94
|
+
|
95
|
+
```yaml
|
96
|
+
measure: flight
|
97
|
+
dimensions:
|
98
|
+
- hours_delayed
|
99
|
+
```
|
100
|
+
[<img src="images/flights_by_hours_delayed.png?raw=true" width="500" />](images/flights_by_hours_delayed.png?raw=true)
|
101
|
+
|
102
|
+
#### Options
|
103
|
+
|
104
|
+
##### `key` *String*
|
105
|
+
|
106
|
+
The dimension's identifier. You can use association names (e.g. `author`), column names (e.g. `created_at`), or the keys of custom dimensions (e.g. `my_dimension`).
|
107
|
+
|
108
|
+
##### `limit` *Integer*
|
109
|
+
|
110
|
+
The maximum number of dimension instances to include. For example, if you set `limit: 5` and have one dimension, then the x-axis will only show 5 items.
|
@@ -0,0 +1,80 @@
|
|
1
|
+
### Display Options
|
2
|
+
|
3
|
+
#### Overview
|
4
|
+
|
5
|
+
Charts are rendered using [Chart.js](http://www.chartjs.org/). You can configure your ReportsKit chart using any [Chart.js options](http://www.chartjs.org/docs/).
|
6
|
+
|
7
|
+
##### `type`
|
8
|
+
|
9
|
+
You can use any `type` value supported by Chart.js, including `bar`, `line`, `horizontalBar`, `radar`, and more.
|
10
|
+
|
11
|
+
Here's an example of a horizontal bar chart:
|
12
|
+
|
13
|
+
```yaml
|
14
|
+
measure: flight
|
15
|
+
dimensions:
|
16
|
+
- carrier
|
17
|
+
chart:
|
18
|
+
type: horizontalBar
|
19
|
+
options:
|
20
|
+
scales:
|
21
|
+
xAxes:
|
22
|
+
- scaleLabel:
|
23
|
+
display: true
|
24
|
+
labelString: Flights
|
25
|
+
yAxes:
|
26
|
+
- scaleLabel:
|
27
|
+
display: true
|
28
|
+
labelString: Carrier
|
29
|
+
```
|
30
|
+
[<img src="images/horizontal_bar.png?raw=true" width="500" />](images/horizontal_bar.png?raw=true)
|
31
|
+
|
32
|
+
##### `options`
|
33
|
+
|
34
|
+
You can use any `options` that are supported by Chart.js.
|
35
|
+
|
36
|
+
Here's an example of a chart with Chart.js options:
|
37
|
+
|
38
|
+
```yaml
|
39
|
+
measure: flight
|
40
|
+
dimensions:
|
41
|
+
- origin_market
|
42
|
+
- carrier
|
43
|
+
chart:
|
44
|
+
type: horizontalBar
|
45
|
+
options:
|
46
|
+
scales:
|
47
|
+
xAxes:
|
48
|
+
- stacked: true
|
49
|
+
scaleLabel:
|
50
|
+
display: true
|
51
|
+
labelString: Flights
|
52
|
+
yAxes:
|
53
|
+
- stacked: true
|
54
|
+
scaleLabel:
|
55
|
+
display: true
|
56
|
+
labelString: Market
|
57
|
+
```
|
58
|
+
[<img src="images/chart_options.png?raw=true" width="500" />](images/chart_options.png?raw=true)
|
59
|
+
|
60
|
+
##### `datasets`
|
61
|
+
|
62
|
+
You can use any `datasets` options that are supported by Chart.js.
|
63
|
+
|
64
|
+
Here's an example of a chart with `datasets` options:
|
65
|
+
|
66
|
+
```yaml
|
67
|
+
measure: flight
|
68
|
+
dimensions:
|
69
|
+
- flight_at
|
70
|
+
- key: carrier
|
71
|
+
limit: 3
|
72
|
+
chart:
|
73
|
+
type: line
|
74
|
+
datasets:
|
75
|
+
fill: false
|
76
|
+
borderDash:
|
77
|
+
- 5
|
78
|
+
- 5
|
79
|
+
```
|
80
|
+
[<img src="images/dashed_line.png?raw=true" width="500" />](images/dashed_line.png?raw=true)
|
data/docs/filters.md
ADDED
@@ -0,0 +1,225 @@
|
|
1
|
+
### Filters
|
2
|
+
|
3
|
+
#### Overview
|
4
|
+
|
5
|
+
A filter is like a SQL `WHERE`: it filters the results to only include results that match a condition. You can use datetime columns, integer columns, string columns, associations, or even define custom filters.
|
6
|
+
|
7
|
+
For example, if the `Flight` model has a `delay` column that's an integer, the chart below will show only flights that have a delay of greater than 15 minutes:
|
8
|
+
|
9
|
+
```yaml
|
10
|
+
measure:
|
11
|
+
key: flight
|
12
|
+
filters:
|
13
|
+
- key: delay
|
14
|
+
criteria:
|
15
|
+
operator: '>'
|
16
|
+
value: 15
|
17
|
+
dimensions:
|
18
|
+
- carrier
|
19
|
+
```
|
20
|
+
[<img src="images/flights_with_configured_number.png?raw=true" width="500" />](images/flights_with_configured_number.png?raw=true)
|
21
|
+
|
22
|
+
You can also create form controls that the user can use to filter the chart:
|
23
|
+
|
24
|
+
```yaml
|
25
|
+
measure:
|
26
|
+
key: flight
|
27
|
+
filters:
|
28
|
+
- carrier
|
29
|
+
- carrier_name
|
30
|
+
- is_on_time
|
31
|
+
- flight_at
|
32
|
+
dimensions:
|
33
|
+
- flight_at
|
34
|
+
- carrier
|
35
|
+
```
|
36
|
+
|
37
|
+
In `app/views/my_view.html.haml`, you can use ReportsKit's form helpers to create the controls:
|
38
|
+
```haml
|
39
|
+
= render_report 'filters' do |f|
|
40
|
+
.pull-right
|
41
|
+
= f.date_range :flight_at
|
42
|
+
= f.multi_autocomplete :carrier, scope: 'top', placeholder: 'Carrier...'
|
43
|
+
= f.string_filter :carrier_name, placeholder: 'Carrier name (e.g. Airlines)...', style: 'width: 175px;'
|
44
|
+
.checkbox
|
45
|
+
= label_tag :is_on_time do
|
46
|
+
= f.check_box :is_on_time
|
47
|
+
On time
|
48
|
+
```
|
49
|
+
[<img src="images/flights_with_filters.png?raw=true" width="500" />](images/flights_with_filters.png?raw=true)
|
50
|
+
|
51
|
+
#### Types
|
52
|
+
|
53
|
+
##### Boolean
|
54
|
+
|
55
|
+
Boolean filters can be used on any `boolean` columns, or you can define your own boolean filter (see [Custom Filters](#custom-filters)).
|
56
|
+
|
57
|
+
```yaml
|
58
|
+
measure:
|
59
|
+
key: flight
|
60
|
+
filters:
|
61
|
+
- key: is_on_time
|
62
|
+
criteria:
|
63
|
+
operator: true
|
64
|
+
dimensions:
|
65
|
+
- carrier
|
66
|
+
```
|
67
|
+
[<img src="images/flights_with_configured_boolean.png?raw=true" width="500" />](images/flights_with_configured_boolean.png?raw=true)
|
68
|
+
|
69
|
+
##### Datetime
|
70
|
+
|
71
|
+
Datetime filters can be used on any `datetime` or `timestamp` columns, or you can define your own datetime filter (see [Custom Filters](#custom-filters)).
|
72
|
+
|
73
|
+
```yaml
|
74
|
+
measure:
|
75
|
+
key: flight
|
76
|
+
filters:
|
77
|
+
- key: flight_at
|
78
|
+
criteria:
|
79
|
+
operator: between
|
80
|
+
value: Oct 1, 2016 - Jan 1, 2017
|
81
|
+
dimensions:
|
82
|
+
- carrier
|
83
|
+
```
|
84
|
+
[<img src="images/flights_with_configured_datetime.png?raw=true" width="500" />](images/flights_with_configured_datetime.png?raw=true)
|
85
|
+
|
86
|
+
##### Number
|
87
|
+
|
88
|
+
Number filters can be used on any `integer`, `float`, or `decimal` columns, or you can define your own number filter (see [Custom Filters](#custom-filters)).
|
89
|
+
|
90
|
+
```yaml
|
91
|
+
measure:
|
92
|
+
key: flight
|
93
|
+
filters:
|
94
|
+
- key: delay
|
95
|
+
criteria:
|
96
|
+
operator: '>'
|
97
|
+
value: 15
|
98
|
+
dimensions:
|
99
|
+
- carrier
|
100
|
+
```
|
101
|
+
[<img src="images/flights_with_configured_number.png?raw=true" width="500" />](images/flights_with_configured_number.png?raw=true)
|
102
|
+
|
103
|
+
##### String
|
104
|
+
|
105
|
+
String filters can be used on any `string` or `text` columns, or you can define your own number filter (see [Custom Filters](#custom-filters)).
|
106
|
+
|
107
|
+
```yaml
|
108
|
+
measure:
|
109
|
+
key: flight
|
110
|
+
filters:
|
111
|
+
- key: carrier_name
|
112
|
+
criteria:
|
113
|
+
operator: contains
|
114
|
+
value: airlines
|
115
|
+
dimensions:
|
116
|
+
- carrier
|
117
|
+
```
|
118
|
+
[<img src="images/flights_with_configured_string.png?raw=true" width="500" />](images/flights_with_configured_string.png?raw=true)
|
119
|
+
|
120
|
+
##### Custom Filters
|
121
|
+
|
122
|
+
You can define custom filters in your model. For example, if `Flight` has a column named `delay` (an integer with a unit of minutes), then we can define a `was_delayed` dimension:
|
123
|
+
|
124
|
+
```ruby
|
125
|
+
class Flight < ApplicationRecord
|
126
|
+
include ReportsKit::Model
|
127
|
+
|
128
|
+
reports_kit do
|
129
|
+
filter :was_delayed, :boolean, conditions: 'delay IS NOT NULL AND delay > 15'
|
130
|
+
end
|
131
|
+
end
|
132
|
+
```
|
133
|
+
|
134
|
+
We can then use the `was_delayed` filter:
|
135
|
+
|
136
|
+
```yaml
|
137
|
+
measure:
|
138
|
+
key: flight
|
139
|
+
filters:
|
140
|
+
- key: was_delayed
|
141
|
+
criteria:
|
142
|
+
operator: true
|
143
|
+
dimensions:
|
144
|
+
- carrier
|
145
|
+
```
|
146
|
+
[<img src="images/flights_by_hours_delayed.png?raw=true" width="500" />](images/flights_by_hours_delayed.png?raw=true)
|
147
|
+
|
148
|
+
#### Form Controls
|
149
|
+
|
150
|
+
Most charting libraries don't provide interactive form controls, but ReportsKit does. It makes it easy to add form controls to allow end users to modify charts.
|
151
|
+
|
152
|
+
##### Check Box
|
153
|
+
|
154
|
+
Check boxes can be used with filters that have a `boolean` type.
|
155
|
+
|
156
|
+
```yaml
|
157
|
+
measure:
|
158
|
+
key: flight
|
159
|
+
filters:
|
160
|
+
- is_on_time
|
161
|
+
dimensions:
|
162
|
+
- flight_at
|
163
|
+
- carrier
|
164
|
+
```
|
165
|
+
```haml
|
166
|
+
= render_report 'filter_check_box' do |f|
|
167
|
+
.checkbox
|
168
|
+
= label_tag :is_on_time do
|
169
|
+
= f.check_box :is_on_time
|
170
|
+
On time
|
171
|
+
```
|
172
|
+
[<img src="images/flights_with_check_box.png?raw=true" width="500" />](images/flights_with_check_box.png?raw=true)
|
173
|
+
|
174
|
+
##### Date Range
|
175
|
+
|
176
|
+
Date ranges can be used with filters that have a `datetime` type.
|
177
|
+
|
178
|
+
```yaml
|
179
|
+
measure:
|
180
|
+
key: flight
|
181
|
+
filters:
|
182
|
+
- flight_at
|
183
|
+
dimensions:
|
184
|
+
- flight_at
|
185
|
+
- carrier
|
186
|
+
```
|
187
|
+
```haml
|
188
|
+
= render_report 'filter_date_range' do |f|
|
189
|
+
= f.date_range :flight_at
|
190
|
+
```
|
191
|
+
[<img src="images/flights_with_date_range.png?raw=true" width="500" />](images/flights_with_date_range.png?raw=true)
|
192
|
+
|
193
|
+
##### Multi-Autocomplete
|
194
|
+
|
195
|
+
```yaml
|
196
|
+
measure:
|
197
|
+
key: flight
|
198
|
+
filters:
|
199
|
+
- carrier
|
200
|
+
dimensions:
|
201
|
+
- flight_at
|
202
|
+
- carrier
|
203
|
+
```
|
204
|
+
```haml
|
205
|
+
= render_report 'filter_multi_autocomplete' do |f|
|
206
|
+
= f.multi_autocomplete :carrier, scope: 'top', placeholder: 'Carrier...'
|
207
|
+
```
|
208
|
+
[<img src="images/flights_with_multi_autocomplete.png?raw=true" width="500" />](images/flights_with_multi_autocomplete.png?raw=true)
|
209
|
+
|
210
|
+
##### String Filter
|
211
|
+
|
212
|
+
```yaml
|
213
|
+
measure:
|
214
|
+
key: flight
|
215
|
+
filters:
|
216
|
+
- carrier_name
|
217
|
+
dimensions:
|
218
|
+
- flight_at
|
219
|
+
- carrier
|
220
|
+
```
|
221
|
+
```haml
|
222
|
+
= render_report 'filter_string' do |f|
|
223
|
+
= f.string_filter :carrier_name, placeholder: 'Carrier name (e.g. Airlines)...', style: 'width: 175px;'
|
224
|
+
```
|
225
|
+
[<img src="images/flights_with_string_filter.png?raw=true" width="500" />](images/flights_with_string_filter.png?raw=true)
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/docs/measures.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
### Measures
|
2
|
+
|
3
|
+
The measure is what is being counted (or aggregated in another way). You can use any model as the measure.
|
4
|
+
|
5
|
+
For example, say we have a `Flight` model with a `flight_at` datetime column. We can chart the number of flights over time:
|
6
|
+
|
7
|
+
```yaml
|
8
|
+
measure: flight
|
9
|
+
dimensions:
|
10
|
+
- flight_at
|
11
|
+
```
|
12
|
+
[<img src="images/flights_by_flight_at.png?raw=true" width="500" />](images/flights_by_flight_at.png?raw=true)
|
data/lib/reports_kit.rb
CHANGED
@@ -6,7 +6,6 @@ require 'reports_kit/engine'
|
|
6
6
|
require 'reports_kit/helper'
|
7
7
|
require 'reports_kit/model'
|
8
8
|
require 'reports_kit/model_configuration'
|
9
|
-
require 'reports_kit/rails'
|
10
9
|
require 'reports_kit/report_builder'
|
11
10
|
require 'reports_kit/resources_controller'
|
12
11
|
require 'reports_kit/reports_controller'
|
@@ -16,13 +16,17 @@ module ReportsKit
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def key
|
19
|
-
properties[:key]
|
19
|
+
properties[:key].underscore
|
20
20
|
end
|
21
21
|
|
22
22
|
def label
|
23
23
|
key.pluralize.titleize
|
24
24
|
end
|
25
25
|
|
26
|
+
def relation_name
|
27
|
+
key.tableize
|
28
|
+
end
|
29
|
+
|
26
30
|
def aggregate_function
|
27
31
|
:count
|
28
32
|
end
|
@@ -32,7 +36,7 @@ module ReportsKit
|
|
32
36
|
end
|
33
37
|
|
34
38
|
def base_relation
|
35
|
-
return context_record.public_send(
|
39
|
+
return context_record.public_send(relation_name) if context_record
|
36
40
|
model_class
|
37
41
|
end
|
38
42
|
|
@@ -1,14 +1,8 @@
|
|
1
1
|
module ReportsKit
|
2
2
|
class ReportsController < ReportsKit::BaseController
|
3
3
|
def index
|
4
|
-
# RubyProf.start
|
5
4
|
properties = ActiveSupport::JSON.decode(params[:properties])
|
6
5
|
report_data = Reports::Data::Generate.new(properties, context_record: context_record).perform
|
7
|
-
# result = RubyProf.stop
|
8
|
-
# printer = RubyProf::CallStackPrinter.new(result)
|
9
|
-
# File.open(Rails.root.join('tmp', 'out.html'), 'w') do |file|
|
10
|
-
# printer.print(file, :min_percent => 2)
|
11
|
-
# end
|
12
6
|
render json: { data: report_data }
|
13
7
|
end
|
14
8
|
end
|
data/lib/reports_kit/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reports_kit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Benner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -136,8 +136,19 @@ files:
|
|
136
136
|
- app/assets/stylesheets/reports_kit/vendor/select2-bootstrap.css
|
137
137
|
- app/assets/stylesheets/reports_kit/vendor/select2.css
|
138
138
|
- config/routes.rb
|
139
|
+
- docs/README.md
|
140
|
+
- docs/dimensions.md
|
141
|
+
- docs/display_options.md
|
142
|
+
- docs/filters.md
|
139
143
|
- docs/images/chart_options.png
|
140
144
|
- docs/images/dashed_line.png
|
145
|
+
- docs/images/demo.gif
|
146
|
+
- docs/images/demo_area.png
|
147
|
+
- docs/images/demo_dashed_line.png
|
148
|
+
- docs/images/demo_horizontal_stacked.png
|
149
|
+
- docs/images/demo_legend.png
|
150
|
+
- docs/images/demo_multiautocomplete.png
|
151
|
+
- docs/images/demo_radar.png
|
141
152
|
- docs/images/flights_by_carrier.png
|
142
153
|
- docs/images/flights_by_carrier_and_flight_at.png
|
143
154
|
- docs/images/flights_by_delay.png
|
@@ -155,7 +166,8 @@ files:
|
|
155
166
|
- docs/images/horizontal_bar.png
|
156
167
|
- docs/images/legend_right.png
|
157
168
|
- docs/images/users_by_created_at.png
|
158
|
-
-
|
169
|
+
- docs/images/users_by_created_at_with_filter.png
|
170
|
+
- docs/measures.md
|
159
171
|
- lib/reports_kit.rb
|
160
172
|
- lib/reports_kit/base_controller.rb
|
161
173
|
- lib/reports_kit/configuration.rb
|
@@ -163,7 +175,6 @@ files:
|
|
163
175
|
- lib/reports_kit/helper.rb
|
164
176
|
- lib/reports_kit/model.rb
|
165
177
|
- lib/reports_kit/model_configuration.rb
|
166
|
-
- lib/reports_kit/rails.rb
|
167
178
|
- lib/reports_kit/report_builder.rb
|
168
179
|
- lib/reports_kit/reports/data/chart_options.rb
|
169
180
|
- lib/reports_kit/reports/data/generate.rb
|
data/gists/doc.txt
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
1. Add ReportsKit
|
2
|
-
|
3
|
-
Gemfile
|
4
|
-
|
5
|
-
source 'https://my-api-key@gems.reportskit.co' do
|
6
|
-
gem 'reportskit'
|
7
|
-
end
|
8
|
-
|
9
|
-
|
10
|
-
2. Configure Models
|
11
|
-
|
12
|
-
Configure the filters and dimensions that can be used in your reports:
|
13
|
-
|
14
|
-
app/models/task.rb
|
15
|
-
|
16
|
-
class Task < ActiveRecord::Base
|
17
|
-
belongs_to :assignee
|
18
|
-
belongs_to :project
|
19
|
-
|
20
|
-
reportskit do
|
21
|
-
filter :assignee
|
22
|
-
filter :project
|
23
|
-
filter :completed_at
|
24
|
-
filter :is_completed, :boolean, conditions: -> { where.not(completed_at: nil) }
|
25
|
-
|
26
|
-
dimension :assignee
|
27
|
-
dimension :project
|
28
|
-
dimension :completed_at
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
|
33
|
-
3. Configure Reports
|
34
|
-
|
35
|
-
config/reportskit/reports/completed_tasks.yml
|
36
|
-
|
37
|
-
name: Completed tasks
|
38
|
-
measures:
|
39
|
-
- tasks
|
40
|
-
dimensions:
|
41
|
-
- completed_at
|
42
|
-
display_format: area
|
43
|
-
|
44
|
-
|
45
|
-
4. Add Report to a View
|
46
|
-
|
47
|
-
app/views/reports/my_view.html.haml
|
48
|
-
|
49
|
-
= render_report 'completed_tasks'
|
50
|
-
|
51
|
-
|
52
|
-
5. Add Routes:
|
53
|
-
|
54
|
-
config/routes.rb
|
55
|
-
|
56
|
-
mount ReportsKit::Engine, at: '/reports'
|
57
|
-
|
58
|
-
That's it! You can now visit the view in step 4. to see the report that you've configured.
|