From 3edccc4758104f98e428245a2e342fe3a1d02389 Mon Sep 17 00:00:00 2001 From: David Mis Date: Wed, 5 Sep 2018 10:44:49 -0500 Subject: [PATCH] Added BaseValue funtionality to bar chart (#94) --- _examples/bar_chart_base_value/main.go | 88 ++++++++++++++++++++++ _examples/bar_chart_base_value/output.png | Bin 0 -> 18491 bytes bar_chart.go | 22 ++++-- 3 files changed, 105 insertions(+), 5 deletions(-) create mode 100644 _examples/bar_chart_base_value/main.go create mode 100644 _examples/bar_chart_base_value/output.png diff --git a/_examples/bar_chart_base_value/main.go b/_examples/bar_chart_base_value/main.go new file mode 100644 index 0000000..1874f0b --- /dev/null +++ b/_examples/bar_chart_base_value/main.go @@ -0,0 +1,88 @@ +package main + +import ( + "fmt" + "log" + "net/http" + "os" + + "github.com/wcharczuk/go-chart" + "github.com/wcharczuk/go-chart/drawing" +) + +func drawChart(res http.ResponseWriter, req *http.Request) { + profitStyle := chart.Style{ + Show: true, + FillColor: drawing.ColorFromHex("13c158"), + StrokeColor: drawing.ColorFromHex("13c158"), + StrokeWidth: 0, + } + + lossStyle := chart.Style{ + Show: true, + FillColor: drawing.ColorFromHex("c11313"), + StrokeColor: drawing.ColorFromHex("c11313"), + StrokeWidth: 0, + } + + sbc := chart.BarChart{ + Title: "Bar Chart Using BaseValue", + TitleStyle: chart.StyleShow(), + Background: chart.Style{ + Padding: chart.Box{ + Top: 40, + }, + }, + Height: 512, + BarWidth: 60, + XAxis: chart.Style{ + Show: true, + }, + YAxis: chart.YAxis{ + Style: chart.Style{ + Show: true, + }, + Ticks: []chart.Tick{ + {-4.0, "-4"}, + {-2.0, "-2"}, + {0, "0"}, + {2.0, "2"}, + {4.0, "4"}, + {6.0, "6"}, + {8.0, "8"}, + {10.0, "10"}, + {12.0, "12"}, + }, + }, + UseBaseValue: true, + BaseValue: 0.0, + Bars: []chart.Value{ + {Value: 10.0, Style: profitStyle, Label: "Profit"}, + {Value: 12.0, Style: profitStyle, Label: "More Profit"}, + {Value: 8.0, Style: profitStyle, Label: "Still Profit"}, + {Value: -4.0, Style: lossStyle, Label: "Loss!"}, + {Value: 3.0, Style: profitStyle, Label: "Phew Ok"}, + {Value: -2.0, Style: lossStyle, Label: "Oh No!"}, + }, + } + + res.Header().Set("Content-Type", "image/png") + err := sbc.Render(chart.PNG, res) + if err != nil { + fmt.Printf("Error rendering chart: %v\n", err) + } +} + +func port() string { + if len(os.Getenv("PORT")) > 0 { + return os.Getenv("PORT") + } + return "8080" +} + +func main() { + listenPort := fmt.Sprintf(":%s", port()) + fmt.Printf("Listening on %s\n", listenPort) + http.HandleFunc("/", drawChart) + log.Fatal(http.ListenAndServe(listenPort, nil)) +} diff --git a/_examples/bar_chart_base_value/output.png b/_examples/bar_chart_base_value/output.png new file mode 100644 index 0000000000000000000000000000000000000000..94231c8515f1e847e9fd3afe7a2271189cf82d00 GIT binary patch literal 18491 zcmeHvcRba7-2Q2Ir=1XKImo6&BD#wTp=4#9lAV!JHZ5gT>Ih{=5<;@)QBm0xAuF=? z-s5+Dbw7VR|2(f}|MUF3?pN+O=X}54&*wd^>v~_GJkKkh*|dRq1Bpc1Bzsm`nM7KR z|6NI1zY^bk6Fmn>q_Zn!rTsJup&u?9RNBBPC&PgZ!{&&35L(PGaL~6cQ5+HC!TKX)tIzq<#*p1$2c2?oMfBp4W zS9yppS(ZX+sjtt>@m_VJ2OsIhbL7axc+dAW486U*fiGTM($J`Wdns94&M!1{4-*p; zJ^lEv53BIS!xLxM>=1n+^7Iw*CG2(GYEEvB;NmjX&({R>-wQ@f&d=D)+#UE9CExn9tLJ;P-M~+FS*o|UyzHv{Vm}_smOMUL>Z3*?tk92~@- zRPv)e$Frodmx~vfR*}NZ8nf*zf4sdUezV{H>Y2tAlkZ=jvUU8VIp)qZX4`19kn(p{Gp>_(;|eI%I=>7Q-Ny0KTn{`zQp(eE!lUp{}v zj+6$8TGqceNX#ZLS$&UI8u}3*^y0+}KR;D5hDej|ukj;BpHCk@^6Tcz1hLxY0}FE0$Qe9?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`` htt&8(e<){Z$@<-!^&8ow1hKv(Ss6v?gp-%={689|Wm^CM literal 0 HcmV?d00001 diff --git a/bar_chart.go b/bar_chart.go index 0c24d92..45ddcc7 100644 --- a/bar_chart.go +++ b/bar_chart.go @@ -31,6 +31,9 @@ type BarChart struct { BarSpacing int + UseBaseValue bool + BaseValue float64 + Font *truetype.Font defaultFont *truetype.Font @@ -199,11 +202,20 @@ func (bc BarChart) drawBars(r Renderer, canvasBox Box, yr Range) { by = canvasBox.Bottom - yr.Translate(bar.Value) - barBox = Box{ - Top: by, - Left: bxl, - Right: bxr, - Bottom: canvasBox.Bottom, + if bc.UseBaseValue { + barBox = Box{ + Top: by, + Left: bxl, + Right: bxr, + Bottom: canvasBox.Bottom - yr.Translate(bc.BaseValue), + } + } else { + barBox = Box{ + Top: by, + Left: bxl, + Right: bxr, + Bottom: canvasBox.Bottom, + } } Draw.Box(r, barBox, bar.Style.InheritFrom(bc.styleDefaultsBar(index)))