supercharts-bullet_train 0.1.13 → 0.1.15
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 56a1d2213a1e73cacd80d1789dfbc7ff1c28ef483b92733dff64c16b1e3bb572
|
4
|
+
data.tar.gz: 9eae7acba85bd87d8b900cd9bc08ef62c5a29f131d4d0e092bebc4cb4d234bfb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3844ff0121f7c43ad7d44ddaa0b857a96506e76f5ae5063fec994577cca4be734bb3b76b9c8a43d74723316e25fe5bd429000dc53c61077000fb244dac054dd8
|
7
|
+
data.tar.gz: ea02a7ecb02ba9e4a291fb37064ea121c8249203cbea077f83585fe011a730975568b0156ac5b34c49f35f99c6ae3f66c2153892a28d721131ccc2384f07c334
|
data/README.md
CHANGED
@@ -78,17 +78,19 @@ You're all set.
|
|
78
78
|
|
79
79
|
## Usage
|
80
80
|
|
81
|
-
Let's you already have a ClickThrough model, storing click-throughs from campaigns. For now we'll just say it click_throughs have a `team_id` (in Bullet Train apps, your account is associated with a team).
|
81
|
+
Let's say you already have a ClickThrough model, storing click-throughs from campaigns. For now we'll just say it click_throughs have a `team_id` (in Bullet Train apps, your account is associated with a team).
|
82
82
|
|
83
|
-
You'd like a chart to appear in your Dashboard, showing how many click-throughs per day (so we'll group by), associated with your Team.
|
83
|
+
You'd like a chart to appear in your Dashboard, showing how many click-throughs per day (so we'll group by day), associated with your Team.
|
84
84
|
|
85
85
|
```bash
|
86
86
|
bin/super-scaffold supercharts:chart ClickThrough Team
|
87
87
|
```
|
88
88
|
|
89
|
+
This will generated some new files and modify some files like inserting a `turbo_frame` in your `team#show` file, modifying your `roles.yml` file, etc. Look over the changes and commit when satisfied.
|
90
|
+
|
89
91
|
### Generate some test data
|
90
92
|
|
91
|
-
We'll use a FactoryBot `trait` to randomize the `created_at` property for the test data we'll create.
|
93
|
+
We'll use a FactoryBot `trait` to randomize the `created_at` property for the test data we'll create. This is the change I suggest you make to your `factories/click_throughs.rb` file:
|
92
94
|
|
93
95
|
```ruby
|
94
96
|
# test/factories/click_throughs.rb
|
@@ -115,12 +117,122 @@ Visit your app in `localhost:3000` and you should see your new chart.
|
|
115
117
|
|
116
118
|
## Modifying the chart
|
117
119
|
|
118
|
-
|
120
|
+
### The smallest change: switching to a bar chart
|
121
|
+
|
122
|
+
Changing to a bar chart is super easy: just change the following line in your `show.html.erb`
|
123
|
+
|
124
|
+
From:
|
125
|
+
|
126
|
+
```html
|
127
|
+
data-superchart-type-value="line"
|
128
|
+
```
|
129
|
+
|
130
|
+
To:
|
131
|
+
|
132
|
+
```html
|
133
|
+
data-superchart-type-value="bar"
|
134
|
+
```
|
135
|
+
|
136
|
+
### Other chart types: new Stimulus controller
|
137
|
+
|
138
|
+
Under the hood, the default Superchart is built using a chart.js instance wrapped inside a Stimulus controller.
|
139
|
+
|
140
|
+
For the following types of changes, you'll need to create your own Stimulus controller, duplicating the main `superchart_controller.js` found in this repo.
|
141
|
+
|
142
|
+
* Changing to a multi-line, stacked area or stacked bar chart
|
143
|
+
* Changing to a radial chart, a scattered plot, a box plot or any other chart
|
144
|
+
|
145
|
+
### Any other change: it depends
|
146
|
+
|
147
|
+
If you just want to make aesthetic changes, you can change the following css variables found at the top of your scaffolded `show.html.erb`. In this case, these are all TailwindCSS classes that set the appropriate custom CSS properties scoped to just that chart.
|
148
|
+
|
149
|
+
```html
|
150
|
+
[--axis-color:theme('colors.gray.300')] dark:[--axis-color:theme('colors.darkPrimary.500')]
|
151
|
+
[--grid-color:theme('colors.gray.100')] dark:[--grid-color:theme('colors.darkPrimary.800')]
|
152
|
+
[--line-color:#a86fe7]
|
153
|
+
[--point-color:theme('colors.gray.800')] dark:[--point-color:theme('colors.white')]
|
154
|
+
[--point-stroke-color:theme('colors.white')] dark:[--point-stroke-color:theme('colors.darkPrimary.700')]
|
155
|
+
[--point-stroke-color-hover:theme('colors.gray.100')] dark:[--point-stroke-color-hover:theme('colors.darkPrimary.800')]
|
156
|
+
[--bar-fill-color:var(--line-color)]
|
157
|
+
[--bar-hover-fill-color:var(--point-color)]
|
158
|
+
[--point-radius:4] md:[--point-radius:6]
|
159
|
+
[--point-hover-radius:6] md:[--point-hover-radius:10]
|
160
|
+
[--point-border-width:3] md:[--point-border-width:4]
|
161
|
+
[--point-hover-border-width:2] md:[--point-hover-border-width:3]
|
162
|
+
```
|
163
|
+
|
164
|
+
If you'd like to override some chart.js options, you can do so in the `chartjsOptions` element:
|
165
|
+
|
166
|
+
```html
|
167
|
+
<!-- This can only include valid JSON, but no functions. This is not code that will be evaluated -->
|
168
|
+
<template data-superchart-target="chartjsOptions">
|
169
|
+
{
|
170
|
+
"borderColor": "#000"
|
171
|
+
}
|
172
|
+
</template>
|
173
|
+
```
|
174
|
+
|
175
|
+
Note that to make this work with both light and dark mode, you might as well use a custom CSS property, which Supercharts lets you do (but chart.js does not support by default):
|
176
|
+
|
177
|
+
```html
|
178
|
+
<!-- cssVar is a special sub-property which Supercharts will properly interpret as the value of the custom CSS property you set it to -->
|
179
|
+
<template data-superchart-target="chartjsOptions">
|
180
|
+
{
|
181
|
+
"borderColor": {
|
182
|
+
"cssVar": "--my-custom-accent-color"
|
183
|
+
}
|
184
|
+
}
|
185
|
+
</template>
|
186
|
+
```
|
187
|
+
|
188
|
+
But if the changes you'd like to make is in the list below, you'll need to make your own custom Stimulus controller:
|
189
|
+
|
190
|
+
* The chart.js options you'd like to override includes JavaScript code (e.g. callback functions on properties)
|
191
|
+
* Including more than one series (multi-line chart, etc)
|
192
|
+
* Including annotations
|
193
|
+
* Including a custom hover overlay
|
194
|
+
* You need to change a chart.js option that's deeply nested (e.g. `scales.x.grid: false`) because it'll override all options in the top option
|
119
195
|
|
120
196
|
## Contributing
|
121
|
-
|
197
|
+
|
198
|
+
### Local development
|
199
|
+
|
200
|
+
* Create a Bullet Train app
|
201
|
+
* Use the instructions above to include the required gems and the npm package
|
202
|
+
* Create a `local/` directory into which you'll clone a copy of this repo:
|
203
|
+
|
204
|
+
```bash
|
205
|
+
mkdir local
|
206
|
+
cd local/
|
207
|
+
git clone <this REPO URL>
|
208
|
+
```
|
209
|
+
|
210
|
+
* In your Gemfile, change the gem to use the local path:
|
211
|
+
|
212
|
+
```ruby
|
213
|
+
gem "supercharts-bullet_train", path: "local/supercharts-bullet_train"
|
214
|
+
```
|
215
|
+
|
216
|
+
Then do
|
217
|
+
|
218
|
+
```bash
|
219
|
+
bundle install
|
220
|
+
```
|
221
|
+
|
222
|
+
* For modifying the JavaScript, Stimulus Controllers, you'll need to install `yalc` and use it to point to your local copy of the npm package:
|
223
|
+
|
224
|
+
```bash
|
225
|
+
yarn global add yalc
|
226
|
+
cd local/supercharts-bullet_train
|
227
|
+
yarn build # build the local changes
|
228
|
+
yalc push # publish the npm package locally on your own computer
|
229
|
+
cd ../../ # go back to the bullet-train project
|
230
|
+
yalc link @supercharts/supercharts-bullet-train
|
231
|
+
cd local/supercharts-bullet_train
|
232
|
+
yarn watch # continually watch for JavaScript changes, re-build the npm package and push to the Bullet Train app
|
233
|
+
```
|
122
234
|
|
123
235
|
## License
|
124
|
-
The gem
|
236
|
+
The gem and npm package are available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
125
237
|
|
126
238
|
[bullet-train]: https://bullettrain.co
|
@@ -6,7 +6,7 @@
|
|
6
6
|
[--line-color:#a86fe7]
|
7
7
|
[--point-color:theme('colors.gray.800')] dark:[--point-color:theme('colors.white')]
|
8
8
|
[--point-stroke-color:theme('colors.white')] dark:[--point-stroke-color:theme('colors.darkPrimary.700')]
|
9
|
-
[--point-stroke-color-hover:theme('colors.gray.100')] dark:[--point-stroke-color-hover:theme('colors.darkPrimary.
|
9
|
+
[--point-stroke-color-hover:theme('colors.gray.100')] dark:[--point-stroke-color-hover:theme('colors.darkPrimary.800')]
|
10
10
|
[--bar-fill-color:var(--line-color)]
|
11
11
|
[--bar-hover-fill-color:var(--point-color)]
|
12
12
|
[--point-radius:4] md:[--point-radius:6]
|
@@ -20,7 +20,7 @@
|
|
20
20
|
data-supercharts--describable-hide-contextual-description-class="hidden"
|
21
21
|
>
|
22
22
|
<%= turbo_frame_tag :charts_tangible_things_filters do %>
|
23
|
-
<div class="flex justify-start">
|
23
|
+
<div class="sm:flex justify-start">
|
24
24
|
<div class="relative">
|
25
25
|
<div data-supercharts--describable-target="overallDescription">
|
26
26
|
<h2 class="text-xs uppercase dark:text-white/50">
|
@@ -50,7 +50,7 @@
|
|
50
50
|
</p>
|
51
51
|
</template>
|
52
52
|
</div>
|
53
|
-
<div class="ml-auto">
|
53
|
+
<div class="mt-4 sm:mt-0 ml-auto">
|
54
54
|
<div
|
55
55
|
data-controller="supercharts--filters" data-supercharts--filters-event-name="superchart:update-chart"
|
56
56
|
>
|
@@ -76,7 +76,15 @@
|
|
76
76
|
data-supercharts--filterable-target="chart"
|
77
77
|
data-action="update-chart->superchart#updateChart"
|
78
78
|
>
|
79
|
-
<canvas data-superchart-target="chartjsCanvas" style="height: var(--chart-height)""
|
79
|
+
<canvas data-superchart-target="chartjsCanvas" style="height: var(--chart-height)"">
|
80
|
+
<% if @timespan == "1w" %>
|
81
|
+
Chart of Tangible Things last 7 days
|
82
|
+
<% elsif @timespan == "1m" %>
|
83
|
+
Chart of Tangible Things last 31 days
|
84
|
+
<% elsif @timespan == "ytd" %>
|
85
|
+
Chart of Tangible Things since start of year
|
86
|
+
<% end %>
|
87
|
+
</canvas>
|
80
88
|
<template data-superchart-target="csvData" data-supercharts--filterable-target="chartSourceData"></template>
|
81
89
|
<template data-superchart-target="chartjsOptions"></template>
|
82
90
|
</div>
|
@@ -22,7 +22,7 @@ class Scaffolding::SuperchartsChartTransformer < Scaffolding::SuperchartsTransfo
|
|
22
22
|
# add children to the show page of their parent.
|
23
23
|
unless cli_options["skip-parent"] || parent == "None"
|
24
24
|
lines_to_add = <<~RUBY
|
25
|
-
<div class="mt-4 [--chart-height:
|
25
|
+
<div class="mt-4 [--chart-height:150px] md:[--chart-height:200px]">
|
26
26
|
<%= turbo_frame_tag :charts_tangible_things, src: polymorphic_path([:account, @creative_concept, :tangible_things, :chart], timespan: "1m") do %>
|
27
27
|
<%= render "shared/supercharts/chart_skeleton" do %>
|
28
28
|
Tangible Things…
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: supercharts-bullet_train
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pascal Laliberté
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-10-
|
11
|
+
date: 2022-10-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|