本文整理汇总了Golang中code/google/com/p/plotinum/vg.Length函数的典型用法代码示例。如果您正苦于以下问题:Golang Length函数的具体用法?Golang Length怎么用?Golang Length使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Length函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: 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:jen6,项目名称:plotinum,代码行数:30,代码来源:vgpdf.go
示例2: crosshair
// crosshair draws a plus at the given point.
func crosshair(img draw.Image, x, y int, str string) {
c := vgimg.NewImage(img)
// drawPlots here because NewImage
// clears the canvas. Instead, the canvas
// should just be stored instead of being
// recreated at each redraw.
drawPlots(img)
c.SetColor(color.RGBA{R: 255, A: 255})
xc := vg.Inches(float64(x) / c.DPI())
yc := vg.Inches(float64(y) / c.DPI())
radius := vg.Points(5)
var p vg.Path
p.Move(xc-radius, yc)
p.Line(xc+radius, yc)
c.Stroke(p)
p = vg.Path{}
p.Move(xc, yc+radius)
p.Line(xc, yc-radius)
c.Stroke(p)
c.SetColor(color.Black)
c.FillString(font, vg.Length(0), vg.Length(0), str)
}
开发者ID:vivounicorn,项目名称:eaburns,代码行数:29,代码来源:main.go
示例3: 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:jen6,项目名称:plotinum,代码行数:10,代码来源:draw.go
示例4: 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].Rect.Min.X = w*vg.Length(l.XAlign) + l.XOffset
bs[i].Rect.Min.Y = h*vg.Length(l.YAlign) + l.YOffset
bs[i].Rect.Size.X = w
bs[i].Rect.Size.Y = h
}
return bs
}
开发者ID:venliong,项目名称:plotinum,代码行数:17,代码来源:labels.go
示例5: Plot
func (s *SparkLines) Plot(da plot.DrawArea, plt *plot.Plot) {
trX, trY := plt.Transforms(&da)
w := vg.Length(1)
da.SetLineWidth(w)
_, _, ymin, ymax := s.DataRange()
for _, d := range s.XYs {
perc := float64(d.Y-ymin) / float64(ymax-ymin)
c := BrightColorGradient.GetInterpolatedColorFor((perc*-1+1)*0.5 + 0.6)
da.SetColor(c)
// Transform the data x, y coordinate of this bubble
// to the corresponding drawing coordinate.
x := trX(d.X)
y := trY(d.Y * 0.9)
//rad := vg.Length(10)
var p vg.Path
p.Move(x-w, y)
p.Line(x-w, 0)
//p.Close()
da.Stroke(p)
//da.StrokeLine2(*sty, x, 0, x, y)
}
}
开发者ID:raff,项目名称:go-sparkline,代码行数:29,代码来源:plot.go
示例6: Plot
func (pt *Dots) Plot(da plot.DrawArea, plt *plot.Plot) {
trX, trY := plt.Transforms(&da)
da.SetColor(pt.Color)
for i := range pt.Y {
// Transform the data x, y coordinate of this bubble
// to the corresponding drawing coordinate.
x := trX(pt.X[i])
y := trY(pt.Y[i])
// Get the radius of this bubble. The radius
// is specified in drawing units (i.e., its size
// is given as the final size at which it will
// be drawn) so it does not need to be transformed.
rad := vg.Length(2)
// Fill a circle centered at x,y on the draw area.
var p vg.Path
p.Move(x+rad, y)
p.Arc(x, y, rad, 0, 2*math.Pi)
p.Close()
da.Fill(p)
}
}
开发者ID:knodos,项目名称:kmodel,代码行数:25,代码来源:dots.go
示例7: draw
// draw draws the legend to the given DrawArea.
func (l *Legend) draw(da DrawArea) {
iconx := da.Min.X
textx := iconx + l.ThumbnailWidth + l.TextStyle.Width(" ")
xalign := 0.0
if !l.Left {
iconx = da.Max().X - l.ThumbnailWidth
textx = iconx - l.TextStyle.Width(" ")
xalign = -1
}
textx += l.XOffs
iconx += l.XOffs
enth := l.entryHeight()
y := da.Max().Y - enth
if !l.Top {
y = da.Min.Y + (enth+l.Padding)*(vg.Length(len(l.entries))-1)
}
y += l.YOffs
icon := &DrawArea{
Canvas: da.Canvas,
Rect: Rect{Min: Point{iconx, y}, Size: Point{l.ThumbnailWidth, enth}},
}
for _, e := range l.entries {
for _, t := range e.thumbs {
t.Thumbnail(icon)
}
yoffs := (enth - l.TextStyle.Height(e.text)) / 2
da.FillText(l.TextStyle, textx, icon.Min.Y+yoffs, xalign, 0, e.text)
icon.Min.Y -= enth + l.Padding
}
}
开发者ID:jackielii,项目名称:go-plotinum,代码行数:33,代码来源:legend.go
示例8: radius
// radius returns the radius of a bubble by linear interpolation.
func (bs *Bubbles) radius(z float64) vg.Length {
rng := bs.MaxRadius - bs.MinRadius
if bs.MaxZ == bs.MinZ {
return rng/2 + bs.MinRadius
}
d := (z - bs.MinZ) / (bs.MaxZ - bs.MinZ)
return vg.Length(d)*rng + bs.MinRadius
}
开发者ID:jackielii,项目名称:go-plotinum,代码行数:9,代码来源:bubbles.go
示例9: 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 (da *DrawArea) FillText(sty TextStyle, x, y vg.Length, xalign, yalign float64, txt string) {
txt = strings.TrimRight(txt, "\n")
if len(txt) == 0 {
return
}
da.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)
da.FillString(sty.Font, x+xoffs, y+n*sty.Font.Size, line)
}
}
开发者ID:jen6,项目名称:plotinum,代码行数:21,代码来源:draw.go
示例10: 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:jackielii,项目名称:go-plotinum,代码行数:28,代码来源:vgpdf.go
示例11: 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)
for left > 0 {
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:jackielii,项目名称:go-plotinum,代码行数:24,代码来源:vgpdf.go
示例12: padX
// padX returns a DrawArea that is padded horizontally
// so that glyphs will no be clipped.
func padX(p *Plot, da DrawArea) DrawArea {
glyphs := p.GlyphBoxes(p)
l := leftMost(&da, glyphs)
xAxis := horizontalAxis{p.X}
glyphs = append(glyphs, xAxis.GlyphBoxes(p)...)
r := rightMost(&da, glyphs)
minx := da.Min.X - l.Min.X
maxx := da.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 DrawArea{
Canvas: vg.Canvas(da),
Rect: Rect{
Min: Point{X: n, Y: da.Min.Y},
Size: Point{X: m - n, Y: da.Size.Y},
},
}
}
开发者ID:jen6,项目名称:plotinum,代码行数:23,代码来源:plot.go
示例13: padY
// padY returns a DrawArea that is padded vertically
// so that glyphs will no be clipped.
func padY(p *Plot, da DrawArea) DrawArea {
glyphs := p.GlyphBoxes(p)
b := bottomMost(&da, glyphs)
yAxis := verticalAxis{p.Y}
glyphs = append(glyphs, yAxis.GlyphBoxes(p)...)
t := topMost(&da, glyphs)
miny := da.Min.Y - b.Min.Y
maxy := da.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 DrawArea{
Canvas: vg.Canvas(da),
Rect: Rect{
Min: Point{Y: n, X: da.Min.X},
Size: Point{Y: m - n, X: da.Size.X},
},
}
}
开发者ID:jen6,项目名称:plotinum,代码行数:23,代码来源:plot.go
示例14: tickLabelHeight
// tickLabelHeight returns height of the tick mark labels.
func tickLabelHeight(sty 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:jackielii,项目名称:go-plotinum,代码行数:14,代码来源:axis.go
示例15: Report
// Report builds up a plot of the response times of the requests
// in SVG format and writes it to out
func (r *TimingsPlotReporter) Report(out io.Writer) error {
timestamps := make([]time.Time, 0)
timings := make([]time.Duration, 0)
for e := r.responses.Front(); e != nil; e = e.Next() {
r := e.Value.(*result)
timestamps = append(timestamps, r.timestamp)
timings = append(timings, r.timing)
}
p, err := plot.New()
if err != nil {
return err
}
pts := make(plotter.XYs, len(timestamps))
for i := 0; i < len(pts); i++ {
pts[i].X = timestamps[i].Sub(timestamps[0]).Seconds()
pts[i].Y = timings[i].Seconds() * 1000
}
line, err := plotter.NewLine(pts)
if err != nil {
return err
}
line.Color = plotutil.Color(1)
p.Add(line)
p.X.Padding = vg.Length(3.0)
p.X.Label.Text = "Time elapsed"
p.Y.Padding = vg.Length(3.0)
p.Y.Label.Text = "Latency (ms)"
w, h := vg.Millimeters(float64(len(timestamps))), vg.Centimeters(12.0)
canvas := vgsvg.New(w, h)
p.Draw(plot.MakeDrawArea(canvas))
_, err = canvas.WriteTo(out)
return err
}
开发者ID:nodesocket,项目名称:vegeta,代码行数:41,代码来源:timings_plot_reporter.go
示例16: tickLabelWidth
// tickLabelWidth returns the width of the widest tick mark label.
func tickLabelWidth(sty 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:jackielii,项目名称:go-plotinum,代码行数:14,代码来源:axis.go
示例17: RunServer
//.........这里部分代码省略.........
c_comments := make(plotter.XYs, 0)
var last *fstopinfo.FSInfoHistory
first := true
cttotal := int32(0)
for _, ii := range d {
if ii.Item != nil {
cttotal++
if first {
p.Title.Text = strings.TrimSpace(ii.Item.Title)
first = false
}
if last != nil && last.Item != nil {
c_seeders = append(c_seeders, struct{ X, Y float64 }{float64(cttotal), float64(ii.Item.Seeders)})
c_leechers = append(c_leechers, struct{ X, Y float64 }{float64(cttotal), float64(ii.Item.Leechers)})
c_complete = append(c_complete, struct{ X, Y float64 }{float64(cttotal), float64(ii.Item.Complete - last.Item.Complete)})
c_comments = append(c_comments, struct{ X, Y float64 }{float64(cttotal), float64(ii.Item.Comments)})
}
last = ii
}
}
w.Header().Add("Content-Type", "image/png")
pl_seeders, err := plotter.NewLine(c_seeders)
if err != nil {
http.Error(w, err.Error(), 500)
return
}
pl_seeders.LineStyle.Width = vg.Length(1)
pl_seeders.LineStyle.Color = color.RGBA{R: 255, A: 255}
p.Add(pl_seeders)
p.Legend.Add("Seeders", pl_seeders)
pl_leechers, err := plotter.NewLine(c_leechers)
if err != nil {
http.Error(w, err.Error(), 500)
return
}
pl_leechers.LineStyle.Width = vg.Length(1)
pl_leechers.LineStyle.Color = color.RGBA{G: 255, A: 255}
p.Add(pl_leechers)
p.Legend.Add("Leechers", pl_leechers)
pl_complete, err := plotter.NewLine(c_complete)
if err != nil {
http.Error(w, err.Error(), 500)
return
}
pl_complete.LineStyle.Width = vg.Length(1)
pl_complete.LineStyle.Color = color.RGBA{B: 255, A: 255}
p.Add(pl_complete)
p.Legend.Add("@Complete", pl_complete)
pl_comments, err := plotter.NewLine(c_comments)
if err != nil {
http.Error(w, err.Error(), 500)
return
}
pl_comments.LineStyle.Width = vg.Length(1)
pl_comments.LineStyle.Color = color.RGBA{R: 255, B: 255, A: 255}
p.Add(pl_comments)
开发者ID:RangelReale,项目名称:filesharetop,代码行数:67,代码来源:server.go
示例18: Y
// Y returns the value of x, given in the unit range,
// in the drawing coordinates of this draw area.
// A value of 0, for example, will return the minimum
// y value of the draw area and a value of 1 will
// return the maximum.
func (da *DrawArea) Y(y float64) vg.Length {
return vg.Length(y)*(da.Max().Y-da.Min.Y) + da.Min.Y
}
开发者ID:jen6,项目名称:plotinum,代码行数:8,代码来源:draw.go
示例19: X
// X returns the value of x, given in the unit range,
// in the drawing coordinates of this draw area.
// A value of 0, for example, will return the minimum
// x value of the draw area and a value of 1 will
// return the maximum.
func (da *DrawArea) X(x float64) vg.Length {
return vg.Length(x)*(da.Max().X-da.Min.X) + da.Min.X
}
开发者ID:jen6,项目名称:plotinum,代码行数:8,代码来源:draw.go
示例20: DrawGlyph
// RingGlyph is a glyph that draws the outline of a circle.
type RingGlyph struct{}
// DrawGlyph implements the Glyph interface.
func (RingGlyph) DrawGlyph(da *DrawArea, sty GlyphStyle, pt Point) {
da.SetLineStyle(LineStyle{Color: sty.Color, Width: vg.Points(0.5)})
var p vg.Path
p.Move(pt.X+sty.Radius, pt.Y)
p.Arc(pt.X, pt.Y, sty.Radius, 0, 2*math.Pi)
p.Close()
da.Stroke(p)
}
const (
cosπover4 = vg.Length(.707106781202420)
sinπover6 = vg.Length(.500000000025921)
cosπover6 = vg.Length(.866025403769473)
)
// SquareGlyph is a glyph that draws the outline of a square.
type SquareGlyph struct{}
// DrawGlyph implements the Glyph interface.
func (SquareGlyph) DrawGlyph(da *DrawArea, sty GlyphStyle, pt Point) {
da.SetLineStyle(LineStyle{Color: sty.Color, Width: vg.Points(0.5)})
x := (sty.Radius-sty.Radius*cosπover4)/2 + sty.Radius*cosπover4
var p vg.Path
p.Move(pt.X-x, pt.Y-x)
p.Line(pt.X+x, pt.Y-x)
p.Line(pt.X+x, pt.Y+x)
开发者ID:jen6,项目名称:plotinum,代码行数:30,代码来源:draw.go
注:本文中的code/google/com/p/plotinum/vg.Length函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论