repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1 value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
wcharczuk/go-chart | polynomial_regression_series.go | GetValues | func (prs *PolynomialRegressionSeries) GetValues(index int) (x, y float64) {
if prs.InnerSeries == nil || prs.InnerSeries.Len() == 0 {
return
}
if prs.coeffs == nil {
coeffs, err := prs.computeCoefficients()
if err != nil {
panic(err)
}
prs.coeffs = coeffs
}
offset := prs.GetOffset()
effectiveIndex := util.Math.MinInt(index+offset, prs.InnerSeries.Len())
x, y = prs.InnerSeries.GetValues(effectiveIndex)
y = prs.apply(x)
return
} | go | func (prs *PolynomialRegressionSeries) GetValues(index int) (x, y float64) {
if prs.InnerSeries == nil || prs.InnerSeries.Len() == 0 {
return
}
if prs.coeffs == nil {
coeffs, err := prs.computeCoefficients()
if err != nil {
panic(err)
}
prs.coeffs = coeffs
}
offset := prs.GetOffset()
effectiveIndex := util.Math.MinInt(index+offset, prs.InnerSeries.Len())
x, y = prs.InnerSeries.GetValues(effectiveIndex)
y = prs.apply(x)
return
} | [
"func",
"(",
"prs",
"*",
"PolynomialRegressionSeries",
")",
"GetValues",
"(",
"index",
"int",
")",
"(",
"x",
",",
"y",
"float64",
")",
"{",
"if",
"prs",
".",
"InnerSeries",
"==",
"nil",
"||",
"prs",
".",
"InnerSeries",
".",
"Len",
"(",
")",
"==",
"0"... | // GetValues returns the series value for a given index. | [
"GetValues",
"returns",
"the",
"series",
"value",
"for",
"a",
"given",
"index",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/polynomial_regression_series.go#L91-L109 | train |
wcharczuk/go-chart | polynomial_regression_series.go | GetFirstValues | func (prs *PolynomialRegressionSeries) GetFirstValues() (x, y float64) {
if prs.InnerSeries == nil || prs.InnerSeries.Len() == 0 {
return
}
if prs.coeffs == nil {
coeffs, err := prs.computeCoefficients()
if err != nil {
panic(err)
}
prs.coeffs = coeffs
}
x, y = prs.InnerSeries.GetValues(0)
y = prs.apply(x)
return
} | go | func (prs *PolynomialRegressionSeries) GetFirstValues() (x, y float64) {
if prs.InnerSeries == nil || prs.InnerSeries.Len() == 0 {
return
}
if prs.coeffs == nil {
coeffs, err := prs.computeCoefficients()
if err != nil {
panic(err)
}
prs.coeffs = coeffs
}
x, y = prs.InnerSeries.GetValues(0)
y = prs.apply(x)
return
} | [
"func",
"(",
"prs",
"*",
"PolynomialRegressionSeries",
")",
"GetFirstValues",
"(",
")",
"(",
"x",
",",
"y",
"float64",
")",
"{",
"if",
"prs",
".",
"InnerSeries",
"==",
"nil",
"||",
"prs",
".",
"InnerSeries",
".",
"Len",
"(",
")",
"==",
"0",
"{",
"ret... | // GetFirstValues computes the first poly regression value. | [
"GetFirstValues",
"computes",
"the",
"first",
"poly",
"regression",
"value",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/polynomial_regression_series.go#L112-L126 | train |
wcharczuk/go-chart | polynomial_regression_series.go | GetLastValues | func (prs *PolynomialRegressionSeries) GetLastValues() (x, y float64) {
if prs.InnerSeries == nil || prs.InnerSeries.Len() == 0 {
return
}
if prs.coeffs == nil {
coeffs, err := prs.computeCoefficients()
if err != nil {
panic(err)
}
prs.coeffs = coeffs
}
endIndex := prs.GetEndIndex()
x, y = prs.InnerSeries.GetValues(endIndex)
y = prs.apply(x)
return
} | go | func (prs *PolynomialRegressionSeries) GetLastValues() (x, y float64) {
if prs.InnerSeries == nil || prs.InnerSeries.Len() == 0 {
return
}
if prs.coeffs == nil {
coeffs, err := prs.computeCoefficients()
if err != nil {
panic(err)
}
prs.coeffs = coeffs
}
endIndex := prs.GetEndIndex()
x, y = prs.InnerSeries.GetValues(endIndex)
y = prs.apply(x)
return
} | [
"func",
"(",
"prs",
"*",
"PolynomialRegressionSeries",
")",
"GetLastValues",
"(",
")",
"(",
"x",
",",
"y",
"float64",
")",
"{",
"if",
"prs",
".",
"InnerSeries",
"==",
"nil",
"||",
"prs",
".",
"InnerSeries",
".",
"Len",
"(",
")",
"==",
"0",
"{",
"retu... | // GetLastValues computes the last poly regression value. | [
"GetLastValues",
"computes",
"the",
"last",
"poly",
"regression",
"value",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/polynomial_regression_series.go#L129-L144 | train |
wcharczuk/go-chart | jet.go | Jet | func Jet(v, vmin, vmax float64) drawing.Color {
c := drawing.Color{R: 0xff, G: 0xff, B: 0xff, A: 0xff} // white
var dv float64
if v < vmin {
v = vmin
}
if v > vmax {
v = vmax
}
dv = vmax - vmin
if v < (vmin + 0.25*dv) {
c.R = 0
c.G = drawing.ColorChannelFromFloat(4 * (v - vmin) / dv)
} else if v < (vmin + 0.5*dv) {
c.R = 0
c.B = drawing.ColorChannelFromFloat(1 + 4*(vmin+0.25*dv-v)/dv)
} else if v < (vmin + 0.75*dv) {
c.R = drawing.ColorChannelFromFloat(4 * (v - vmin - 0.5*dv) / dv)
c.B = 0
} else {
c.G = drawing.ColorChannelFromFloat(1 + 4*(vmin+0.75*dv-v)/dv)
c.B = 0
}
return c
} | go | func Jet(v, vmin, vmax float64) drawing.Color {
c := drawing.Color{R: 0xff, G: 0xff, B: 0xff, A: 0xff} // white
var dv float64
if v < vmin {
v = vmin
}
if v > vmax {
v = vmax
}
dv = vmax - vmin
if v < (vmin + 0.25*dv) {
c.R = 0
c.G = drawing.ColorChannelFromFloat(4 * (v - vmin) / dv)
} else if v < (vmin + 0.5*dv) {
c.R = 0
c.B = drawing.ColorChannelFromFloat(1 + 4*(vmin+0.25*dv-v)/dv)
} else if v < (vmin + 0.75*dv) {
c.R = drawing.ColorChannelFromFloat(4 * (v - vmin - 0.5*dv) / dv)
c.B = 0
} else {
c.G = drawing.ColorChannelFromFloat(1 + 4*(vmin+0.75*dv-v)/dv)
c.B = 0
}
return c
} | [
"func",
"Jet",
"(",
"v",
",",
"vmin",
",",
"vmax",
"float64",
")",
"drawing",
".",
"Color",
"{",
"c",
":=",
"drawing",
".",
"Color",
"{",
"R",
":",
"0xff",
",",
"G",
":",
"0xff",
",",
"B",
":",
"0xff",
",",
"A",
":",
"0xff",
"}",
"// white",
... | // Jet is a color map provider based on matlab's jet color map. | [
"Jet",
"is",
"a",
"color",
"map",
"provider",
"based",
"on",
"matlab",
"s",
"jet",
"color",
"map",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/jet.go#L6-L33 | train |
wcharczuk/go-chart | drawing/color.go | ColorFromHex | func ColorFromHex(hex string) Color {
var c Color
if len(hex) == 3 {
c.R = parseHex(string(hex[0])) * 0x11
c.G = parseHex(string(hex[1])) * 0x11
c.B = parseHex(string(hex[2])) * 0x11
} else {
c.R = parseHex(string(hex[0:2]))
c.G = parseHex(string(hex[2:4]))
c.B = parseHex(string(hex[4:6]))
}
c.A = 255
return c
} | go | func ColorFromHex(hex string) Color {
var c Color
if len(hex) == 3 {
c.R = parseHex(string(hex[0])) * 0x11
c.G = parseHex(string(hex[1])) * 0x11
c.B = parseHex(string(hex[2])) * 0x11
} else {
c.R = parseHex(string(hex[0:2]))
c.G = parseHex(string(hex[2:4]))
c.B = parseHex(string(hex[4:6]))
}
c.A = 255
return c
} | [
"func",
"ColorFromHex",
"(",
"hex",
"string",
")",
"Color",
"{",
"var",
"c",
"Color",
"\n",
"if",
"len",
"(",
"hex",
")",
"==",
"3",
"{",
"c",
".",
"R",
"=",
"parseHex",
"(",
"string",
"(",
"hex",
"[",
"0",
"]",
")",
")",
"*",
"0x11",
"\n",
"... | // ColorFromHex returns a color from a css hex code. | [
"ColorFromHex",
"returns",
"a",
"color",
"from",
"a",
"css",
"hex",
"code",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/color.go#L34-L47 | train |
wcharczuk/go-chart | drawing/color.go | ColorFromAlphaMixedRGBA | func ColorFromAlphaMixedRGBA(r, g, b, a uint32) Color {
fa := float64(a) / 255.0
var c Color
c.R = uint8(float64(r) / fa)
c.G = uint8(float64(g) / fa)
c.B = uint8(float64(b) / fa)
c.A = uint8(a | (a >> 8))
return c
} | go | func ColorFromAlphaMixedRGBA(r, g, b, a uint32) Color {
fa := float64(a) / 255.0
var c Color
c.R = uint8(float64(r) / fa)
c.G = uint8(float64(g) / fa)
c.B = uint8(float64(b) / fa)
c.A = uint8(a | (a >> 8))
return c
} | [
"func",
"ColorFromAlphaMixedRGBA",
"(",
"r",
",",
"g",
",",
"b",
",",
"a",
"uint32",
")",
"Color",
"{",
"fa",
":=",
"float64",
"(",
"a",
")",
"/",
"255.0",
"\n",
"var",
"c",
"Color",
"\n",
"c",
".",
"R",
"=",
"uint8",
"(",
"float64",
"(",
"r",
... | // ColorFromAlphaMixedRGBA returns the system alpha mixed rgba values. | [
"ColorFromAlphaMixedRGBA",
"returns",
"the",
"system",
"alpha",
"mixed",
"rgba",
"values",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/color.go#L50-L58 | train |
wcharczuk/go-chart | drawing/color.go | RGBA | func (c Color) RGBA() (r, g, b, a uint32) {
fa := float64(c.A) / 255.0
r = uint32(float64(uint32(c.R)) * fa)
r |= r << 8
g = uint32(float64(uint32(c.G)) * fa)
g |= g << 8
b = uint32(float64(uint32(c.B)) * fa)
b |= b << 8
a = uint32(c.A)
a |= a << 8
return
} | go | func (c Color) RGBA() (r, g, b, a uint32) {
fa := float64(c.A) / 255.0
r = uint32(float64(uint32(c.R)) * fa)
r |= r << 8
g = uint32(float64(uint32(c.G)) * fa)
g |= g << 8
b = uint32(float64(uint32(c.B)) * fa)
b |= b << 8
a = uint32(c.A)
a |= a << 8
return
} | [
"func",
"(",
"c",
"Color",
")",
"RGBA",
"(",
")",
"(",
"r",
",",
"g",
",",
"b",
",",
"a",
"uint32",
")",
"{",
"fa",
":=",
"float64",
"(",
"c",
".",
"A",
")",
"/",
"255.0",
"\n",
"r",
"=",
"uint32",
"(",
"float64",
"(",
"uint32",
"(",
"c",
... | // RGBA returns the color as a pre-alpha mixed color set. | [
"RGBA",
"returns",
"the",
"color",
"as",
"a",
"pre",
"-",
"alpha",
"mixed",
"color",
"set",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/color.go#L71-L82 | train |
wcharczuk/go-chart | drawing/color.go | IsZero | func (c Color) IsZero() bool {
return c.R == 0 && c.G == 0 && c.B == 0 && c.A == 0
} | go | func (c Color) IsZero() bool {
return c.R == 0 && c.G == 0 && c.B == 0 && c.A == 0
} | [
"func",
"(",
"c",
"Color",
")",
"IsZero",
"(",
")",
"bool",
"{",
"return",
"c",
".",
"R",
"==",
"0",
"&&",
"c",
".",
"G",
"==",
"0",
"&&",
"c",
".",
"B",
"==",
"0",
"&&",
"c",
".",
"A",
"==",
"0",
"\n",
"}"
] | // IsZero returns if the color has been set or not. | [
"IsZero",
"returns",
"if",
"the",
"color",
"has",
"been",
"set",
"or",
"not",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/color.go#L85-L87 | train |
wcharczuk/go-chart | drawing/color.go | WithAlpha | func (c Color) WithAlpha(a uint8) Color {
return Color{
R: c.R,
G: c.G,
B: c.B,
A: a,
}
} | go | func (c Color) WithAlpha(a uint8) Color {
return Color{
R: c.R,
G: c.G,
B: c.B,
A: a,
}
} | [
"func",
"(",
"c",
"Color",
")",
"WithAlpha",
"(",
"a",
"uint8",
")",
"Color",
"{",
"return",
"Color",
"{",
"R",
":",
"c",
".",
"R",
",",
"G",
":",
"c",
".",
"G",
",",
"B",
":",
"c",
".",
"B",
",",
"A",
":",
"a",
",",
"}",
"\n",
"}"
] | // WithAlpha returns a copy of the color with a given alpha. | [
"WithAlpha",
"returns",
"a",
"copy",
"of",
"the",
"color",
"with",
"a",
"given",
"alpha",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/color.go#L95-L102 | train |
wcharczuk/go-chart | drawing/color.go | Equals | func (c Color) Equals(other Color) bool {
return c.R == other.R &&
c.G == other.G &&
c.B == other.B &&
c.A == other.A
} | go | func (c Color) Equals(other Color) bool {
return c.R == other.R &&
c.G == other.G &&
c.B == other.B &&
c.A == other.A
} | [
"func",
"(",
"c",
"Color",
")",
"Equals",
"(",
"other",
"Color",
")",
"bool",
"{",
"return",
"c",
".",
"R",
"==",
"other",
".",
"R",
"&&",
"c",
".",
"G",
"==",
"other",
".",
"G",
"&&",
"c",
".",
"B",
"==",
"other",
".",
"B",
"&&",
"c",
".",... | // Equals returns true if the color equals another. | [
"Equals",
"returns",
"true",
"if",
"the",
"color",
"equals",
"another",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/color.go#L105-L110 | train |
wcharczuk/go-chart | drawing/color.go | AverageWith | func (c Color) AverageWith(other Color) Color {
return Color{
R: (c.R + other.R) >> 1,
G: (c.G + other.G) >> 1,
B: (c.B + other.B) >> 1,
A: c.A,
}
} | go | func (c Color) AverageWith(other Color) Color {
return Color{
R: (c.R + other.R) >> 1,
G: (c.G + other.G) >> 1,
B: (c.B + other.B) >> 1,
A: c.A,
}
} | [
"func",
"(",
"c",
"Color",
")",
"AverageWith",
"(",
"other",
"Color",
")",
"Color",
"{",
"return",
"Color",
"{",
"R",
":",
"(",
"c",
".",
"R",
"+",
"other",
".",
"R",
")",
">>",
"1",
",",
"G",
":",
"(",
"c",
".",
"G",
"+",
"other",
".",
"G"... | // AverageWith averages two colors. | [
"AverageWith",
"averages",
"two",
"colors",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/color.go#L113-L120 | train |
wcharczuk/go-chart | drawing/color.go | String | func (c Color) String() string {
fa := float64(c.A) / float64(255)
return fmt.Sprintf("rgba(%v,%v,%v,%.1f)", c.R, c.G, c.B, fa)
} | go | func (c Color) String() string {
fa := float64(c.A) / float64(255)
return fmt.Sprintf("rgba(%v,%v,%v,%.1f)", c.R, c.G, c.B, fa)
} | [
"func",
"(",
"c",
"Color",
")",
"String",
"(",
")",
"string",
"{",
"fa",
":=",
"float64",
"(",
"c",
".",
"A",
")",
"/",
"float64",
"(",
"255",
")",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"c",
".",
"R",
",",
"c",
".",
"... | // String returns a css string representation of the color. | [
"String",
"returns",
"a",
"css",
"string",
"representation",
"of",
"the",
"color",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/color.go#L123-L126 | train |
wcharczuk/go-chart | annotation_series.go | Measure | func (as AnnotationSeries) Measure(r Renderer, canvasBox Box, xrange, yrange Range, defaults Style) Box {
box := Box{
Top: math.MaxInt32,
Left: math.MaxInt32,
Right: 0,
Bottom: 0,
}
if as.Style.IsZero() || as.Style.Show {
seriesStyle := as.Style.InheritFrom(as.annotationStyleDefaults(defaults))
for _, a := range as.Annotations {
style := a.Style.InheritFrom(seriesStyle)
lx := canvasBox.Left + xrange.Translate(a.XValue)
ly := canvasBox.Bottom - yrange.Translate(a.YValue)
ab := Draw.MeasureAnnotation(r, canvasBox, style, lx, ly, a.Label)
box.Top = util.Math.MinInt(box.Top, ab.Top)
box.Left = util.Math.MinInt(box.Left, ab.Left)
box.Right = util.Math.MaxInt(box.Right, ab.Right)
box.Bottom = util.Math.MaxInt(box.Bottom, ab.Bottom)
}
}
return box
} | go | func (as AnnotationSeries) Measure(r Renderer, canvasBox Box, xrange, yrange Range, defaults Style) Box {
box := Box{
Top: math.MaxInt32,
Left: math.MaxInt32,
Right: 0,
Bottom: 0,
}
if as.Style.IsZero() || as.Style.Show {
seriesStyle := as.Style.InheritFrom(as.annotationStyleDefaults(defaults))
for _, a := range as.Annotations {
style := a.Style.InheritFrom(seriesStyle)
lx := canvasBox.Left + xrange.Translate(a.XValue)
ly := canvasBox.Bottom - yrange.Translate(a.YValue)
ab := Draw.MeasureAnnotation(r, canvasBox, style, lx, ly, a.Label)
box.Top = util.Math.MinInt(box.Top, ab.Top)
box.Left = util.Math.MinInt(box.Left, ab.Left)
box.Right = util.Math.MaxInt(box.Right, ab.Right)
box.Bottom = util.Math.MaxInt(box.Bottom, ab.Bottom)
}
}
return box
} | [
"func",
"(",
"as",
"AnnotationSeries",
")",
"Measure",
"(",
"r",
"Renderer",
",",
"canvasBox",
"Box",
",",
"xrange",
",",
"yrange",
"Range",
",",
"defaults",
"Style",
")",
"Box",
"{",
"box",
":=",
"Box",
"{",
"Top",
":",
"math",
".",
"MaxInt32",
",",
... | // Measure returns a bounds box of the series. | [
"Measure",
"returns",
"a",
"bounds",
"box",
"of",
"the",
"series",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/annotation_series.go#L51-L72 | train |
wcharczuk/go-chart | annotation_series.go | Render | func (as AnnotationSeries) Render(r Renderer, canvasBox Box, xrange, yrange Range, defaults Style) {
if as.Style.IsZero() || as.Style.Show {
seriesStyle := as.Style.InheritFrom(as.annotationStyleDefaults(defaults))
for _, a := range as.Annotations {
style := a.Style.InheritFrom(seriesStyle)
lx := canvasBox.Left + xrange.Translate(a.XValue)
ly := canvasBox.Bottom - yrange.Translate(a.YValue)
Draw.Annotation(r, canvasBox, style, lx, ly, a.Label)
}
}
} | go | func (as AnnotationSeries) Render(r Renderer, canvasBox Box, xrange, yrange Range, defaults Style) {
if as.Style.IsZero() || as.Style.Show {
seriesStyle := as.Style.InheritFrom(as.annotationStyleDefaults(defaults))
for _, a := range as.Annotations {
style := a.Style.InheritFrom(seriesStyle)
lx := canvasBox.Left + xrange.Translate(a.XValue)
ly := canvasBox.Bottom - yrange.Translate(a.YValue)
Draw.Annotation(r, canvasBox, style, lx, ly, a.Label)
}
}
} | [
"func",
"(",
"as",
"AnnotationSeries",
")",
"Render",
"(",
"r",
"Renderer",
",",
"canvasBox",
"Box",
",",
"xrange",
",",
"yrange",
"Range",
",",
"defaults",
"Style",
")",
"{",
"if",
"as",
".",
"Style",
".",
"IsZero",
"(",
")",
"||",
"as",
".",
"Style... | // Render draws the series. | [
"Render",
"draws",
"the",
"series",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/annotation_series.go#L75-L85 | train |
wcharczuk/go-chart | drawing/line.go | PolylineBresenham | func PolylineBresenham(img draw.Image, c color.Color, s ...float64) {
for i := 2; i < len(s); i += 2 {
Bresenham(img, c, int(s[i-2]+0.5), int(s[i-1]+0.5), int(s[i]+0.5), int(s[i+1]+0.5))
}
} | go | func PolylineBresenham(img draw.Image, c color.Color, s ...float64) {
for i := 2; i < len(s); i += 2 {
Bresenham(img, c, int(s[i-2]+0.5), int(s[i-1]+0.5), int(s[i]+0.5), int(s[i+1]+0.5))
}
} | [
"func",
"PolylineBresenham",
"(",
"img",
"draw",
".",
"Image",
",",
"c",
"color",
".",
"Color",
",",
"s",
"...",
"float64",
")",
"{",
"for",
"i",
":=",
"2",
";",
"i",
"<",
"len",
"(",
"s",
")",
";",
"i",
"+=",
"2",
"{",
"Bresenham",
"(",
"img",... | // PolylineBresenham draws a polyline to an image | [
"PolylineBresenham",
"draws",
"a",
"polyline",
"to",
"an",
"image"
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/line.go#L9-L13 | train |
wcharczuk/go-chart | drawing/matrix.go | Transform | func (tr Matrix) Transform(points []float64) {
for i, j := 0, 1; j < len(points); i, j = i+2, j+2 {
x := points[i]
y := points[j]
points[i] = x*tr[0] + y*tr[2] + tr[4]
points[j] = x*tr[1] + y*tr[3] + tr[5]
}
} | go | func (tr Matrix) Transform(points []float64) {
for i, j := 0, 1; j < len(points); i, j = i+2, j+2 {
x := points[i]
y := points[j]
points[i] = x*tr[0] + y*tr[2] + tr[4]
points[j] = x*tr[1] + y*tr[3] + tr[5]
}
} | [
"func",
"(",
"tr",
"Matrix",
")",
"Transform",
"(",
"points",
"[",
"]",
"float64",
")",
"{",
"for",
"i",
",",
"j",
":=",
"0",
",",
"1",
";",
"j",
"<",
"len",
"(",
"points",
")",
";",
"i",
",",
"j",
"=",
"i",
"+",
"2",
",",
"j",
"+",
"2",
... | // Transform applies the transformation matrix to points. It modify the points passed in parameter. | [
"Transform",
"applies",
"the",
"transformation",
"matrix",
"to",
"points",
".",
"It",
"modify",
"the",
"points",
"passed",
"in",
"parameter",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/matrix.go#L20-L27 | train |
wcharczuk/go-chart | drawing/matrix.go | TransformPoint | func (tr Matrix) TransformPoint(x, y float64) (xres, yres float64) {
xres = x*tr[0] + y*tr[2] + tr[4]
yres = x*tr[1] + y*tr[3] + tr[5]
return xres, yres
} | go | func (tr Matrix) TransformPoint(x, y float64) (xres, yres float64) {
xres = x*tr[0] + y*tr[2] + tr[4]
yres = x*tr[1] + y*tr[3] + tr[5]
return xres, yres
} | [
"func",
"(",
"tr",
"Matrix",
")",
"TransformPoint",
"(",
"x",
",",
"y",
"float64",
")",
"(",
"xres",
",",
"yres",
"float64",
")",
"{",
"xres",
"=",
"x",
"*",
"tr",
"[",
"0",
"]",
"+",
"y",
"*",
"tr",
"[",
"2",
"]",
"+",
"tr",
"[",
"4",
"]",... | // TransformPoint applies the transformation matrix to point. It returns the point the transformed point. | [
"TransformPoint",
"applies",
"the",
"transformation",
"matrix",
"to",
"point",
".",
"It",
"returns",
"the",
"point",
"the",
"transformed",
"point",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/matrix.go#L30-L34 | train |
wcharczuk/go-chart | drawing/matrix.go | TransformRectangle | func (tr Matrix) TransformRectangle(x0, y0, x2, y2 float64) (nx0, ny0, nx2, ny2 float64) {
points := []float64{x0, y0, x2, y0, x2, y2, x0, y2}
tr.Transform(points)
points[0], points[2] = minMax(points[0], points[2])
points[4], points[6] = minMax(points[4], points[6])
points[1], points[3] = minMax(points[1], points[3])
points[5], points[7] = minMax(points[5], points[7])
nx0 = math.Min(points[0], points[4])
ny0 = math.Min(points[1], points[5])
nx2 = math.Max(points[2], points[6])
ny2 = math.Max(points[3], points[7])
return nx0, ny0, nx2, ny2
} | go | func (tr Matrix) TransformRectangle(x0, y0, x2, y2 float64) (nx0, ny0, nx2, ny2 float64) {
points := []float64{x0, y0, x2, y0, x2, y2, x0, y2}
tr.Transform(points)
points[0], points[2] = minMax(points[0], points[2])
points[4], points[6] = minMax(points[4], points[6])
points[1], points[3] = minMax(points[1], points[3])
points[5], points[7] = minMax(points[5], points[7])
nx0 = math.Min(points[0], points[4])
ny0 = math.Min(points[1], points[5])
nx2 = math.Max(points[2], points[6])
ny2 = math.Max(points[3], points[7])
return nx0, ny0, nx2, ny2
} | [
"func",
"(",
"tr",
"Matrix",
")",
"TransformRectangle",
"(",
"x0",
",",
"y0",
",",
"x2",
",",
"y2",
"float64",
")",
"(",
"nx0",
",",
"ny0",
",",
"nx2",
",",
"ny2",
"float64",
")",
"{",
"points",
":=",
"[",
"]",
"float64",
"{",
"x0",
",",
"y0",
... | // TransformRectangle applies the transformation matrix to the rectangle represented by the min and the max point of the rectangle | [
"TransformRectangle",
"applies",
"the",
"transformation",
"matrix",
"to",
"the",
"rectangle",
"represented",
"by",
"the",
"min",
"and",
"the",
"max",
"point",
"of",
"the",
"rectangle"
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/matrix.go#L44-L57 | train |
wcharczuk/go-chart | drawing/matrix.go | InverseTransform | func (tr Matrix) InverseTransform(points []float64) {
d := tr.Determinant() // matrix determinant
for i, j := 0, 1; j < len(points); i, j = i+2, j+2 {
x := points[i]
y := points[j]
points[i] = ((x-tr[4])*tr[3] - (y-tr[5])*tr[2]) / d
points[j] = ((y-tr[5])*tr[0] - (x-tr[4])*tr[1]) / d
}
} | go | func (tr Matrix) InverseTransform(points []float64) {
d := tr.Determinant() // matrix determinant
for i, j := 0, 1; j < len(points); i, j = i+2, j+2 {
x := points[i]
y := points[j]
points[i] = ((x-tr[4])*tr[3] - (y-tr[5])*tr[2]) / d
points[j] = ((y-tr[5])*tr[0] - (x-tr[4])*tr[1]) / d
}
} | [
"func",
"(",
"tr",
"Matrix",
")",
"InverseTransform",
"(",
"points",
"[",
"]",
"float64",
")",
"{",
"d",
":=",
"tr",
".",
"Determinant",
"(",
")",
"// matrix determinant",
"\n",
"for",
"i",
",",
"j",
":=",
"0",
",",
"1",
";",
"j",
"<",
"len",
"(",
... | // InverseTransform applies the transformation inverse matrix to the rectangle represented by the min and the max point of the rectangle | [
"InverseTransform",
"applies",
"the",
"transformation",
"inverse",
"matrix",
"to",
"the",
"rectangle",
"represented",
"by",
"the",
"min",
"and",
"the",
"max",
"point",
"of",
"the",
"rectangle"
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/matrix.go#L60-L68 | train |
wcharczuk/go-chart | drawing/matrix.go | InverseTransformPoint | func (tr Matrix) InverseTransformPoint(x, y float64) (xres, yres float64) {
d := tr.Determinant() // matrix determinant
xres = ((x-tr[4])*tr[3] - (y-tr[5])*tr[2]) / d
yres = ((y-tr[5])*tr[0] - (x-tr[4])*tr[1]) / d
return xres, yres
} | go | func (tr Matrix) InverseTransformPoint(x, y float64) (xres, yres float64) {
d := tr.Determinant() // matrix determinant
xres = ((x-tr[4])*tr[3] - (y-tr[5])*tr[2]) / d
yres = ((y-tr[5])*tr[0] - (x-tr[4])*tr[1]) / d
return xres, yres
} | [
"func",
"(",
"tr",
"Matrix",
")",
"InverseTransformPoint",
"(",
"x",
",",
"y",
"float64",
")",
"(",
"xres",
",",
"yres",
"float64",
")",
"{",
"d",
":=",
"tr",
".",
"Determinant",
"(",
")",
"// matrix determinant",
"\n",
"xres",
"=",
"(",
"(",
"x",
"-... | // InverseTransformPoint applies the transformation inverse matrix to point. It returns the point the transformed point. | [
"InverseTransformPoint",
"applies",
"the",
"transformation",
"inverse",
"matrix",
"to",
"point",
".",
"It",
"returns",
"the",
"point",
"the",
"transformed",
"point",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/matrix.go#L71-L76 | train |
wcharczuk/go-chart | drawing/matrix.go | NewRotationMatrix | func NewRotationMatrix(angle float64) Matrix {
c := math.Cos(angle)
s := math.Sin(angle)
return Matrix{c, s, -s, c, 0, 0}
} | go | func NewRotationMatrix(angle float64) Matrix {
c := math.Cos(angle)
s := math.Sin(angle)
return Matrix{c, s, -s, c, 0, 0}
} | [
"func",
"NewRotationMatrix",
"(",
"angle",
"float64",
")",
"Matrix",
"{",
"c",
":=",
"math",
".",
"Cos",
"(",
"angle",
")",
"\n",
"s",
":=",
"math",
".",
"Sin",
"(",
"angle",
")",
"\n",
"return",
"Matrix",
"{",
"c",
",",
"s",
",",
"-",
"s",
",",
... | // NewRotationMatrix creates a rotation transformation matrix. angle is in radian | [
"NewRotationMatrix",
"creates",
"a",
"rotation",
"transformation",
"matrix",
".",
"angle",
"is",
"in",
"radian"
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/matrix.go#L105-L109 | train |
wcharczuk/go-chart | drawing/matrix.go | NewMatrixFromRects | func NewMatrixFromRects(rectangle1, rectangle2 [4]float64) Matrix {
xScale := (rectangle2[2] - rectangle2[0]) / (rectangle1[2] - rectangle1[0])
yScale := (rectangle2[3] - rectangle2[1]) / (rectangle1[3] - rectangle1[1])
xOffset := rectangle2[0] - (rectangle1[0] * xScale)
yOffset := rectangle2[1] - (rectangle1[1] * yScale)
return Matrix{xScale, 0, 0, yScale, xOffset, yOffset}
} | go | func NewMatrixFromRects(rectangle1, rectangle2 [4]float64) Matrix {
xScale := (rectangle2[2] - rectangle2[0]) / (rectangle1[2] - rectangle1[0])
yScale := (rectangle2[3] - rectangle2[1]) / (rectangle1[3] - rectangle1[1])
xOffset := rectangle2[0] - (rectangle1[0] * xScale)
yOffset := rectangle2[1] - (rectangle1[1] * yScale)
return Matrix{xScale, 0, 0, yScale, xOffset, yOffset}
} | [
"func",
"NewMatrixFromRects",
"(",
"rectangle1",
",",
"rectangle2",
"[",
"4",
"]",
"float64",
")",
"Matrix",
"{",
"xScale",
":=",
"(",
"rectangle2",
"[",
"2",
"]",
"-",
"rectangle2",
"[",
"0",
"]",
")",
"/",
"(",
"rectangle1",
"[",
"2",
"]",
"-",
"re... | // NewMatrixFromRects creates a transformation matrix, combining a scale and a translation, that transform rectangle1 into rectangle2. | [
"NewMatrixFromRects",
"creates",
"a",
"transformation",
"matrix",
"combining",
"a",
"scale",
"and",
"a",
"translation",
"that",
"transform",
"rectangle1",
"into",
"rectangle2",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/matrix.go#L112-L118 | train |
wcharczuk/go-chart | drawing/matrix.go | Inverse | func (tr *Matrix) Inverse() {
d := tr.Determinant() // matrix determinant
tr0, tr1, tr2, tr3, tr4, tr5 := tr[0], tr[1], tr[2], tr[3], tr[4], tr[5]
tr[0] = tr3 / d
tr[1] = -tr1 / d
tr[2] = -tr2 / d
tr[3] = tr0 / d
tr[4] = (tr2*tr5 - tr3*tr4) / d
tr[5] = (tr1*tr4 - tr0*tr5) / d
} | go | func (tr *Matrix) Inverse() {
d := tr.Determinant() // matrix determinant
tr0, tr1, tr2, tr3, tr4, tr5 := tr[0], tr[1], tr[2], tr[3], tr[4], tr[5]
tr[0] = tr3 / d
tr[1] = -tr1 / d
tr[2] = -tr2 / d
tr[3] = tr0 / d
tr[4] = (tr2*tr5 - tr3*tr4) / d
tr[5] = (tr1*tr4 - tr0*tr5) / d
} | [
"func",
"(",
"tr",
"*",
"Matrix",
")",
"Inverse",
"(",
")",
"{",
"d",
":=",
"tr",
".",
"Determinant",
"(",
")",
"// matrix determinant",
"\n",
"tr0",
",",
"tr1",
",",
"tr2",
",",
"tr3",
",",
"tr4",
",",
"tr5",
":=",
"tr",
"[",
"0",
"]",
",",
"t... | // Inverse computes the inverse matrix | [
"Inverse",
"computes",
"the",
"inverse",
"matrix"
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/matrix.go#L121-L130 | train |
wcharczuk/go-chart | drawing/matrix.go | Copy | func (tr Matrix) Copy() Matrix {
var result Matrix
copy(result[:], tr[:])
return result
} | go | func (tr Matrix) Copy() Matrix {
var result Matrix
copy(result[:], tr[:])
return result
} | [
"func",
"(",
"tr",
"Matrix",
")",
"Copy",
"(",
")",
"Matrix",
"{",
"var",
"result",
"Matrix",
"\n",
"copy",
"(",
"result",
"[",
":",
"]",
",",
"tr",
"[",
":",
"]",
")",
"\n",
"return",
"result",
"\n",
"}"
] | // Copy copies the matrix. | [
"Copy",
"copies",
"the",
"matrix",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/matrix.go#L133-L137 | train |
wcharczuk/go-chart | drawing/matrix.go | Compose | func (tr *Matrix) Compose(trToCompose Matrix) {
tr0, tr1, tr2, tr3, tr4, tr5 := tr[0], tr[1], tr[2], tr[3], tr[4], tr[5]
tr[0] = trToCompose[0]*tr0 + trToCompose[1]*tr2
tr[1] = trToCompose[1]*tr3 + trToCompose[0]*tr1
tr[2] = trToCompose[2]*tr0 + trToCompose[3]*tr2
tr[3] = trToCompose[3]*tr3 + trToCompose[2]*tr1
tr[4] = trToCompose[4]*tr0 + trToCompose[5]*tr2 + tr4
tr[5] = trToCompose[5]*tr3 + trToCompose[4]*tr1 + tr5
} | go | func (tr *Matrix) Compose(trToCompose Matrix) {
tr0, tr1, tr2, tr3, tr4, tr5 := tr[0], tr[1], tr[2], tr[3], tr[4], tr[5]
tr[0] = trToCompose[0]*tr0 + trToCompose[1]*tr2
tr[1] = trToCompose[1]*tr3 + trToCompose[0]*tr1
tr[2] = trToCompose[2]*tr0 + trToCompose[3]*tr2
tr[3] = trToCompose[3]*tr3 + trToCompose[2]*tr1
tr[4] = trToCompose[4]*tr0 + trToCompose[5]*tr2 + tr4
tr[5] = trToCompose[5]*tr3 + trToCompose[4]*tr1 + tr5
} | [
"func",
"(",
"tr",
"*",
"Matrix",
")",
"Compose",
"(",
"trToCompose",
"Matrix",
")",
"{",
"tr0",
",",
"tr1",
",",
"tr2",
",",
"tr3",
",",
"tr4",
",",
"tr5",
":=",
"tr",
"[",
"0",
"]",
",",
"tr",
"[",
"1",
"]",
",",
"tr",
"[",
"2",
"]",
",",... | // Compose multiplies trToConcat x tr | [
"Compose",
"multiplies",
"trToConcat",
"x",
"tr"
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/matrix.go#L140-L148 | train |
wcharczuk/go-chart | drawing/matrix.go | Scale | func (tr *Matrix) Scale(sx, sy float64) {
tr[0] = sx * tr[0]
tr[1] = sx * tr[1]
tr[2] = sy * tr[2]
tr[3] = sy * tr[3]
} | go | func (tr *Matrix) Scale(sx, sy float64) {
tr[0] = sx * tr[0]
tr[1] = sx * tr[1]
tr[2] = sy * tr[2]
tr[3] = sy * tr[3]
} | [
"func",
"(",
"tr",
"*",
"Matrix",
")",
"Scale",
"(",
"sx",
",",
"sy",
"float64",
")",
"{",
"tr",
"[",
"0",
"]",
"=",
"sx",
"*",
"tr",
"[",
"0",
"]",
"\n",
"tr",
"[",
"1",
"]",
"=",
"sx",
"*",
"tr",
"[",
"1",
"]",
"\n",
"tr",
"[",
"2",
... | // Scale adds a scale to the matrix | [
"Scale",
"adds",
"a",
"scale",
"to",
"the",
"matrix"
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/matrix.go#L151-L156 | train |
wcharczuk/go-chart | drawing/matrix.go | Translate | func (tr *Matrix) Translate(tx, ty float64) {
tr[4] = tx*tr[0] + ty*tr[2] + tr[4]
tr[5] = ty*tr[3] + tx*tr[1] + tr[5]
} | go | func (tr *Matrix) Translate(tx, ty float64) {
tr[4] = tx*tr[0] + ty*tr[2] + tr[4]
tr[5] = ty*tr[3] + tx*tr[1] + tr[5]
} | [
"func",
"(",
"tr",
"*",
"Matrix",
")",
"Translate",
"(",
"tx",
",",
"ty",
"float64",
")",
"{",
"tr",
"[",
"4",
"]",
"=",
"tx",
"*",
"tr",
"[",
"0",
"]",
"+",
"ty",
"*",
"tr",
"[",
"2",
"]",
"+",
"tr",
"[",
"4",
"]",
"\n",
"tr",
"[",
"5"... | // Translate adds a translation to the matrix | [
"Translate",
"adds",
"a",
"translation",
"to",
"the",
"matrix"
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/matrix.go#L159-L162 | train |
wcharczuk/go-chart | drawing/matrix.go | Rotate | func (tr *Matrix) Rotate(radians float64) {
c := math.Cos(radians)
s := math.Sin(radians)
t0 := c*tr[0] + s*tr[2]
t1 := s*tr[3] + c*tr[1]
t2 := c*tr[2] - s*tr[0]
t3 := c*tr[3] - s*tr[1]
tr[0] = t0
tr[1] = t1
tr[2] = t2
tr[3] = t3
} | go | func (tr *Matrix) Rotate(radians float64) {
c := math.Cos(radians)
s := math.Sin(radians)
t0 := c*tr[0] + s*tr[2]
t1 := s*tr[3] + c*tr[1]
t2 := c*tr[2] - s*tr[0]
t3 := c*tr[3] - s*tr[1]
tr[0] = t0
tr[1] = t1
tr[2] = t2
tr[3] = t3
} | [
"func",
"(",
"tr",
"*",
"Matrix",
")",
"Rotate",
"(",
"radians",
"float64",
")",
"{",
"c",
":=",
"math",
".",
"Cos",
"(",
"radians",
")",
"\n",
"s",
":=",
"math",
".",
"Sin",
"(",
"radians",
")",
"\n",
"t0",
":=",
"c",
"*",
"tr",
"[",
"0",
"]... | // Rotate adds a rotation to the matrix. | [
"Rotate",
"adds",
"a",
"rotation",
"to",
"the",
"matrix",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/matrix.go#L165-L176 | train |
wcharczuk/go-chart | drawing/matrix.go | GetScale | func (tr Matrix) GetScale() float64 {
x := 0.707106781*tr[0] + 0.707106781*tr[1]
y := 0.707106781*tr[2] + 0.707106781*tr[3]
return math.Sqrt(x*x + y*y)
} | go | func (tr Matrix) GetScale() float64 {
x := 0.707106781*tr[0] + 0.707106781*tr[1]
y := 0.707106781*tr[2] + 0.707106781*tr[3]
return math.Sqrt(x*x + y*y)
} | [
"func",
"(",
"tr",
"Matrix",
")",
"GetScale",
"(",
")",
"float64",
"{",
"x",
":=",
"0.707106781",
"*",
"tr",
"[",
"0",
"]",
"+",
"0.707106781",
"*",
"tr",
"[",
"1",
"]",
"\n",
"y",
":=",
"0.707106781",
"*",
"tr",
"[",
"2",
"]",
"+",
"0.707106781"... | // GetScale computes a scale for the matrix | [
"GetScale",
"computes",
"a",
"scale",
"for",
"the",
"matrix"
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/matrix.go#L189-L193 | train |
wcharczuk/go-chart | drawing/matrix.go | IsIdentity | func (tr Matrix) IsIdentity() bool {
return fequals(tr[4], 0) && fequals(tr[5], 0) && tr.IsTranslation()
} | go | func (tr Matrix) IsIdentity() bool {
return fequals(tr[4], 0) && fequals(tr[5], 0) && tr.IsTranslation()
} | [
"func",
"(",
"tr",
"Matrix",
")",
"IsIdentity",
"(",
")",
"bool",
"{",
"return",
"fequals",
"(",
"tr",
"[",
"4",
"]",
",",
"0",
")",
"&&",
"fequals",
"(",
"tr",
"[",
"5",
"]",
",",
"0",
")",
"&&",
"tr",
".",
"IsTranslation",
"(",
")",
"\n",
"... | // IsIdentity tests if a transformation is the identity transformation. A tolerance is applied when comparing matrix elements. | [
"IsIdentity",
"tests",
"if",
"a",
"transformation",
"is",
"the",
"identity",
"transformation",
".",
"A",
"tolerance",
"is",
"applied",
"when",
"comparing",
"matrix",
"elements",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/matrix.go#L208-L210 | train |
wcharczuk/go-chart | drawing/matrix.go | IsTranslation | func (tr Matrix) IsTranslation() bool {
return fequals(tr[0], 1) && fequals(tr[1], 0) && fequals(tr[2], 0) && fequals(tr[3], 1)
} | go | func (tr Matrix) IsTranslation() bool {
return fequals(tr[0], 1) && fequals(tr[1], 0) && fequals(tr[2], 0) && fequals(tr[3], 1)
} | [
"func",
"(",
"tr",
"Matrix",
")",
"IsTranslation",
"(",
")",
"bool",
"{",
"return",
"fequals",
"(",
"tr",
"[",
"0",
"]",
",",
"1",
")",
"&&",
"fequals",
"(",
"tr",
"[",
"1",
"]",
",",
"0",
")",
"&&",
"fequals",
"(",
"tr",
"[",
"2",
"]",
",",
... | // IsTranslation tests if a transformation is is a pure translation. A tolerance is applied when comparing matrix elements. | [
"IsTranslation",
"tests",
"if",
"a",
"transformation",
"is",
"is",
"a",
"pure",
"translation",
".",
"A",
"tolerance",
"is",
"applied",
"when",
"comparing",
"matrix",
"elements",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/matrix.go#L213-L215 | train |
wcharczuk/go-chart | drawing/matrix.go | fequals | func fequals(float1, float2 float64) bool {
return math.Abs(float1-float2) <= epsilon
} | go | func fequals(float1, float2 float64) bool {
return math.Abs(float1-float2) <= epsilon
} | [
"func",
"fequals",
"(",
"float1",
",",
"float2",
"float64",
")",
"bool",
"{",
"return",
"math",
".",
"Abs",
"(",
"float1",
"-",
"float2",
")",
"<=",
"epsilon",
"\n",
"}"
] | // fequals compares two floats. return true if the distance between the two floats is less than epsilon, false otherwise | [
"fequals",
"compares",
"two",
"floats",
".",
"return",
"true",
"if",
"the",
"distance",
"between",
"the",
"two",
"floats",
"is",
"less",
"than",
"epsilon",
"false",
"otherwise"
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/matrix.go#L218-L220 | train |
wcharczuk/go-chart | raster_renderer.go | LineTo | func (rr *rasterRenderer) LineTo(x, y int) {
rr.gc.LineTo(float64(x), float64(y))
} | go | func (rr *rasterRenderer) LineTo(x, y int) {
rr.gc.LineTo(float64(x), float64(y))
} | [
"func",
"(",
"rr",
"*",
"rasterRenderer",
")",
"LineTo",
"(",
"x",
",",
"y",
"int",
")",
"{",
"rr",
".",
"gc",
".",
"LineTo",
"(",
"float64",
"(",
"x",
")",
",",
"float64",
"(",
"y",
")",
")",
"\n",
"}"
] | // LineTo implements the interface method. | [
"LineTo",
"implements",
"the",
"interface",
"method",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/raster_renderer.go#L82-L84 | train |
wcharczuk/go-chart | raster_renderer.go | QuadCurveTo | func (rr *rasterRenderer) QuadCurveTo(cx, cy, x, y int) {
rr.gc.QuadCurveTo(float64(cx), float64(cy), float64(x), float64(y))
} | go | func (rr *rasterRenderer) QuadCurveTo(cx, cy, x, y int) {
rr.gc.QuadCurveTo(float64(cx), float64(cy), float64(x), float64(y))
} | [
"func",
"(",
"rr",
"*",
"rasterRenderer",
")",
"QuadCurveTo",
"(",
"cx",
",",
"cy",
",",
"x",
",",
"y",
"int",
")",
"{",
"rr",
".",
"gc",
".",
"QuadCurveTo",
"(",
"float64",
"(",
"cx",
")",
",",
"float64",
"(",
"cy",
")",
",",
"float64",
"(",
"... | // QuadCurveTo implements the interface method. | [
"QuadCurveTo",
"implements",
"the",
"interface",
"method",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/raster_renderer.go#L87-L89 | train |
wcharczuk/go-chart | raster_renderer.go | ArcTo | func (rr *rasterRenderer) ArcTo(cx, cy int, rx, ry, startAngle, delta float64) {
rr.gc.ArcTo(float64(cx), float64(cy), rx, ry, startAngle, delta)
} | go | func (rr *rasterRenderer) ArcTo(cx, cy int, rx, ry, startAngle, delta float64) {
rr.gc.ArcTo(float64(cx), float64(cy), rx, ry, startAngle, delta)
} | [
"func",
"(",
"rr",
"*",
"rasterRenderer",
")",
"ArcTo",
"(",
"cx",
",",
"cy",
"int",
",",
"rx",
",",
"ry",
",",
"startAngle",
",",
"delta",
"float64",
")",
"{",
"rr",
".",
"gc",
".",
"ArcTo",
"(",
"float64",
"(",
"cx",
")",
",",
"float64",
"(",
... | // ArcTo implements the interface method. | [
"ArcTo",
"implements",
"the",
"interface",
"method",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/raster_renderer.go#L92-L94 | train |
wcharczuk/go-chart | raster_renderer.go | Stroke | func (rr *rasterRenderer) Stroke() {
rr.gc.SetStrokeColor(rr.s.StrokeColor)
rr.gc.SetLineWidth(rr.s.StrokeWidth)
rr.gc.SetLineDash(rr.s.StrokeDashArray, 0)
rr.gc.Stroke()
} | go | func (rr *rasterRenderer) Stroke() {
rr.gc.SetStrokeColor(rr.s.StrokeColor)
rr.gc.SetLineWidth(rr.s.StrokeWidth)
rr.gc.SetLineDash(rr.s.StrokeDashArray, 0)
rr.gc.Stroke()
} | [
"func",
"(",
"rr",
"*",
"rasterRenderer",
")",
"Stroke",
"(",
")",
"{",
"rr",
".",
"gc",
".",
"SetStrokeColor",
"(",
"rr",
".",
"s",
".",
"StrokeColor",
")",
"\n",
"rr",
".",
"gc",
".",
"SetLineWidth",
"(",
"rr",
".",
"s",
".",
"StrokeWidth",
")",
... | // Stroke implements the interface method. | [
"Stroke",
"implements",
"the",
"interface",
"method",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/raster_renderer.go#L102-L107 | train |
wcharczuk/go-chart | raster_renderer.go | Fill | func (rr *rasterRenderer) Fill() {
rr.gc.SetFillColor(rr.s.FillColor)
rr.gc.Fill()
} | go | func (rr *rasterRenderer) Fill() {
rr.gc.SetFillColor(rr.s.FillColor)
rr.gc.Fill()
} | [
"func",
"(",
"rr",
"*",
"rasterRenderer",
")",
"Fill",
"(",
")",
"{",
"rr",
".",
"gc",
".",
"SetFillColor",
"(",
"rr",
".",
"s",
".",
"FillColor",
")",
"\n",
"rr",
".",
"gc",
".",
"Fill",
"(",
")",
"\n",
"}"
] | // Fill implements the interface method. | [
"Fill",
"implements",
"the",
"interface",
"method",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/raster_renderer.go#L110-L113 | train |
wcharczuk/go-chart | raster_renderer.go | FillStroke | func (rr *rasterRenderer) FillStroke() {
rr.gc.SetFillColor(rr.s.FillColor)
rr.gc.SetStrokeColor(rr.s.StrokeColor)
rr.gc.SetLineWidth(rr.s.StrokeWidth)
rr.gc.SetLineDash(rr.s.StrokeDashArray, 0)
rr.gc.FillStroke()
} | go | func (rr *rasterRenderer) FillStroke() {
rr.gc.SetFillColor(rr.s.FillColor)
rr.gc.SetStrokeColor(rr.s.StrokeColor)
rr.gc.SetLineWidth(rr.s.StrokeWidth)
rr.gc.SetLineDash(rr.s.StrokeDashArray, 0)
rr.gc.FillStroke()
} | [
"func",
"(",
"rr",
"*",
"rasterRenderer",
")",
"FillStroke",
"(",
")",
"{",
"rr",
".",
"gc",
".",
"SetFillColor",
"(",
"rr",
".",
"s",
".",
"FillColor",
")",
"\n",
"rr",
".",
"gc",
".",
"SetStrokeColor",
"(",
"rr",
".",
"s",
".",
"StrokeColor",
")"... | // FillStroke implements the interface method. | [
"FillStroke",
"implements",
"the",
"interface",
"method",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/raster_renderer.go#L116-L122 | train |
wcharczuk/go-chart | raster_renderer.go | Circle | func (rr *rasterRenderer) Circle(radius float64, x, y int) {
xf := float64(x)
yf := float64(y)
rr.gc.MoveTo(xf-radius, yf) //9
rr.gc.QuadCurveTo(xf-radius, yf-radius, xf, yf-radius) //12
rr.gc.QuadCurveTo(xf+radius, yf-radius, xf+radius, yf) //3
rr.gc.QuadCurveTo(xf+radius, yf+radius, xf, yf+radius) //6
rr.gc.QuadCurveTo(xf-radius, yf+radius, xf-radius, yf) //9
} | go | func (rr *rasterRenderer) Circle(radius float64, x, y int) {
xf := float64(x)
yf := float64(y)
rr.gc.MoveTo(xf-radius, yf) //9
rr.gc.QuadCurveTo(xf-radius, yf-radius, xf, yf-radius) //12
rr.gc.QuadCurveTo(xf+radius, yf-radius, xf+radius, yf) //3
rr.gc.QuadCurveTo(xf+radius, yf+radius, xf, yf+radius) //6
rr.gc.QuadCurveTo(xf-radius, yf+radius, xf-radius, yf) //9
} | [
"func",
"(",
"rr",
"*",
"rasterRenderer",
")",
"Circle",
"(",
"radius",
"float64",
",",
"x",
",",
"y",
"int",
")",
"{",
"xf",
":=",
"float64",
"(",
"x",
")",
"\n",
"yf",
":=",
"float64",
"(",
"y",
")",
"\n\n",
"rr",
".",
"gc",
".",
"MoveTo",
"(... | // Circle fully draws a circle at a given point but does not apply the fill or stroke. | [
"Circle",
"fully",
"draws",
"a",
"circle",
"at",
"a",
"given",
"point",
"but",
"does",
"not",
"apply",
"the",
"fill",
"or",
"stroke",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/raster_renderer.go#L125-L134 | train |
wcharczuk/go-chart | raster_renderer.go | Text | func (rr *rasterRenderer) Text(body string, x, y int) {
xf, yf := rr.getCoords(x, y)
rr.gc.SetFont(rr.s.Font)
rr.gc.SetFontSize(rr.s.FontSize)
rr.gc.SetFillColor(rr.s.FontColor)
rr.gc.CreateStringPath(body, float64(xf), float64(yf))
rr.gc.Fill()
} | go | func (rr *rasterRenderer) Text(body string, x, y int) {
xf, yf := rr.getCoords(x, y)
rr.gc.SetFont(rr.s.Font)
rr.gc.SetFontSize(rr.s.FontSize)
rr.gc.SetFillColor(rr.s.FontColor)
rr.gc.CreateStringPath(body, float64(xf), float64(yf))
rr.gc.Fill()
} | [
"func",
"(",
"rr",
"*",
"rasterRenderer",
")",
"Text",
"(",
"body",
"string",
",",
"x",
",",
"y",
"int",
")",
"{",
"xf",
",",
"yf",
":=",
"rr",
".",
"getCoords",
"(",
"x",
",",
"y",
")",
"\n",
"rr",
".",
"gc",
".",
"SetFont",
"(",
"rr",
".",
... | // Text implements the interface method. | [
"Text",
"implements",
"the",
"interface",
"method",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/raster_renderer.go#L152-L159 | train |
wcharczuk/go-chart | raster_renderer.go | MeasureText | func (rr *rasterRenderer) MeasureText(body string) Box {
rr.gc.SetFont(rr.s.Font)
rr.gc.SetFontSize(rr.s.FontSize)
rr.gc.SetFillColor(rr.s.FontColor)
l, t, r, b, err := rr.gc.GetStringBounds(body)
if err != nil {
return Box{}
}
if l < 0 {
r = r - l // equivalent to r+(-1*l)
l = 0
}
if t < 0 {
b = b - t
t = 0
}
if l > 0 {
r = r + l
l = 0
}
if t > 0 {
b = b + t
t = 0
}
textBox := Box{
Top: int(math.Ceil(t)),
Left: int(math.Ceil(l)),
Right: int(math.Ceil(r)),
Bottom: int(math.Ceil(b)),
}
if rr.rotateRadians == nil {
return textBox
}
return textBox.Corners().Rotate(util.Math.RadiansToDegrees(*rr.rotateRadians)).Box()
} | go | func (rr *rasterRenderer) MeasureText(body string) Box {
rr.gc.SetFont(rr.s.Font)
rr.gc.SetFontSize(rr.s.FontSize)
rr.gc.SetFillColor(rr.s.FontColor)
l, t, r, b, err := rr.gc.GetStringBounds(body)
if err != nil {
return Box{}
}
if l < 0 {
r = r - l // equivalent to r+(-1*l)
l = 0
}
if t < 0 {
b = b - t
t = 0
}
if l > 0 {
r = r + l
l = 0
}
if t > 0 {
b = b + t
t = 0
}
textBox := Box{
Top: int(math.Ceil(t)),
Left: int(math.Ceil(l)),
Right: int(math.Ceil(r)),
Bottom: int(math.Ceil(b)),
}
if rr.rotateRadians == nil {
return textBox
}
return textBox.Corners().Rotate(util.Math.RadiansToDegrees(*rr.rotateRadians)).Box()
} | [
"func",
"(",
"rr",
"*",
"rasterRenderer",
")",
"MeasureText",
"(",
"body",
"string",
")",
"Box",
"{",
"rr",
".",
"gc",
".",
"SetFont",
"(",
"rr",
".",
"s",
".",
"Font",
")",
"\n",
"rr",
".",
"gc",
".",
"SetFontSize",
"(",
"rr",
".",
"s",
".",
"... | // MeasureText returns the height and width in pixels of a string. | [
"MeasureText",
"returns",
"the",
"height",
"and",
"width",
"in",
"pixels",
"of",
"a",
"string",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/raster_renderer.go#L162-L200 | train |
wcharczuk/go-chart | raster_renderer.go | ClearTextRotation | func (rr *rasterRenderer) ClearTextRotation() {
rr.gc.SetMatrixTransform(drawing.NewIdentityMatrix())
rr.rotateRadians = nil
} | go | func (rr *rasterRenderer) ClearTextRotation() {
rr.gc.SetMatrixTransform(drawing.NewIdentityMatrix())
rr.rotateRadians = nil
} | [
"func",
"(",
"rr",
"*",
"rasterRenderer",
")",
"ClearTextRotation",
"(",
")",
"{",
"rr",
".",
"gc",
".",
"SetMatrixTransform",
"(",
"drawing",
".",
"NewIdentityMatrix",
"(",
")",
")",
"\n",
"rr",
".",
"rotateRadians",
"=",
"nil",
"\n",
"}"
] | // ClearTextRotation clears text rotation. | [
"ClearTextRotation",
"clears",
"text",
"rotation",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/raster_renderer.go#L220-L223 | train |
wcharczuk/go-chart | raster_renderer.go | Save | func (rr *rasterRenderer) Save(w io.Writer) error {
if typed, isTyped := w.(RGBACollector); isTyped {
typed.SetRGBA(rr.i)
return nil
}
return png.Encode(w, rr.i)
} | go | func (rr *rasterRenderer) Save(w io.Writer) error {
if typed, isTyped := w.(RGBACollector); isTyped {
typed.SetRGBA(rr.i)
return nil
}
return png.Encode(w, rr.i)
} | [
"func",
"(",
"rr",
"*",
"rasterRenderer",
")",
"Save",
"(",
"w",
"io",
".",
"Writer",
")",
"error",
"{",
"if",
"typed",
",",
"isTyped",
":=",
"w",
".",
"(",
"RGBACollector",
")",
";",
"isTyped",
"{",
"typed",
".",
"SetRGBA",
"(",
"rr",
".",
"i",
... | // Save implements the interface method. | [
"Save",
"implements",
"the",
"interface",
"method",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/raster_renderer.go#L226-L232 | train |
wcharczuk/go-chart | continuous_series.go | GetValues | func (cs ContinuousSeries) GetValues(index int) (float64, float64) {
return cs.XValues[index], cs.YValues[index]
} | go | func (cs ContinuousSeries) GetValues(index int) (float64, float64) {
return cs.XValues[index], cs.YValues[index]
} | [
"func",
"(",
"cs",
"ContinuousSeries",
")",
"GetValues",
"(",
"index",
"int",
")",
"(",
"float64",
",",
"float64",
")",
"{",
"return",
"cs",
".",
"XValues",
"[",
"index",
"]",
",",
"cs",
".",
"YValues",
"[",
"index",
"]",
"\n",
"}"
] | // GetValues gets the x,y values at a given index. | [
"GetValues",
"gets",
"the",
"x",
"y",
"values",
"at",
"a",
"given",
"index",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/continuous_series.go#L42-L44 | train |
wcharczuk/go-chart | continuous_series.go | GetLastValues | func (cs ContinuousSeries) GetLastValues() (float64, float64) {
return cs.XValues[len(cs.XValues)-1], cs.YValues[len(cs.YValues)-1]
} | go | func (cs ContinuousSeries) GetLastValues() (float64, float64) {
return cs.XValues[len(cs.XValues)-1], cs.YValues[len(cs.YValues)-1]
} | [
"func",
"(",
"cs",
"ContinuousSeries",
")",
"GetLastValues",
"(",
")",
"(",
"float64",
",",
"float64",
")",
"{",
"return",
"cs",
".",
"XValues",
"[",
"len",
"(",
"cs",
".",
"XValues",
")",
"-",
"1",
"]",
",",
"cs",
".",
"YValues",
"[",
"len",
"(",
... | // GetLastValues gets the last x,y values. | [
"GetLastValues",
"gets",
"the",
"last",
"x",
"y",
"values",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/continuous_series.go#L52-L54 | train |
wcharczuk/go-chart | draw.go | BoundedSeries | func (d draw) BoundedSeries(r Renderer, canvasBox Box, xrange, yrange Range, style Style, bbs BoundedValuesProvider, drawOffsetIndexes ...int) {
drawOffsetIndex := 0
if len(drawOffsetIndexes) > 0 {
drawOffsetIndex = drawOffsetIndexes[0]
}
cb := canvasBox.Bottom
cl := canvasBox.Left
v0x, v0y1, v0y2 := bbs.GetBoundedValues(0)
x0 := cl + xrange.Translate(v0x)
y0 := cb - yrange.Translate(v0y1)
var vx, vy1, vy2 float64
var x, y int
xvalues := make([]float64, bbs.Len())
xvalues[0] = v0x
y2values := make([]float64, bbs.Len())
y2values[0] = v0y2
style.GetFillAndStrokeOptions().WriteToRenderer(r)
r.MoveTo(x0, y0)
for i := 1; i < bbs.Len(); i++ {
vx, vy1, vy2 = bbs.GetBoundedValues(i)
xvalues[i] = vx
y2values[i] = vy2
x = cl + xrange.Translate(vx)
y = cb - yrange.Translate(vy1)
if i > drawOffsetIndex {
r.LineTo(x, y)
} else {
r.MoveTo(x, y)
}
}
y = cb - yrange.Translate(vy2)
r.LineTo(x, y)
for i := bbs.Len() - 1; i >= drawOffsetIndex; i-- {
vx, vy2 = xvalues[i], y2values[i]
x = cl + xrange.Translate(vx)
y = cb - yrange.Translate(vy2)
r.LineTo(x, y)
}
r.Close()
r.FillStroke()
} | go | func (d draw) BoundedSeries(r Renderer, canvasBox Box, xrange, yrange Range, style Style, bbs BoundedValuesProvider, drawOffsetIndexes ...int) {
drawOffsetIndex := 0
if len(drawOffsetIndexes) > 0 {
drawOffsetIndex = drawOffsetIndexes[0]
}
cb := canvasBox.Bottom
cl := canvasBox.Left
v0x, v0y1, v0y2 := bbs.GetBoundedValues(0)
x0 := cl + xrange.Translate(v0x)
y0 := cb - yrange.Translate(v0y1)
var vx, vy1, vy2 float64
var x, y int
xvalues := make([]float64, bbs.Len())
xvalues[0] = v0x
y2values := make([]float64, bbs.Len())
y2values[0] = v0y2
style.GetFillAndStrokeOptions().WriteToRenderer(r)
r.MoveTo(x0, y0)
for i := 1; i < bbs.Len(); i++ {
vx, vy1, vy2 = bbs.GetBoundedValues(i)
xvalues[i] = vx
y2values[i] = vy2
x = cl + xrange.Translate(vx)
y = cb - yrange.Translate(vy1)
if i > drawOffsetIndex {
r.LineTo(x, y)
} else {
r.MoveTo(x, y)
}
}
y = cb - yrange.Translate(vy2)
r.LineTo(x, y)
for i := bbs.Len() - 1; i >= drawOffsetIndex; i-- {
vx, vy2 = xvalues[i], y2values[i]
x = cl + xrange.Translate(vx)
y = cb - yrange.Translate(vy2)
r.LineTo(x, y)
}
r.Close()
r.FillStroke()
} | [
"func",
"(",
"d",
"draw",
")",
"BoundedSeries",
"(",
"r",
"Renderer",
",",
"canvasBox",
"Box",
",",
"xrange",
",",
"yrange",
"Range",
",",
"style",
"Style",
",",
"bbs",
"BoundedValuesProvider",
",",
"drawOffsetIndexes",
"...",
"int",
")",
"{",
"drawOffsetInd... | // BoundedSeries draws a series that implements BoundedValuesProvider. | [
"BoundedSeries",
"draws",
"a",
"series",
"that",
"implements",
"BoundedValuesProvider",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/draw.go#L90-L137 | train |
wcharczuk/go-chart | draw.go | HistogramSeries | func (d draw) HistogramSeries(r Renderer, canvasBox Box, xrange, yrange Range, style Style, vs ValuesProvider, barWidths ...int) {
if vs.Len() == 0 {
return
}
//calculate bar width?
seriesLength := vs.Len()
barWidth := int(math.Floor(float64(xrange.GetDomain()) / float64(seriesLength)))
if len(barWidths) > 0 {
barWidth = barWidths[0]
}
cb := canvasBox.Bottom
cl := canvasBox.Left
//foreach datapoint, draw a box.
for index := 0; index < seriesLength; index++ {
vx, vy := vs.GetValues(index)
y0 := yrange.Translate(0)
x := cl + xrange.Translate(vx)
y := yrange.Translate(vy)
d.Box(r, Box{
Top: cb - y0,
Left: x - (barWidth >> 1),
Right: x + (barWidth >> 1),
Bottom: cb - y,
}, style)
}
} | go | func (d draw) HistogramSeries(r Renderer, canvasBox Box, xrange, yrange Range, style Style, vs ValuesProvider, barWidths ...int) {
if vs.Len() == 0 {
return
}
//calculate bar width?
seriesLength := vs.Len()
barWidth := int(math.Floor(float64(xrange.GetDomain()) / float64(seriesLength)))
if len(barWidths) > 0 {
barWidth = barWidths[0]
}
cb := canvasBox.Bottom
cl := canvasBox.Left
//foreach datapoint, draw a box.
for index := 0; index < seriesLength; index++ {
vx, vy := vs.GetValues(index)
y0 := yrange.Translate(0)
x := cl + xrange.Translate(vx)
y := yrange.Translate(vy)
d.Box(r, Box{
Top: cb - y0,
Left: x - (barWidth >> 1),
Right: x + (barWidth >> 1),
Bottom: cb - y,
}, style)
}
} | [
"func",
"(",
"d",
"draw",
")",
"HistogramSeries",
"(",
"r",
"Renderer",
",",
"canvasBox",
"Box",
",",
"xrange",
",",
"yrange",
"Range",
",",
"style",
"Style",
",",
"vs",
"ValuesProvider",
",",
"barWidths",
"...",
"int",
")",
"{",
"if",
"vs",
".",
"Len"... | // HistogramSeries draws a value provider as boxes from 0. | [
"HistogramSeries",
"draws",
"a",
"value",
"provider",
"as",
"boxes",
"from",
"0",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/draw.go#L140-L169 | train |
wcharczuk/go-chart | draw.go | MeasureAnnotation | func (d draw) MeasureAnnotation(r Renderer, canvasBox Box, style Style, lx, ly int, label string) Box {
style.WriteToRenderer(r)
defer r.ResetStyle()
textBox := r.MeasureText(label)
textWidth := textBox.Width()
textHeight := textBox.Height()
halfTextHeight := textHeight >> 1
pt := style.Padding.GetTop(DefaultAnnotationPadding.Top)
pl := style.Padding.GetLeft(DefaultAnnotationPadding.Left)
pr := style.Padding.GetRight(DefaultAnnotationPadding.Right)
pb := style.Padding.GetBottom(DefaultAnnotationPadding.Bottom)
strokeWidth := style.GetStrokeWidth()
top := ly - (pt + halfTextHeight)
right := lx + pl + pr + textWidth + DefaultAnnotationDeltaWidth + int(strokeWidth)
bottom := ly + (pb + halfTextHeight)
return Box{
Top: top,
Left: lx,
Right: right,
Bottom: bottom,
}
} | go | func (d draw) MeasureAnnotation(r Renderer, canvasBox Box, style Style, lx, ly int, label string) Box {
style.WriteToRenderer(r)
defer r.ResetStyle()
textBox := r.MeasureText(label)
textWidth := textBox.Width()
textHeight := textBox.Height()
halfTextHeight := textHeight >> 1
pt := style.Padding.GetTop(DefaultAnnotationPadding.Top)
pl := style.Padding.GetLeft(DefaultAnnotationPadding.Left)
pr := style.Padding.GetRight(DefaultAnnotationPadding.Right)
pb := style.Padding.GetBottom(DefaultAnnotationPadding.Bottom)
strokeWidth := style.GetStrokeWidth()
top := ly - (pt + halfTextHeight)
right := lx + pl + pr + textWidth + DefaultAnnotationDeltaWidth + int(strokeWidth)
bottom := ly + (pb + halfTextHeight)
return Box{
Top: top,
Left: lx,
Right: right,
Bottom: bottom,
}
} | [
"func",
"(",
"d",
"draw",
")",
"MeasureAnnotation",
"(",
"r",
"Renderer",
",",
"canvasBox",
"Box",
",",
"style",
"Style",
",",
"lx",
",",
"ly",
"int",
",",
"label",
"string",
")",
"Box",
"{",
"style",
".",
"WriteToRenderer",
"(",
"r",
")",
"\n",
"def... | // MeasureAnnotation measures how big an annotation would be. | [
"MeasureAnnotation",
"measures",
"how",
"big",
"an",
"annotation",
"would",
"be",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/draw.go#L172-L198 | train |
wcharczuk/go-chart | draw.go | Annotation | func (d draw) Annotation(r Renderer, canvasBox Box, style Style, lx, ly int, label string) {
style.GetTextOptions().WriteToRenderer(r)
defer r.ResetStyle()
textBox := r.MeasureText(label)
textWidth := textBox.Width()
halfTextHeight := textBox.Height() >> 1
style.GetFillAndStrokeOptions().WriteToRenderer(r)
pt := style.Padding.GetTop(DefaultAnnotationPadding.Top)
pl := style.Padding.GetLeft(DefaultAnnotationPadding.Left)
pr := style.Padding.GetRight(DefaultAnnotationPadding.Right)
pb := style.Padding.GetBottom(DefaultAnnotationPadding.Bottom)
textX := lx + pl + DefaultAnnotationDeltaWidth
textY := ly + halfTextHeight
ltx := lx + DefaultAnnotationDeltaWidth
lty := ly - (pt + halfTextHeight)
rtx := lx + pl + pr + textWidth + DefaultAnnotationDeltaWidth
rty := ly - (pt + halfTextHeight)
rbx := lx + pl + pr + textWidth + DefaultAnnotationDeltaWidth
rby := ly + (pb + halfTextHeight)
lbx := lx + DefaultAnnotationDeltaWidth
lby := ly + (pb + halfTextHeight)
r.MoveTo(lx, ly)
r.LineTo(ltx, lty)
r.LineTo(rtx, rty)
r.LineTo(rbx, rby)
r.LineTo(lbx, lby)
r.LineTo(lx, ly)
r.Close()
r.FillStroke()
style.GetTextOptions().WriteToRenderer(r)
r.Text(label, textX, textY)
} | go | func (d draw) Annotation(r Renderer, canvasBox Box, style Style, lx, ly int, label string) {
style.GetTextOptions().WriteToRenderer(r)
defer r.ResetStyle()
textBox := r.MeasureText(label)
textWidth := textBox.Width()
halfTextHeight := textBox.Height() >> 1
style.GetFillAndStrokeOptions().WriteToRenderer(r)
pt := style.Padding.GetTop(DefaultAnnotationPadding.Top)
pl := style.Padding.GetLeft(DefaultAnnotationPadding.Left)
pr := style.Padding.GetRight(DefaultAnnotationPadding.Right)
pb := style.Padding.GetBottom(DefaultAnnotationPadding.Bottom)
textX := lx + pl + DefaultAnnotationDeltaWidth
textY := ly + halfTextHeight
ltx := lx + DefaultAnnotationDeltaWidth
lty := ly - (pt + halfTextHeight)
rtx := lx + pl + pr + textWidth + DefaultAnnotationDeltaWidth
rty := ly - (pt + halfTextHeight)
rbx := lx + pl + pr + textWidth + DefaultAnnotationDeltaWidth
rby := ly + (pb + halfTextHeight)
lbx := lx + DefaultAnnotationDeltaWidth
lby := ly + (pb + halfTextHeight)
r.MoveTo(lx, ly)
r.LineTo(ltx, lty)
r.LineTo(rtx, rty)
r.LineTo(rbx, rby)
r.LineTo(lbx, lby)
r.LineTo(lx, ly)
r.Close()
r.FillStroke()
style.GetTextOptions().WriteToRenderer(r)
r.Text(label, textX, textY)
} | [
"func",
"(",
"d",
"draw",
")",
"Annotation",
"(",
"r",
"Renderer",
",",
"canvasBox",
"Box",
",",
"style",
"Style",
",",
"lx",
",",
"ly",
"int",
",",
"label",
"string",
")",
"{",
"style",
".",
"GetTextOptions",
"(",
")",
".",
"WriteToRenderer",
"(",
"... | // Annotation draws an anotation with a renderer. | [
"Annotation",
"draws",
"an",
"anotation",
"with",
"a",
"renderer",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/draw.go#L201-L242 | train |
wcharczuk/go-chart | draw.go | Box | func (d draw) Box(r Renderer, b Box, s Style) {
s.GetFillAndStrokeOptions().WriteToRenderer(r)
defer r.ResetStyle()
r.MoveTo(b.Left, b.Top)
r.LineTo(b.Right, b.Top)
r.LineTo(b.Right, b.Bottom)
r.LineTo(b.Left, b.Bottom)
r.LineTo(b.Left, b.Top)
r.FillStroke()
} | go | func (d draw) Box(r Renderer, b Box, s Style) {
s.GetFillAndStrokeOptions().WriteToRenderer(r)
defer r.ResetStyle()
r.MoveTo(b.Left, b.Top)
r.LineTo(b.Right, b.Top)
r.LineTo(b.Right, b.Bottom)
r.LineTo(b.Left, b.Bottom)
r.LineTo(b.Left, b.Top)
r.FillStroke()
} | [
"func",
"(",
"d",
"draw",
")",
"Box",
"(",
"r",
"Renderer",
",",
"b",
"Box",
",",
"s",
"Style",
")",
"{",
"s",
".",
"GetFillAndStrokeOptions",
"(",
")",
".",
"WriteToRenderer",
"(",
"r",
")",
"\n",
"defer",
"r",
".",
"ResetStyle",
"(",
")",
"\n\n",... | // Box draws a box with a given style. | [
"Box",
"draws",
"a",
"box",
"with",
"a",
"given",
"style",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/draw.go#L245-L255 | train |
wcharczuk/go-chart | draw.go | Text | func (d draw) Text(r Renderer, text string, x, y int, style Style) {
style.GetTextOptions().WriteToRenderer(r)
defer r.ResetStyle()
r.Text(text, x, y)
} | go | func (d draw) Text(r Renderer, text string, x, y int, style Style) {
style.GetTextOptions().WriteToRenderer(r)
defer r.ResetStyle()
r.Text(text, x, y)
} | [
"func",
"(",
"d",
"draw",
")",
"Text",
"(",
"r",
"Renderer",
",",
"text",
"string",
",",
"x",
",",
"y",
"int",
",",
"style",
"Style",
")",
"{",
"style",
".",
"GetTextOptions",
"(",
")",
".",
"WriteToRenderer",
"(",
"r",
")",
"\n",
"defer",
"r",
"... | // DrawText draws text with a given style. | [
"DrawText",
"draws",
"text",
"with",
"a",
"given",
"style",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/draw.go#L274-L279 | train |
wcharczuk/go-chart | draw.go | TextWithin | func (d draw) TextWithin(r Renderer, text string, box Box, style Style) {
style.GetTextOptions().WriteToRenderer(r)
defer r.ResetStyle()
lines := Text.WrapFit(r, text, box.Width(), style)
linesBox := Text.MeasureLines(r, lines, style)
y := box.Top
switch style.GetTextVerticalAlign() {
case TextVerticalAlignBottom, TextVerticalAlignBaseline: // i have to build better baseline handling into measure text
y = y - linesBox.Height()
case TextVerticalAlignMiddle, TextVerticalAlignMiddleBaseline:
y = (y - linesBox.Height()) >> 1
}
var tx, ty int
for _, line := range lines {
lineBox := r.MeasureText(line)
switch style.GetTextHorizontalAlign() {
case TextHorizontalAlignCenter:
tx = box.Left + ((box.Width() - lineBox.Width()) >> 1)
case TextHorizontalAlignRight:
tx = box.Right - lineBox.Width()
default:
tx = box.Left
}
if style.TextRotationDegrees == 0 {
ty = y + lineBox.Height()
} else {
ty = y
}
r.Text(line, tx, ty)
y += lineBox.Height() + style.GetTextLineSpacing()
}
} | go | func (d draw) TextWithin(r Renderer, text string, box Box, style Style) {
style.GetTextOptions().WriteToRenderer(r)
defer r.ResetStyle()
lines := Text.WrapFit(r, text, box.Width(), style)
linesBox := Text.MeasureLines(r, lines, style)
y := box.Top
switch style.GetTextVerticalAlign() {
case TextVerticalAlignBottom, TextVerticalAlignBaseline: // i have to build better baseline handling into measure text
y = y - linesBox.Height()
case TextVerticalAlignMiddle, TextVerticalAlignMiddleBaseline:
y = (y - linesBox.Height()) >> 1
}
var tx, ty int
for _, line := range lines {
lineBox := r.MeasureText(line)
switch style.GetTextHorizontalAlign() {
case TextHorizontalAlignCenter:
tx = box.Left + ((box.Width() - lineBox.Width()) >> 1)
case TextHorizontalAlignRight:
tx = box.Right - lineBox.Width()
default:
tx = box.Left
}
if style.TextRotationDegrees == 0 {
ty = y + lineBox.Height()
} else {
ty = y
}
r.Text(line, tx, ty)
y += lineBox.Height() + style.GetTextLineSpacing()
}
} | [
"func",
"(",
"d",
"draw",
")",
"TextWithin",
"(",
"r",
"Renderer",
",",
"text",
"string",
",",
"box",
"Box",
",",
"style",
"Style",
")",
"{",
"style",
".",
"GetTextOptions",
"(",
")",
".",
"WriteToRenderer",
"(",
"r",
")",
"\n",
"defer",
"r",
".",
... | // TextWithin draws the text within a given box. | [
"TextWithin",
"draws",
"the",
"text",
"within",
"a",
"given",
"box",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/draw.go#L289-L325 | train |
wcharczuk/go-chart | last_value_annotation.go | LastValueAnnotation | func LastValueAnnotation(innerSeries ValuesProvider, vfs ...ValueFormatter) AnnotationSeries {
var vf ValueFormatter
if len(vfs) > 0 {
vf = vfs[0]
} else if typed, isTyped := innerSeries.(ValueFormatterProvider); isTyped {
_, vf = typed.GetValueFormatters()
} else {
vf = FloatValueFormatter
}
var lastValue Value2
if typed, isTyped := innerSeries.(LastValuesProvider); isTyped {
lastValue.XValue, lastValue.YValue = typed.GetLastValues()
lastValue.Label = vf(lastValue.YValue)
} else {
lastValue.XValue, lastValue.YValue = innerSeries.GetValues(innerSeries.Len() - 1)
lastValue.Label = vf(lastValue.YValue)
}
var seriesName string
var seriesStyle Style
if typed, isTyped := innerSeries.(Series); isTyped {
seriesName = fmt.Sprintf("%s - Last Value", typed.GetName())
seriesStyle = typed.GetStyle()
}
return AnnotationSeries{
Name: seriesName,
Style: seriesStyle,
Annotations: []Value2{lastValue},
}
} | go | func LastValueAnnotation(innerSeries ValuesProvider, vfs ...ValueFormatter) AnnotationSeries {
var vf ValueFormatter
if len(vfs) > 0 {
vf = vfs[0]
} else if typed, isTyped := innerSeries.(ValueFormatterProvider); isTyped {
_, vf = typed.GetValueFormatters()
} else {
vf = FloatValueFormatter
}
var lastValue Value2
if typed, isTyped := innerSeries.(LastValuesProvider); isTyped {
lastValue.XValue, lastValue.YValue = typed.GetLastValues()
lastValue.Label = vf(lastValue.YValue)
} else {
lastValue.XValue, lastValue.YValue = innerSeries.GetValues(innerSeries.Len() - 1)
lastValue.Label = vf(lastValue.YValue)
}
var seriesName string
var seriesStyle Style
if typed, isTyped := innerSeries.(Series); isTyped {
seriesName = fmt.Sprintf("%s - Last Value", typed.GetName())
seriesStyle = typed.GetStyle()
}
return AnnotationSeries{
Name: seriesName,
Style: seriesStyle,
Annotations: []Value2{lastValue},
}
} | [
"func",
"LastValueAnnotation",
"(",
"innerSeries",
"ValuesProvider",
",",
"vfs",
"...",
"ValueFormatter",
")",
"AnnotationSeries",
"{",
"var",
"vf",
"ValueFormatter",
"\n",
"if",
"len",
"(",
"vfs",
")",
">",
"0",
"{",
"vf",
"=",
"vfs",
"[",
"0",
"]",
"\n",... | // LastValueAnnotation returns an annotation series of just the last value of a value provider. | [
"LastValueAnnotation",
"returns",
"an",
"annotation",
"series",
"of",
"just",
"the",
"last",
"value",
"of",
"a",
"value",
"provider",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/last_value_annotation.go#L6-L37 | train |
wcharczuk/go-chart | vector_renderer.go | SetDPI | func (vr *vectorRenderer) SetDPI(dpi float64) {
vr.dpi = dpi
vr.c.dpi = dpi
} | go | func (vr *vectorRenderer) SetDPI(dpi float64) {
vr.dpi = dpi
vr.c.dpi = dpi
} | [
"func",
"(",
"vr",
"*",
"vectorRenderer",
")",
"SetDPI",
"(",
"dpi",
"float64",
")",
"{",
"vr",
".",
"dpi",
"=",
"dpi",
"\n",
"vr",
".",
"c",
".",
"dpi",
"=",
"dpi",
"\n",
"}"
] | // SetDPI implements the interface method. | [
"SetDPI",
"implements",
"the",
"interface",
"method",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/vector_renderer.go#L71-L74 | train |
wcharczuk/go-chart | vector_renderer.go | QuadCurveTo | func (vr *vectorRenderer) QuadCurveTo(cx, cy, x, y int) {
vr.p = append(vr.p, fmt.Sprintf("Q%d,%d %d,%d", cx, cy, x, y))
} | go | func (vr *vectorRenderer) QuadCurveTo(cx, cy, x, y int) {
vr.p = append(vr.p, fmt.Sprintf("Q%d,%d %d,%d", cx, cy, x, y))
} | [
"func",
"(",
"vr",
"*",
"vectorRenderer",
")",
"QuadCurveTo",
"(",
"cx",
",",
"cy",
",",
"x",
",",
"y",
"int",
")",
"{",
"vr",
".",
"p",
"=",
"append",
"(",
"vr",
".",
"p",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"cx",
",",
"cy",
... | // QuadCurveTo draws a quad curve. | [
"QuadCurveTo",
"draws",
"a",
"quad",
"curve",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/vector_renderer.go#L112-L114 | train |
wcharczuk/go-chart | vector_renderer.go | Close | func (vr *vectorRenderer) Close() {
vr.p = append(vr.p, fmt.Sprintf("Z"))
} | go | func (vr *vectorRenderer) Close() {
vr.p = append(vr.p, fmt.Sprintf("Z"))
} | [
"func",
"(",
"vr",
"*",
"vectorRenderer",
")",
"Close",
"(",
")",
"{",
"vr",
".",
"p",
"=",
"append",
"(",
"vr",
".",
"p",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
")",
")",
"\n",
"}"
] | // Close closes a shape. | [
"Close",
"closes",
"a",
"shape",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/vector_renderer.go#L143-L145 | train |
wcharczuk/go-chart | vector_renderer.go | drawPath | func (vr *vectorRenderer) drawPath(s Style) {
vr.c.Path(strings.Join(vr.p, "\n"), vr.s.GetFillAndStrokeOptions())
vr.p = []string{} // clear the path
} | go | func (vr *vectorRenderer) drawPath(s Style) {
vr.c.Path(strings.Join(vr.p, "\n"), vr.s.GetFillAndStrokeOptions())
vr.p = []string{} // clear the path
} | [
"func",
"(",
"vr",
"*",
"vectorRenderer",
")",
"drawPath",
"(",
"s",
"Style",
")",
"{",
"vr",
".",
"c",
".",
"Path",
"(",
"strings",
".",
"Join",
"(",
"vr",
".",
"p",
",",
"\"",
"\\n",
"\"",
")",
",",
"vr",
".",
"s",
".",
"GetFillAndStrokeOptions... | // drawPath draws a path. | [
"drawPath",
"draws",
"a",
"path",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/vector_renderer.go#L163-L166 | train |
wcharczuk/go-chart | vector_renderer.go | Circle | func (vr *vectorRenderer) Circle(radius float64, x, y int) {
vr.c.Circle(x, y, int(radius), vr.s.GetFillAndStrokeOptions())
} | go | func (vr *vectorRenderer) Circle(radius float64, x, y int) {
vr.c.Circle(x, y, int(radius), vr.s.GetFillAndStrokeOptions())
} | [
"func",
"(",
"vr",
"*",
"vectorRenderer",
")",
"Circle",
"(",
"radius",
"float64",
",",
"x",
",",
"y",
"int",
")",
"{",
"vr",
".",
"c",
".",
"Circle",
"(",
"x",
",",
"y",
",",
"int",
"(",
"radius",
")",
",",
"vr",
".",
"s",
".",
"GetFillAndStro... | // Circle implements the interface method. | [
"Circle",
"implements",
"the",
"interface",
"method",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/vector_renderer.go#L169-L171 | train |
wcharczuk/go-chart | vector_renderer.go | Text | func (vr *vectorRenderer) Text(body string, x, y int) {
vr.c.Text(x, y, body, vr.s.GetTextOptions())
} | go | func (vr *vectorRenderer) Text(body string, x, y int) {
vr.c.Text(x, y, body, vr.s.GetTextOptions())
} | [
"func",
"(",
"vr",
"*",
"vectorRenderer",
")",
"Text",
"(",
"body",
"string",
",",
"x",
",",
"y",
"int",
")",
"{",
"vr",
".",
"c",
".",
"Text",
"(",
"x",
",",
"y",
",",
"body",
",",
"vr",
".",
"s",
".",
"GetTextOptions",
"(",
")",
")",
"\n",
... | // Text draws a text blob. | [
"Text",
"draws",
"a",
"text",
"blob",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/vector_renderer.go#L189-L191 | train |
wcharczuk/go-chart | vector_renderer.go | MeasureText | func (vr *vectorRenderer) MeasureText(body string) (box Box) {
if vr.s.GetFont() != nil {
vr.fc = &font.Drawer{
Face: truetype.NewFace(vr.s.GetFont(), &truetype.Options{
DPI: vr.dpi,
Size: vr.s.FontSize,
}),
}
w := vr.fc.MeasureString(body).Ceil()
box.Right = w
box.Bottom = int(drawing.PointsToPixels(vr.dpi, vr.s.FontSize))
if vr.c.textTheta == nil {
return
}
box = box.Corners().Rotate(util.Math.RadiansToDegrees(*vr.c.textTheta)).Box()
}
return
} | go | func (vr *vectorRenderer) MeasureText(body string) (box Box) {
if vr.s.GetFont() != nil {
vr.fc = &font.Drawer{
Face: truetype.NewFace(vr.s.GetFont(), &truetype.Options{
DPI: vr.dpi,
Size: vr.s.FontSize,
}),
}
w := vr.fc.MeasureString(body).Ceil()
box.Right = w
box.Bottom = int(drawing.PointsToPixels(vr.dpi, vr.s.FontSize))
if vr.c.textTheta == nil {
return
}
box = box.Corners().Rotate(util.Math.RadiansToDegrees(*vr.c.textTheta)).Box()
}
return
} | [
"func",
"(",
"vr",
"*",
"vectorRenderer",
")",
"MeasureText",
"(",
"body",
"string",
")",
"(",
"box",
"Box",
")",
"{",
"if",
"vr",
".",
"s",
".",
"GetFont",
"(",
")",
"!=",
"nil",
"{",
"vr",
".",
"fc",
"=",
"&",
"font",
".",
"Drawer",
"{",
"Fac... | // MeasureText uses the truetype font drawer to measure the width of text. | [
"MeasureText",
"uses",
"the",
"truetype",
"font",
"drawer",
"to",
"measure",
"the",
"width",
"of",
"text",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/vector_renderer.go#L194-L212 | train |
wcharczuk/go-chart | vector_renderer.go | Save | func (vr *vectorRenderer) Save(w io.Writer) error {
vr.c.End()
_, err := w.Write(vr.b.Bytes())
return err
} | go | func (vr *vectorRenderer) Save(w io.Writer) error {
vr.c.End()
_, err := w.Write(vr.b.Bytes())
return err
} | [
"func",
"(",
"vr",
"*",
"vectorRenderer",
")",
"Save",
"(",
"w",
"io",
".",
"Writer",
")",
"error",
"{",
"vr",
".",
"c",
".",
"End",
"(",
")",
"\n",
"_",
",",
"err",
":=",
"w",
".",
"Write",
"(",
"vr",
".",
"b",
".",
"Bytes",
"(",
")",
")",... | // Save saves the renderer's contents to a writer. | [
"Save",
"saves",
"the",
"renderer",
"s",
"contents",
"to",
"a",
"writer",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/vector_renderer.go#L225-L229 | train |
wcharczuk/go-chart | vector_renderer.go | getStrokeDashArray | func (c *canvas) getStrokeDashArray(s Style) string {
if len(s.StrokeDashArray) > 0 {
var values []string
for _, v := range s.StrokeDashArray {
values = append(values, fmt.Sprintf("%0.1f", v))
}
return "stroke-dasharray=\"" + strings.Join(values, ", ") + "\""
}
return ""
} | go | func (c *canvas) getStrokeDashArray(s Style) string {
if len(s.StrokeDashArray) > 0 {
var values []string
for _, v := range s.StrokeDashArray {
values = append(values, fmt.Sprintf("%0.1f", v))
}
return "stroke-dasharray=\"" + strings.Join(values, ", ") + "\""
}
return ""
} | [
"func",
"(",
"c",
"*",
"canvas",
")",
"getStrokeDashArray",
"(",
"s",
"Style",
")",
"string",
"{",
"if",
"len",
"(",
"s",
".",
"StrokeDashArray",
")",
">",
"0",
"{",
"var",
"values",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
... | // getStrokeDashArray returns the stroke-dasharray property of a style. | [
"getStrokeDashArray",
"returns",
"the",
"stroke",
"-",
"dasharray",
"property",
"of",
"a",
"style",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/vector_renderer.go#L289-L298 | train |
wcharczuk/go-chart | vector_renderer.go | getFontFace | func (c *canvas) getFontFace(s Style) string {
family := "sans-serif"
if s.GetFont() != nil {
name := s.GetFont().Name(truetype.NameIDFontFamily)
if len(name) != 0 {
family = fmt.Sprintf(`'%s',%s`, name, family)
}
}
return fmt.Sprintf("font-family:%s", family)
} | go | func (c *canvas) getFontFace(s Style) string {
family := "sans-serif"
if s.GetFont() != nil {
name := s.GetFont().Name(truetype.NameIDFontFamily)
if len(name) != 0 {
family = fmt.Sprintf(`'%s',%s`, name, family)
}
}
return fmt.Sprintf("font-family:%s", family)
} | [
"func",
"(",
"c",
"*",
"canvas",
")",
"getFontFace",
"(",
"s",
"Style",
")",
"string",
"{",
"family",
":=",
"\"",
"\"",
"\n",
"if",
"s",
".",
"GetFont",
"(",
")",
"!=",
"nil",
"{",
"name",
":=",
"s",
".",
"GetFont",
"(",
")",
".",
"Name",
"(",
... | // GetFontFace returns the font face for the style. | [
"GetFontFace",
"returns",
"the",
"font",
"face",
"for",
"the",
"style",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/vector_renderer.go#L301-L310 | train |
wcharczuk/go-chart | vector_renderer.go | styleAsSVG | func (c *canvas) styleAsSVG(s Style) string {
sw := s.StrokeWidth
sc := s.StrokeColor
fc := s.FillColor
fs := s.FontSize
fnc := s.FontColor
if s.ClassName != "" {
var classes []string
classes = append(classes, s.ClassName)
if !sc.IsZero() {
classes = append(classes, "stroke")
}
if !fc.IsZero() {
classes = append(classes, "fill")
}
if fs != 0 || s.Font != nil {
classes = append(classes, "text")
}
return fmt.Sprintf("class=\"%s\"", strings.Join(classes, " "))
}
var pieces []string
if sw != 0 {
pieces = append(pieces, "stroke-width:"+fmt.Sprintf("%d", int(sw)))
} else {
pieces = append(pieces, "stroke-width:0")
}
if !sc.IsZero() {
pieces = append(pieces, "stroke:"+sc.String())
} else {
pieces = append(pieces, "stroke:none")
}
if !fnc.IsZero() {
pieces = append(pieces, "fill:"+fnc.String())
} else if !fc.IsZero() {
pieces = append(pieces, "fill:"+fc.String())
} else {
pieces = append(pieces, "fill:none")
}
if fs != 0 {
pieces = append(pieces, "font-size:"+fmt.Sprintf("%.1fpx", drawing.PointsToPixels(c.dpi, fs)))
}
if s.Font != nil {
pieces = append(pieces, c.getFontFace(s))
}
return fmt.Sprintf("style=\"%s\"", strings.Join(pieces, ";"))
} | go | func (c *canvas) styleAsSVG(s Style) string {
sw := s.StrokeWidth
sc := s.StrokeColor
fc := s.FillColor
fs := s.FontSize
fnc := s.FontColor
if s.ClassName != "" {
var classes []string
classes = append(classes, s.ClassName)
if !sc.IsZero() {
classes = append(classes, "stroke")
}
if !fc.IsZero() {
classes = append(classes, "fill")
}
if fs != 0 || s.Font != nil {
classes = append(classes, "text")
}
return fmt.Sprintf("class=\"%s\"", strings.Join(classes, " "))
}
var pieces []string
if sw != 0 {
pieces = append(pieces, "stroke-width:"+fmt.Sprintf("%d", int(sw)))
} else {
pieces = append(pieces, "stroke-width:0")
}
if !sc.IsZero() {
pieces = append(pieces, "stroke:"+sc.String())
} else {
pieces = append(pieces, "stroke:none")
}
if !fnc.IsZero() {
pieces = append(pieces, "fill:"+fnc.String())
} else if !fc.IsZero() {
pieces = append(pieces, "fill:"+fc.String())
} else {
pieces = append(pieces, "fill:none")
}
if fs != 0 {
pieces = append(pieces, "font-size:"+fmt.Sprintf("%.1fpx", drawing.PointsToPixels(c.dpi, fs)))
}
if s.Font != nil {
pieces = append(pieces, c.getFontFace(s))
}
return fmt.Sprintf("style=\"%s\"", strings.Join(pieces, ";"))
} | [
"func",
"(",
"c",
"*",
"canvas",
")",
"styleAsSVG",
"(",
"s",
"Style",
")",
"string",
"{",
"sw",
":=",
"s",
".",
"StrokeWidth",
"\n",
"sc",
":=",
"s",
".",
"StrokeColor",
"\n",
"fc",
":=",
"s",
".",
"FillColor",
"\n",
"fs",
":=",
"s",
".",
"FontS... | // styleAsSVG returns the style as a svg style or class string. | [
"styleAsSVG",
"returns",
"the",
"style",
"as",
"a",
"svg",
"style",
"or",
"class",
"string",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/vector_renderer.go#L313-L366 | train |
wcharczuk/go-chart | seq/time.go | Days | func (ts timeSequence) Days(days int) []time.Time {
var values []time.Time
for day := days; day >= 0; day-- {
values = append(values, time.Now().AddDate(0, 0, -day))
}
return values
} | go | func (ts timeSequence) Days(days int) []time.Time {
var values []time.Time
for day := days; day >= 0; day-- {
values = append(values, time.Now().AddDate(0, 0, -day))
}
return values
} | [
"func",
"(",
"ts",
"timeSequence",
")",
"Days",
"(",
"days",
"int",
")",
"[",
"]",
"time",
".",
"Time",
"{",
"var",
"values",
"[",
"]",
"time",
".",
"Time",
"\n",
"for",
"day",
":=",
"days",
";",
"day",
">=",
"0",
";",
"day",
"--",
"{",
"values... | // Days generates a seq of timestamps by day, from -days to today. | [
"Days",
"generates",
"a",
"seq",
"of",
"timestamps",
"by",
"day",
"from",
"-",
"days",
"to",
"today",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/seq/time.go#L15-L21 | train |
wcharczuk/go-chart | seq/time.go | HoursFilled | func (ts timeSequence) HoursFilled(xdata []time.Time, ydata []float64) ([]time.Time, []float64) {
start, end := util.Time.StartAndEnd(xdata...)
totalHours := util.Time.DiffHours(start, end)
finalTimes := ts.Hours(start, totalHours+1)
finalValues := make([]float64, totalHours+1)
var hoursFromStart int
for i, xd := range xdata {
hoursFromStart = util.Time.DiffHours(start, xd)
finalValues[hoursFromStart] = ydata[i]
}
return finalTimes, finalValues
} | go | func (ts timeSequence) HoursFilled(xdata []time.Time, ydata []float64) ([]time.Time, []float64) {
start, end := util.Time.StartAndEnd(xdata...)
totalHours := util.Time.DiffHours(start, end)
finalTimes := ts.Hours(start, totalHours+1)
finalValues := make([]float64, totalHours+1)
var hoursFromStart int
for i, xd := range xdata {
hoursFromStart = util.Time.DiffHours(start, xd)
finalValues[hoursFromStart] = ydata[i]
}
return finalTimes, finalValues
} | [
"func",
"(",
"ts",
"timeSequence",
")",
"HoursFilled",
"(",
"xdata",
"[",
"]",
"time",
".",
"Time",
",",
"ydata",
"[",
"]",
"float64",
")",
"(",
"[",
"]",
"time",
".",
"Time",
",",
"[",
"]",
"float64",
")",
"{",
"start",
",",
"end",
":=",
"util",... | // HoursFilled adds zero values for the data bounded by the start and end of the xdata array. | [
"HoursFilled",
"adds",
"zero",
"values",
"for",
"the",
"data",
"bounded",
"by",
"the",
"start",
"and",
"end",
"of",
"the",
"xdata",
"array",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/seq/time.go#L36-L50 | train |
wcharczuk/go-chart | drawing/flattener.go | Flatten | func Flatten(path *Path, flattener Flattener, scale float64) {
// First Point
var startX, startY float64
// Current Point
var x, y float64
var i int
for _, cmp := range path.Components {
switch cmp {
case MoveToComponent:
x, y = path.Points[i], path.Points[i+1]
startX, startY = x, y
if i != 0 {
flattener.End()
}
flattener.MoveTo(x, y)
i += 2
case LineToComponent:
x, y = path.Points[i], path.Points[i+1]
flattener.LineTo(x, y)
flattener.LineJoin()
i += 2
case QuadCurveToComponent:
// we include the previous point for the start of the curve
TraceQuad(flattener, path.Points[i-2:], 0.5)
x, y = path.Points[i+2], path.Points[i+3]
flattener.LineTo(x, y)
i += 4
case CubicCurveToComponent:
TraceCubic(flattener, path.Points[i-2:], 0.5)
x, y = path.Points[i+4], path.Points[i+5]
flattener.LineTo(x, y)
i += 6
case ArcToComponent:
x, y = TraceArc(flattener, path.Points[i], path.Points[i+1], path.Points[i+2], path.Points[i+3], path.Points[i+4], path.Points[i+5], scale)
flattener.LineTo(x, y)
i += 6
case CloseComponent:
flattener.LineTo(startX, startY)
flattener.Close()
}
}
flattener.End()
} | go | func Flatten(path *Path, flattener Flattener, scale float64) {
// First Point
var startX, startY float64
// Current Point
var x, y float64
var i int
for _, cmp := range path.Components {
switch cmp {
case MoveToComponent:
x, y = path.Points[i], path.Points[i+1]
startX, startY = x, y
if i != 0 {
flattener.End()
}
flattener.MoveTo(x, y)
i += 2
case LineToComponent:
x, y = path.Points[i], path.Points[i+1]
flattener.LineTo(x, y)
flattener.LineJoin()
i += 2
case QuadCurveToComponent:
// we include the previous point for the start of the curve
TraceQuad(flattener, path.Points[i-2:], 0.5)
x, y = path.Points[i+2], path.Points[i+3]
flattener.LineTo(x, y)
i += 4
case CubicCurveToComponent:
TraceCubic(flattener, path.Points[i-2:], 0.5)
x, y = path.Points[i+4], path.Points[i+5]
flattener.LineTo(x, y)
i += 6
case ArcToComponent:
x, y = TraceArc(flattener, path.Points[i], path.Points[i+1], path.Points[i+2], path.Points[i+3], path.Points[i+4], path.Points[i+5], scale)
flattener.LineTo(x, y)
i += 6
case CloseComponent:
flattener.LineTo(startX, startY)
flattener.Close()
}
}
flattener.End()
} | [
"func",
"Flatten",
"(",
"path",
"*",
"Path",
",",
"flattener",
"Flattener",
",",
"scale",
"float64",
")",
"{",
"// First Point",
"var",
"startX",
",",
"startY",
"float64",
"\n",
"// Current Point",
"var",
"x",
",",
"y",
"float64",
"\n",
"var",
"i",
"int",
... | // Flatten convert curves into straight segments keeping join segments info | [
"Flatten",
"convert",
"curves",
"into",
"straight",
"segments",
"keeping",
"join",
"segments",
"info"
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/flattener.go#L24-L66 | train |
wcharczuk/go-chart | drawing/flattener.go | MoveTo | func (p *SegmentedPath) MoveTo(x, y float64) {
p.Points = append(p.Points, x, y)
// TODO need to mark this point as moveto
} | go | func (p *SegmentedPath) MoveTo(x, y float64) {
p.Points = append(p.Points, x, y)
// TODO need to mark this point as moveto
} | [
"func",
"(",
"p",
"*",
"SegmentedPath",
")",
"MoveTo",
"(",
"x",
",",
"y",
"float64",
")",
"{",
"p",
".",
"Points",
"=",
"append",
"(",
"p",
".",
"Points",
",",
"x",
",",
"y",
")",
"\n",
"// TODO need to mark this point as moveto",
"}"
] | // MoveTo implements the path interface. | [
"MoveTo",
"implements",
"the",
"path",
"interface",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/flattener.go#L74-L77 | train |
wcharczuk/go-chart | drawing/flattener.go | LineTo | func (p *SegmentedPath) LineTo(x, y float64) {
p.Points = append(p.Points, x, y)
} | go | func (p *SegmentedPath) LineTo(x, y float64) {
p.Points = append(p.Points, x, y)
} | [
"func",
"(",
"p",
"*",
"SegmentedPath",
")",
"LineTo",
"(",
"x",
",",
"y",
"float64",
")",
"{",
"p",
".",
"Points",
"=",
"append",
"(",
"p",
".",
"Points",
",",
"x",
",",
"y",
")",
"\n",
"}"
] | // LineTo implements the path interface. | [
"LineTo",
"implements",
"the",
"path",
"interface",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/flattener.go#L80-L82 | train |
wcharczuk/go-chart | xaxis.go | GetTickPosition | func (xa XAxis) GetTickPosition(defaults ...TickPosition) TickPosition {
if xa.TickPosition == TickPositionUnset {
if len(defaults) > 0 {
return defaults[0]
}
return TickPositionUnderTick
}
return xa.TickPosition
} | go | func (xa XAxis) GetTickPosition(defaults ...TickPosition) TickPosition {
if xa.TickPosition == TickPositionUnset {
if len(defaults) > 0 {
return defaults[0]
}
return TickPositionUnderTick
}
return xa.TickPosition
} | [
"func",
"(",
"xa",
"XAxis",
")",
"GetTickPosition",
"(",
"defaults",
"...",
"TickPosition",
")",
"TickPosition",
"{",
"if",
"xa",
".",
"TickPosition",
"==",
"TickPositionUnset",
"{",
"if",
"len",
"(",
"defaults",
")",
">",
"0",
"{",
"return",
"defaults",
"... | // GetTickPosition returns the tick position option for the axis. | [
"GetTickPosition",
"returns",
"the",
"tick",
"position",
"option",
"for",
"the",
"axis",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/xaxis.go#L46-L54 | train |
wcharczuk/go-chart | first_value_annotation.go | FirstValueAnnotation | func FirstValueAnnotation(innerSeries ValuesProvider, vfs ...ValueFormatter) AnnotationSeries {
var vf ValueFormatter
if len(vfs) > 0 {
vf = vfs[0]
} else if typed, isTyped := innerSeries.(ValueFormatterProvider); isTyped {
_, vf = typed.GetValueFormatters()
} else {
vf = FloatValueFormatter
}
var firstValue Value2
if typed, isTyped := innerSeries.(FirstValuesProvider); isTyped {
firstValue.XValue, firstValue.YValue = typed.GetFirstValues()
firstValue.Label = vf(firstValue.YValue)
} else {
firstValue.XValue, firstValue.YValue = innerSeries.GetValues(0)
firstValue.Label = vf(firstValue.YValue)
}
var seriesName string
var seriesStyle Style
if typed, isTyped := innerSeries.(Series); isTyped {
seriesName = fmt.Sprintf("%s - First Value", typed.GetName())
seriesStyle = typed.GetStyle()
}
return AnnotationSeries{
Name: seriesName,
Style: seriesStyle,
Annotations: []Value2{firstValue},
}
} | go | func FirstValueAnnotation(innerSeries ValuesProvider, vfs ...ValueFormatter) AnnotationSeries {
var vf ValueFormatter
if len(vfs) > 0 {
vf = vfs[0]
} else if typed, isTyped := innerSeries.(ValueFormatterProvider); isTyped {
_, vf = typed.GetValueFormatters()
} else {
vf = FloatValueFormatter
}
var firstValue Value2
if typed, isTyped := innerSeries.(FirstValuesProvider); isTyped {
firstValue.XValue, firstValue.YValue = typed.GetFirstValues()
firstValue.Label = vf(firstValue.YValue)
} else {
firstValue.XValue, firstValue.YValue = innerSeries.GetValues(0)
firstValue.Label = vf(firstValue.YValue)
}
var seriesName string
var seriesStyle Style
if typed, isTyped := innerSeries.(Series); isTyped {
seriesName = fmt.Sprintf("%s - First Value", typed.GetName())
seriesStyle = typed.GetStyle()
}
return AnnotationSeries{
Name: seriesName,
Style: seriesStyle,
Annotations: []Value2{firstValue},
}
} | [
"func",
"FirstValueAnnotation",
"(",
"innerSeries",
"ValuesProvider",
",",
"vfs",
"...",
"ValueFormatter",
")",
"AnnotationSeries",
"{",
"var",
"vf",
"ValueFormatter",
"\n",
"if",
"len",
"(",
"vfs",
")",
">",
"0",
"{",
"vf",
"=",
"vfs",
"[",
"0",
"]",
"\n"... | // FirstValueAnnotation returns an annotation series of just the first value of a value provider as an annotation. | [
"FirstValueAnnotation",
"returns",
"an",
"annotation",
"series",
"of",
"just",
"the",
"first",
"value",
"of",
"a",
"value",
"provider",
"as",
"an",
"annotation",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/first_value_annotation.go#L6-L37 | train |
wcharczuk/go-chart | bar_chart.go | box | func (bc BarChart) box() Box {
dpr := bc.Background.Padding.GetRight(10)
dpb := bc.Background.Padding.GetBottom(50)
return Box{
Top: bc.Background.Padding.GetTop(20),
Left: bc.Background.Padding.GetLeft(20),
Right: bc.GetWidth() - dpr,
Bottom: bc.GetHeight() - dpb,
}
} | go | func (bc BarChart) box() Box {
dpr := bc.Background.Padding.GetRight(10)
dpb := bc.Background.Padding.GetBottom(50)
return Box{
Top: bc.Background.Padding.GetTop(20),
Left: bc.Background.Padding.GetLeft(20),
Right: bc.GetWidth() - dpr,
Bottom: bc.GetHeight() - dpb,
}
} | [
"func",
"(",
"bc",
"BarChart",
")",
"box",
"(",
")",
"Box",
"{",
"dpr",
":=",
"bc",
".",
"Background",
".",
"Padding",
".",
"GetRight",
"(",
"10",
")",
"\n",
"dpb",
":=",
"bc",
".",
"Background",
".",
"Padding",
".",
"GetBottom",
"(",
"50",
")",
... | // box returns the chart bounds as a box. | [
"box",
"returns",
"the",
"chart",
"bounds",
"as",
"a",
"box",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/bar_chart.go#L436-L446 | train |
wcharczuk/go-chart | drawing/dasher.go | NewDashVertexConverter | func NewDashVertexConverter(dash []float64, dashOffset float64, flattener Flattener) *DashVertexConverter {
var dasher DashVertexConverter
dasher.dash = dash
dasher.currentDash = 0
dasher.dashOffset = dashOffset
dasher.next = flattener
return &dasher
} | go | func NewDashVertexConverter(dash []float64, dashOffset float64, flattener Flattener) *DashVertexConverter {
var dasher DashVertexConverter
dasher.dash = dash
dasher.currentDash = 0
dasher.dashOffset = dashOffset
dasher.next = flattener
return &dasher
} | [
"func",
"NewDashVertexConverter",
"(",
"dash",
"[",
"]",
"float64",
",",
"dashOffset",
"float64",
",",
"flattener",
"Flattener",
")",
"*",
"DashVertexConverter",
"{",
"var",
"dasher",
"DashVertexConverter",
"\n",
"dasher",
".",
"dash",
"=",
"dash",
"\n",
"dasher... | // NewDashVertexConverter creates a new dash converter. | [
"NewDashVertexConverter",
"creates",
"a",
"new",
"dash",
"converter",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/dasher.go#L4-L11 | train |
wcharczuk/go-chart | drawing/dasher.go | LineTo | func (dasher *DashVertexConverter) LineTo(x, y float64) {
dasher.lineTo(x, y)
} | go | func (dasher *DashVertexConverter) LineTo(x, y float64) {
dasher.lineTo(x, y)
} | [
"func",
"(",
"dasher",
"*",
"DashVertexConverter",
")",
"LineTo",
"(",
"x",
",",
"y",
"float64",
")",
"{",
"dasher",
".",
"lineTo",
"(",
"x",
",",
"y",
")",
"\n",
"}"
] | // LineTo implements the pathbuilder interface. | [
"LineTo",
"implements",
"the",
"pathbuilder",
"interface",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/dasher.go#L23-L25 | train |
wcharczuk/go-chart | drawing/dasher.go | MoveTo | func (dasher *DashVertexConverter) MoveTo(x, y float64) {
dasher.next.MoveTo(x, y)
dasher.x, dasher.y = x, y
dasher.distance = dasher.dashOffset
dasher.currentDash = 0
} | go | func (dasher *DashVertexConverter) MoveTo(x, y float64) {
dasher.next.MoveTo(x, y)
dasher.x, dasher.y = x, y
dasher.distance = dasher.dashOffset
dasher.currentDash = 0
} | [
"func",
"(",
"dasher",
"*",
"DashVertexConverter",
")",
"MoveTo",
"(",
"x",
",",
"y",
"float64",
")",
"{",
"dasher",
".",
"next",
".",
"MoveTo",
"(",
"x",
",",
"y",
")",
"\n",
"dasher",
".",
"x",
",",
"dasher",
".",
"y",
"=",
"x",
",",
"y",
"\n... | // MoveTo implements the pathbuilder interface. | [
"MoveTo",
"implements",
"the",
"pathbuilder",
"interface",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/dasher.go#L28-L33 | train |
wcharczuk/go-chart | drawing/path.go | LastPoint | func (p *Path) LastPoint() (x, y float64) {
return p.x, p.y
} | go | func (p *Path) LastPoint() (x, y float64) {
return p.x, p.y
} | [
"func",
"(",
"p",
"*",
"Path",
")",
"LastPoint",
"(",
")",
"(",
"x",
",",
"y",
"float64",
")",
"{",
"return",
"p",
".",
"x",
",",
"p",
".",
"y",
"\n",
"}"
] | // LastPoint returns the current point of the current path | [
"LastPoint",
"returns",
"the",
"current",
"point",
"of",
"the",
"current",
"path"
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/path.go#L62-L64 | train |
wcharczuk/go-chart | drawing/path.go | LineTo | func (p *Path) LineTo(x, y float64) {
if len(p.Components) == 0 { //special case when no move has been done
p.MoveTo(0, 0)
}
p.appendToPath(LineToComponent, x, y)
p.x = x
p.y = y
} | go | func (p *Path) LineTo(x, y float64) {
if len(p.Components) == 0 { //special case when no move has been done
p.MoveTo(0, 0)
}
p.appendToPath(LineToComponent, x, y)
p.x = x
p.y = y
} | [
"func",
"(",
"p",
"*",
"Path",
")",
"LineTo",
"(",
"x",
",",
"y",
"float64",
")",
"{",
"if",
"len",
"(",
"p",
".",
"Components",
")",
"==",
"0",
"{",
"//special case when no move has been done",
"p",
".",
"MoveTo",
"(",
"0",
",",
"0",
")",
"\n",
"}... | // LineTo adds a line to the current path | [
"LineTo",
"adds",
"a",
"line",
"to",
"the",
"current",
"path"
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/path.go#L74-L81 | train |
wcharczuk/go-chart | drawing/path.go | QuadCurveTo | func (p *Path) QuadCurveTo(cx, cy, x, y float64) {
if len(p.Components) == 0 { //special case when no move has been done
p.MoveTo(0, 0)
}
p.appendToPath(QuadCurveToComponent, cx, cy, x, y)
p.x = x
p.y = y
} | go | func (p *Path) QuadCurveTo(cx, cy, x, y float64) {
if len(p.Components) == 0 { //special case when no move has been done
p.MoveTo(0, 0)
}
p.appendToPath(QuadCurveToComponent, cx, cy, x, y)
p.x = x
p.y = y
} | [
"func",
"(",
"p",
"*",
"Path",
")",
"QuadCurveTo",
"(",
"cx",
",",
"cy",
",",
"x",
",",
"y",
"float64",
")",
"{",
"if",
"len",
"(",
"p",
".",
"Components",
")",
"==",
"0",
"{",
"//special case when no move has been done",
"p",
".",
"MoveTo",
"(",
"0"... | // QuadCurveTo adds a quadratic bezier curve to the current path | [
"QuadCurveTo",
"adds",
"a",
"quadratic",
"bezier",
"curve",
"to",
"the",
"current",
"path"
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/path.go#L84-L91 | train |
wcharczuk/go-chart | drawing/path.go | Copy | func (p *Path) Copy() (dest *Path) {
dest = new(Path)
dest.Components = make([]PathComponent, len(p.Components))
copy(dest.Components, p.Components)
dest.Points = make([]float64, len(p.Points))
copy(dest.Points, p.Points)
dest.x, dest.y = p.x, p.y
return dest
} | go | func (p *Path) Copy() (dest *Path) {
dest = new(Path)
dest.Components = make([]PathComponent, len(p.Components))
copy(dest.Components, p.Components)
dest.Points = make([]float64, len(p.Points))
copy(dest.Points, p.Points)
dest.x, dest.y = p.x, p.y
return dest
} | [
"func",
"(",
"p",
"*",
"Path",
")",
"Copy",
"(",
")",
"(",
"dest",
"*",
"Path",
")",
"{",
"dest",
"=",
"new",
"(",
"Path",
")",
"\n",
"dest",
".",
"Components",
"=",
"make",
"(",
"[",
"]",
"PathComponent",
",",
"len",
"(",
"p",
".",
"Components... | // Copy make a clone of the current path and return it | [
"Copy",
"make",
"a",
"clone",
"of",
"the",
"current",
"path",
"and",
"return",
"it"
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/path.go#L138-L146 | train |
wcharczuk/go-chart | drawing/path.go | Clear | func (p *Path) Clear() {
p.Components = p.Components[0:0]
p.Points = p.Points[0:0]
return
} | go | func (p *Path) Clear() {
p.Components = p.Components[0:0]
p.Points = p.Points[0:0]
return
} | [
"func",
"(",
"p",
"*",
"Path",
")",
"Clear",
"(",
")",
"{",
"p",
".",
"Components",
"=",
"p",
".",
"Components",
"[",
"0",
":",
"0",
"]",
"\n",
"p",
".",
"Points",
"=",
"p",
".",
"Points",
"[",
"0",
":",
"0",
"]",
"\n",
"return",
"\n",
"}"
... | // Clear reset the path | [
"Clear",
"reset",
"the",
"path"
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/path.go#L149-L153 | train |
wcharczuk/go-chart | drawing/path.go | String | func (p *Path) String() string {
s := ""
j := 0
for _, cmd := range p.Components {
switch cmd {
case MoveToComponent:
s += fmt.Sprintf("MoveTo: %f, %f\n", p.Points[j], p.Points[j+1])
j = j + 2
case LineToComponent:
s += fmt.Sprintf("LineTo: %f, %f\n", p.Points[j], p.Points[j+1])
j = j + 2
case QuadCurveToComponent:
s += fmt.Sprintf("QuadCurveTo: %f, %f, %f, %f\n", p.Points[j], p.Points[j+1], p.Points[j+2], p.Points[j+3])
j = j + 4
case CubicCurveToComponent:
s += fmt.Sprintf("CubicCurveTo: %f, %f, %f, %f, %f, %f\n", p.Points[j], p.Points[j+1], p.Points[j+2], p.Points[j+3], p.Points[j+4], p.Points[j+5])
j = j + 6
case ArcToComponent:
s += fmt.Sprintf("ArcTo: %f, %f, %f, %f, %f, %f\n", p.Points[j], p.Points[j+1], p.Points[j+2], p.Points[j+3], p.Points[j+4], p.Points[j+5])
j = j + 6
case CloseComponent:
s += "Close\n"
}
}
return s
} | go | func (p *Path) String() string {
s := ""
j := 0
for _, cmd := range p.Components {
switch cmd {
case MoveToComponent:
s += fmt.Sprintf("MoveTo: %f, %f\n", p.Points[j], p.Points[j+1])
j = j + 2
case LineToComponent:
s += fmt.Sprintf("LineTo: %f, %f\n", p.Points[j], p.Points[j+1])
j = j + 2
case QuadCurveToComponent:
s += fmt.Sprintf("QuadCurveTo: %f, %f, %f, %f\n", p.Points[j], p.Points[j+1], p.Points[j+2], p.Points[j+3])
j = j + 4
case CubicCurveToComponent:
s += fmt.Sprintf("CubicCurveTo: %f, %f, %f, %f, %f, %f\n", p.Points[j], p.Points[j+1], p.Points[j+2], p.Points[j+3], p.Points[j+4], p.Points[j+5])
j = j + 6
case ArcToComponent:
s += fmt.Sprintf("ArcTo: %f, %f, %f, %f, %f, %f\n", p.Points[j], p.Points[j+1], p.Points[j+2], p.Points[j+3], p.Points[j+4], p.Points[j+5])
j = j + 6
case CloseComponent:
s += "Close\n"
}
}
return s
} | [
"func",
"(",
"p",
"*",
"Path",
")",
"String",
"(",
")",
"string",
"{",
"s",
":=",
"\"",
"\"",
"\n",
"j",
":=",
"0",
"\n",
"for",
"_",
",",
"cmd",
":=",
"range",
"p",
".",
"Components",
"{",
"switch",
"cmd",
"{",
"case",
"MoveToComponent",
":",
... | // String returns a debug text view of the path | [
"String",
"returns",
"a",
"debug",
"text",
"view",
"of",
"the",
"path"
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/path.go#L161-L186 | train |
wcharczuk/go-chart | box.go | IsZero | func (b Box) IsZero() bool {
if b.IsSet {
return false
}
return b.Top == 0 && b.Left == 0 && b.Right == 0 && b.Bottom == 0
} | go | func (b Box) IsZero() bool {
if b.IsSet {
return false
}
return b.Top == 0 && b.Left == 0 && b.Right == 0 && b.Bottom == 0
} | [
"func",
"(",
"b",
"Box",
")",
"IsZero",
"(",
")",
"bool",
"{",
"if",
"b",
".",
"IsSet",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"b",
".",
"Top",
"==",
"0",
"&&",
"b",
".",
"Left",
"==",
"0",
"&&",
"b",
".",
"Right",
"==",
"0",
"&... | // IsZero returns if the box is set or not. | [
"IsZero",
"returns",
"if",
"the",
"box",
"is",
"set",
"or",
"not",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/box.go#L36-L41 | train |
wcharczuk/go-chart | box.go | String | func (b Box) String() string {
return fmt.Sprintf("box(%d,%d,%d,%d)", b.Top, b.Left, b.Right, b.Bottom)
} | go | func (b Box) String() string {
return fmt.Sprintf("box(%d,%d,%d,%d)", b.Top, b.Left, b.Right, b.Bottom)
} | [
"func",
"(",
"b",
"Box",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"b",
".",
"Top",
",",
"b",
".",
"Left",
",",
"b",
".",
"Right",
",",
"b",
".",
"Bottom",
")",
"\n",
"}"
] | // String returns a string representation of the box. | [
"String",
"returns",
"a",
"string",
"representation",
"of",
"the",
"box",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/box.go#L44-L46 | train |
wcharczuk/go-chart | box.go | GetTop | func (b Box) GetTop(defaults ...int) int {
if !b.IsSet && b.Top == 0 {
if len(defaults) > 0 {
return defaults[0]
}
return 0
}
return b.Top
} | go | func (b Box) GetTop(defaults ...int) int {
if !b.IsSet && b.Top == 0 {
if len(defaults) > 0 {
return defaults[0]
}
return 0
}
return b.Top
} | [
"func",
"(",
"b",
"Box",
")",
"GetTop",
"(",
"defaults",
"...",
"int",
")",
"int",
"{",
"if",
"!",
"b",
".",
"IsSet",
"&&",
"b",
".",
"Top",
"==",
"0",
"{",
"if",
"len",
"(",
"defaults",
")",
">",
"0",
"{",
"return",
"defaults",
"[",
"0",
"]"... | // GetTop returns a coalesced value with a default. | [
"GetTop",
"returns",
"a",
"coalesced",
"value",
"with",
"a",
"default",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/box.go#L49-L57 | train |
wcharczuk/go-chart | box.go | GetLeft | func (b Box) GetLeft(defaults ...int) int {
if !b.IsSet && b.Left == 0 {
if len(defaults) > 0 {
return defaults[0]
}
return 0
}
return b.Left
} | go | func (b Box) GetLeft(defaults ...int) int {
if !b.IsSet && b.Left == 0 {
if len(defaults) > 0 {
return defaults[0]
}
return 0
}
return b.Left
} | [
"func",
"(",
"b",
"Box",
")",
"GetLeft",
"(",
"defaults",
"...",
"int",
")",
"int",
"{",
"if",
"!",
"b",
".",
"IsSet",
"&&",
"b",
".",
"Left",
"==",
"0",
"{",
"if",
"len",
"(",
"defaults",
")",
">",
"0",
"{",
"return",
"defaults",
"[",
"0",
"... | // GetLeft returns a coalesced value with a default. | [
"GetLeft",
"returns",
"a",
"coalesced",
"value",
"with",
"a",
"default",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/box.go#L60-L68 | train |
wcharczuk/go-chart | box.go | GetRight | func (b Box) GetRight(defaults ...int) int {
if !b.IsSet && b.Right == 0 {
if len(defaults) > 0 {
return defaults[0]
}
return 0
}
return b.Right
} | go | func (b Box) GetRight(defaults ...int) int {
if !b.IsSet && b.Right == 0 {
if len(defaults) > 0 {
return defaults[0]
}
return 0
}
return b.Right
} | [
"func",
"(",
"b",
"Box",
")",
"GetRight",
"(",
"defaults",
"...",
"int",
")",
"int",
"{",
"if",
"!",
"b",
".",
"IsSet",
"&&",
"b",
".",
"Right",
"==",
"0",
"{",
"if",
"len",
"(",
"defaults",
")",
">",
"0",
"{",
"return",
"defaults",
"[",
"0",
... | // GetRight returns a coalesced value with a default. | [
"GetRight",
"returns",
"a",
"coalesced",
"value",
"with",
"a",
"default",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/box.go#L71-L79 | train |
wcharczuk/go-chart | box.go | GetBottom | func (b Box) GetBottom(defaults ...int) int {
if !b.IsSet && b.Bottom == 0 {
if len(defaults) > 0 {
return defaults[0]
}
return 0
}
return b.Bottom
} | go | func (b Box) GetBottom(defaults ...int) int {
if !b.IsSet && b.Bottom == 0 {
if len(defaults) > 0 {
return defaults[0]
}
return 0
}
return b.Bottom
} | [
"func",
"(",
"b",
"Box",
")",
"GetBottom",
"(",
"defaults",
"...",
"int",
")",
"int",
"{",
"if",
"!",
"b",
".",
"IsSet",
"&&",
"b",
".",
"Bottom",
"==",
"0",
"{",
"if",
"len",
"(",
"defaults",
")",
">",
"0",
"{",
"return",
"defaults",
"[",
"0",... | // GetBottom returns a coalesced value with a default. | [
"GetBottom",
"returns",
"a",
"coalesced",
"value",
"with",
"a",
"default",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/box.go#L82-L90 | train |
wcharczuk/go-chart | box.go | Aspect | func (b Box) Aspect() float64 {
return float64(b.Width()) / float64(b.Height())
} | go | func (b Box) Aspect() float64 {
return float64(b.Width()) / float64(b.Height())
} | [
"func",
"(",
"b",
"Box",
")",
"Aspect",
"(",
")",
"float64",
"{",
"return",
"float64",
"(",
"b",
".",
"Width",
"(",
")",
")",
"/",
"float64",
"(",
"b",
".",
"Height",
"(",
")",
")",
"\n",
"}"
] | // Aspect returns the aspect ratio of the box. | [
"Aspect",
"returns",
"the",
"aspect",
"ratio",
"of",
"the",
"box",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/box.go#L109-L111 | train |
wcharczuk/go-chart | box.go | Clone | func (b Box) Clone() Box {
return Box{
IsSet: b.IsSet,
Top: b.Top,
Left: b.Left,
Right: b.Right,
Bottom: b.Bottom,
}
} | go | func (b Box) Clone() Box {
return Box{
IsSet: b.IsSet,
Top: b.Top,
Left: b.Left,
Right: b.Right,
Bottom: b.Bottom,
}
} | [
"func",
"(",
"b",
"Box",
")",
"Clone",
"(",
")",
"Box",
"{",
"return",
"Box",
"{",
"IsSet",
":",
"b",
".",
"IsSet",
",",
"Top",
":",
"b",
".",
"Top",
",",
"Left",
":",
"b",
".",
"Left",
",",
"Right",
":",
"b",
".",
"Right",
",",
"Bottom",
"... | // Clone returns a new copy of the box. | [
"Clone",
"returns",
"a",
"new",
"copy",
"of",
"the",
"box",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/box.go#L114-L122 | train |
wcharczuk/go-chart | box.go | IsBiggerThan | func (b Box) IsBiggerThan(other Box) bool {
return b.Top < other.Top ||
b.Bottom > other.Bottom ||
b.Left < other.Left ||
b.Right > other.Right
} | go | func (b Box) IsBiggerThan(other Box) bool {
return b.Top < other.Top ||
b.Bottom > other.Bottom ||
b.Left < other.Left ||
b.Right > other.Right
} | [
"func",
"(",
"b",
"Box",
")",
"IsBiggerThan",
"(",
"other",
"Box",
")",
"bool",
"{",
"return",
"b",
".",
"Top",
"<",
"other",
".",
"Top",
"||",
"b",
".",
"Bottom",
">",
"other",
".",
"Bottom",
"||",
"b",
".",
"Left",
"<",
"other",
".",
"Left",
... | // IsBiggerThan returns if a box is bigger than another box. | [
"IsBiggerThan",
"returns",
"if",
"a",
"box",
"is",
"bigger",
"than",
"another",
"box",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/box.go#L125-L130 | train |
wcharczuk/go-chart | box.go | Grow | func (b Box) Grow(other Box) Box {
return Box{
Top: util.Math.MinInt(b.Top, other.Top),
Left: util.Math.MinInt(b.Left, other.Left),
Right: util.Math.MaxInt(b.Right, other.Right),
Bottom: util.Math.MaxInt(b.Bottom, other.Bottom),
}
} | go | func (b Box) Grow(other Box) Box {
return Box{
Top: util.Math.MinInt(b.Top, other.Top),
Left: util.Math.MinInt(b.Left, other.Left),
Right: util.Math.MaxInt(b.Right, other.Right),
Bottom: util.Math.MaxInt(b.Bottom, other.Bottom),
}
} | [
"func",
"(",
"b",
"Box",
")",
"Grow",
"(",
"other",
"Box",
")",
"Box",
"{",
"return",
"Box",
"{",
"Top",
":",
"util",
".",
"Math",
".",
"MinInt",
"(",
"b",
".",
"Top",
",",
"other",
".",
"Top",
")",
",",
"Left",
":",
"util",
".",
"Math",
".",... | // Grow grows a box based on another box. | [
"Grow",
"grows",
"a",
"box",
"based",
"on",
"another",
"box",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/box.go#L149-L156 | train |
wcharczuk/go-chart | box.go | Shift | func (b Box) Shift(x, y int) Box {
return Box{
Top: b.Top + y,
Left: b.Left + x,
Right: b.Right + x,
Bottom: b.Bottom + y,
}
} | go | func (b Box) Shift(x, y int) Box {
return Box{
Top: b.Top + y,
Left: b.Left + x,
Right: b.Right + x,
Bottom: b.Bottom + y,
}
} | [
"func",
"(",
"b",
"Box",
")",
"Shift",
"(",
"x",
",",
"y",
"int",
")",
"Box",
"{",
"return",
"Box",
"{",
"Top",
":",
"b",
".",
"Top",
"+",
"y",
",",
"Left",
":",
"b",
".",
"Left",
"+",
"x",
",",
"Right",
":",
"b",
".",
"Right",
"+",
"x",
... | // Shift pushes a box by x,y. | [
"Shift",
"pushes",
"a",
"box",
"by",
"x",
"y",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/box.go#L159-L166 | train |
wcharczuk/go-chart | box.go | Corners | func (b Box) Corners() BoxCorners {
return BoxCorners{
TopLeft: Point{b.Left, b.Top},
TopRight: Point{b.Right, b.Top},
BottomRight: Point{b.Right, b.Bottom},
BottomLeft: Point{b.Left, b.Bottom},
}
} | go | func (b Box) Corners() BoxCorners {
return BoxCorners{
TopLeft: Point{b.Left, b.Top},
TopRight: Point{b.Right, b.Top},
BottomRight: Point{b.Right, b.Bottom},
BottomLeft: Point{b.Left, b.Bottom},
}
} | [
"func",
"(",
"b",
"Box",
")",
"Corners",
"(",
")",
"BoxCorners",
"{",
"return",
"BoxCorners",
"{",
"TopLeft",
":",
"Point",
"{",
"b",
".",
"Left",
",",
"b",
".",
"Top",
"}",
",",
"TopRight",
":",
"Point",
"{",
"b",
".",
"Right",
",",
"b",
".",
... | // Corners returns the box as a set of corners. | [
"Corners",
"returns",
"the",
"box",
"as",
"a",
"set",
"of",
"corners",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/box.go#L169-L176 | train |
wcharczuk/go-chart | box.go | Fit | func (b Box) Fit(other Box) Box {
ba := b.Aspect()
oa := other.Aspect()
if oa == ba {
return b.Clone()
}
bw, bh := float64(b.Width()), float64(b.Height())
bw2 := int(bw) >> 1
bh2 := int(bh) >> 1
if oa > ba { // ex. 16:9 vs. 4:3
var noh2 int
if oa > 1.0 {
noh2 = int(bw/oa) >> 1
} else {
noh2 = int(bh*oa) >> 1
}
return Box{
Top: (b.Top + bh2) - noh2,
Left: b.Left,
Right: b.Right,
Bottom: (b.Top + bh2) + noh2,
}
}
var now2 int
if oa > 1.0 {
now2 = int(bh/oa) >> 1
} else {
now2 = int(bw*oa) >> 1
}
return Box{
Top: b.Top,
Left: (b.Left + bw2) - now2,
Right: (b.Left + bw2) + now2,
Bottom: b.Bottom,
}
} | go | func (b Box) Fit(other Box) Box {
ba := b.Aspect()
oa := other.Aspect()
if oa == ba {
return b.Clone()
}
bw, bh := float64(b.Width()), float64(b.Height())
bw2 := int(bw) >> 1
bh2 := int(bh) >> 1
if oa > ba { // ex. 16:9 vs. 4:3
var noh2 int
if oa > 1.0 {
noh2 = int(bw/oa) >> 1
} else {
noh2 = int(bh*oa) >> 1
}
return Box{
Top: (b.Top + bh2) - noh2,
Left: b.Left,
Right: b.Right,
Bottom: (b.Top + bh2) + noh2,
}
}
var now2 int
if oa > 1.0 {
now2 = int(bh/oa) >> 1
} else {
now2 = int(bw*oa) >> 1
}
return Box{
Top: b.Top,
Left: (b.Left + bw2) - now2,
Right: (b.Left + bw2) + now2,
Bottom: b.Bottom,
}
} | [
"func",
"(",
"b",
"Box",
")",
"Fit",
"(",
"other",
"Box",
")",
"Box",
"{",
"ba",
":=",
"b",
".",
"Aspect",
"(",
")",
"\n",
"oa",
":=",
"other",
".",
"Aspect",
"(",
")",
"\n\n",
"if",
"oa",
"==",
"ba",
"{",
"return",
"b",
".",
"Clone",
"(",
... | // Fit is functionally the inverse of grow.
// Fit maintains the original aspect ratio of the `other` box,
// but constrains it to the bounds of the target box. | [
"Fit",
"is",
"functionally",
"the",
"inverse",
"of",
"grow",
".",
"Fit",
"maintains",
"the",
"original",
"aspect",
"ratio",
"of",
"the",
"other",
"box",
"but",
"constrains",
"it",
"to",
"the",
"bounds",
"of",
"the",
"target",
"box",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/box.go#L181-L218 | train |
wcharczuk/go-chart | box.go | Constrain | func (b Box) Constrain(other Box) Box {
newBox := b.Clone()
newBox.Top = util.Math.MaxInt(newBox.Top, other.Top)
newBox.Left = util.Math.MaxInt(newBox.Left, other.Left)
newBox.Right = util.Math.MinInt(newBox.Right, other.Right)
newBox.Bottom = util.Math.MinInt(newBox.Bottom, other.Bottom)
return newBox
} | go | func (b Box) Constrain(other Box) Box {
newBox := b.Clone()
newBox.Top = util.Math.MaxInt(newBox.Top, other.Top)
newBox.Left = util.Math.MaxInt(newBox.Left, other.Left)
newBox.Right = util.Math.MinInt(newBox.Right, other.Right)
newBox.Bottom = util.Math.MinInt(newBox.Bottom, other.Bottom)
return newBox
} | [
"func",
"(",
"b",
"Box",
")",
"Constrain",
"(",
"other",
"Box",
")",
"Box",
"{",
"newBox",
":=",
"b",
".",
"Clone",
"(",
")",
"\n\n",
"newBox",
".",
"Top",
"=",
"util",
".",
"Math",
".",
"MaxInt",
"(",
"newBox",
".",
"Top",
",",
"other",
".",
"... | // Constrain is similar to `Fit` except that it will work
// more literally like the opposite of grow. | [
"Constrain",
"is",
"similar",
"to",
"Fit",
"except",
"that",
"it",
"will",
"work",
"more",
"literally",
"like",
"the",
"opposite",
"of",
"grow",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/box.go#L222-L231 | train |
wcharczuk/go-chart | box.go | OuterConstrain | func (b Box) OuterConstrain(bounds, other Box) Box {
newBox := b.Clone()
if other.Top < bounds.Top {
delta := bounds.Top - other.Top
newBox.Top = b.Top + delta
}
if other.Left < bounds.Left {
delta := bounds.Left - other.Left
newBox.Left = b.Left + delta
}
if other.Right > bounds.Right {
delta := other.Right - bounds.Right
newBox.Right = b.Right - delta
}
if other.Bottom > bounds.Bottom {
delta := other.Bottom - bounds.Bottom
newBox.Bottom = b.Bottom - delta
}
return newBox
} | go | func (b Box) OuterConstrain(bounds, other Box) Box {
newBox := b.Clone()
if other.Top < bounds.Top {
delta := bounds.Top - other.Top
newBox.Top = b.Top + delta
}
if other.Left < bounds.Left {
delta := bounds.Left - other.Left
newBox.Left = b.Left + delta
}
if other.Right > bounds.Right {
delta := other.Right - bounds.Right
newBox.Right = b.Right - delta
}
if other.Bottom > bounds.Bottom {
delta := other.Bottom - bounds.Bottom
newBox.Bottom = b.Bottom - delta
}
return newBox
} | [
"func",
"(",
"b",
"Box",
")",
"OuterConstrain",
"(",
"bounds",
",",
"other",
"Box",
")",
"Box",
"{",
"newBox",
":=",
"b",
".",
"Clone",
"(",
")",
"\n",
"if",
"other",
".",
"Top",
"<",
"bounds",
".",
"Top",
"{",
"delta",
":=",
"bounds",
".",
"Top"... | // OuterConstrain is similar to `Constraint` with the difference
// that it applies corrections | [
"OuterConstrain",
"is",
"similar",
"to",
"Constraint",
"with",
"the",
"difference",
"that",
"it",
"applies",
"corrections"
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/box.go#L235-L257 | train |
wcharczuk/go-chart | box.go | Box | func (bc BoxCorners) Box() Box {
return Box{
Top: util.Math.MinInt(bc.TopLeft.Y, bc.TopRight.Y),
Left: util.Math.MinInt(bc.TopLeft.X, bc.BottomLeft.X),
Right: util.Math.MaxInt(bc.TopRight.X, bc.BottomRight.X),
Bottom: util.Math.MaxInt(bc.BottomLeft.Y, bc.BottomRight.Y),
}
} | go | func (bc BoxCorners) Box() Box {
return Box{
Top: util.Math.MinInt(bc.TopLeft.Y, bc.TopRight.Y),
Left: util.Math.MinInt(bc.TopLeft.X, bc.BottomLeft.X),
Right: util.Math.MaxInt(bc.TopRight.X, bc.BottomRight.X),
Bottom: util.Math.MaxInt(bc.BottomLeft.Y, bc.BottomRight.Y),
}
} | [
"func",
"(",
"bc",
"BoxCorners",
")",
"Box",
"(",
")",
"Box",
"{",
"return",
"Box",
"{",
"Top",
":",
"util",
".",
"Math",
".",
"MinInt",
"(",
"bc",
".",
"TopLeft",
".",
"Y",
",",
"bc",
".",
"TopRight",
".",
"Y",
")",
",",
"Left",
":",
"util",
... | // Box return the BoxCorners as a regular box. | [
"Box",
"return",
"the",
"BoxCorners",
"as",
"a",
"regular",
"box",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/box.go#L265-L272 | train |
wcharczuk/go-chart | box.go | Rotate | func (bc BoxCorners) Rotate(thetaDegrees float64) BoxCorners {
cx, cy := bc.Center()
thetaRadians := util.Math.DegreesToRadians(thetaDegrees)
tlx, tly := util.Math.RotateCoordinate(cx, cy, bc.TopLeft.X, bc.TopLeft.Y, thetaRadians)
trx, try := util.Math.RotateCoordinate(cx, cy, bc.TopRight.X, bc.TopRight.Y, thetaRadians)
brx, bry := util.Math.RotateCoordinate(cx, cy, bc.BottomRight.X, bc.BottomRight.Y, thetaRadians)
blx, bly := util.Math.RotateCoordinate(cx, cy, bc.BottomLeft.X, bc.BottomLeft.Y, thetaRadians)
return BoxCorners{
TopLeft: Point{tlx, tly},
TopRight: Point{trx, try},
BottomRight: Point{brx, bry},
BottomLeft: Point{blx, bly},
}
} | go | func (bc BoxCorners) Rotate(thetaDegrees float64) BoxCorners {
cx, cy := bc.Center()
thetaRadians := util.Math.DegreesToRadians(thetaDegrees)
tlx, tly := util.Math.RotateCoordinate(cx, cy, bc.TopLeft.X, bc.TopLeft.Y, thetaRadians)
trx, try := util.Math.RotateCoordinate(cx, cy, bc.TopRight.X, bc.TopRight.Y, thetaRadians)
brx, bry := util.Math.RotateCoordinate(cx, cy, bc.BottomRight.X, bc.BottomRight.Y, thetaRadians)
blx, bly := util.Math.RotateCoordinate(cx, cy, bc.BottomLeft.X, bc.BottomLeft.Y, thetaRadians)
return BoxCorners{
TopLeft: Point{tlx, tly},
TopRight: Point{trx, try},
BottomRight: Point{brx, bry},
BottomLeft: Point{blx, bly},
}
} | [
"func",
"(",
"bc",
"BoxCorners",
")",
"Rotate",
"(",
"thetaDegrees",
"float64",
")",
"BoxCorners",
"{",
"cx",
",",
"cy",
":=",
"bc",
".",
"Center",
"(",
")",
"\n\n",
"thetaRadians",
":=",
"util",
".",
"Math",
".",
"DegreesToRadians",
"(",
"thetaDegrees",
... | // Rotate rotates the box. | [
"Rotate",
"rotates",
"the",
"box",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/box.go#L303-L319 | train |
wcharczuk/go-chart | box.go | Equals | func (bc BoxCorners) Equals(other BoxCorners) bool {
return bc.TopLeft.Equals(other.TopLeft) &&
bc.TopRight.Equals(other.TopRight) &&
bc.BottomRight.Equals(other.BottomRight) &&
bc.BottomLeft.Equals(other.BottomLeft)
} | go | func (bc BoxCorners) Equals(other BoxCorners) bool {
return bc.TopLeft.Equals(other.TopLeft) &&
bc.TopRight.Equals(other.TopRight) &&
bc.BottomRight.Equals(other.BottomRight) &&
bc.BottomLeft.Equals(other.BottomLeft)
} | [
"func",
"(",
"bc",
"BoxCorners",
")",
"Equals",
"(",
"other",
"BoxCorners",
")",
"bool",
"{",
"return",
"bc",
".",
"TopLeft",
".",
"Equals",
"(",
"other",
".",
"TopLeft",
")",
"&&",
"bc",
".",
"TopRight",
".",
"Equals",
"(",
"other",
".",
"TopRight",
... | // Equals returns if the box equals another box. | [
"Equals",
"returns",
"if",
"the",
"box",
"equals",
"another",
"box",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/box.go#L322-L327 | train |
wcharczuk/go-chart | box.go | DistanceTo | func (p Point) DistanceTo(other Point) float64 {
dx := math.Pow(float64(p.X-other.X), 2)
dy := math.Pow(float64(p.Y-other.Y), 2)
return math.Pow(dx+dy, 0.5)
} | go | func (p Point) DistanceTo(other Point) float64 {
dx := math.Pow(float64(p.X-other.X), 2)
dy := math.Pow(float64(p.Y-other.Y), 2)
return math.Pow(dx+dy, 0.5)
} | [
"func",
"(",
"p",
"Point",
")",
"DistanceTo",
"(",
"other",
"Point",
")",
"float64",
"{",
"dx",
":=",
"math",
".",
"Pow",
"(",
"float64",
"(",
"p",
".",
"X",
"-",
"other",
".",
"X",
")",
",",
"2",
")",
"\n",
"dy",
":=",
"math",
".",
"Pow",
"(... | // DistanceTo calculates the distance to another point. | [
"DistanceTo",
"calculates",
"the",
"distance",
"to",
"another",
"point",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/box.go#L339-L343 | train |
Subsets and Splits
SQL Console for semeru/code-text-go
Retrieves a limited set of code samples with their languages, with a specific case adjustment for 'Go' language.