supercharts-bullet_train 0.1.14 → 1.0.0

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: 4e5ec9ffd3a3ecf773b6793ae88d0c14693e87df5715182dc91512eb01a8baf4
4
- data.tar.gz: 2a7114b0474c1419eada79c1d07a1e6c1fea4d76e1db36a4bd5c53c05244927e
3
+ metadata.gz: a2f0bde3d3e9cf606feab507df6d18cf5796d366e20fd4c2c326bff9baa9f7ea
4
+ data.tar.gz: ef0c87fdd8b008ef513515085f804a77b5304148f142339f1369ad038a78ab8b
5
5
  SHA512:
6
- metadata.gz: 7e429f870a0f055aa05ea9279eca6d58eaea52b278cf611aec4ee809947316246b98dd782f887ce53ce21373a3dcfebe77260b74a29b7f70cfdb9d9c218ae71b
7
- data.tar.gz: 8e086d10be125ada08f5609e56af8552ebf264d0cd8f09553eb4e1d56f0c4365e9979c802030c2f4686fc91717bebb76492b98115e3c6adaad406a45496b5c8b
6
+ metadata.gz: c8e6dc53dbf3bb5ee9c927e87f11c05d53725e970da5129d8334924cec2a25c162f4ab914f7b425287be6aa797ed56ab41a11576d0cbd6ad18be3c1e5ce45fb1
7
+ data.tar.gz: 90122ff8e4e5672f9c16a5d0779fbf887082353d8a9ebb9e52f18a3080f37bb80aee6d50ada5e14b38fd530fd5842a00610919157003af8e4729fa8cc13fc8dd
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
@@ -111,16 +113,126 @@ FactoryBot.create_list(:click_through, 450, :created_last_2_months, team_id: 1)
111
113
 
112
114
  Visit your app in `localhost:3000` and you should see your new chart.
113
115
 
114
- ![Example chart inside a Bullet Train app showing Click Throughs in the last 30 days](https://user-images.githubusercontent.com/104179/194341008-c8b9f232-4117-4c8a-b93f-e95cf1d5159f.gif)
116
+ ![Example chart inside a Bullet Train app showing Click Throughs in the last 30 days](https://user-images.githubusercontent.com/104179/198366639-cd73eba5-eeb7-4654-bb35-8b0415b964c8.gif)
115
117
 
116
118
  ## Modifying the chart
117
119
 
118
- Coming soon...
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
- Contribution directions go here.
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 is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
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
@@ -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
  >
@@ -1,5 +1,5 @@
1
1
  module BulletTrain
2
2
  module Supercharts
3
- VERSION = "0.1.14"
3
+ VERSION = "1.0.0"
4
4
  end
5
5
  end
@@ -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:250px] md:[--chart-height:200px]">
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&hellip;
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.14
4
+ version: 1.0.0
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-18 00:00:00.000000000 Z
11
+ date: 2022-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails