diff --git a/handlers/chart.handlers.go b/handlers/chart.handlers.go index 3a0e382..5193e38 100644 --- a/handlers/chart.handlers.go +++ b/handlers/chart.handlers.go @@ -10,9 +10,9 @@ import ( "github.com/a-h/templ" "github.com/emarifer/go-templ-project-structure/services" + mcupeserta "github.com/emarifer/go-templ-project-structure/views/mcu/peserta" "github.com/emarifer/go-templ-project-structure/views/piechart" "github.com/emarifer/go-templ-project-structure/views/xsample" - "github.com/labstack/echo/v4" ) @@ -35,6 +35,7 @@ func (uh *PiechartHandler) Hello(c echo.Context) error { return uh.View(c, helo) } +// example pie chart func (uh *PiechartHandler) ShowPieChart(c echo.Context) error { // helo := piechart.MainPieChart("main_001") var code = "mcu006" @@ -61,6 +62,75 @@ func (uh *PiechartHandler) ShowPieChart(c echo.Context) error { return uh.View(c, helo) } +// mcu peserta +func (uh *PiechartHandler) ShowMcuPeserta(c echo.Context) error { + + // 1 + var code001 = "mcu001" + title001, udata001, err001 := uh.PiechartService.GetPieChart(code001, 1) + if err001 != nil { + return err001 + } + + jsonData001, err001 := json.MarshalIndent(udata001, "", " ") + if err001 != nil { + fmt.Println("Error:", err001) + return err001 + } + + seed001 := title001 + time.Now().String() + hash001 := md5.Sum([]byte(seed001)) + randomID001 := hex.EncodeToString(hash001[:]) + randomID001 = strings.ReplaceAll(randomID001, "-", "") + + // 2 + var code002 = "mcu002" + title002, udata002, err002 := uh.PiechartService.GetPieChart(code002, 1) + if err002 != nil { + return err002 + } + + jsonData002, err002 := json.MarshalIndent(udata002, "", " ") + if err002 != nil { + fmt.Println("Error:", err002) + return err002 + } + + seed002 := title002 + time.Now().String() + hash002 := md5.Sum([]byte(seed002)) + randomID002 := hex.EncodeToString(hash002[:]) + randomID002 = strings.ReplaceAll(randomID002, "-", "") + + // 3 + var code003 = "mcu003" + title003, udata003, err003 := uh.PiechartService.GetPieChart(code003, 1) + if err003 != nil { + return err003 + } + + jsonData003, err003 := json.MarshalIndent(udata003, "", " ") + if err003 != nil { + fmt.Println("Error:", err003) + return err003 + } + + seed003 := title003 + time.Now().String() + hash003 := md5.Sum([]byte(seed003)) + randomID003 := hex.EncodeToString(hash003[:]) + randomID003 = strings.ReplaceAll(randomID003, "-", "") + + helo := mcupeserta.ShowMcuPeserta("Peserta", mcupeserta.MainMcuPeserta( + randomID001, string(jsonData001), + randomID002, string(jsonData002), + randomID003, string(jsonData003), + ), + mcupeserta.CssMcuPeserta(), + mcupeserta.JsMcuPeserta(), + ) + + return uh.View(c, helo) +} + func (uh *PiechartHandler) View(c echo.Context, cmp templ.Component) error { c.Response().Header().Set(echo.HeaderContentType, echo.MIMETextHTML) diff --git a/handlers/routes.go b/handlers/routes.go index f6d2762..db0226f 100644 --- a/handlers/routes.go +++ b/handlers/routes.go @@ -26,6 +26,7 @@ func SetupRoutesLandingPage(app *echo.Echo, h *LandingPageHandler) { func SetupRoutesPieChart(app *echo.Echo, h *PiechartHandler) { Lp := app.Group("/pie_chart") Lp.GET("/", h.ShowPieChart) + Lp.GET("/peserta", h.ShowMcuPeserta) } func SetupRoutesProject(app *echo.Echo) { diff --git a/services/chart.services.go b/services/chart.services.go index 2c0b74b..e15b4c6 100644 --- a/services/chart.services.go +++ b/services/chart.services.go @@ -106,8 +106,9 @@ type Piechart struct { // CreatedAt time.Time `json:"created_at,omitempty"` Title struct { - Text string `json:"text"` - Left string `json:"left"` + Text string `json:"text"` + SubText string `json:"subtext"` + Left string `json:"left"` } `json:"title"` Tooltip struct { Trigger string `json:"trigger"` @@ -180,14 +181,16 @@ type ServicesPiechart struct { // Peserta MCU -- MCU001 func GetPieChartMcu001(code string, id int) (string, Piechart, error) { - var title = "Status Index Masa Tubuh (BMI)" + var title = "Peserta MCU" option := Piechart{ Title: struct { - Text string `json:"text"` - Left string `json:"left"` + Text string `json:"text"` + SubText string `json:"subtext"` + Left string `json:"left"` }{ - Text: title, - Left: "center", + Text: title, + SubText: "Total Peserta 506", + Left: "center", }, Tooltip: struct { Trigger string `json:"trigger"` @@ -202,6 +205,11 @@ func GetPieChartMcu001(code string, id int) (string, Piechart, error) { Top: "bottom", Left: "center", Orient: "vertical", + + // KALAU BERTABRAKAN DGN ATASNYA SETTING PAKE DIBAWAH INI + // Top: "bottom", + // Left: "center", + // Orient: "horizontal", }, Series: []Series{ { @@ -252,17 +260,17 @@ func GetPieChartMcu001(code string, id int) (string, Piechart, error) { } // Kepersertaan MCU Berdasarkan Jenis Kelamin -- MCU002 - -// Status Index Masa Tubuh (BMI) -- MCU006 -func GetPieChartMcu006(code string, id int) (string, Piechart, error) { - var title = "Status Index Masa Tubuh (BMI)" +func GetPieChartMcu002(code string, id int) (string, Piechart, error) { + var title = "Kepesertaan MCU" option := Piechart{ Title: struct { - Text string `json:"text"` - Left string `json:"left"` + Text string `json:"text"` + SubText string `json:"subtext"` + Left string `json:"left"` }{ - Text: title, - Left: "center", + Text: title, + SubText: "Berdasarkan Jenis Kelamin", + Left: "center", }, Tooltip: struct { Trigger string `json:"trigger"` @@ -277,6 +285,173 @@ func GetPieChartMcu006(code string, id int) (string, Piechart, error) { Top: "bottom", Left: "center", Orient: "vertical", + + // KALAU BERTABRAKAN DGN ATASNYA SETTING PAKE DIBAWAH INI + // Top: "bottom", + // Left: "center", + // Orient: "horizontal", + }, + Series: []Series{ + { + Label: struct { + Position string `json:"position"` + Formatter string `json:"formatter"` + }{ + Position: "inner", + Formatter: "{d}%", + }, + Name: "Access From", + Type: "pie", + Radius: []string{"20%", "50%"}, + ItemStyle: struct { + BorderRadius int `json:"borderRadius"` + BorderColor string `json:"borderColor"` + BorderWidth int `json:"borderWidth"` + }{ + BorderRadius: 10, + BorderColor: "#fff", + BorderWidth: 2, + }, + Data: []SeriesData{ + {Value: 143, Name: "Laki-laki : 143 Peserta"}, + {Value: 114, Name: "Perempuan : 114 Peserta"}, + }, + Emphasis: struct { + ItemStyle struct { + ShadowBlur int `json:"shadowBlur"` + ShadowOffsetX int `json:"shadowOffsetX"` + ShadowColor string `json:"shadowColor"` + } `json:"itemStyle"` + }{ + ItemStyle: struct { + ShadowBlur int `json:"shadowBlur"` + ShadowOffsetX int `json:"shadowOffsetX"` + ShadowColor string `json:"shadowColor"` + }{ + ShadowBlur: 10, + ShadowOffsetX: 0, + ShadowColor: "rgba(0, 0, 0, 0.5)", + }, + }, + }, + }, + } + return title, option, nil +} + +// Peserta MCU berdasarkan umur +func GetPieChartMcu003(code string, id int) (string, Piechart, error) { + var title = "Peserta MCU" + option := Piechart{ + Title: struct { + Text string `json:"text"` + SubText string `json:"subtext"` + Left string `json:"left"` + }{ + Text: title, + SubText: "Berdasarkan Umur", + Left: "center", + }, + Tooltip: struct { + Trigger string `json:"trigger"` + }{ + Trigger: "item", + }, + Legend: struct { + Top string `json:"top"` + Left string `json:"left"` + Orient string `json:"orient"` + }{ + Top: "bottom", + Left: "center", + Orient: "vertical", + + // KALAU BERTABRAKAN DGN ATASNYA SETTING PAKE DIBAWAH INI + // Top: "bottom", + // Left: "center", + // Orient: "horizontal", + }, + Series: []Series{ + { + Label: struct { + Position string `json:"position"` + Formatter string `json:"formatter"` + }{ + Position: "inner", + Formatter: "{d}%", + }, + Name: "Access From", + Type: "pie", + Radius: []string{"20%", "50%"}, + ItemStyle: struct { + BorderRadius int `json:"borderRadius"` + BorderColor string `json:"borderColor"` + BorderWidth int `json:"borderWidth"` + }{ + BorderRadius: 10, + BorderColor: "#fff", + BorderWidth: 2, + }, + Data: []SeriesData{ + {Value: 188, Name: "< 30 Tahun : 188 Peserta"}, + {Value: 194, Name: "30 - < 40 Tahun : 194 Peserta"}, + {Value: 123, Name: "40 - < 50 Tahun : 123 Peserta"}, + {Value: 55, Name: "≥ 50 Tahun : 55 Peserta"}, + }, + Emphasis: struct { + ItemStyle struct { + ShadowBlur int `json:"shadowBlur"` + ShadowOffsetX int `json:"shadowOffsetX"` + ShadowColor string `json:"shadowColor"` + } `json:"itemStyle"` + }{ + ItemStyle: struct { + ShadowBlur int `json:"shadowBlur"` + ShadowOffsetX int `json:"shadowOffsetX"` + ShadowColor string `json:"shadowColor"` + }{ + ShadowBlur: 10, + ShadowOffsetX: 0, + ShadowColor: "rgba(0, 0, 0, 0.5)", + }, + }, + }, + }, + } + return title, option, nil +} + +// Status Index Masa Tubuh (BMI) -- MCU006 +func GetPieChartMcu006(code string, id int) (string, Piechart, error) { + var title = "Status Index Masa Tubuh (BMI)" + option := Piechart{ + Title: struct { + Text string `json:"text"` + SubText string `json:"subtext"` + Left string `json:"left"` + }{ + Text: title, + SubText: "", + Left: "center", + }, + Tooltip: struct { + Trigger string `json:"trigger"` + }{ + Trigger: "item", + }, + Legend: struct { + Top string `json:"top"` + Left string `json:"left"` + Orient string `json:"orient"` + }{ + Top: "bottom", + Left: "center", + Orient: "vertical", + + // KALAU BERTABRAKAN DGN ATASNYA SETTING PAKE DIBAWAH INI + // Top: "bottom", + // Left: "center", + // Orient: "horizontal", }, Series: []Series{ { @@ -329,14 +504,196 @@ func GetPieChartMcu006(code string, id int) (string, Piechart, error) { return title, option, nil } +// Kriteria Hipertensi -- MCU007 +func GetPieChartMcu007(code string, id int) (string, Piechart, error) { + var title = "Kriteria Hipertensi" + option := Piechart{ + Title: struct { + Text string `json:"text"` + SubText string `json:"subtext"` + Left string `json:"left"` + }{ + Text: title, + SubText: "", + Left: "center", + }, + Tooltip: struct { + Trigger string `json:"trigger"` + }{ + Trigger: "item", + }, + Legend: struct { + Top string `json:"top"` + Left string `json:"left"` + Orient string `json:"orient"` + }{ + Top: "bottom", + Left: "center", + Orient: "vertical", + + // KALAU BERTABRAKAN DGN ATASNYA SETTING PAKE DIBAWAH INI + // Top: "bottom", + // Left: "center", + // Orient: "horizontal", + }, + Series: []Series{ + { + Label: struct { + Position string `json:"position"` + Formatter string `json:"formatter"` + }{ + Position: "inner", + Formatter: "{d}%", + }, + Name: "Access From", + Type: "pie", + Radius: []string{"20%", "50%"}, + ItemStyle: struct { + BorderRadius int `json:"borderRadius"` + BorderColor string `json:"borderColor"` + BorderWidth int `json:"borderWidth"` + }{ + BorderRadius: 10, + BorderColor: "#fff", + BorderWidth: 2, + }, + Data: []SeriesData{ + {Value: 237, Name: "Normal : 237 Peserta"}, + {Value: 215, Name: "Prehipertensi : 215 Peserta"}, + {Value: 66, Name: "Hipertensi Grade I : 66 Peserta"}, + {Value: 33, Name: "Hipertensi Grade II : 33 Peserta"}, + }, + Emphasis: struct { + ItemStyle struct { + ShadowBlur int `json:"shadowBlur"` + ShadowOffsetX int `json:"shadowOffsetX"` + ShadowColor string `json:"shadowColor"` + } `json:"itemStyle"` + }{ + ItemStyle: struct { + ShadowBlur int `json:"shadowBlur"` + ShadowOffsetX int `json:"shadowOffsetX"` + ShadowColor string `json:"shadowColor"` + }{ + ShadowBlur: 10, + ShadowOffsetX: 0, + ShadowColor: "rgba(0, 0, 0, 0.5)", + }, + }, + }, + }, + } + + return title, option, nil +} + +// Visus Jauh -- MCU008 +func GetPieChartMcu008(code string, id int) (string, Piechart, error) { + var title = "Visus Jauh" + option := Piechart{ + Title: struct { + Text string `json:"text"` + SubText string `json:"subtext"` + Left string `json:"left"` + }{ + Text: title, + SubText: "", + Left: "center", + }, + Tooltip: struct { + Trigger string `json:"trigger"` + }{ + Trigger: "item", + }, + Legend: struct { + Top string `json:"top"` + Left string `json:"left"` + Orient string `json:"orient"` + }{ + Top: "bottom", + Left: "center", + Orient: "vertical", + + // KALAU BERTABRAKAN DGN ATASNYA SETTING PAKE DIBAWAH INI + // Top: "bottom", + // Left: "center", + // Orient: "horizontal", + }, + Series: []Series{ + { + Label: struct { + Position string `json:"position"` + Formatter string `json:"formatter"` + }{ + Position: "inner", + Formatter: "{d}%", + }, + Name: "Access From", + Type: "pie", + Radius: []string{"20%", "50%"}, + ItemStyle: struct { + BorderRadius int `json:"borderRadius"` + BorderColor string `json:"borderColor"` + BorderWidth int `json:"borderWidth"` + }{ + BorderRadius: 10, + BorderColor: "#fff", + BorderWidth: 2, + }, + Data: []SeriesData{ + {Value: 237, Name: "Normal : 237 Peserta"}, + {Value: 194, Name: "Kelainan Refraksi : 194 Peserta"}, + {Value: 64, Name: "Kelainan Refraksi terkoreksi : 64 Peserta"}, + {Value: 56, Name: "Kelainan Refraksi tidak terkoreksi : 56 Peserta"}, + }, + Emphasis: struct { + ItemStyle struct { + ShadowBlur int `json:"shadowBlur"` + ShadowOffsetX int `json:"shadowOffsetX"` + ShadowColor string `json:"shadowColor"` + } `json:"itemStyle"` + }{ + ItemStyle: struct { + ShadowBlur int `json:"shadowBlur"` + ShadowOffsetX int `json:"shadowOffsetX"` + ShadowColor string `json:"shadowColor"` + }{ + ShadowBlur: 10, + ShadowOffsetX: 0, + ShadowColor: "rgba(0, 0, 0, 0.5)", + }, + }, + }, + }, + } + + return title, option, nil +} + func (su *ServicesPiechart) GetPieChart(code string, id int) (string, Piechart, error) { if code == "mcu001" { return GetPieChartMcu001(code, id) } + if code == "mcu002" { + return GetPieChartMcu002(code, id) + } + + if code == "mcu003" { + return GetPieChartMcu003(code, id) + } + if code == "mcu006" { return GetPieChartMcu006(code, id) } + if code == "mcu007" { + return GetPieChartMcu007(code, id) + } + + if code == "mcu008" { + return GetPieChartMcu008(code, id) + } + return "", Piechart{}, fmt.Errorf("code " + code + " not found") } diff --git a/views/mcu/peserta/mcupeserta.templ b/views/mcu/peserta/mcupeserta.templ new file mode 100644 index 0000000..729859c --- /dev/null +++ b/views/mcu/peserta/mcupeserta.templ @@ -0,0 +1,132 @@ +package mcupeserta + +import ( + "github.com/emarifer/go-templ-project-structure/views/layout" + chart "github.com/emarifer/go-templ-project-structure/views/component/chart" +) + +templ MainMcuPeserta(divPesertaMcu string, dataPesertaMcu string, divKepesertaanMcu string, dataKepesertaanMcu string, divPesertaMcuUmur string, dataPesertaMcuUmur string) { +