示例#1
0
文件: plot.go 项目: vron/plotinum
// New returns a new plot with some reasonable
// default settings.
func New() (*Plot, error) {
	titleFont, err := vg.MakeFont(defaultFont, 12)
	if err != nil {
		return nil, err
	}
	x, err := makeAxis()
	if err != nil {
		return nil, err
	}
	y, err := makeAxis()
	if err != nil {
		return nil, err
	}
	legend, err := makeLegend()
	if err != nil {
		return nil, err
	}
	p := &Plot{
		BackgroundColor: color.White,
		X:               x,
		Y:               y,
		Legend:          legend,
	}
	p.Title.TextStyle = TextStyle{
		Color: color.Black,
		Font:  titleFont,
	}
	return p, nil
}
示例#2
0
文件: legend.go 项目: vron/plotinum
// makeLegend returns a legend with the default
// parameter settings.
func makeLegend() (Legend, error) {
	font, err := vg.MakeFont(defaultFont, vg.Points(12))
	if err != nil {
		return Legend{}, err
	}
	return Legend{
		ThumbnailWidth: vg.Points(20),
		TextStyle:      TextStyle{Font: font},
	}, nil
}
示例#3
0
文件: axis.go 项目: vron/plotinum
// makeAxis returns a default Axis.
//
// The default range is (∞, ­∞), and thus any finite
// value is less than Min and greater than Max.
func makeAxis() (Axis, error) {
	labelFont, err := vg.MakeFont(defaultFont, vg.Points(12))
	if err != nil {
		return Axis{}, err
	}

	tickFont, err := vg.MakeFont(defaultFont, vg.Points(10))
	if err != nil {
		return Axis{}, err
	}

	a := Axis{
		Min: math.Inf(1),
		Max: math.Inf(-1),
		LineStyle: LineStyle{
			Color: color.Black,
			Width: vg.Points(0.5),
		},
		Padding: vg.Points(5),
	}
	a.Label.TextStyle = TextStyle{
		Color: color.Black,
		Font:  labelFont,
	}
	a.Tick.Label = TextStyle{
		Color: color.Black,
		Font:  tickFont,
	}
	a.Tick.LineStyle = LineStyle{
		Color: color.Black,
		Width: vg.Points(0.5),
	}
	a.Tick.Length = vg.Points(8)
	a.Tick.Marker = DefaultTicks

	return a, nil
}
示例#4
0
文件: labels.go 项目: vron/plotinum
// NewLabels returns a new Labels using
// the DefaultFont and the DefaultFontSize.
// An error may be returned if there is an
// error loading the default font.
func NewLabels(d interface {
	XYer
	Labeller
}) (*Labels, error) {
	fnt, err := vg.MakeFont(DefaultFont, DefaultFontSize)
	if err != nil {
		return nil, err
	}
	strs := make([]string, d.Len())
	for i := range strs {
		strs[i] = d.Label(i)
	}
	return &Labels{
		XYs:       CopyXYs(d),
		Labels:    strs,
		TextStyle: plot.TextStyle{Font: fnt},
	}, nil
}