Skip to content

Commit

Permalink
Removed dependency from github.com/wcharczuk/go-chart and replaced wi…
Browse files Browse the repository at this point in the history
…th unichart.
  • Loading branch information
anovik committed Oct 14, 2024
1 parent 28eaf65 commit 7d45193
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 47 deletions.
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ require (
github.com/unidoc/pkcs7 v0.2.0
github.com/unidoc/unichart v0.3.0
github.com/unidoc/unipdf/v3 v3.62.0
github.com/wcharczuk/go-chart/v2 v2.1.0
golang.org/x/crypto v0.22.0
golang.org/x/image v0.18.0
golang.org/x/text v0.16.0
Expand All @@ -32,7 +31,6 @@ require (
github.com/adrg/sysfont v0.1.2 // indirect
github.com/adrg/xdg v0.4.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-cmp v0.5.9 // indirect
Expand Down
5 changes: 0 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e h1:1r7pUrabqp18hOBcwBwiTsbnFeTZHV9eER/QT5JVZxY=
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
Expand Down Expand Up @@ -134,16 +132,13 @@ github.com/unidoc/unipdf/v3 v3.62.0 h1:CVsxq6k1SSIrprotlFvq6iBhA+5745dWaApB0LKtG
github.com/unidoc/unipdf/v3 v3.62.0/go.mod h1:0OIzSHHno23Y8WzaK+852abK8d3AxUZ1GQkMqpyCzu8=
github.com/unidoc/unitype v0.4.0 h1:/TMZ3wgwfWWX64mU5x2O9no9UmoBqYCB089LYYqHyQQ=
github.com/unidoc/unitype v0.4.0/go.mod h1:HV5zuUeqMKA4QgYQq3KDlJY/P96XF90BQB+6czK6LVA=
github.com/wcharczuk/go-chart/v2 v2.1.0 h1:tY2slqVQ6bN+yHSnDYwZebLQFkphK4WNrVwnt7CJZ2I=
github.com/wcharczuk/go-chart/v2 v2.1.0/go.mod h1:yx7MvAVNcP/kN9lKXM/NTce4au4DFN99j6i1OwDclNA=
go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30=
golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/image v0.0.0-20200927104501-e162460cd6b5/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20211028202545-6944b10bf410/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
golang.org/x/image v0.18.0 h1:jGzIakQa/ZXI1I0Fxvaa9W7yP25TqT6cHIHn+6CqvSQ=
golang.org/x/image v0.18.0/go.mod h1:4yyo5vMFQjVjUcVk4jEQcU9MGy/rulF5WvUILseCM2E=
Expand Down
31 changes: 11 additions & 20 deletions report/pdf_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,24 @@
*/
/*
* NOTE: This example depends on github.com/boombuler/barcode, MIT licensed,
* and github.com/wcharczuk/go-chart, MIT licensed,
* and github.com/unidoc/unichart, MIT licensed,
* and the Roboto font (Roboto-Bold.ttf, Roboto-Regular.ttf), Apache-2 licensed.
*/

package main

import (
"bytes"
"fmt"
"image"
"math"
"os"
"time"

"github.com/wcharczuk/go-chart/v2"

"github.com/boombuler/barcode"
"github.com/boombuler/barcode/qr"

"github.com/unidoc/unichart"
"github.com/unidoc/unichart/dataset"
"github.com/unidoc/unipdf/v3/common"
"github.com/unidoc/unipdf/v3/common/license"
"github.com/unidoc/unipdf/v3/creator"
Expand Down Expand Up @@ -452,34 +451,26 @@ func DoFeatureOverview(c *creator.Creator, fontRegular *model.PdfFont, fontBold
sc.GetHeading().SetFontSize(chapterFontSize)
sc.GetHeading().SetColor(chapterFontColor)

p = c.NewParagraph("Graphs can be generated via packages such as github.com/wcharczuk/go-chart as illustrated " +
p = c.NewParagraph("Graphs can be generated via packages such as github.com/unidoc/unichart as illustrated " +
"in the following plot:")
p.SetFont(normalFont)
p.SetFontSize(normalFontSize)
p.SetColor(normalFontColor)
p.SetMargins(0, 0, 5, 0)
sc.Add(p)

graph := chart.PieChart{
Width: 200,
Height: 200,
Values: []chart.Value{
chart := &unichart.PieChart{
Values: []dataset.Value{
{Value: 70, Label: "Compliant"},
{Value: 30, Label: "Non-Compliant"},
},
}
chart.SetWidth(175)
chart.SetHeight(175)

buffer := bytes.NewBuffer([]byte{})
err = graph.Render(chart.PNG, buffer)
if err != nil {
panic(err)
}
img, err = c.NewImageFromData(buffer.Bytes())
if err != nil {
panic(err)
}
img.SetMargins(0, 0, 10, 0)
sc.Add(img)
// Create unipdf chart component.
chartComponent := creator.NewChart(chart)
sc.Add(chartComponent)

sc = ch.NewSubchapter("Headers and footers")
sc.GetHeading().SetMargins(0, 0, 20, 0)
Expand Down
31 changes: 11 additions & 20 deletions report/pdf_report_landscape.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,24 @@

/*
* NOTE: This example depends on github.com/boombuler/barcode, MIT licensed,
* and github.com/wcharczuk/go-chart, MIT licensed,
* and github.com/unidoc/unichart, MIT licensed,
* and the Roboto font (Roboto-Bold.ttf, Roboto-Regular.ttf), Apache-2 licensed.
*/

package main

import (
"bytes"
"fmt"
"image"
"math"
"os"
"time"

"github.com/wcharczuk/go-chart/v2"

"github.com/boombuler/barcode"
"github.com/boombuler/barcode/qr"

"github.com/unidoc/unichart"
"github.com/unidoc/unichart/dataset"
"github.com/unidoc/unipdf/v3/common"
"github.com/unidoc/unipdf/v3/common/license"
"github.com/unidoc/unipdf/v3/creator"
Expand Down Expand Up @@ -457,34 +456,26 @@ func DoFeatureOverview(c *creator.Creator, fontRegular *model.PdfFont, fontBold
sc.GetHeading().SetFontSize(chapterFontSize)
sc.GetHeading().SetColor(chapterFontColor)

p = c.NewParagraph("Graphs can be generated via packages such as github.com/wcharczuk/go-chart as illustrated " +
p = c.NewParagraph("Graphs can be generated via packages such as github.com/unidoc/unichart as illustrated " +
"in the following plot:")
p.SetFont(normalFont)
p.SetFontSize(normalFontSize)
p.SetColor(normalFontColor)
p.SetMargins(0, 0, 5, 0)
sc.Add(p)

graph := chart.PieChart{
Width: 200,
Height: 200,
Values: []chart.Value{
chart := &unichart.PieChart{
Values: []dataset.Value{
{Value: 70, Label: "Compliant"},
{Value: 30, Label: "Non-Compliant"},
},
}
chart.SetWidth(175)
chart.SetHeight(175)

buffer := bytes.NewBuffer([]byte{})
err = graph.Render(chart.PNG, buffer)
if err != nil {
panic(err)
}
img, err = c.NewImageFromData(buffer.Bytes())
if err != nil {
panic(err)
}
img.SetMargins(0, 0, 10, 0)
sc.Add(img)
// Create unipdf chart component.
chartComponent := creator.NewChart(chart)
sc.Add(chartComponent)

sc = ch.NewSubchapter("Headers and footers")
sc.GetHeading().SetMargins(0, 0, 20, 0)
Expand Down
Binary file modified report/unidoc-report-landscape.pdf
Binary file not shown.
Binary file modified report/unidoc-report.pdf
Binary file not shown.

0 comments on commit 7d45193

Please sign in to comment.