Skip to content

Commit

Permalink
(feat) added metric for horizontal bar
Browse files Browse the repository at this point in the history
  • Loading branch information
kevincobain2000 committed Dec 27, 2023
1 parent a31c62c commit e36ad16
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .air.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ full_bin = "PP_USER=air ./tmp/main"
# Watch these filename extensions.
include_ext = ["go", "tpl", "tmpl", "html", "env", "conf"]
# Ignore these filename extensions or directories.
exclude_dir = ["assets", "tmp", "vendor", "dist", "node_modules", "public"]
exclude_dir = ["assets", "tmp", "vendor", "dist", "node_modules", "public", "site"]
# Watch these directories if you specified.
include_dir = []
# Exclude files.
Expand Down
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,17 @@

**URL** `https://instachart.coveritup.app`

| Query | Required | Description | Default |
| :--------- | :------- | :---------- | :---------------- |
| `data` || JSON | |
| `title` | | string | |
| `fill` | | boolean | `false` |
| `subtitle` | | string | |
| `theme` | | string | `light` or `dark` |
| `metric` | | string | |
| `height` | | int | 400 |
| `width` | | int | 600 |
| Query | Required | Description | Default |
| :----------- | :------- | :---------- | :-------------------- |
| `data` || JSON | |
| `title` | | string | |
| `subtitle` | | string | |
| `theme` | | string | `light` or `dark` |
| `metric` | | string | |
| `height` | | int | 400 |
| `width` | | int | 600 |
| `fill` | | boolean | `false` for `/line` |
| `horizontal` | | boolean | `false` for `/bar` |



Expand Down
7 changes: 7 additions & 0 deletions pkg/bar_chart_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type BarChartRequest struct {
Metric string `json:"metric" query:"metric" form:"metric"`
Height int `json:"height" query:"height" form:"height"`
Theme string `json:"theme" query:"theme" form:"theme"`
Type string `json:"type" query:"type" form:"type"`
Width int `json:"width" query:"width" form:"width"`
Horizontal bool `json:"horizontal" query:"horizontal" form:"horizontal"`
}
Expand Down Expand Up @@ -107,6 +108,12 @@ func (h *BarChartHandler) Get(c echo.Context) ([]byte, error) {
charts.HeightOptionFunc(req.Height),
charts.WidthOptionFunc(req.Width),
charts.YAxisDataOptionFunc(data.XData),
func(opt *charts.ChartOption) {
opt.Theme = req.Theme
opt.ValueFormatter = func(f float64) string {
return fmt.Sprintf("%.0f%s", f, req.Metric)
}
},
)

if err != nil {
Expand Down

0 comments on commit e36ad16

Please sign in to comment.