apexcharts 0.1.9 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +149 -56
  3. data/lib/apex_charts/charts/base_chart.rb +1 -1
  4. data/lib/apex_charts/charts/box_plot_chart.rb +9 -0
  5. data/lib/apex_charts/charts.rb +1 -0
  6. data/lib/apex_charts/helper.rb +9 -8
  7. data/lib/apex_charts/options_builder.rb +146 -123
  8. data/lib/apex_charts/renderer.rb +69 -25
  9. data/lib/apex_charts/series/bubble_series.rb +2 -3
  10. data/lib/apex_charts/series/cartesian_series.rb +8 -2
  11. data/lib/apex_charts/theme.rb +0 -16
  12. data/lib/apex_charts/version.rb +2 -1
  13. data/vendor/assets/javascripts/apexcharts.js +5 -5
  14. metadata +4 -51
  15. data/lib/apex_charts/options/annotations_options.rb +0 -12
  16. data/lib/apex_charts/options/axis_options.rb +0 -19
  17. data/lib/apex_charts/options/chart_options.rb +0 -28
  18. data/lib/apex_charts/options/data_labels_options.rb +0 -16
  19. data/lib/apex_charts/options/div_attributes.rb +0 -11
  20. data/lib/apex_charts/options/fill_options.rb +0 -14
  21. data/lib/apex_charts/options/grid_options.rb +0 -17
  22. data/lib/apex_charts/options/legend_options.rb +0 -29
  23. data/lib/apex_charts/options/markers_options.rb +0 -20
  24. data/lib/apex_charts/options/no_data_options.rb +0 -14
  25. data/lib/apex_charts/options/plot_options.rb +0 -14
  26. data/lib/apex_charts/options/root_options.rb +0 -46
  27. data/lib/apex_charts/options/states_options.rb +0 -11
  28. data/lib/apex_charts/options/stroke_options.rb +0 -14
  29. data/lib/apex_charts/options/theme_options.rb +0 -10
  30. data/lib/apex_charts/options/title_subtitle_options.rb +0 -15
  31. data/lib/apex_charts/options/tooltip_options.rb +0 -24
  32. data/lib/apex_charts/options/x_axis_options.rb +0 -14
  33. data/lib/apex_charts/options/y_axis_options.rb +0 -18
  34. data/lib/apexcharts/prefix_with_apex.rb +0 -20
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 737afc5c5ce435bfa18cfe6b7d00f51ffd74c040f8f5f51728dec1711a2514fc
4
- data.tar.gz: e46f31763675b25c6cf0f010a16423aa2e6249240302af88e793f65277c7a816
3
+ metadata.gz: e97e5e996cb05991f345e7cf9c6591aab1405925b2b92643f518687017923170
4
+ data.tar.gz: 5a64c5b2a09074483ab53abcbcaed281efe8241ae83978d04e48e0486c1bf5b5
5
5
  SHA512:
6
- metadata.gz: a4d469bb0d6ccb22595939a9e5305ce8cfb75db59c2e54db786d937c10cf1f07d0cfe342238ab3289fbebad2149b7e3eee0df5c20fcea17230c9eb45fb8b0cee
7
- data.tar.gz: 67de41d4a272ee5ed1cfd200c20e9d2b2a95300c00d03463a9561000481655af329f6629f1a6a3d1443ef92bffbc33f4593247f983943faa58eae78cbd3e559f
6
+ metadata.gz: 438e96dcecf8766666b1b1d48bfa7f0a134ee3ee70d14a6309850ef9e47ea28633bf68101b3c11a90f92cabdece41da05e3e599b3523a2de3295470133c980e1
7
+ data.tar.gz: 1677bef319ca1190860641f188e0914f29400709f96d9afc42a3f4cb833671865227c61ae9d22cfec7c2ae14af88cfa78f47a0328e91f4c60809d1bbdcf7db46
data/README.md CHANGED
@@ -6,8 +6,8 @@
6
6
  <a href="https://rubygems.org/gems/apexcharts">
7
7
  <img src="https://img.shields.io/gem/v/apexcharts.svg?label=apexcharts" alt="Gem Version" />
8
8
  </a>
9
- <a href="https://travis-ci.org/styd/apexcharts.rb">
10
- <img src="https://travis-ci.org/styd/apexcharts.rb.svg?branch=master" alt="Build Status" />
9
+ <a href="https://github.com/styd/apexcharts.rb/actions">
10
+ <img src="https://github.com/styd/apexcharts.rb/workflows/build-test/badge.svg?branch=master" alt="Build Test Status" />
11
11
  </a>
