Skip to content

Fix for [[]] -> [] for /line #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@

| `data` | Required | Description |
| :------ | :------- | :--------------- |
| `x` | ◯ | []Array (string) |
| `x` | ◯ | Array (string) |
| `y` | ◯ | []Array (int) |
| `names` | | Array |


```sh
https://instachart.coveritup.app/line?title=Line+Chart+Simple&subtitle=Sleeping+Hours&data={
"x": [["Mon","Tue","Wed"]],
"x": ["Mon","Tue","Wed"],
"y": [[4,8,7], [10,20,24]],
"names": ["Sleeping", "Awake"]
}
Expand All @@ -79,14 +79,14 @@ https://instachart.coveritup.app/line?title=Line+Chart+Simple&subtitle=Sleeping+


<p align="center">
<a href='https://instachart.coveritup.app/line?title=Line+Chart&width=1024&height=620&subtitle=Sleeping+Hours&data={%20"x":%20[["Mon","Tue","Wed"]],%20"y":%20[[4,8,7],%20[10,20,24]],%20"names":%20["Sleeping",%20"Awake"]%20}'>
<img alt="line chart" src='https://instachart.coveritup.app/line?title=Line+Chart&width=1024&height=620&subtitle=Sleeping+Hours&data={%20"x":%20[["Mon","Tue","Wed"]],%20"y":%20[[4,8,7],%20[10,20,24]],%20"names":%20["Sleeping",%20"Awake"]%20}'>
<a href='https://instachart.coveritup.app/line?title=Line+Chart&width=1024&height=620&subtitle=Sleeping+Hours&data={%20"x":%20["Mon","Tue","Wed"],%20"y":%20[[4,8,7],%20[10,20,24]],%20"names":%20["Sleeping",%20"Awake"]%20}'>
<img alt="line chart" src='https://instachart.coveritup.app/line?title=Line+Chart&width=1024&height=620&subtitle=Sleeping+Hours&data={%20"x":%20["Mon","Tue","Wed"],%20"y":%20[[4,8,7],%20[10,20,24]],%20"names":%20["Sleeping",%20"Awake"]%20}'>
</a>
</p>

```sh
https://instachart.coveritup.app/line?title=Line+Chart+Simple&subtitle=Sleeping+Hours&data={
"x": [["Mon","Tue","Wed"]],
"x": ["Mon","Tue","Wed"],
"y": [[4,8,7], [10,20,24]],
"names": ["Sleeping", "Awake"]
}
Expand All @@ -95,8 +95,8 @@ https://instachart.coveritup.app/line?title=Line+Chart+Simple&subtitle=Sleeping+
<br>

<p align="center">
<a href='https://instachart.coveritup.app/line?title=Line+Chart+Area&width=1020&height=620&subtitle=Sleeping+Hours&fill=true&data={%20"x":%20[["Mon","Tue","Wed"]],%20"y":%20[[4,8,7],%20[10,20,24]],%20"names":%20["Sleeping",%20"Awake"]%20}'>
<img alt="line area chart" src='https://instachart.coveritup.app/line?title=Line+Chart+Area&width=1020&height=620&subtitle=Sleeping+Hours&fill=true&data={%20"x":%20[["Mon","Tue","Wed"]],%20"y":%20[[4,8,7],%20[10,20,24]],%20"names":%20["Sleeping",%20"Awake"]%20}'>
<a href='https://instachart.coveritup.app/line?title=Line+Chart+Area&width=1020&height=620&subtitle=Sleeping+Hours&fill=true&data={%20"x":%20["Mon","Tue","Wed"],%20"y":%20[[4,8,7],%20[10,20,24]],%20"names":%20["Sleeping",%20"Awake"]%20}'>
<img alt="line area chart" src='https://instachart.coveritup.app/line?title=Line+Chart+Area&width=1020&height=620&subtitle=Sleeping+Hours&fill=true&data={%20"x":%20["Mon","Tue","Wed"],%20"y":%20[[4,8,7],%20[10,20,24]],%20"names":%20["Sleeping",%20"Awake"]%20}'>
</a>
</p>

Expand Down
4 changes: 2 additions & 2 deletions frontend/dist/index.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion frontend/src/components/Hero.astro
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<div class="w-full xl:w-3/5 p-12 overflow-hidden">
<img
class="mx-auto w-full md:w-4/5 transform -rotate-6 transition hover:scale-105 duration-700 ease-in-out hover:rotate-6"
src="https://instachart.coveritup.app/line?title=Line+Chart&subtitle=Sleeping+Hours&width=760&height=560&data={%20%22x%22:%20[[%22Mon%22,%22Tue%22,%22Wed%22]],%20%22y%22:%20[[4,8,7],%20[10,20,24]],%20%22names%22:%20[%22Sleeping%22,%20%22Awake%22]%20}&theme=dark"
src="https://instachart.coveritup.app/line?title=Line+Chart&subtitle=Sleeping+Hours&width=760&height=560&data={%20%22x%22:%20[%22Mon%22,%22Tue%22,%22Wed%22],%20%22y%22:%20[[4,8,7],%20[10,20,24]],%20%22names%22:%20[%22Sleeping%22,%20%22Awake%22]%20}&theme=dark"
/>
</div>
<style></style>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/LineChart.astro
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ https://instachart.coveritup.app/line?title=Line
<div class="w-full xl:w-3/5 pt-5 overflow-hidden">
<img
class="mx-auto w-full md:w-4/5"
src="https://instachart.coveritup.app/line?title=Line+Chart+Simple&subtitle=Sleeping+Hours&width=760&height=560&data={%20%22x%22:%20[[%22Mon%22,%22Tue%22,%22Wed%22]],%20%22y%22:%20[[4,8,7],%20[10,20,24]],%20%22names%22:%20[%22Sleeping%22,%20%22Awake%22]%20}&theme=dark"
src="https://instachart.coveritup.app/line?title=Line+Chart+Simple&subtitle=Sleeping+Hours&width=760&height=560&data={%20%22x%22:%20[%22Mon%22,%22Tue%22,%22Wed%22],%20%22y%22:%20[[4,8,7],%20[10,20,24]],%20%22names%22:%20[%22Sleeping%22,%20%22Awake%22]%20}&theme=dark"
/>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/Themes.astro
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ import sun from "@assets/sun.svg?raw";
<p class="text-center font-bold pb-5 text-white">Light</p>
<div class="flex w-full items-center justify-center md:justify-center lg:pb-0 fade-in">
<img
src="https://instachart.coveritup.app/line?title=Line+Chart&subtitle=Sleeping+Hours&fill=true&width=690&height=390&data={%20%22x%22:%20[[%22Mon%22,%22Tue%22,%22Wed%22]],%20%22y%22:%20[[4,8,7],%20[10,20,24]],%20%22names%22:%20[%22Sleeping%22,%20%22Awake%22]%20}&theme=light"
src="https://instachart.coveritup.app/line?title=Line+Chart&subtitle=Sleeping+Hours&fill=true&width=690&height=390&data={%20%22x%22:%20[%22Mon%22,%22Tue%22,%22Wed%22],%20%22y%22:%20[[4,8,7],%20[10,20,24]],%20%22names%22:%20[%22Sleeping%22,%20%22Awake%22]%20}&theme=light"
class="transform hover:scale-110 duration-300 ease-in-out"
/>
</div>
<br />
<p class="text-center font-bold pb-5 text-gray-400">Dark</p>
<div class="flex w-full justify-center md:justify-center lg:pb-0 fade-in">
<img
src="https://instachart.coveritup.app/line?title=Line+Chart+Simple&subtitle=Sleeping+Hours&fill=true&width=690&height=390&data={%20%22x%22:%20[[%22Mon%22,%22Tue%22,%22Wed%22]],%20%22y%22:%20[[4,8,7],%20[10,20,24]],%20%22names%22:%20[%22Sleeping%22,%20%22Awake%22]%20}&theme=dark"
src="https://instachart.coveritup.app/line?title=Line+Chart+Simple&subtitle=Sleeping+Hours&fill=true&width=690&height=390&data={%20%22x%22:%20[%22Mon%22,%22Tue%22,%22Wed%22],%20%22y%22:%20[[4,8,7],%20[10,20,24]],%20%22names%22:%20[%22Sleeping%22,%20%22Awake%22]%20}&theme=dark"
class="transform hover:scale-110 duration-300 ease-in-out"
/>
</div>
Expand Down
4 changes: 2 additions & 2 deletions pkg/line_chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func NewLineChart() *LineChart {
}
}

