From d18fa6ef1874d616bc85f35583c350a35ebafa77 Mon Sep 17 00:00:00 2001 From: Pulkit Kathuria Date: Thu, 4 Jan 2024 12:36:36 +0900 Subject: [PATCH 1/2] (feat) adds multi bar --- README.md | 150 +++++++++++++++++++++++------------- go.mod | 3 +- go.sum | 15 ++-- pkg/bar_chart.go | 78 +++++++++++++++++++ pkg/bar_chart_handler.go | 37 ++++++++- pkg/chart.go | 16 ++-- pkg/donut_chart_handler.go | 2 + pkg/funnel_chart_handler.go | 2 + pkg/line_chart_handler.go | 6 +- pkg/pie_chart_handler.go | 2 + pkg/radar_chart_handler.go | 2 + pkg/table_chart_handler.go | 2 + 12 files changed, 242 insertions(+), 73 deletions(-) diff --git a/README.md b/README.md index b42a94b..df9e4ac 100644 --- a/README.md +++ b/README.md @@ -41,34 +41,36 @@ **URL** `https://instachart.coveritup.app` -| Common Queries | Required | Description | Default | -| :------------- | :------- | :---------- | :---------------- | -| `data` | ◯ | JSON or URL | | -| `title` | | string | | -| `subtitle` | | string | | -| `theme` | | string | `light` or `dark` | -| `metric` | | string | | -| `height` | | int | 400 | -| `width` | | int | 600 | +| Common Queries | Required | Type | Default | Description | +| :------------- | :------- | :----- | :---------------- | :---------- | +| `data` | ◯ | string | | JSON Format | +| `title` | | string | | | +| `subtitle` | | string | | | +| `theme` | | string | `light` or `dark` | | +| `metric` | | string | | | +| `height` | | int | 768 | | +| `width` | | int | 1024 | | ## `GET /line` -| Query | Required | Description | Default | -| :----- | :------- | :---------- | :------ | -| `fill` | | boolean | `false` | +| Query | Required | Type | Default | +| :----- | :------- | :------ | :------ | +| `fill` | | boolean | `false` | -| `data` | Required | Description | -| :------ | :------- | :--------------- | -| `x` | ◯ | Array (string) | -| `y` | ◯ | []Array (int) | -| `names` | | Array | +| `data` | Required | Type | +| :------ | :------- | :------- | +| `x` | ◯ | []string | +| `y` | ◯ | [][]int | +| `names` | | []string | ```sh -https://instachart.coveritup.app/line?title=Line+Chart+Simple&subtitle=Sleeping+Hours&data={ +https://instachart.coveritup.app/line?title=Line+Chart +&subtitle=Sleeping+Hours +&data={ "x": ["Mon","Tue","Wed"], "y": [[4,8,7], [10,20,24]], "names": ["Sleeping", "Awake"] @@ -85,7 +87,10 @@ https://instachart.coveritup.app/line?title=Line+Chart+Simple&subtitle=Sleeping+

```sh -https://instachart.coveritup.app/line?title=Line+Chart+Simple&subtitle=Sleeping+Hours&data={ +https://instachart.coveritup.app/line?title=Area+Chart +&subtitle=Sleeping+Hours +&fill=true +&data={ "x": ["Mon","Tue","Wed"], "y": [[4,8,7], [10,20,24]], "names": ["Sleeping", "Awake"] @@ -103,18 +108,24 @@ https://instachart.coveritup.app/line?title=Line+Chart+Simple&subtitle=Sleeping+ ## `GET /bar` -| Query | Required | Description | Default | -| :----------- | :------- | :---------- | :------ | -| `horizontal` | | boolean | `false` | +Extra params for `bar` chart. +| Query | Required | Type | Default | Validation | +| :-------- | :------- | :----- | :--------- | :------------------------- | +| `style` | | string | `vertical` | `vertical` or `horizontal` | +| `zmetric` | | string | `vertical` | when `z` data is provided | -| `data` | Required | Description | -| :----- | :------- | :------------- | -| `x` | ◯ | Array (string) | -| `y` | ◯ | []Array (int) | + +| `data` | Required | Type | Description | +| :----- | :------- | :------- | :----------------------------------------- | +| `x` | ◯ | []string | | +| `y` | ◯ | [][]int | | +| `z` | | []string | Style will be `vertical` with `z` is given | ```sh -https://instachart.coveritup.app/bar?title=Bar+Chart&subtitle=Sleeping+hours&data={ +https://instachart.coveritup.app/bar?title=Bar+Chart +&subtitle=Sleeping+hours +&data={ "x": ["Monday", "Friday", "Sunday"], "y": [[8,2,14]], "names": ["Sleeping", "Awake"] @@ -129,16 +140,41 @@ https://instachart.coveritup.app/bar?title=Bar+Chart&subtitle=Sleeping+hours&dat