12
12
  <a href="https://rubygems.org/gems/apexcharts">
13
13
  <img alt="Downloads" src="https://img.shields.io/gem/dt/apexcharts">
@@ -19,12 +19,16 @@
19
19
  <a href="https://codeclimate.com/github/styd/apexcharts.rb/maintainability">
20
20
  <img src="https://api.codeclimate.com/v1/badges/07a4f59e67abfeae21cb/maintainability" />
21
21
  </a>
22
- <a href='https://coveralls.io/github/styd/apexcharts.rb?branch=master'>
23
- <img src='https://coveralls.io/repos/github/styd/apexcharts.rb/badge.svg?branch=master' alt='Coverage Status' />
22
+ <a href="https://codebeat.co/projects/github-com-styd-apexcharts-rb-master">
23
+ <img alt="codebeat badge" src="https://codebeat.co/badges/7be581d6-e74a-406b-ae76-65605a2bff78" />
24
24
  </a>
25
25
  <a href='http://clayallsopp.github.io/readme-score/?url=styd/apexcharts.rb'>
26
26
  <img src='http://readme-score-api.herokuapp.com/score.svg?url=styd/apexcharts.rb' alt='README Score' />
27
27
  </a>
28
+ <br />
29
+ <a href='https://ko-fi.com/setyadi' target='_blank'>
30
+ <img height='36' style='border:0px;height:36px;' src='https://cdn.ko-fi.com/cdn/kofi4.png?v=2' border='0' alt='Buy Me a Coffee at ko-fi.com' />
31
+ </a>
28
32
  </p>
29
33
 
30
34
 
@@ -46,14 +50,7 @@ Organization/Company | Use Cas
46
50
  <img src="/images/users/ventrata.png" width="180" height="40" /> | Ticket sales for clients (visitor attractions and tour operators)
47
51
 
48
52
  > If your organization/company uses ApexCharts.RB in production, please comment on
