Skip to content

Commit

Permalink
Merge pull request #19 from kevincobain2000/develop
Browse files Browse the repository at this point in the history
(feat) adds multi bar
  • Loading branch information
kevincobain2000 authored Jan 4, 2024
2 parents e04507c + dc34721 commit ed2ebd2
Show file tree
Hide file tree
Showing 12 changed files with 244 additions and 75 deletions.
154 changes: 99 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -85,7 +87,10 @@ https://instachart.coveritup.app/line?title=Line+Chart+Simple&subtitle=Sleeping+
</p>

```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"]
Expand All @@ -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"]
Expand All @@ -129,16 +140,41 @@ https://instachart.coveritup.app/bar?title=Bar+Chart&subtitle=Sleeping+hours&dat
</a>
</p>

<br>

```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"]
}
```

<br>

<p align="center">
<a href='bar?title=Bar+Chart%20&subtitle=Sleeping+hours&metric=hours&zmetric=days&theme=dark&data={%20"x":%20["Monday",%20"Friday",%20"Sunday"],%20"y":%20[[8,2,14]],%20"z":%20[[9,3,15]],%20"names":%20["Sleeping",%20"Awake"]%20}'>
<img alt="bar chart" src='https://instachart.coveritup.app/bar?title=Bar+Chart%20&subtitle=Sleeping+hours&metric=hours&zmetric=days&theme=dark&data={%20"x":%20["Monday",%20"Friday",%20"Sunday"],%20"y":%20[[8,2,14]],%20"z":%20[[9,3,15]],%20"names":%20["Sleeping",%20"Awake"]%20}'>
</a>
</p>

## `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]
}
Expand All @@ -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]
}
Expand All @@ -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]]
Expand All @@ -197,20 +236,21 @@ https://instachart.coveritup.app/radar?title=Radar+Chart&data={
<br>

<p align="center">
<a href='https://instachart.coveritup.app/radar?title=Radar+Chart&data={%20%22names%22:%20[%22Mon%22,%22Tue%22,%20%22Wed%22,%20%22Fri%22],%20%22labels%22:%20[%22Work%22,%20%22Relax%22,%20%22Travel%22],%20%22values%22:%20[[1,2,3,4],%20[15,7,8,9],%20[15,17,5,7]]%20}'>
<img alt="radar chart" src='https://instachart.coveritup.app/radar?title=Radar+Chart&&height=520&data={%20%22names%22:%20[%22Mon%22,%22Tue%22,%20%22Wed%22,%20%22Fri%22],%20%22labels%22:%20[%22Work%22,%20%22Relax%22,%20%22Travel%22],%20%22values%22:%20[[1,2,3,4],%20[15,7,8,9],%20[15,17,5,7]]%20}'>
<a href='https://instachart.coveritup.app/radar?title=Radar+Chart&theme=dark&data={%20%22names%22:%20[%22Mon%22,%22Tue%22,%20%22Wed%22,%20%22Fri%22],%20%22labels%22:%20[%22Work%22,%20%22Relax%22,%20%22Travel%22],%20%22values%22:%20[[1,2,3,4],%20[15,7,8,9],%20[15,17,5,7]]%20}'>
<img alt="radar chart" src='https://instachart.coveritup.app/radar?title=Radar+Chart&theme=dark&height=520&data={%20%22names%22:%20[%22Mon%22,%22Tue%22,%20%22Wed%22,%20%22Fri%22],%20%22labels%22:%20[%22Work%22,%20%22Relax%22,%20%22Travel%22],%20%22values%22:%20[[1,2,3,4],%20[15,7,8,9],%20[15,17,5,7]]%20}'>
</a>
</p>

## `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]
}
Expand All @@ -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"]]
}
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
15 changes: 8 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand All @@ -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=
Expand All @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
78 changes: 78 additions & 0 deletions pkg/bar_chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading

0 comments on commit ed2ebd2

Please sign in to comment.