func (lbl *Label) labels(c draw.Canvas, p *plot.Plot) *plotter.Labels {
	if lbl.plt != nil {
		return lbl.plt
	}

	var (
		x = lbl.X
		y = lbl.Y

		err error
	)

	if lbl.Normalized {
		// Check whether the label fits in the canvas
		box := lbl.TextStyle.Rectangle(lbl.Text)
		rect := c.Rectangle.Size()
		xmax := lbl.X + box.Max.X.Points()/rect.X.Points()
		ymax := lbl.Y + box.Max.Y.Points()/rect.Y.Points()
		if xmax > 1 || ymax > 1 {
			switch {
			case lbl.AutoAdjust:
				x, y = lbl.adjust(1/rect.X.Points(), 1/rect.Y.Points())
			default:
				panic(fmt.Errorf(
					"hplot: label (%g, %g) falls outside data canvas",
					x, y,
				))
			}
		}

		// Turn relative into absolute coordinates
		x = lbl.scale(x, p.X.Min, p.X.Max, p.X.Scale)
		y = lbl.scale(y, p.Y.Min, p.Y.Max, p.Y.Scale)
	}

	lbl.plt, err = plotter.NewLabels(plotter.XYLabels{
		XYs:    []plotter.XY{{X: x, Y: y}},
		Labels: []string{lbl.Text},
	})
	if err != nil {
		panic(fmt.Errorf("hplot: could not create labels: %w", err))
	}

	lbl.plt.TextStyle = []draw.TextStyle{lbl.TextStyle}

	return lbl.plt
}
// Internal helper function to get plotter.Labels type.
Internal helper function to get plotter.Labels type.
// Internal helper function to get plotter . Labels type .
func (lbl *Label) labels(c draw.Canvas, p *plot.Plot) *plotter.Labels {
	if lbl.plt != nil {
		return lbl.plt
	}
	var (
		x = lbl.X
		y = lbl.Y
		err error
	)
	if lbl.Normalized {
		box := lbl.TextStyle.Rectangle(lbl.Text)
		rect := c.Rectangle.Size()
		xmax := lbl.X + box.Max.X.Points()/rect.X.Points()
		ymax := lbl.Y + box.Max.Y.Points()/rect.Y.Points()
		if xmax > 1 || ymax > 1 {
			switch {
			case lbl.AutoAdjust:
				x, y = lbl.adjust(1/rect.X.Points(), 1/rect.Y.Points())
			default:
				panic(fmt.Errorf(
					"hplot: label (%g, %g) falls outside data canvas",
					x, y,
				))
			}
		}
		x = lbl.scale(x, p.X.Min, p.X.Max, p.X.Scale)
		y = lbl.scale(y, p.Y.Min, p.Y.Max, p.Y.Scale)
	}
	lbl.plt, err = plotter.NewLabels(plotter.XYLabels{
		XYs:    []plotter.XY{{X: x, Y: y}},
		Labels: []string{lbl.Text},
	})
	if err != nil {
		panic(fmt.Errorf("hplot: could not create labels: %w", err))
	}
	lbl.plt.TextStyle = []draw.TextStyle{lbl.TextStyle}
	return lbl.plt
}
func ( lbl * Label ) labels ( c draw . Canvas , p * plot . Plot ) * plotter . Labels { if lbl . plt != nil { return lbl . plt } var ( x = lbl . X y = lbl . Y err error ) if lbl . Normalized { box := lbl . TextStyle . Rectangle ( lbl . Text ) rect := c . Rectangle . Size ( ) xmax := lbl . X + box . Max . X . Points ( ) / rect . X . Points ( ) ymax := lbl . Y + box . Max . Y . Points ( ) / rect . Y . Points ( ) if xmax > 1 || ymax > 1 { switch { case lbl . AutoAdjust : x , y = lbl . adjust ( 1 / rect . X . Points ( ) , 1 / rect . Y . Points ( ) ) default : panic ( fmt . Errorf ( " " , x , y , ) ) } } x = lbl . scale ( x , p . X . Min , p . X . Max , p . X . Scale ) y = lbl . scale ( y , p . Y . Min , p . Y . Max , p . Y . Scale ) } lbl . plt , err = plotter . NewLabels ( plotter . XYLabels { XYs : [ ] plotter . XY { { X : x , Y : y } } , Labels : [ ] string { lbl . Text } , } ) if err != nil { panic ( fmt . Errorf ( " " , err ) ) } lbl . plt . TextStyle = [ ] draw . TextStyle { lbl . TextStyle } return lbl . plt }
Internal helper function to get plotter.Labels type.
Internal helper function to get plotter . Labels type .
// Check whether the label fits in the canvas // Turn relative into absolute coordinates