本文整理汇总了Golang中github.com/gonum/plot/vg.Length函数的典型用法代码示例。如果您正苦于以下问题:Golang Length函数的具体用法?Golang Length怎么用?Golang Length使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Length函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: RenderGuides
func (plot *Plot) RenderGuides() {
maxWidth := vg.Length(0)
yCum := vg.Length(0)
ySep := vg.Length(5) // TODO; make configurable
guides := GrobGroup{x0: 0, y0: 0}
for aes, scale := range plot.Scales {
if aes == "x" || aes == "y" {
// X and y axes are draw on a per-panel base.
continue
}
fmt.Printf("%s\n", scale.String())
grobs, width, height := scale.Render()
if width > maxWidth {
maxWidth = width
}
gg := grobs.(GrobGroup)
gg.y0 = float64(yCum)
guides.elements = append(guides.elements, gg)
yCum += height + ySep
}
plot.Grobs["Guides"] = guides
plot.renderInfo["Guides.Width"] = maxWidth
}
开发者ID:vdobler,项目名称:plot,代码行数:25,代码来源:plot.go
示例2: Draw
func (text GrobText) Draw(vp Viewport) {
vp.Canvas.Push()
vp.Canvas.SetColor(text.color)
x, y := vp.X(text.x), vp.Y(text.y)
font := text.Font()
ww, hh := text.BoundingBox()
// w := font.Width(text.text)
h := font.Extents().Ascent
dx := ww * vg.Length(text.hjust)
dy := hh * vg.Length(text.vjust)
if text.angle <= math.Pi/2 {
dx -= h * vg.Length(math.Sin(text.angle))
} else if text.angle <= math.Pi {
dx -= ww
dy += h * vg.Length(math.Cos(text.angle))
} else {
panic("Implement me....")
}
vp.Canvas.Translate(x-dx, y-dy)
vp.Canvas.Rotate(text.angle)
vp.Canvas.FillString(font, 0, 0, text.text)
// fmt.Printf("Printed %s %.1f %.1f\n", text.String(), ww, hh)
vp.Canvas.Pop()
}
开发者ID:vdobler,项目名称:plot,代码行数:26,代码来源:grob.go
示例3: arc
// Approximate a circular arc using multiple
// cubic Bézier curves, one for each π/2 segment.
//
// This is from:
// http://hansmuller-flex.blogspot.com/2011/04/approximating-circular-arc-with-cubic.html
func arc(p *pdf.Path, comp vg.PathComp) {
x0 := comp.X + comp.Radius*vg.Length(math.Cos(comp.Start))
y0 := comp.Y + comp.Radius*vg.Length(math.Sin(comp.Start))
p.Line(pdfPoint(x0, y0))
a1 := comp.Start
end := a1 + comp.Angle
sign := 1.0
if end < a1 {
sign = -1.0
}
left := math.Abs(comp.Angle)
// Square root of the machine epsilon for IEEE 64-bit floating
// point values. This is the equality threshold recommended
// in Numerical Recipes, if I recall correctly—it's small enough.
const epsilon = 1.4901161193847656e-08
for left > epsilon {
a2 := a1 + sign*math.Min(math.Pi/2, left)
partialArc(p, comp.X, comp.Y, comp.Radius, a1, a2)
left -= math.Abs(a2 - a1)
a1 = a2
}
}
开发者ID:zzn01,项目名称:plot,代码行数:30,代码来源:vgpdf.go
示例4: ticsExtents
// ticsExtents computes the width of the y-tics and the height of the x-tics
// needed to display the tics.
func (plot *Plot) ticsExtents() (ywidth, xheight vg.Length) {
label := MergeStyles(plot.Theme.TicLabel, DefaultTheme.TicLabel)
size := String2Float(label["size"], 4, 36)
angle := String2Float(label["angle"], 0, 2*math.Pi) // TODO: Should be different for x and y.
sep := vg.Length(String2Float(label["sep"], 0, 100))
tic := MergeStyles(plot.Theme.Tic, DefaultTheme.Tic)
length := vg.Length(String2Float(tic["length"], 0, 100))
// Look for longest y label.
for r := range plot.Panels {
sy := plot.Panels[r][0].Scales["y"]
for _, label := range sy.Labels {
w, _ := GrobText{text: label, size: size, angle: angle}.BoundingBox()
if w > ywidth {
ywidth = w
}
}
}
ywidth += length + sep
// Look for highest x label.
for c := range plot.Panels[0] {
sx := plot.Panels[0][c].Scales["x"]
for _, label := range sx.Labels {
_, h := GrobText{text: label, size: size, angle: angle}.BoundingBox()
if h > xheight {
xheight = h
}
}
}
xheight += length + sep
return ywidth, xheight
}
开发者ID:vdobler,项目名称:plot,代码行数:36,代码来源:plot.go
示例5: Height
// Height returns the height of the text when using
// the given font.
func (sty TextStyle) Height(txt string) vg.Length {
nl := textNLines(txt)
if nl == 0 {
return vg.Length(0)
}
e := sty.Font.Extents()
return e.Height*vg.Length(nl-1) + e.Ascent
}
开发者ID:nolenroyalty,项目名称:bangarang,代码行数:10,代码来源:canvas.go
示例6: Y
func (vp Viewport) Y(y float64) vg.Length {
ans := vp.Y0
if !vp.Direct {
ans += vg.Length(y) * vp.Height
} else {
ans += vg.Length(y)
}
// fmt.Printf("Y( %.3f ) = %.1fin\n", y, ans.Inches())
return ans
}
开发者ID:vdobler,项目名称:plot,代码行数:10,代码来源:grob.go
示例7: X
// X and Y turn natural grob coordinates [0,1] to canvas lengths.
func (vp Viewport) X(x float64) vg.Length {
ans := vp.X0
if !vp.Direct {
ans += vg.Length(x) * vp.Width
} else {
ans += vg.Length(x)
}
// fmt.Printf("X( %.3f ) = %.1fin\n", x, ans.Inches())
return ans
}
开发者ID:vdobler,项目名称:plot,代码行数:11,代码来源:grob.go
示例8: Sub
// SubViewport returns the area described by x0,y0,width,height in
// natural grob coordinates [0,1] as a viewport.
func (vp Viewport) Sub(x0, y0, width, height float64) Viewport {
sub := Viewport{
X0: vp.X0 + vg.Length(x0)*vp.Width,
Y0: vp.Y0 + vg.Length(y0)*vp.Height,
Width: vg.Length(width) * vp.Width,
Height: vg.Length(height) * vp.Height,
Canvas: vp.Canvas,
}
return sub
}
开发者ID:vdobler,项目名称:plot,代码行数:13,代码来源:grob.go
示例9: BoundingBox
func (text GrobText) BoundingBox() (vg.Length, vg.Length) {
font := text.Font()
// Compute width ww and height hh of the rotateted bounding box.
w := font.Width(text.text)
h := font.Extents().Ascent
s := math.Sin(text.angle)
z := vg.Length(math.Sqrt(1 - s*s))
ww := w*z + h*vg.Length(s)
hh := w*vg.Length(s) + h*z
return ww, hh
}
开发者ID:vdobler,项目名称:plot,代码行数:13,代码来源:grob.go
示例10: GlyphBoxes
// GlyphBoxes returns a slice of GlyphBoxes,
// one for each of the labels, implementing the
// plot.GlyphBoxer interface.
func (l *Labels) GlyphBoxes(p *plot.Plot) []plot.GlyphBox {
bs := make([]plot.GlyphBox, len(l.Labels))
for i, label := range l.Labels {
bs[i].X = p.X.Norm(l.XYs[i].X)
bs[i].Y = p.Y.Norm(l.XYs[i].Y)
w := l.Width(label)
h := l.Height(label)
bs[i].Rectangle.Min.X = w*vg.Length(l.XAlign) + l.XOffset
bs[i].Rectangle.Min.Y = h*vg.Length(l.YAlign) + l.YOffset
bs[i].Rectangle.Max.X = w + w*vg.Length(l.XAlign) + l.XOffset
bs[i].Rectangle.Max.Y = h + h*vg.Length(l.YAlign) + l.YOffset
}
return bs
}
开发者ID:nolenroyalty,项目名称:bangarang,代码行数:17,代码来源:labels.go
示例11: CreateImage
// CreateImage creates graph of nyanpass
func (n *Nyanpass) CreateImage(fileName string) error {
if n.Counts == nil {
return errors.New("Count is not defined.")
}
p, err := plot.New()
if err != nil {
return err
}
bar, err := plotter.NewBarChart(n.Counts, vg.Points(30))
if err != nil {
return err
}
bar.LineStyle.Width = vg.Length(0)
bar.Color = plotutil.Color(2)
p.Add(bar)
p.Title.Text = "Nyanpass Graph"
p.X.Label.Text = "Days"
p.Y.Label.Text = "Nyanpass count"
p.NominalX(n.labels...)
p.Y.Tick.Marker = RelabelTicks{}
if err := p.Save(6*vg.Inch, 6*vg.Inch, fileName); err != nil {
return err
}
n.imagePath = fileName
return nil
}
开发者ID:Rompei,项目名称:nyanpass-graph2,代码行数:31,代码来源:nyanpass.go
示例12: FillText
// FillText fills lines of text in the draw area.
// The text is offset by its width times xalign and
// its height times yalign. x and y give the bottom
// left corner of the text befor e it is offset.
func (c *Canvas) FillText(sty TextStyle, x, y vg.Length, xalign, yalign float64, txt string) {
txt = strings.TrimRight(txt, "\n")
if len(txt) == 0 {
return
}
c.SetColor(sty.Color)
ht := sty.Height(txt)
y += ht*vg.Length(yalign) - sty.Font.Extents().Ascent
nl := textNLines(txt)
for i, line := range strings.Split(txt, "\n") {
xoffs := vg.Length(xalign) * sty.Font.Width(line)
n := vg.Length(nl - i)
c.FillString(sty.Font, x+xoffs, y+n*sty.Font.Size, line)
}
}
开发者ID:nolenroyalty,项目名称:bangarang,代码行数:21,代码来源:canvas.go
示例13: partialArc
// Approximate a circular arc of fewer than π/2
// radians with cubic Bézier curve.
func partialArc(p *pdf.Path, x, y, r vg.Length, a1, a2 float64) {
a := (a2 - a1) / 2
x4 := r * vg.Length(math.Cos(a))
y4 := r * vg.Length(math.Sin(a))
x1 := x4
y1 := -y4
const k = 0.5522847498 // some magic constant
f := k * vg.Length(math.Tan(a))
x2 := x1 + f*y4
y2 := y1 + f*x4
x3 := x2
y3 := -y2
// Rotate and translate points into position.
ar := a + a1
sinar := vg.Length(math.Sin(ar))
cosar := vg.Length(math.Cos(ar))
x2r := x2*cosar - y2*sinar + x
y2r := x2*sinar + y2*cosar + y
x3r := x3*cosar - y3*sinar + x
y3r := x3*sinar + y3*cosar + y
x4 = r*vg.Length(math.Cos(a2)) + x
y4 = r*vg.Length(math.Sin(a2)) + y
p.Curve(pdfPoint(x2r, y2r), pdfPoint(x3r, y3r), pdfPoint(x4, y4))
}
开发者ID:zzn01,项目名称:plot,代码行数:28,代码来源:vgpdf.go
示例14: Font
func (text GrobText) Font() vg.Font {
fname := text.font
if fname == "" {
fname = "Courier-Bold"
}
font, err := vg.MakeFont(fname, vg.Length(text.size))
if err != nil {
panic(err.Error())
}
return font
}
开发者ID:vdobler,项目名称:plot,代码行数:11,代码来源:grob.go
示例15: NewWith
// NewWith returns a new image canvas created according to the specified
// options. The currently accepted options are UseWH,
// UseDPI, UseImage, and UseImageWithContext.
// Each of the options specifies the size of the canvas (UseWH, UseImage),
// the resolution of the canvas (UseDPI), or both (useImageWithContext).
// If size or resolution are not specified, defaults are used.
// It panics if size and resolution are overspecified (i.e., too many options are
// passed).
func NewWith(o ...option) *Canvas {
c := new(Canvas)
var g uint32
for _, opt := range o {
f := opt(c)
if g&f != 0 {
panic("incompatible options")
}
g |= f
}
if c.dpi == 0 {
c.dpi = DefaultDPI
}
if c.w == 0 { // h should also == 0.
if c.img == nil {
c.w = DefaultWidth
c.h = DefaultHeight
} else {
w := float64(c.img.Bounds().Max.X - c.img.Bounds().Min.X)
h := float64(c.img.Bounds().Max.Y - c.img.Bounds().Min.Y)
c.w = vg.Length(w/float64(c.dpi)) * vg.Inch
c.h = vg.Length(h/float64(c.dpi)) * vg.Inch
}
}
if c.img == nil {
w := c.w / vg.Inch * vg.Length(c.dpi)
h := c.h / vg.Inch * vg.Length(c.dpi)
c.img = draw.Image(image.NewRGBA(image.Rect(0, 0, int(w+0.5), int(h+0.5))))
}
if c.gc == nil {
h := float64(c.img.Bounds().Max.Y - c.img.Bounds().Min.Y)
c.gc = draw2dimg.NewGraphicContext(c.img)
c.gc.SetDPI(c.dpi)
c.gc.Scale(1, -1)
c.gc.Translate(0, -h)
}
draw.Draw(c.img, c.img.Bounds(), image.White, image.ZP, draw.Src)
c.color = []color.Color{color.Black}
vg.Initialize(c)
return c
}
开发者ID:zzn01,项目名称:plot,代码行数:49,代码来源:vgimg.go
示例16: padY
// padY returns a draw.Canvas that is padded vertically
// so that glyphs will no be clipped.
func padY(p *Plot, c draw.Canvas) draw.Canvas {
glyphs := p.GlyphBoxes(p)
b := bottomMost(&c, glyphs)
yAxis := verticalAxis{p.Y}
glyphs = append(glyphs, yAxis.GlyphBoxes(p)...)
t := topMost(&c, glyphs)
miny := c.Min.Y - b.Min.Y
maxy := c.Max.Y - (t.Min.Y + t.Size().Y)
by := vg.Length(b.Y)
ty := vg.Length(t.Y)
n := (by*maxy - ty*miny) / (by - ty)
m := ((by-1)*maxy - ty*miny + miny) / (by - ty)
return draw.Canvas{
Canvas: vg.Canvas(c),
Rectangle: draw.Rectangle{
Min: draw.Point{Y: n, X: c.Min.X},
Max: draw.Point{Y: m, X: c.Max.X},
},
}
}
开发者ID:zzn01,项目名称:plot,代码行数:23,代码来源:plot.go
示例17: padX
// padX returns a draw.Canvas that is padded horizontally
// so that glyphs will no be clipped.
func padX(p *Plot, c draw.Canvas) draw.Canvas {
glyphs := p.GlyphBoxes(p)
l := leftMost(&c, glyphs)
xAxis := horizontalAxis{p.X}
glyphs = append(glyphs, xAxis.GlyphBoxes(p)...)
r := rightMost(&c, glyphs)
minx := c.Min.X - l.Min.X
maxx := c.Max.X - (r.Min.X + r.Size().X)
lx := vg.Length(l.X)
rx := vg.Length(r.X)
n := (lx*maxx - rx*minx) / (lx - rx)
m := ((lx-1)*maxx - rx*minx + minx) / (lx - rx)
return draw.Canvas{
Canvas: vg.Canvas(c),
Rectangle: draw.Rectangle{
Min: draw.Point{X: n, Y: c.Min.Y},
Max: draw.Point{X: m, Y: c.Max.Y},
},
}
}
开发者ID:zzn01,项目名称:plot,代码行数:23,代码来源:plot.go
示例18: Save
func (g *Graph) Save(filename string, w, h int) error {
g.Plot.Add(plotter.NewGrid())
for _, c := range g.Curves {
lpLine, lpPoints, err := plotter.NewLinePoints(c.Points)
if err != nil {
return err
}
if len(c.RGB) != 3 {
return errors.New("bad RGB")
}
color := color.RGBA{R: c.RGB[0], G: c.RGB[1], B: c.RGB[2], A: 255}
lpLine.LineStyle.Color = color
lpPoints.Color = color
g.Plot.Add(lpLine, lpPoints)
if c.Name != "" {
g.Plot.Legend.Add(c.Name, lpLine, lpPoints)
}
}
return g.Plot.Save(vg.Length(w), vg.Length(h), filename)
}
开发者ID:Theodus,项目名称:graph,代码行数:21,代码来源:graph.go
示例19: tickLabelWidth
// tickLabelWidth returns the width of the widest tick mark label.
func tickLabelWidth(sty draw.TextStyle, ticks []Tick) vg.Length {
maxWidth := vg.Length(0)
for _, t := range ticks {
if t.IsMinor() {
continue
}
w := sty.Width(t.Label)
if w > maxWidth {
maxWidth = w
}
}
return maxWidth
}
开发者ID:nolenroyalty,项目名称:bangarang,代码行数:14,代码来源:axis.go
示例20: tickLabelHeight
// tickLabelHeight returns height of the tick mark labels.
func tickLabelHeight(sty draw.TextStyle, ticks []Tick) vg.Length {
maxHeight := vg.Length(0)
for _, t := range ticks {
if t.IsMinor() {
continue
}
h := sty.Height(t.Label)
if h > maxHeight {
maxHeight = h
}
}
return maxHeight
}
开发者ID:nolenroyalty,项目名称:bangarang,代码行数:14,代码来源:axis.go
注:本文中的github.com/gonum/plot/vg.Length函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论