Skip to content

Commit

Permalink
(docs) fixes #9 and #10
Browse files Browse the repository at this point in the history
  • Loading branch information
kevincobain2000 committed Dec 27, 2023
1 parent 7986199 commit 9eee333
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 72 deletions.
89 changes: 19 additions & 70 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,47 +24,40 @@

**Lightweight:** Written in Go. No external dependencies. Download and self-host binary.


# API

**URL** `https://instachart.coveritup.app`
**API Documentation** Restful API with `image/png` response.

- [API](#api)
- [`GET /line`](#get-line)
- [Line Chart Simple](#line-chart-simple)
- [`GET /bar`](#get-bar)
- [Bars](#bars)
- [`GET /donut`](#get-donut)
- [Donuts](#donuts)
- [`GET /pie`](#get-pie)
- [Pies](#pies)
- [`GET /radar`](#get-radar)
- [Radars](#radars)

# API

## `GET /line`
**URL** `https://instachart.coveritup.app`

| Query | Required | Description | Example |
| :--------- | :------- | :---------- | :--------------------------------------------------------- |
| `data` || JSON | `?data={ "x": [["2022-12-23","2023-12-25"]],"y": [[1,2]]}` |
| `title` | | string | |
| `fill` | | boolean | |
| `subtitle` | | string | |
| `theme` | | string | |
| `metric` | | string | |
| `height` | | int | |
| `width` | | int | |
| 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 |



## `GET /line`

| `data` | Required | Description | Example |
| :------ | :------- | :--------------- | :---------------------------------------------------------------- |
| `x` || []Array (string) | `"x": [["2022-12-23","2022-12-24"], ["2022-12-23","2022-12-24"]]` |
| `y` || []Array (int) | `"y": [[1,2],[3,4]]` |
| `names` | | Array | `"names": ["Series A", "Series B"]` |


### Line Chart Simple

<details>
<summary><b>REQUEST URL</b></summary>

Expand Down Expand Up @@ -105,25 +98,11 @@ https://instachart.coveritup.app/line?title=Line+Chart+Simple&subtitle=Sleeping+
## `GET /bar`



| Query | Required | Description | Example |
| :--------- | :------- | :---------- | :--------------------------------------------------- |
| `data` || JSON | `?data={ "x": [["Mon","Tue","Wed"]],"y": [[1,2,3]]}` |
| `title` | | string | |
| `subtitle` | | string | |
| `theme` | | string | |
| `height` | | int | |
| `width` | | int | |


| `data` | Required | Description | Example |
| :----- | :------- | :--------------- | :--------------------------- |
| `x` || []Array (string) | `"x": [["Mon","Tue", "Wed"]` |
| `y` || []Array (int) | `"y": [[1,2,3]]` |


### Bars

<details>
<summary><b>REQUEST URL</b></summary>

Expand All @@ -139,8 +118,8 @@ https://instachart.coveritup.app/bar?title=Bar+Chart&subtitle=Sleeping+hours&dat
<br>

<p align="center">
<a href="https://instachart.coveritup.app/bar?title=Bar+Chart&subtitle=Sleeping+hours&data={%20%22x%22:%20[%22Monday%22,%20%22Friday%22,%20%22Sunday%22],%20%22y%22:%20[[8,%202%20,14]]%20}">
<img alt="bar chart" src='https://instachart.coveritup.app/bar?title=Bar+Chart&subtitle=Sleeping+hours&data={%20%22x%22:%20[%22Monday%22,%20%22Friday%22,%20%22Sunday%22],%20%22y%22:%20[[8,%202%20,14]]%20}'>
<a href="https://instachart.coveritup.app/bar?title=Bar+Chart&subtitle=Sleeping+hours&metric=h&data={%20%22x%22:%20[%22Monday%22,%20%22Friday%22,%20%22Sunday%22],%20%22y%22:%20[[8,%202%20,14]]%20}">
<img alt="bar chart" src='https://instachart.coveritup.app/bar?title=Bar+Chart&subtitle=Sleeping+hours&metric=h&data={%20%22x%22:%20[%22Monday%22,%20%22Friday%22,%20%22Sunday%22],%20%22y%22:%20[[8,%202%20,14]]%20}'>
</a>
</p>

Expand All @@ -160,9 +139,6 @@ https://instachart.coveritup.app/bar?title=Bar+Chart&subtitle=Sleeping+hours&dat
| `names` || Array (string) | `"x": ["Mon","Tue", "Wed"]` |
| `values` || Array (int) | `"y": [1,2,3]` |


### Donuts

<details>
<summary><b>REQUEST URL</b></summary>

Expand All @@ -187,25 +163,12 @@ https://instachart.coveritup.app/donut?title=Donut+Chart&data={

## `GET /pie`


| Query | Required | Description | Example |
| :--------- | :------- | :---------- | :-------------------------------------------------------- |
| `data` || JSON | `?data={ "names": ["Mon","Tue","Wed"],"values": [1,2,3]}` |
| `title` | | string | |
| `subtitle` | | string | |
| `theme` | | string | |
| `height` | | int | |
| `width` | | int | |


| `data` | Required | Description | Example |
| :------- | :------- | :------------- | :-------------------------- |
| `names` || Array (string) | `"x": ["Mon","Tue", "Wed"]` |
| `values` || Array (int) | `"y": [1,2,3]` |


### Pies

<details>
<summary><b>REQUEST URL</b></summary>

Expand All @@ -229,26 +192,12 @@ https://instachart.coveritup.app/pie?title=Pie+Chart&subtitle=Sleeping+Hours&dat

## `GET /radar`


| Query | Required | Description | Example |
| :--------- | :------- | :---------- | :--------------------------------------------------------------------------------------- |
| `data` || JSON | `data={"names": ["Mon","Tue", "Wed"], "labels": ["Work", "Relax"], "values": [[1,2,4]]}` |
| `title` | | string | |
| `subtitle` | | string | |
| `theme` | | string | |
| `height` | | int | |
| `width` | | int | |


| `data` | Required | Description | Example | Valid |
| `data` | Required | Description | Example | Validation |
| :------- | :------- | :------------- | :-------------------------------------- | :--------------------------------- |
| `names` || Array (string) | `"names": ["Mon","Tue", "Wed"]` | `>=3` |
| `values` || []Array (int) | `"values": [[1,2,3], [3,4,5]]` | `count(names) == count(values[0])` |
| `labels` | | Array (string) | `"labels": ["Work", "Relax", "Travel"]` | |


### Radars

<details>
<summary><b>REQUEST URL</b></summary>

Expand Down
11 changes: 9 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,29 @@ package main

import (
"flag"
"fmt"
"os"

"github.com/kevincobain2000/instachart/pkg"
)

var (
port string
)
var version = "dev"

func main() {
cliArgs()
if len(os.Args) > 1 && os.Args[1] == "version" {
fmt.Println(version)
return
}
flags()
e := pkg.NewEcho()

pkg.GracefulServerWithPid(e, port)
}

func cliArgs() {
func flags() {
flag.StringVar(&port, "port", "3001", "port to serve")
flag.Parse()
}

0 comments on commit 9eee333

Please sign in to comment.