Skip to content

Commit

Permalink
Add alternative options schema
Browse files Browse the repository at this point in the history
  • Loading branch information
styd committed Oct 10, 2020
1 parent 0028f88 commit fff1bb4
Show file tree
Hide file tree
Showing 78 changed files with 1,286 additions and 436 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.
- Make obsolete previously deprecated local palette creation
- Update options schema to match ApexCharts.JS version 3.22.0
- ApexCharts.JS version from 3.21.0 to 3.22.0
- Add alternative options schema :dry_schema

## [0.1.10] - 2020-10-04
### Added
Expand Down
32 changes: 19 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ Choose the right README:
- [Global Options](#global-options)
- [Formatter Function](#formatter-function)
- [Defer Chart Rendering](#defer-chart-rendering)
- [Schema](#schema)
- [Reusable Custom Palette](#reusable-custom-palette)
- [Use Alongside Other Charting Libraries](#use-alongside-other-charting-libraries)
- [Alongside Chartkick](#alongside-chartkick)
Expand All @@ -116,7 +117,6 @@ Choose the right README:
- [Rails](#rails)
- [Sinatra](#sinatra)
- [Plain HTML+ERB (Without Framework)](#plain-htmlerb-without-framework)
- [Roadmap](#roadmap)
- [Contributing](#contributing)
- [License](#license)
- [Like the charts?](#like-the-charts)
Expand Down Expand Up @@ -649,6 +649,23 @@ It's possible to defer chart rendering by passing the argument `defer: true` as
```


## Schema

To use [dry-schema] as an alternative options schema, you can specify the following config
before calling your charts:

```ruby
ApexCharts.config.schema = :dry_schema
```

or

```ruby
ApexCharts.configure do |config|
config.schema = :dry_schema
end
```

## Reusable Custom Palette

To create palettes to be used anywhere on your any parts of your app, you can use
Expand Down Expand Up @@ -848,25 +865,13 @@ $ erb sample.html.erb > sample.html
```


## Roadmap

- Support other ruby frameworks (hanami, roda, cuba, middleman, etc.)
- v0.1.x
- Add more features (e.g. gradient line, background image, etc.)
- v0.2.x
- Replace dependency `smart_kv` with `dry-schema`
- Display warnings on browser console on development instead of error page when
schema doesn't meet


## Contributing

Everyone is encouraged to help improve this project by:
- Reporting bugs
- Fixing bugs and submiting pull requests
- Fixing documentation
- Suggesting new features
- Implementing todos on Roadmap above


## License
Expand All @@ -882,6 +887,7 @@ The gem is available as open source under the terms of the


[ApexCharts.JS]: https://github.com/apexcharts/apexcharts.js
[dry-schema]: https://github.com/dry-rb/dry-schema


[v0.1.10]: https://github.com/styd/apexcharts.rb/blob/v0.1.10/README.md
Expand Down
1 change: 1 addition & 0 deletions apexcharts.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
spec.files = Dir['{lib,vendor}/**/*', 'LICENSE', 'README.md']

spec.add_dependency 'smart_kv', '~> 0.2.8'
spec.add_dependency 'dry-schema', '~> 1.5'

spec.add_development_dependency 'bundler'
spec.add_development_dependency 'coveralls'
Expand Down
20 changes: 20 additions & 0 deletions lib/apex_charts/config/schema.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

module ApexCharts
module Config
module Schema
def schema
@schema ||= 'Default'
end

def schema=(name)
@schema = case name
when :dry_schema, 'dry_schema', 'dry-schema'
'DrySchema'
else
'Default'
end
end
end
end
end
2 changes: 2 additions & 0 deletions lib/apex_charts/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require_relative 'config/default_options'
require_relative 'config/schema'

module ApexCharts
class << self
Expand All @@ -21,5 +22,6 @@ def config

class Configuration
include ApexCharts::Config::DefaultOptions
include ApexCharts::Config::Schema
end
end
14 changes: 0 additions & 14 deletions lib/apex_charts/options/annotations_options.rb

This file was deleted.

32 changes: 0 additions & 32 deletions lib/apex_charts/options/chart_options.rb

This file was deleted.

18 changes: 0 additions & 18 deletions lib/apex_charts/options/data_labels_options.rb

This file was deleted.

14 changes: 14 additions & 0 deletions lib/apex_charts/options/default/annotations_options.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module ApexCharts::Options
module Default
class AnnotationsOptions < ::SmartKv
optional *%i[
images
points
position
texts
xaxis
yaxis
]
end
end
end
32 changes: 32 additions & 0 deletions lib/apex_charts/options/default/chart_options.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module ApexCharts::Options
module Default
class ChartOptions < ::SmartKv
optional *%i[
animations
background
brush
defaultLocale
dropShadow
events
fontFamily
foreColor
group
height
id
locales
offsetX
offsetY
parentHeightOffset
redrawOnParentResize
selection
sparkline
stackType
stacked
toolbar
type
width
zoom
]
end
end
end
18 changes: 18 additions & 0 deletions lib/apex_charts/options/default/data_labels_options.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module ApexCharts::Options
module Default
class DataLabelsOptions < ::SmartKv
optional *%i[
background
distributed
dropShadow
enabled
enabledOnSeries
formatter
offsetX
offsetY
style
textAnchor
]
end
end
end
14 changes: 14 additions & 0 deletions lib/apex_charts/options/default/fill_options.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module ApexCharts::Options
module Default
class FillOptions < ::SmartKv
optional *%i[
colors
gradient
image
opacity
pattern
type
]
end
end
end
17 changes: 17 additions & 0 deletions lib/apex_charts/options/default/grid_options.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module ApexCharts::Options
module Default
class GridOptions < ::SmartKv
optional *%i[
borderColor
column
padding
position
row
show
strokeDashArray
xaxis
yaxis
]
end
end
end
22 changes: 22 additions & 0 deletions lib/apex_charts/options/default/helper_options.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require 'smart_kv'

module ApexCharts::Options
module Default
class HelperOptions < ::SmartKv
optional *%i[
brushTarget
class
chartId
defer
group
id
style
var
xtitle
xtype
ytitle
ytype
]
end
end
end
32 changes: 32 additions & 0 deletions lib/apex_charts/options/default/legend_options.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module ApexCharts::Options
module Default
class LegendOptions < ::SmartKv
optional *%i[
containerMargin
floating
fontFamily
fontSize
fontWeight
formatter
height
horizontalAlign
inverseOrder
itemMargin
labels
markers
offsetX
offsetY
onItemClick
onItemHover
position
show
showForNullSeries
showForSingleSeries
showForZeroSeries
textAnchor
tooltipHoverFormatter
width
]
end
end
end
24 changes: 24 additions & 0 deletions lib/apex_charts/options/default/markers_options.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module ApexCharts::Options
module Default
class MarkersOptions < ::SmartKv
optional *%i[
colors
discrete
fillOpacity
hover
offsetX
offsetY
radius
shape
size
strokeColors
strokeOpacity
strokeWidth
strokeDashArray
showNullDataPoints
onClick
onDblClick
]
end
end
end
14 changes: 14 additions & 0 deletions lib/apex_charts/options/default/no_data_options.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module ApexCharts::Options
module Default
class NoDataOptions < ::SmartKv
optional *%i[
align
offsetX
offsetY
style
text
verticalAlign
]
end
end
end
Loading

0 comments on commit fff1bb4

Please sign in to comment.