gonum / gonum/plot

Enable Glyphs to have an outline

Open
#297 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
3k
Forks
201
PR merge metrics
No merged PRs in 30d

Description

screen shot 2016-07-15 at 4 42 05 pm

Just in case anyone is wanting to ask why we would do this, 1. other libraries do it, and 2. In my case I need to make my application create a graph that looks like the current ones (with an outline). Consider for example the javascript library, [chart.js](http://www.chartjs.org)

A patch for this _could_ be done without altering the API. Here is my current solution:

```
--- a/vg/draw/canvas.go
+++ b/vg/draw/canvas.go
@@ -55,6 +55,12 @@ type GlyphStyle struct {
// Radius specifies the size of the glyph's radius.
Radius vg.Length

+ // Width of the line around the glyph. If set, LineColour is used to outline the glyph
+ Width vg.Length
+
+ // Outline glyph with this color if Width is set.
+ LineColor color.Color
+
// Shape draws the shape of the glyph.
Shape GlyphDrawer
}
@@ -106,6 +112,11 @@ func (CircleGlyph) DrawGlyph(c *Canvas, sty GlyphStyle, pt vg.Point) {
p.Arc(pt, sty.Radius, 0, 2*math.Pi)
p.Close()
c.Fill(p)
+
+ if sty.Width > 0 {
+ c.SetLineStyle(LineStyle{Color: sty.LineColor, Width: sty.Width})
+ c.Stroke(p)
+ }
}

// RingGlyph is a glyph that draws the outline of a circle.

```

This simply add's two fields, if you want to set an outline, you can set the new `Width` field, and the new `LineColor` field.

Patch: https://github.com/gonum/plot/pull/298

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.