49
- > [this issue](https://github.com/styd/apexcharts.rb/issues/34).
50
-
51
-
52
- ## Supported By
53
-
54
- <a href="https://www.jetbrains.com/?from=ApexCharts.RB">
55
- <img src="images/supporters/jetbrains.svg" title="Grants 1 License for All Products Pack" width="120" height="120" />
56
- </a>
53
+ > [this discussion](https://github.com/styd/apexcharts.rb/discussions/34).
57
54
 
58
55
 
59
56
  ## README Versions
@@ -61,13 +58,13 @@ Organization/Company | Use Cas
61
58
  This README might not be for the version you use.
62
59
  Choose the right README:
63
60
 
64
- > [v0.1.9] | [v0.1.8] | [v0.1.7] | [v0.1.6] | [v0.1.5] | [v0.1.4] | [v0.1.3] | [v0.1.2] | [v0.1.1]
61
+ > [v0.2.0] | [v0.1.11] | [v0.1.10] | [v0.1.9] | [v0.1.8] | [v0.1.7] |
62
+ > [v0.1.6] | [v0.1.5] | [v0.1.4] | [v0.1.3] | [v0.1.2] | [v0.1.1]
65
63
 
66
64
  ## Table of Contents
67
65
 
68
66
  - [About](#about)
69
67
  - [Trusted By](#trusted-by)
70
- - [Supported By](#supported-by)
71
68
  - [README Versions](#readme-versions)
72
69
  - [Table of Contents](#table-of-contents)
73
70
  - [Usage](#usage)
@@ -80,10 +77,12 @@ Choose the right README:
80
77
  - [Range Bar Chart](#range-bar-chart)
81
78
  - [Scatter Chart](#scatter-chart)
82
79
  - [Candlestick Chart](#candlestick-chart)
80
+ - [Box Plot Chart](#box-plot-chart)
83
81
  - [Mixed Charts](#mixed-charts)
84
82
  - [Syncing Charts](#syncing-charts)
85
83
  - [Brush Chart](#brush-chart)
86
84
  - [Annotations](#annotations)
85
+ - [Multiple Y-Axes](#multiple-y-axes)
87
86
  - [Heatmap Chart](#heatmap-chart)
88
87
  - [Radar Chart](#radar-chart)
89
88
  - [Bubble Chart](#bubble-chart)
@@ -94,6 +93,7 @@ Choose the right README:
94
93
  - [Data Formats](#data-formats)
95
94
  - [Cartesian Charts](#cartesian-charts-1)
96
95
  - [Candlestick Chart](#candlestick-chart-1)
96
+ - [Box Plot Chart](#box-plot-chart-1)
97
97
  - [Heatmap Chart](#heatmap-chart-1)
98
98
  - [Radar Chart](#radar-chart-1)
99
99
  - [Bubble Chart](#bubble-chart-1)
@@ -101,9 +101,9 @@ Choose the right README:
101
101
  - [Options](#options)
102
102
  - [Global Options](#global-options)
103
103
  - [Formatter Function](#formatter-function)
104
+ - [Defer Chart Rendering](#defer-chart-rendering)
105
+ - [Render with a script whose type is module](#render-with-a-script-whose-type-is-module)
104
106
  - [Reusable Custom Palette](#reusable-custom-palette)
105
- - [Global Palette](#global-palette)
106
- - [Local Palette](#local-palette)
107
107
  - [Use Alongside Other Charting Libraries](#use-alongside-other-charting-libraries)
108
108
  - [Alongside Chartkick](#alongside-chartkick)
109
109
  - [Chartkick (Chart.js) and ApexCharts](#chartkick-chartjs-and-apexcharts)
@@ -114,10 +114,9 @@ Choose the right README:
114
114
  - [Rails](#rails)
115
115
  - [Sinatra](#sinatra)
116
116
  - [Plain HTML+ERB (Without Framework)](#plain-htmlerb-without-framework)
117
- - [Roadmap](#roadmap)
118
117
  - [Contributing](#contributing)
119
118
  - [License](#license)
120
- - [Like the charts?](#like-the-charts)
119
+ - [Articles](#articles)
121
120
 
122
121
 
123
122
  ## Usage
@@ -284,6 +283,46 @@ You can make candlestick chart with this:
284
283
  ![Example Candlestick Chart](images/candlestick_chart.gif)
285
284
 
286
285
 
286
+ #### Box Plot Chart
287
+
288
+ Given:
289
+ ```erb
290
+ <%
291
+ require 'date'
292
+
293
+ def box_plot_data
294
+ 20.times.map {|i| [Date.today - 20 + i, box_plot_datum] }.to_h
295
+ end
296
+
297
+ def box_plot_datum
298
+ level = 1000
299
+ max = level + rand(50..300)
300
+ min = level - rand(50..300)
301
+ q1 = min + rand(10..50)
302
+ q3 = max - rand(10..50)
303
+ median = (min + q1 + q3 + max)/4
304
+ [min, q1, median, q3, max]
305
+ end
306
+
307
+ box_plot_options = {
308
+ plot_options: {
309
+ boxPlot: {
310
+ colors: {
311
+ upper: '#aaffaa',
312
+ lower: '#ffaaFF'
313
+ }
314
+ }
315
+ }
316
+ }
317
+ %>
318
+ ```
319
+ You can make box plot chart with this:
320
+ ```erb
321
+ <%= box_plot_chart(box_plot_data, box_plot_options) %>
322
+ ```
323
+ ![Example Box Plot Chart](images/box_plot_chart.gif)
324
+
325
+
287
326
  #### Mixed Charts
288
327
 
289
328
  You can mix charts by using `mixed_charts` or `combo_charts` methods.
@@ -353,6 +392,52 @@ All cartesian charts can have annotations, for example:
353
392
  ![Example Area Chart with Annotations](images/chart_with_annotations.gif)
354
393
 
355
394
 
395
+ #### Multiple Y-Axes
396
+
397
+ There's no fancy shortcut for multiple Y axes yet, but it is allowed. Here is an example
398
+ for that.
399
+
400
+ ```erb
401
+ <% series = [
402
+ {
403
+ name: 'Income',
404
+ type: 'column',
405
+ data: [1.4, 2, 2.5, 1.5, 2.5, 2.8, 3.8, 4.6]
406
+ },
407
+ {
408
+ name: 'Cashflow',
409
+ type: 'column',
410
+ data: [1.1, 3, 3.1, 4, 4.1, 4.9, 6.5, 8.5]
411
+ },
412
+ {
413
+ name: 'Revenue',
414
+ data: [20, 29, 37, 36, 44, 45, 50, 58]
415
+ }
416
+ ]
417
+
418
+ xaxis = {
419
+ title: {text: 'Year'},
420
+ categories: [2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016]
421
+ }
422
+
423
+ yaxis = [
424
+ {title: {text: "Income"}},
425
+ {
426
+ title: {text: "Operating Cashflow"},
427
+ opposite: true,
428
+ seriesName: 'Cashflow'
429
+ },
430
+ {
431
+ title: {text: "Revenue"},
432
+ opposite: true,
433
+ seriesName: 'Revenue'
434
+ }
435
+ ]
436
+ %>
437
+ <%= line_chart(series, xaxis: xaxis, yaxis: yaxis) %>
438
+ ```
439
+ ![Example Chart with multiple Y-Axes](images/chart_with_multiple_y-axes.gif)
440
+
356
441
  ### Heatmap Chart
357
442
 
358
443
  ```erb
@@ -489,6 +574,29 @@ or this:
489
574
  ]
490
575
  ```
491
576
 
577
+ #### Box Plot Chart
578
+
579
+ Box plot chart is similar to candlestick chart, only the y value is
580
+ an array of 5 members (Minimum-First Quartile-Median-Third Quartile-Maximum):
581
+
582
+ ```ruby
583
+ {
584
+ <x value> => [<Min>, <Q1>, <Median>, <Q3>, <Max>],
585
+ <x value> => [<Min>, <Q1>, <Median>, <Q3>, <Max>],
586
+ ...
587
+ }
588
+ ```
589
+
590
+ or this:
591
+
592
+ ```ruby
593
+ [
594
+ [<x value>, [<Min>, <Q1>, <Median>, <Q3>, <Max>]],
595
+ [<x value>, [<Min>, <Q1>, <Median>, <Q3>, <Max>]],
596
+ ...
597
+ ]
598
+ ```
599
+
492
600
  ### Heatmap Chart
493
601
 
494
602
  The data format for heatmap chart **per-series** is similar to cartesian
@@ -638,13 +746,28 @@ Or, without the _functionable-json_ gem, use function as object as follows:
638
746
  ```
639
747
 
640
748
 
641
- ## Reusable Custom Palette
749
+ ### Defer Chart Rendering
642
750
 
643
- You can create custom palette that works globally or locally.
751
+ It's possible to defer chart rendering by passing the argument `defer: true` as option.
644
752
 
645
- ### Global Palette
753
+ ```erb
754
+ <%= line_chart series, defer: true %>
755
+ ```
756
+
757
+ ### Render with a script whose type is module
646
758
 
647
- To create global palettes to be used anywhere on your any parts of your app, you can use
759
+ The charts are rendered by inserting a <script> block in the HTML.
760
+ In order to generate this <script> with `type="module"` use the
761
+ option `module: true`.
762
+
763
+ ```erb
764
+ <%= line_chart series, module: true %>
765
+ ```
766
+
767
+
768
+ ## Reusable Custom Palette
769
+
770
+ To create palettes to be used anywhere on your any parts of your app, you can use
648
771
  `ApexCharts::Theme.create`.
649
772
 
650
773
  For example, in rails app, you would write it in initializers:
@@ -669,26 +792,6 @@ If later for some reason I don't know you want to destroy the palette you can us
669
792
  ApexCharts::Theme.destroy "rainbow"
670
793
  ```
671
794
 
672
- ### Local Palette
673
-
674
- To create local palettes to be used only for current thread (usually for the duration
675
- of a request), you can use the `create_palette` helper. The theme will only be available
676
- on that page and inside its partials after the palette created.
677
-
678
- For example:
679
-
680
- ```ruby
681
- create_palette "ephemeral", ["#ab356d", "#12cdf3", "#665572", "#ababac"]
682
- ```
683
-
684
- To destroy the palette:
685
-
686
- ```ruby
687
- destroy_palette "ephemeral"
688
- ```
689
-
690
- on the same page or in its partials. Otherwise, nothing will happen.
691
-
692
795
 
693
796
  ## Use Alongside Other Charting Libraries
694
797
 
@@ -696,8 +799,7 @@ You can prefix the helper methods name with your chosen words to avoid name clas
696
799
  other charting libraries (e.g. chartkick, google_charts, etc.) you already use. Just set
697
800
  the `APEXCHARTS_PREFIX` environment variable to a string before you start your app server,
698
801
  say, 'awesome\_' and then on your views/templates use the chart helpers as `awesome_line_chart`,
699
- `awesome_area_chart`, and so on. `create_palette` and `destroy_palette` are left as is (not
700
- prefixed) as other libraries don't seem to have anything similar to them.
802
+ `awesome_area_chart`, and so on.
701
803
 
702
804
  Besides setting the environtment variable, if you just want a quick prefix, you can instead
703
805
  do this on your _Gemfile_:
@@ -862,17 +964,6 @@ $ erb sample.html.erb > sample.html
862
964
  ```
863
965
 
864
966
 
865
- ## Roadmap
866
-
867
- - Support other ruby frameworks (hanami, roda, cuba, middleman, etc.)
868
- - v0.1.x
869
- - Add more features (e.g. gradient line, background image, etc.)
870
- - v0.2.x
871
- - Replace dependency `smart_kv` with `dry-schema`
872
- - Display warnings on browser console on development instead of error page when
873
- schema doesn't meet
874
-
875
-
876
967
  ## Contributing
877
968
 
878
969
  Everyone is encouraged to help improve this project by:
@@ -880,7 +971,6 @@ Everyone is encouraged to help improve this project by:
880
971
  - Fixing bugs and submiting pull requests
881
972
  - Fixing documentation
882
973
  - Suggesting new features
883
- - Implementing todos on Roadmap above
884
974
 
885
975
 
886
976
  ## License
@@ -898,6 +988,9 @@ The gem is available as open source under the terms of the
898
988
  [ApexCharts.JS]: https://github.com/apexcharts/apexcharts.js
899
989
 
900
990
 
991
+ [v0.2.0]: https://github.com/styd/apexcharts.rb/blob/v0.2.0/README.md
992
+ [v0.1.11]: https://github.com/styd/apexcharts.rb/blob/v0.1.11/README.md
993
+ [v0.1.10]: https://github.com/styd/apexcharts.rb/blob/v0.1.10/README.md
901
994
  [v0.1.9]: https://github.com/styd/apexcharts.rb/blob/v0.1.9/README.md
902
995
  [v0.1.8]: https://github.com/styd/apexcharts.rb/blob/v0.1.8/README.md
903
996
  [v0.1.7]: https://github.com/styd/apexcharts.rb/blob/v0.1.7/README.md
@@ -12,7 +12,7 @@ module ApexCharts::Charts
12
12
  end
13
13
 
14
14
  def render
15
- ApexCharts::Renderer.render_default(options)
15
+ ApexCharts::Renderer.render(options)
16
16
  end
17
17
 
18
18
  def chart_type; end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ApexCharts::Charts
4
+ class BoxPlotChart < CartesianChart
5
+ def chart_type
6
+ 'boxPlot'
7
+ end
8
+ end
9
+ end
@@ -8,6 +8,7 @@ module ApexCharts::Charts
8
8
  autoload :"#{type.capitalize}Chart", "apex_charts/charts/#{type}_chart.rb"
9
9
  end
10
10
 
11
+ autoload :BoxPlotChart, 'apex_charts/charts/box_plot_chart.rb'
11
12
  autoload :RangeBarChart, 'apex_charts/charts/range_bar_chart.rb'
12
13
  autoload :RadialBarChart, 'apex_charts/charts/radial_bar_chart.rb'
13
14
 
@@ -78,6 +78,15 @@ module ApexCharts
78
78
  end
79
79
  alias_method :ohlc_chart, :candlestick_chart
80
80
 
81
+ def box_plot_chart(series, options={}, &block)
82
+ outer_self = eval('self', block.binding, __FILE__, __LINE__) if block_given?
83
+ draw_chart(
84
+ ApexCharts::Charts::BoxPlotChart.new(
85
+ outer_self, *prepare_series_and_options(series, options), &block
86
+ )
87
+ )
88
+ end
89
+
81
90
  def heatmap_chart(series, options={})
82
91
  draw_chart(
83
92
  ApexCharts::Charts::HeatmapChart.new(
@@ -148,14 +157,6 @@ module ApexCharts
148
157
  alias_method :circle_chart, :radial_bar_chart
149
158
  end
150
159
 
151
- def create_palette(palette_name, colors)
152
- Theme::Local.create palette_name, colors
153
- end
154
-
155
- def destroy_palette(palette_name)
156
- Theme::Local.destroy palette_name
157
- end
158
-
159
160
  private
160
161
 
161
162
  def draw_chart(chart)