+
+ +```sh +https://instachart.coveritup.app/bar?title=Bar+Chart +&subtitle=Sleeping+hours +&metric=hours +&zmetric=days +&theme=dark +&data={ + "x": ["Monday", "Friday", "Sunday"], + "y": [[8,2,14]], + "z": [[9,3,15]], + "names": ["Sleeping", "Awake"] +} +``` + +
+ +

+ + bar chart + +

+ ## `GET /donut` -| `data` | Required | Description | -| :------- | :------- | :------------- | -| `names` | ◯ | Array (string) | -| `values` | ◯ | Array (int) | +| `data` | Required | Type | +| :------- | :------- | :------- | +| `names` | ◯ | []string | +| `values` | ◯ | []int | ```sh -https://instachart.coveritup.app/donut?title=Donut+Chart&data={ +https://instachart.coveritup.app/donut?title=Donut+Chart +&data={ "names": ["Monday", "Friday", "Saturday", "Sunday"], "values": [4, 6 ,7, 9] } @@ -156,14 +192,16 @@ https://instachart.coveritup.app/donut?title=Donut+Chart&data={ ## `GET /pie` -| `data` | Required | Description | -| :------- | :------- | :------------- | -| `names` | ◯ | Array (string) | -| `values` | ◯ | Array (int) | +| `data` | Required | Type | +| :------- | :------- | :------- | +| `names` | ◯ | []string | +| `values` | ◯ | []int | ```sh -https://instachart.coveritup.app/pie?title=Pie+Chart&subtitle=Sleeping+Hours&data={ +https://instachart.coveritup.app/pie?title=Pie+Chart +&subtitle=Sleeping+Hours +&data={ "names": ["Monday", "Friday", "Saturday", "Sunday"], "values": [4, 6 ,7, 9] } @@ -180,14 +218,15 @@ https://instachart.coveritup.app/pie?title=Pie+Chart&subtitle=Sleeping+Hours&dat ## `GET /radar` -| `data` | Required | Description | Validation | -| :------- | :------- | :------------- | :--------------------------------- | -| `names` | ◯ | Array (string) | `>=3` | -| `values` | ◯ | []Array (int) | `count(names) == count(values[0])` | -| `labels` | | Array (string) | | +| `data` | Required | Type | Validation | +| :------- | :------- | :------- | :--------------------------------- | +| `names` | ◯ | []string | `>=3` | +| `values` | ◯ | [][]int | `count(names) == count(values[0])` | +| `labels` | | []string | | ```sh -https://instachart.coveritup.app/radar?title=Radar+Chart&data={ +https://instachart.coveritup.app/radar?title=Radar+Chart +&data={ "names": ["Mon","Tue", "Wed", "Fri"], "labels": ["Work", "Relax", "Travel"], "values": [[1,2,3,4], [15,7,8,9], [15,17,5,7]] @@ -204,13 +243,14 @@ https://instachart.coveritup.app/radar?title=Radar+Chart&data={ ## `GET /funnel` -| `data` | Required | Description | -| :------- | :------- | :------------- | -| `names` | ◯ | Array (string) | -| `values` | ◯ | Array (int) | +| `data` | Required | Type | +| :------- | :------- | :------- | +| `names` | ◯ | []string | +| `values` | ◯ | []int | ```sh -https://instachart.coveritup.app/funnel?title=Radar+Chart&width=500&data={ +https://instachart.coveritup.app/funnel?title=Radar+Chart +&data={ "names": ["Mon","Tue", "Thu", "Fri", "Sat", "Sun"], "values": [100,80,60,40,20,10] } @@ -226,13 +266,14 @@ https://instachart.coveritup.app/funnel?title=Radar+Chart&width=500&data={ ## `GET /table` -| `data` | Required | Description | -| :------- | :------- | :-------------------------- | -| `names` | ◯ | Array (string) `aka header` | -| `values` | ◯ | []Array (string) `aka rows` | +| `data` | Required | Type | Description | +| :------- | :------- | :--------- | :----------- | +| `names` | ◯ | []string | `aka header` | +| `values` | ◯ | [][]string | `aka rows` | ```sh -https://instachart.coveritup.app/table?title=Table+Chart&data={ +https://instachart.coveritup.app/table?title=Table+Chart +&data={ "names": ["Branch","Code Coverage", "Quality"], "values": [["master","80","90"], ["develop","70","79"]] } @@ -251,6 +292,9 @@ https://instachart.coveritup.app/table?title=Table+Chart&data={ ```sh curl -sLk https://raw.githubusercontent.com/kevincobain2000/instachart/master/install.sh | sh +## Will run server on localhost:3001 +# For more options see --help +./instachart ``` # CHANGE LOG diff --git a/go.mod b/go.mod index f435df2..7ab8394 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,7 @@ require ( github.com/go-playground/validator v9.31.0+incompatible github.com/imroc/req/v3 v3.42.2 github.com/labstack/echo/v4 v4.11.3 + github.com/mcuadros/go-defaults v1.2.0 github.com/sirupsen/logrus v1.9.3 github.com/stretchr/testify v1.8.4 github.com/vicanso/go-charts/v2 v2.6.1 @@ -30,7 +31,7 @@ require ( github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect github.com/klauspost/compress v1.16.7 // indirect - github.com/kr/pretty v0.3.1 // indirect + github.com/kr/text v0.2.0 // indirect github.com/labstack/gommon v0.4.0 // indirect github.com/leodido/go-urn v1.2.4 // indirect github.com/mattn/go-colorable v0.1.13 // indirect diff --git a/go.sum b/go.sum index 729b60c..7d82eb5 100644 --- a/go.sum +++ b/go.sum @@ -45,8 +45,8 @@ github.com/imroc/req/v3 v3.42.2 h1:/BwrKXGR7X1/ptccaQAiziDCeZ7T6ye55g3ZhiLy1fc= github.com/imroc/req/v3 v3.42.2/go.mod h1:W7dOrfQORA9nFoj+CafIZ6P5iyk+rWdbp2sffOAvABU= github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I= github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= -github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= -github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/labstack/echo/v4 v4.11.3 h1:Upyu3olaqSHkCjs1EJJwQ3WId8b8b1hxbogyommKktM= @@ -62,11 +62,14 @@ github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27k github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mcuadros/go-defaults v1.2.0 h1:FODb8WSf0uGaY8elWJAkoLL0Ri6AlZ1bFlenk56oZtc= +github.com/mcuadros/go-defaults v1.2.0/go.mod h1:WEZtHEVIGYVDqkKSWBdWKUVdRyKlMfulPaGDWIVeCWY= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/onsi/ginkgo/v2 v2.12.0 h1:UIVDowFPwpg6yMUpPjGkYvf06K3RAiJXUhCxEwQVHRI= github.com/onsi/ginkgo/v2 v2.12.0/go.mod h1:ZNEzXISYlqpb8S36iN71ifqLi3vVD1rVJGvWRCJOUpQ= github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M= -github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/quic-go/qpack v0.4.0 h1:Cr9BXA1sQS2SmDUWjSofMPNKmvF6IiIfDRmgU0w1ZCo= @@ -77,8 +80,6 @@ github.com/quic-go/quic-go v0.38.1 h1:M36YWA5dEhEeT+slOu/SwMEucbYd0YFidxG3KlGPZa github.com/quic-go/quic-go v0.38.1/go.mod h1:ijnZM7JsFIkp4cRyjxJNIzdSfCLmUMg9wdyhGmg+SN4= github.com/refraction-networking/utls v1.5.3 h1:Ds5Ocg1+MC1ahNx5iBEcHe0jHeLaA/fLey61EENm7ro= github.com/refraction-networking/utls v1.5.3/go.mod h1:SPuDbBmgLGp8s+HLNc83FuavwZCFoMmExj+ltUHiHUw= -github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= -github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -170,8 +171,8 @@ golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8T google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw= google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM= gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/pkg/bar_chart.go b/pkg/bar_chart.go index d87eb78..79e2eb3 100644 --- a/pkg/bar_chart.go +++ b/pkg/bar_chart.go @@ -71,6 +71,84 @@ func (c *BarChart) GetVertical(xData []string, yData [][]float64, names []string return buf, err } +func (c *BarChart) GetStacked(xData []string, yData [][]float64, zData [][]float64, names []string, req *ChartRequest) ([]byte, error) { + series := make([]charts.Series, 0) + for _, y := range yData { + s := charts.Series{ + Type: charts.ChartTypeBar, + Data: charts.NewSeriesDataFromValues(y), + } + series = append(series, s) + } + + for idx, z := range zData { + s := charts.Series{ + Data: charts.NewSeriesDataFromValues(z), + AxisIndex: idx, + } + series = append(series, s) + } + + opt := charts.ChartOption{ + Title: charts.TitleOption{ + Text: req.ChartTitle, + Subtext: req.ChartSubtitle, + SubtextFontSize: DEFAULT_SUBTITLE_FONT_SIZE, + Left: charts.PositionCenter, + }, + XAxis: charts.NewXAxisOption(xData), + Legend: charts.NewLegendOption(names), + YAxisOptions: []charts.YAxisOption{ + { + Formatter: "{value}" + req.Metric, + Color: charts.Color{ + R: 84, + G: 112, + B: 198, + A: 255, + }, + }, + { + Formatter: "{value}" + req.ZMetric, + Color: charts.Color{ + R: 250, + G: 200, + B: 88, + A: 255, + }, + }, + }, + SeriesList: series, + } + opt.Theme = req.Theme + opt.Legend.Padding = charts.Box{ + Top: DEFAULT_PADDING_TOP * 2, + Bottom: DEFAULT_PADDING_BOTTOM, + } + opt.Legend.Orient = charts.OrientHorizontal + opt.Legend.Left = charts.PositionLeft + opt.Width = req.Width + opt.Height = req.Height + + idx := len(opt.SeriesList) - 1 + if len(opt.SeriesList) > 1 { + idx = 1 + } + opt.SeriesList[idx].MarkPoint = charts.NewMarkPoint( + charts.SeriesMarkDataTypeMax, + charts.SeriesMarkDataTypeMin, + ) + opt.SeriesList[idx].MarkLine = charts.NewMarkLine( + charts.SeriesMarkDataTypeAverage, + ) + + d, err := charts.Render(opt) + if err != nil { + return nil, err + } + return d.Bytes() +} + func (c *BarChart) GetHorizontal(xData []string, yData [][]float64, names []string, req *ChartRequest) ([]byte, error) { p, err := charts.HorizontalBarRender( yData, diff --git a/pkg/bar_chart_handler.go b/pkg/bar_chart_handler.go index 4d4c7d0..dc6114b 100644 --- a/pkg/bar_chart_handler.go +++ b/pkg/bar_chart_handler.go @@ -5,6 +5,7 @@ import ( "net/http" "github.com/labstack/echo/v4" + "github.com/mcuadros/go-defaults" ) type BarChartHandler struct { @@ -22,11 +23,13 @@ func NewBarChartHandler(allowedRemoteDomains string) *BarChartHandler { type BarChartData struct { XData []string `json:"x"` YData [][]float64 `json:"y"` + ZData [][]float64 `json:"z"` Names []string `json:"names"` } func (h *BarChartHandler) Get(c echo.Context) ([]byte, error) { req := new(ChartRequest) + defaults.SetDefaults(req) if err := BindRequest(c, req); err != nil { return nil, echo.NewHTTPError(http.StatusUnprocessableEntity, err) } @@ -46,16 +49,42 @@ func (h *BarChartHandler) Get(c echo.Context) ([]byte, error) { return nil, echo.NewHTTPError(http.StatusUnprocessableEntity, msgs) } - if len(data.XData) == 0 || len(data.XData) != len(data.YData[0]) { + if len(data.XData) == 0 || len(data.YData) == 0 { msgs := map[string]string{ - "data": "Counts are invalid", + "data": "X or Y Counts are invalid", } return nil, echo.NewHTTPError(http.StatusUnprocessableEntity, msgs) } + for _, y := range data.YData { + if len(y) != len(data.XData) { + msgs := map[string]string{ + "data": "Y Counts are invalid", + } + return nil, echo.NewHTTPError(http.StatusUnprocessableEntity, msgs) + } + } + if len(data.ZData) != 0 { + for _, z := range data.ZData { + if len(z) != len(data.XData) { + msgs := map[string]string{ + "data": "Z Counts are invalid", + } + return nil, echo.NewHTTPError(http.StatusUnprocessableEntity, msgs) + } + } + req.Style = BAR_STYLE_STACKED + } + SetHeadersResponseImage(c.Response().Header()) - if req.Horizontal { + switch req.Style { + case BAR_STYLE_VERTICAL: + return h.chart.GetVertical(data.XData, data.YData, data.Names, req) + case BAR_STYLE_HORIZONTAL: return h.chart.GetHorizontal(data.XData, data.YData, data.Names, req) + case BAR_STYLE_STACKED: + return h.chart.GetStacked(data.XData, data.YData, data.ZData, data.Names, req) } - return h.chart.GetVertical(data.XData, data.YData, data.Names, req) + return nil, echo.NewHTTPError(http.StatusUnprocessableEntity, "Invalid style") + } diff --git a/pkg/chart.go b/pkg/chart.go index 8a401d5..047d4b4 100644 --- a/pkg/chart.go +++ b/pkg/chart.go @@ -15,6 +15,10 @@ const ( DEFAULT_PADDING_BOTTOM = 20 DEFAULT_PADDING_LEFT = 20 DEFAULT_SUBTITLE_FONT_SIZE = 10 + + BAR_STYLE_VERTICAL = "vertical" + BAR_STYLE_HORIZONTAL = "horizontal" + BAR_STYLE_STACKED = "stacked" ) type Chart struct { @@ -29,12 +33,12 @@ type ChartRequest struct { ChartTitle string `json:"title" query:"title" form:"title"` ChartSubtitle string `json:"subtitle" query:"subtitle" form:"subtitle"` 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"` - Fill bool `json:"fill" query:"fill" form:"fill"` + ZMetric string `json:"zmetric" query:"zmetric" form:"zmetric"` + Theme string `json:"theme" query:"theme" form:"theme" default:"light"` + Width int `json:"width" query:"width" form:"width" default:"1024"` + Height int `json:"height" query:"height" form:"height" default:"768"` + Style string `json:"style" query:"style" form:"style" default:"vertical"` + Fill bool `json:"fill" query:"fill" form:"fill" default:"false"` } func SetHeadersResponseImage(header http.Header) { diff --git a/pkg/donut_chart_handler.go b/pkg/donut_chart_handler.go index 2ea3bae..8c0ff48 100644 --- a/pkg/donut_chart_handler.go +++ b/pkg/donut_chart_handler.go @@ -5,6 +5,7 @@ import ( "net/http" "github.com/labstack/echo/v4" + "github.com/mcuadros/go-defaults" ) type DonutChartHandler struct { @@ -26,6 +27,7 @@ type DonutChartData struct { func (h *DonutChartHandler) Get(c echo.Context) ([]byte, error) { req := new(ChartRequest) + defaults.SetDefaults(req) if err := BindRequest(c, req); err != nil { return nil, echo.NewHTTPError(http.StatusUnprocessableEntity, err) } diff --git a/pkg/funnel_chart_handler.go b/pkg/funnel_chart_handler.go index 9213092..e751544 100644 --- a/pkg/funnel_chart_handler.go +++ b/pkg/funnel_chart_handler.go @@ -5,6 +5,7 @@ import ( "net/http" "github.com/labstack/echo/v4" + "github.com/mcuadros/go-defaults" ) type FunnelChartHandler struct { @@ -26,6 +27,7 @@ type FunnelChartData struct { func (h *FunnelChartHandler) Get(c echo.Context) ([]byte, error) { req := new(ChartRequest) + defaults.SetDefaults(req) if err := BindRequest(c, req); err != nil { return nil, echo.NewHTTPError(http.StatusUnprocessableEntity, err) } diff --git a/pkg/line_chart_handler.go b/pkg/line_chart_handler.go index caaf1bd..2358851 100644 --- a/pkg/line_chart_handler.go +++ b/pkg/line_chart_handler.go @@ -5,6 +5,7 @@ import ( "net/http" "github.com/labstack/echo/v4" + "github.com/mcuadros/go-defaults" ) type LineChartHandler struct { @@ -12,10 +13,10 @@ type LineChartHandler struct { allowedRemoteDomains string } -func NewLineChartHandler(allowedRemoteURLS string) *LineChartHandler { +func NewLineChartHandler(allowedRemoteDomains string) *LineChartHandler { return &LineChartHandler{ chart: NewLineChart(), - allowedRemoteDomains: allowedRemoteURLS, + allowedRemoteDomains: allowedRemoteDomains, } } @@ -27,6 +28,7 @@ type LineChartData struct { func (h *LineChartHandler) Get(c echo.Context) ([]byte, error) { req := new(ChartRequest) + defaults.SetDefaults(req) if err := BindRequest(c, req); err != nil { return nil, echo.NewHTTPError(http.StatusUnprocessableEntity, err) } diff --git a/pkg/pie_chart_handler.go b/pkg/pie_chart_handler.go index 2382502..efcab44 100644 --- a/pkg/pie_chart_handler.go +++ b/pkg/pie_chart_handler.go @@ -5,6 +5,7 @@ import ( "net/http" "github.com/labstack/echo/v4" + "github.com/mcuadros/go-defaults" ) type PieChartHandler struct { @@ -26,6 +27,7 @@ type PieChartData struct { func (h *PieChartHandler) Get(c echo.Context) ([]byte, error) { req := new(ChartRequest) + defaults.SetDefaults(req) if err := BindRequest(c, req); err != nil { return nil, echo.NewHTTPError(http.StatusUnprocessableEntity, err) } diff --git a/pkg/radar_chart_handler.go b/pkg/radar_chart_handler.go index 8e894f8..ad82d16 100644 --- a/pkg/radar_chart_handler.go +++ b/pkg/radar_chart_handler.go @@ -5,6 +5,7 @@ import ( "net/http" "github.com/labstack/echo/v4" + "github.com/mcuadros/go-defaults" ) type RadarChartHandler struct { @@ -27,6 +28,7 @@ type RadarChartData struct { func (h *RadarChartHandler) Get(c echo.Context) ([]byte, error) { req := new(ChartRequest) + defaults.SetDefaults(req) if err := BindRequest(c, req); err != nil { return nil, echo.NewHTTPError(http.StatusUnprocessableEntity, err) } diff --git a/pkg/table_chart_handler.go b/pkg/table_chart_handler.go index 6df59fd..7b43ef3 100644 --- a/pkg/table_chart_handler.go +++ b/pkg/table_chart_handler.go @@ -5,6 +5,7 @@ import ( "net/http" "github.com/labstack/echo/v4" + "github.com/mcuadros/go-defaults" ) type TableChartHandler struct { @@ -26,6 +27,7 @@ type TableChartData struct { func (h *TableChartHandler) Get(c echo.Context) ([]byte, error) { req := new(ChartRequest) + defaults.SetDefaults(req) if err := BindRequest(c, req); err != nil { return nil, echo.NewHTTPError(http.StatusUnprocessableEntity, err) } From dc34721ad6b77ff1a2c7869e2453c899504e771c Mon Sep 17 00:00:00 2001 From: Pulkit Kathuria Date: Thu, 4 Jan 2024 12:39:46 +0900 Subject: [PATCH 2/2] (feat) fixesdocs --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index df9e4ac..fca0926 100644 --- a/README.md +++ b/README.md @@ -236,8 +236,8 @@ https://instachart.coveritup.app/radar?title=Radar+Chart

- - radar chart + + radar chart