func (c *LineChart) Get(xData [][]string, yData [][]float64, names []string, req *ChartRequest) ([]byte, error) {
func (c *LineChart) Get(xData []string, yData [][]float64, names []string, req *ChartRequest) ([]byte, error) {
p, err := charts.LineRender(
yData,
charts.HeightOptionFunc(req.Height),
Expand All @@ -27,7 +27,7 @@ func (c *LineChart) Get(xData [][]string, yData [][]float64, names []string, req
SubtextFontSize: DEFAULT_SUBTITLE_FONT_SIZE,
Left: charts.PositionCenter,
}),
charts.XAxisDataOptionFunc(xData[0]),
charts.XAxisDataOptionFunc(xData),
charts.LegendOptionFunc(charts.LegendOption{
Orient: charts.OrientHorizontal,
Data: names,
Expand Down
16 changes: 15 additions & 1 deletion pkg/line_chart_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func NewLineChartHandler() *LineChartHandler {
}

type LineChartData struct {
XData [][]string `json:"x"`
XData []string `json:"x"`
YData [][]float64 `json:"y"`
Names []string `json:"names"`
}
Expand All @@ -36,6 +36,20 @@ func (h *LineChartHandler) Get(c echo.Context) ([]byte, error) {
}
return nil, echo.NewHTTPError(http.StatusUnprocessableEntity, msgs)
}
if len(data.XData) == 0 || len(data.YData) == 0 {
msgs := map[string]string{
"data": "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": "Counts are invalid",
}
return nil, echo.NewHTTPError(http.StatusUnprocessableEntity, msgs)
}
}

SetHeadersResponseImage(c.Response().Header())
return h.chart.Get(data.XData, data.YData, data.Names, req)
Expand Down
10 changes: 7 additions & 3 deletions pkg/line_chart_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,19 @@ func TestGetLineChart(t *testing.T) {
}
testCases := []TestCase{
{
QueryParams: `{"x": [["2022-12-23","2022-12-24","2023-12-25"], ["2022-12-23","2022-12-28","2023-12-30"]], "y": [[1,2,3], [2,5,3]]}`,
QueryParams: `{"x": ["2022-12-23","2022-12-24","2023-12-25"], "y": [[1,2,3], [2,5,3]]}`,
ExpectedStatus: http.StatusOK,
},
{
QueryParams: `{"x": [["abc","2022-12-24","2023-12-25"], ["2022-12-23","2022-12-28","2023-12-30"]], "y": [[1,2,3], [2,5,3]]}`,
QueryParams: `{"x": [["2022-12-23","2022-12-24","2023-12-25"], ["2022-12-23","2022-12-28","2023-12-30"]], "y": [[1,2,3], [2,5,3]]}`,
ExpectedStatus: http.StatusUnprocessableEntity,
},
{
QueryParams: `{"x": ["abc","2022-12-24","2023-12-25"], "y": [[1,2,3], [2,5,3]]}`,
ExpectedStatus: http.StatusOK,
},
{
QueryParams: `{"x": [[2022-12-23,"2022-12-24","2023-12-25"], ["2022-12-23","2022-12-28","2023-12-30"]], "y": [[1,2,3], [2,5,3]]}`,
QueryParams: `{"x": [2022-12-23,"2022-12-24","2023-12-25"], ["2022-12-23","2022-12-28","2023-12-30"], "y": [[1,2,3], [2,5,3]]}`,
ExpectedStatus: http.StatusUnprocessableEntity,
},
}
Expand Down