id
int32 0
167k
| 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
sequencelengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
sequencelengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
147,500 | 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",
"]",
"+",
"s",
"*",
"tr",
"[",
"2",
"]",
"\n",
"t1",
":=",
"s",
"*",
"tr",
"[",
"3",
"]",
"+",
"c",
"*",
"tr",
"[",
"1",
"]",
"\n",
"t2",
":=",
"c",
"*",
"tr",
"[",
"2",
"]",
"-",
"s",
"*",
"tr",
"[",
"0",
"]",
"\n",
"t3",
":=",
"c",
"*",
"tr",
"[",
"3",
"]",
"-",
"s",
"*",
"tr",
"[",
"1",
"]",
"\n",
"tr",
"[",
"0",
"]",
"=",
"t0",
"\n",
"tr",
"[",
"1",
"]",
"=",
"t1",
"\n",
"tr",
"[",
"2",
"]",
"=",
"t2",
"\n",
"tr",
"[",
"3",
"]",
"=",
"t3",
"\n",
"}"
] | // 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 |
147,501 | 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",
"*",
"tr",
"[",
"3",
"]",
"\n",
"return",
"math",
".",
"Sqrt",
"(",
"x",
"*",
"x",
"+",
"y",
"*",
"y",
")",
"\n",
"}"
] | // 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 |
147,502 | 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 |
147,503 | 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",
"]",
",",
"0",
")",
"&&",
"fequals",
"(",
"tr",
"[",
"3",
"]",
",",
"1",
")",
"\n",
"}"
] | // 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 |
147,504 | 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 |
147,505 | 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 |
147,506 | 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",
"(",
"x",
")",
",",
"float64",
"(",
"y",
")",
")",
"\n",
"}"
] | // QuadCurveTo implements the interface method. | [
"QuadCurveTo",
"implements",
"the",
"interface",
"method",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/raster_renderer.go#L87-L89 |
147,507 | 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",
"(",
"cy",
")",
",",
"rx",
",",
"ry",
",",
"startAngle",
",",
"delta",
")",
"\n",
"}"
] | // ArcTo implements the interface method. | [
"ArcTo",
"implements",
"the",
"interface",
"method",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/raster_renderer.go#L92-L94 |
147,508 | 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",
")",
"\n",
"rr",
".",
"gc",
".",
"SetLineDash",
"(",
"rr",
".",
"s",
".",
"StrokeDashArray",
",",
"0",
")",
"\n",
"rr",
".",
"gc",
".",
"Stroke",
"(",
")",
"\n",
"}"
] | // Stroke implements the interface method. | [
"Stroke",
"implements",
"the",
"interface",
"method",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/raster_renderer.go#L102-L107 |
147,509 | 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 |
147,510 | 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",
")",
"\n",
"rr",
".",
"gc",
".",
"SetLineWidth",
"(",
"rr",
".",
"s",
".",
"StrokeWidth",
")",
"\n",
"rr",
".",
"gc",
".",
"SetLineDash",
"(",
"rr",
".",
"s",
".",
"StrokeDashArray",
",",
"0",
")",
"\n",
"rr",
".",
"gc",
".",
"FillStroke",
"(",
")",
"\n",
"}"
] | // FillStroke implements the interface method. | [
"FillStroke",
"implements",
"the",
"interface",
"method",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/raster_renderer.go#L116-L122 |
147,511 | 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",
"(",
"xf",
"-",
"radius",
",",
"yf",
")",
"//9",
"\n",
"rr",
".",
"gc",
".",
"QuadCurveTo",
"(",
"xf",
"-",
"radius",
",",
"yf",
"-",
"radius",
",",
"xf",
",",
"yf",
"-",
"radius",
")",
"//12",
"\n",
"rr",
".",
"gc",
".",
"QuadCurveTo",
"(",
"xf",
"+",
"radius",
",",
"yf",
"-",
"radius",
",",
"xf",
"+",
"radius",
",",
"yf",
")",
"//3",
"\n",
"rr",
".",
"gc",
".",
"QuadCurveTo",
"(",
"xf",
"+",
"radius",
",",
"yf",
"+",
"radius",
",",
"xf",
",",
"yf",
"+",
"radius",
")",
"//6",
"\n",
"rr",
".",
"gc",
".",
"QuadCurveTo",
"(",
"xf",
"-",
"radius",
",",
"yf",
"+",
"radius",
",",
"xf",
"-",
"radius",
",",
"yf",
")",
"//9",
"\n",
"}"
] | // 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 |
147,512 | 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",
".",
"s",
".",
"Font",
")",
"\n",
"rr",
".",
"gc",
".",
"SetFontSize",
"(",
"rr",
".",
"s",
".",
"FontSize",
")",
"\n",
"rr",
".",
"gc",
".",
"SetFillColor",
"(",
"rr",
".",
"s",
".",
"FontColor",
")",
"\n",
"rr",
".",
"gc",
".",
"CreateStringPath",
"(",
"body",
",",
"float64",
"(",
"xf",
")",
",",
"float64",
"(",
"yf",
")",
")",
"\n",
"rr",
".",
"gc",
".",
"Fill",
"(",
")",
"\n",
"}"
] | // Text implements the interface method. | [
"Text",
"implements",
"the",
"interface",
"method",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/raster_renderer.go#L152-L159 |
147,513 | 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",
".",
"FontSize",
")",
"\n",
"rr",
".",
"gc",
".",
"SetFillColor",
"(",
"rr",
".",
"s",
".",
"FontColor",
")",
"\n",
"l",
",",
"t",
",",
"r",
",",
"b",
",",
"err",
":=",
"rr",
".",
"gc",
".",
"GetStringBounds",
"(",
"body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"Box",
"{",
"}",
"\n",
"}",
"\n",
"if",
"l",
"<",
"0",
"{",
"r",
"=",
"r",
"-",
"l",
"// equivalent to r+(-1*l)",
"\n",
"l",
"=",
"0",
"\n",
"}",
"\n",
"if",
"t",
"<",
"0",
"{",
"b",
"=",
"b",
"-",
"t",
"\n",
"t",
"=",
"0",
"\n",
"}",
"\n\n",
"if",
"l",
">",
"0",
"{",
"r",
"=",
"r",
"+",
"l",
"\n",
"l",
"=",
"0",
"\n",
"}",
"\n\n",
"if",
"t",
">",
"0",
"{",
"b",
"=",
"b",
"+",
"t",
"\n",
"t",
"=",
"0",
"\n",
"}",
"\n\n",
"textBox",
":=",
"Box",
"{",
"Top",
":",
"int",
"(",
"math",
".",
"Ceil",
"(",
"t",
")",
")",
",",
"Left",
":",
"int",
"(",
"math",
".",
"Ceil",
"(",
"l",
")",
")",
",",
"Right",
":",
"int",
"(",
"math",
".",
"Ceil",
"(",
"r",
")",
")",
",",
"Bottom",
":",
"int",
"(",
"math",
".",
"Ceil",
"(",
"b",
")",
")",
",",
"}",
"\n",
"if",
"rr",
".",
"rotateRadians",
"==",
"nil",
"{",
"return",
"textBox",
"\n",
"}",
"\n\n",
"return",
"textBox",
".",
"Corners",
"(",
")",
".",
"Rotate",
"(",
"util",
".",
"Math",
".",
"RadiansToDegrees",
"(",
"*",
"rr",
".",
"rotateRadians",
")",
")",
".",
"Box",
"(",
")",
"\n",
"}"
] | // 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 |
147,514 | 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 |
147,515 | 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",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"png",
".",
"Encode",
"(",
"w",
",",
"rr",
".",
"i",
")",
"\n",
"}"
] | // Save implements the interface method. | [
"Save",
"implements",
"the",
"interface",
"method",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/raster_renderer.go#L226-L232 |
147,516 | 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 |
147,517 | 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",
"(",
"cs",
".",
"YValues",
")",
"-",
"1",
"]",
"\n",
"}"
] | // 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 |
147,518 | 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",
")",
"{",
"drawOffsetIndex",
":=",
"0",
"\n",
"if",
"len",
"(",
"drawOffsetIndexes",
")",
">",
"0",
"{",
"drawOffsetIndex",
"=",
"drawOffsetIndexes",
"[",
"0",
"]",
"\n",
"}",
"\n\n",
"cb",
":=",
"canvasBox",
".",
"Bottom",
"\n",
"cl",
":=",
"canvasBox",
".",
"Left",
"\n\n",
"v0x",
",",
"v0y1",
",",
"v0y2",
":=",
"bbs",
".",
"GetBoundedValues",
"(",
"0",
")",
"\n",
"x0",
":=",
"cl",
"+",
"xrange",
".",
"Translate",
"(",
"v0x",
")",
"\n",
"y0",
":=",
"cb",
"-",
"yrange",
".",
"Translate",
"(",
"v0y1",
")",
"\n\n",
"var",
"vx",
",",
"vy1",
",",
"vy2",
"float64",
"\n",
"var",
"x",
",",
"y",
"int",
"\n\n",
"xvalues",
":=",
"make",
"(",
"[",
"]",
"float64",
",",
"bbs",
".",
"Len",
"(",
")",
")",
"\n",
"xvalues",
"[",
"0",
"]",
"=",
"v0x",
"\n",
"y2values",
":=",
"make",
"(",
"[",
"]",
"float64",
",",
"bbs",
".",
"Len",
"(",
")",
")",
"\n",
"y2values",
"[",
"0",
"]",
"=",
"v0y2",
"\n\n",
"style",
".",
"GetFillAndStrokeOptions",
"(",
")",
".",
"WriteToRenderer",
"(",
"r",
")",
"\n",
"r",
".",
"MoveTo",
"(",
"x0",
",",
"y0",
")",
"\n",
"for",
"i",
":=",
"1",
";",
"i",
"<",
"bbs",
".",
"Len",
"(",
")",
";",
"i",
"++",
"{",
"vx",
",",
"vy1",
",",
"vy2",
"=",
"bbs",
".",
"GetBoundedValues",
"(",
"i",
")",
"\n\n",
"xvalues",
"[",
"i",
"]",
"=",
"vx",
"\n",
"y2values",
"[",
"i",
"]",
"=",
"vy2",
"\n\n",
"x",
"=",
"cl",
"+",
"xrange",
".",
"Translate",
"(",
"vx",
")",
"\n",
"y",
"=",
"cb",
"-",
"yrange",
".",
"Translate",
"(",
"vy1",
")",
"\n",
"if",
"i",
">",
"drawOffsetIndex",
"{",
"r",
".",
"LineTo",
"(",
"x",
",",
"y",
")",
"\n",
"}",
"else",
"{",
"r",
".",
"MoveTo",
"(",
"x",
",",
"y",
")",
"\n",
"}",
"\n",
"}",
"\n",
"y",
"=",
"cb",
"-",
"yrange",
".",
"Translate",
"(",
"vy2",
")",
"\n",
"r",
".",
"LineTo",
"(",
"x",
",",
"y",
")",
"\n",
"for",
"i",
":=",
"bbs",
".",
"Len",
"(",
")",
"-",
"1",
";",
"i",
">=",
"drawOffsetIndex",
";",
"i",
"--",
"{",
"vx",
",",
"vy2",
"=",
"xvalues",
"[",
"i",
"]",
",",
"y2values",
"[",
"i",
"]",
"\n",
"x",
"=",
"cl",
"+",
"xrange",
".",
"Translate",
"(",
"vx",
")",
"\n",
"y",
"=",
"cb",
"-",
"yrange",
".",
"Translate",
"(",
"vy2",
")",
"\n",
"r",
".",
"LineTo",
"(",
"x",
",",
"y",
")",
"\n",
"}",
"\n",
"r",
".",
"Close",
"(",
")",
"\n",
"r",
".",
"FillStroke",
"(",
")",
"\n",
"}"
] | // 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 |
147,519 | 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",
"(",
")",
"==",
"0",
"{",
"return",
"\n",
"}",
"\n\n",
"//calculate bar width?",
"seriesLength",
":=",
"vs",
".",
"Len",
"(",
")",
"\n",
"barWidth",
":=",
"int",
"(",
"math",
".",
"Floor",
"(",
"float64",
"(",
"xrange",
".",
"GetDomain",
"(",
")",
")",
"/",
"float64",
"(",
"seriesLength",
")",
")",
")",
"\n",
"if",
"len",
"(",
"barWidths",
")",
">",
"0",
"{",
"barWidth",
"=",
"barWidths",
"[",
"0",
"]",
"\n",
"}",
"\n\n",
"cb",
":=",
"canvasBox",
".",
"Bottom",
"\n",
"cl",
":=",
"canvasBox",
".",
"Left",
"\n\n",
"//foreach datapoint, draw a box.",
"for",
"index",
":=",
"0",
";",
"index",
"<",
"seriesLength",
";",
"index",
"++",
"{",
"vx",
",",
"vy",
":=",
"vs",
".",
"GetValues",
"(",
"index",
")",
"\n",
"y0",
":=",
"yrange",
".",
"Translate",
"(",
"0",
")",
"\n",
"x",
":=",
"cl",
"+",
"xrange",
".",
"Translate",
"(",
"vx",
")",
"\n",
"y",
":=",
"yrange",
".",
"Translate",
"(",
"vy",
")",
"\n\n",
"d",
".",
"Box",
"(",
"r",
",",
"Box",
"{",
"Top",
":",
"cb",
"-",
"y0",
",",
"Left",
":",
"x",
"-",
"(",
"barWidth",
">>",
"1",
")",
",",
"Right",
":",
"x",
"+",
"(",
"barWidth",
">>",
"1",
")",
",",
"Bottom",
":",
"cb",
"-",
"y",
",",
"}",
",",
"style",
")",
"\n",
"}",
"\n",
"}"
] | // 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 |
147,520 | 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",
"defer",
"r",
".",
"ResetStyle",
"(",
")",
"\n\n",
"textBox",
":=",
"r",
".",
"MeasureText",
"(",
"label",
")",
"\n",
"textWidth",
":=",
"textBox",
".",
"Width",
"(",
")",
"\n",
"textHeight",
":=",
"textBox",
".",
"Height",
"(",
")",
"\n",
"halfTextHeight",
":=",
"textHeight",
">>",
"1",
"\n\n",
"pt",
":=",
"style",
".",
"Padding",
".",
"GetTop",
"(",
"DefaultAnnotationPadding",
".",
"Top",
")",
"\n",
"pl",
":=",
"style",
".",
"Padding",
".",
"GetLeft",
"(",
"DefaultAnnotationPadding",
".",
"Left",
")",
"\n",
"pr",
":=",
"style",
".",
"Padding",
".",
"GetRight",
"(",
"DefaultAnnotationPadding",
".",
"Right",
")",
"\n",
"pb",
":=",
"style",
".",
"Padding",
".",
"GetBottom",
"(",
"DefaultAnnotationPadding",
".",
"Bottom",
")",
"\n\n",
"strokeWidth",
":=",
"style",
".",
"GetStrokeWidth",
"(",
")",
"\n\n",
"top",
":=",
"ly",
"-",
"(",
"pt",
"+",
"halfTextHeight",
")",
"\n",
"right",
":=",
"lx",
"+",
"pl",
"+",
"pr",
"+",
"textWidth",
"+",
"DefaultAnnotationDeltaWidth",
"+",
"int",
"(",
"strokeWidth",
")",
"\n",
"bottom",
":=",
"ly",
"+",
"(",
"pb",
"+",
"halfTextHeight",
")",
"\n\n",
"return",
"Box",
"{",
"Top",
":",
"top",
",",
"Left",
":",
"lx",
",",
"Right",
":",
"right",
",",
"Bottom",
":",
"bottom",
",",
"}",
"\n",
"}"
] | // 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 |
147,521 | 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",
"(",
"r",
")",
"\n",
"defer",
"r",
".",
"ResetStyle",
"(",
")",
"\n\n",
"textBox",
":=",
"r",
".",
"MeasureText",
"(",
"label",
")",
"\n",
"textWidth",
":=",
"textBox",
".",
"Width",
"(",
")",
"\n",
"halfTextHeight",
":=",
"textBox",
".",
"Height",
"(",
")",
">>",
"1",
"\n\n",
"style",
".",
"GetFillAndStrokeOptions",
"(",
")",
".",
"WriteToRenderer",
"(",
"r",
")",
"\n\n",
"pt",
":=",
"style",
".",
"Padding",
".",
"GetTop",
"(",
"DefaultAnnotationPadding",
".",
"Top",
")",
"\n",
"pl",
":=",
"style",
".",
"Padding",
".",
"GetLeft",
"(",
"DefaultAnnotationPadding",
".",
"Left",
")",
"\n",
"pr",
":=",
"style",
".",
"Padding",
".",
"GetRight",
"(",
"DefaultAnnotationPadding",
".",
"Right",
")",
"\n",
"pb",
":=",
"style",
".",
"Padding",
".",
"GetBottom",
"(",
"DefaultAnnotationPadding",
".",
"Bottom",
")",
"\n\n",
"textX",
":=",
"lx",
"+",
"pl",
"+",
"DefaultAnnotationDeltaWidth",
"\n",
"textY",
":=",
"ly",
"+",
"halfTextHeight",
"\n\n",
"ltx",
":=",
"lx",
"+",
"DefaultAnnotationDeltaWidth",
"\n",
"lty",
":=",
"ly",
"-",
"(",
"pt",
"+",
"halfTextHeight",
")",
"\n\n",
"rtx",
":=",
"lx",
"+",
"pl",
"+",
"pr",
"+",
"textWidth",
"+",
"DefaultAnnotationDeltaWidth",
"\n",
"rty",
":=",
"ly",
"-",
"(",
"pt",
"+",
"halfTextHeight",
")",
"\n\n",
"rbx",
":=",
"lx",
"+",
"pl",
"+",
"pr",
"+",
"textWidth",
"+",
"DefaultAnnotationDeltaWidth",
"\n",
"rby",
":=",
"ly",
"+",
"(",
"pb",
"+",
"halfTextHeight",
")",
"\n\n",
"lbx",
":=",
"lx",
"+",
"DefaultAnnotationDeltaWidth",
"\n",
"lby",
":=",
"ly",
"+",
"(",
"pb",
"+",
"halfTextHeight",
")",
"\n\n",
"r",
".",
"MoveTo",
"(",
"lx",
",",
"ly",
")",
"\n",
"r",
".",
"LineTo",
"(",
"ltx",
",",
"lty",
")",
"\n",
"r",
".",
"LineTo",
"(",
"rtx",
",",
"rty",
")",
"\n",
"r",
".",
"LineTo",
"(",
"rbx",
",",
"rby",
")",
"\n",
"r",
".",
"LineTo",
"(",
"lbx",
",",
"lby",
")",
"\n",
"r",
".",
"LineTo",
"(",
"lx",
",",
"ly",
")",
"\n",
"r",
".",
"Close",
"(",
")",
"\n",
"r",
".",
"FillStroke",
"(",
")",
"\n\n",
"style",
".",
"GetTextOptions",
"(",
")",
".",
"WriteToRenderer",
"(",
"r",
")",
"\n",
"r",
".",
"Text",
"(",
"label",
",",
"textX",
",",
"textY",
")",
"\n",
"}"
] | // 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 |
147,522 | 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",
"r",
".",
"MoveTo",
"(",
"b",
".",
"Left",
",",
"b",
".",
"Top",
")",
"\n",
"r",
".",
"LineTo",
"(",
"b",
".",
"Right",
",",
"b",
".",
"Top",
")",
"\n",
"r",
".",
"LineTo",
"(",
"b",
".",
"Right",
",",
"b",
".",
"Bottom",
")",
"\n",
"r",
".",
"LineTo",
"(",
"b",
".",
"Left",
",",
"b",
".",
"Bottom",
")",
"\n",
"r",
".",
"LineTo",
"(",
"b",
".",
"Left",
",",
"b",
".",
"Top",
")",
"\n",
"r",
".",
"FillStroke",
"(",
")",
"\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 |
147,523 | 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",
".",
"ResetStyle",
"(",
")",
"\n\n",
"r",
".",
"Text",
"(",
"text",
",",
"x",
",",
"y",
")",
"\n",
"}"
] | // 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 |
147,524 | 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",
".",
"ResetStyle",
"(",
")",
"\n\n",
"lines",
":=",
"Text",
".",
"WrapFit",
"(",
"r",
",",
"text",
",",
"box",
".",
"Width",
"(",
")",
",",
"style",
")",
"\n",
"linesBox",
":=",
"Text",
".",
"MeasureLines",
"(",
"r",
",",
"lines",
",",
"style",
")",
"\n\n",
"y",
":=",
"box",
".",
"Top",
"\n\n",
"switch",
"style",
".",
"GetTextVerticalAlign",
"(",
")",
"{",
"case",
"TextVerticalAlignBottom",
",",
"TextVerticalAlignBaseline",
":",
"// i have to build better baseline handling into measure text",
"y",
"=",
"y",
"-",
"linesBox",
".",
"Height",
"(",
")",
"\n",
"case",
"TextVerticalAlignMiddle",
",",
"TextVerticalAlignMiddleBaseline",
":",
"y",
"=",
"(",
"y",
"-",
"linesBox",
".",
"Height",
"(",
")",
")",
">>",
"1",
"\n",
"}",
"\n\n",
"var",
"tx",
",",
"ty",
"int",
"\n",
"for",
"_",
",",
"line",
":=",
"range",
"lines",
"{",
"lineBox",
":=",
"r",
".",
"MeasureText",
"(",
"line",
")",
"\n",
"switch",
"style",
".",
"GetTextHorizontalAlign",
"(",
")",
"{",
"case",
"TextHorizontalAlignCenter",
":",
"tx",
"=",
"box",
".",
"Left",
"+",
"(",
"(",
"box",
".",
"Width",
"(",
")",
"-",
"lineBox",
".",
"Width",
"(",
")",
")",
">>",
"1",
")",
"\n",
"case",
"TextHorizontalAlignRight",
":",
"tx",
"=",
"box",
".",
"Right",
"-",
"lineBox",
".",
"Width",
"(",
")",
"\n",
"default",
":",
"tx",
"=",
"box",
".",
"Left",
"\n",
"}",
"\n",
"if",
"style",
".",
"TextRotationDegrees",
"==",
"0",
"{",
"ty",
"=",
"y",
"+",
"lineBox",
".",
"Height",
"(",
")",
"\n",
"}",
"else",
"{",
"ty",
"=",
"y",
"\n",
"}",
"\n\n",
"r",
".",
"Text",
"(",
"line",
",",
"tx",
",",
"ty",
")",
"\n",
"y",
"+=",
"lineBox",
".",
"Height",
"(",
")",
"+",
"style",
".",
"GetTextLineSpacing",
"(",
")",
"\n",
"}",
"\n",
"}"
] | // 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 |
147,525 | 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",
"}",
"else",
"if",
"typed",
",",
"isTyped",
":=",
"innerSeries",
".",
"(",
"ValueFormatterProvider",
")",
";",
"isTyped",
"{",
"_",
",",
"vf",
"=",
"typed",
".",
"GetValueFormatters",
"(",
")",
"\n",
"}",
"else",
"{",
"vf",
"=",
"FloatValueFormatter",
"\n",
"}",
"\n\n",
"var",
"lastValue",
"Value2",
"\n",
"if",
"typed",
",",
"isTyped",
":=",
"innerSeries",
".",
"(",
"LastValuesProvider",
")",
";",
"isTyped",
"{",
"lastValue",
".",
"XValue",
",",
"lastValue",
".",
"YValue",
"=",
"typed",
".",
"GetLastValues",
"(",
")",
"\n",
"lastValue",
".",
"Label",
"=",
"vf",
"(",
"lastValue",
".",
"YValue",
")",
"\n",
"}",
"else",
"{",
"lastValue",
".",
"XValue",
",",
"lastValue",
".",
"YValue",
"=",
"innerSeries",
".",
"GetValues",
"(",
"innerSeries",
".",
"Len",
"(",
")",
"-",
"1",
")",
"\n",
"lastValue",
".",
"Label",
"=",
"vf",
"(",
"lastValue",
".",
"YValue",
")",
"\n",
"}",
"\n\n",
"var",
"seriesName",
"string",
"\n",
"var",
"seriesStyle",
"Style",
"\n",
"if",
"typed",
",",
"isTyped",
":=",
"innerSeries",
".",
"(",
"Series",
")",
";",
"isTyped",
"{",
"seriesName",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"typed",
".",
"GetName",
"(",
")",
")",
"\n",
"seriesStyle",
"=",
"typed",
".",
"GetStyle",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"AnnotationSeries",
"{",
"Name",
":",
"seriesName",
",",
"Style",
":",
"seriesStyle",
",",
"Annotations",
":",
"[",
"]",
"Value2",
"{",
"lastValue",
"}",
",",
"}",
"\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 |
147,526 | 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 |
147,527 | 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",
",",
"x",
",",
"y",
")",
")",
"\n",
"}"
] | // QuadCurveTo draws a quad curve. | [
"QuadCurveTo",
"draws",
"a",
"quad",
"curve",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/vector_renderer.go#L112-L114 |
147,528 | 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 |
147,529 | 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",
"(",
")",
")",
"\n",
"vr",
".",
"p",
"=",
"[",
"]",
"string",
"{",
"}",
"// clear the path",
"\n",
"}"
] | // drawPath draws a path. | [
"drawPath",
"draws",
"a",
"path",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/vector_renderer.go#L163-L166 |
147,530 | 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",
".",
"GetFillAndStrokeOptions",
"(",
")",
")",
"\n",
"}"
] | // Circle implements the interface method. | [
"Circle",
"implements",
"the",
"interface",
"method",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/vector_renderer.go#L169-L171 |
147,531 | 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 |
147,532 | 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",
"{",
"Face",
":",
"truetype",
".",
"NewFace",
"(",
"vr",
".",
"s",
".",
"GetFont",
"(",
")",
",",
"&",
"truetype",
".",
"Options",
"{",
"DPI",
":",
"vr",
".",
"dpi",
",",
"Size",
":",
"vr",
".",
"s",
".",
"FontSize",
",",
"}",
")",
",",
"}",
"\n",
"w",
":=",
"vr",
".",
"fc",
".",
"MeasureString",
"(",
"body",
")",
".",
"Ceil",
"(",
")",
"\n\n",
"box",
".",
"Right",
"=",
"w",
"\n",
"box",
".",
"Bottom",
"=",
"int",
"(",
"drawing",
".",
"PointsToPixels",
"(",
"vr",
".",
"dpi",
",",
"vr",
".",
"s",
".",
"FontSize",
")",
")",
"\n",
"if",
"vr",
".",
"c",
".",
"textTheta",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"box",
"=",
"box",
".",
"Corners",
"(",
")",
".",
"Rotate",
"(",
"util",
".",
"Math",
".",
"RadiansToDegrees",
"(",
"*",
"vr",
".",
"c",
".",
"textTheta",
")",
")",
".",
"Box",
"(",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // 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 |
147,533 | 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",
"(",
")",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // 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 |
147,534 | 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",
"s",
".",
"StrokeDashArray",
"{",
"values",
"=",
"append",
"(",
"values",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"v",
")",
")",
"\n",
"}",
"\n",
"return",
"\"",
"\\\"",
"\"",
"+",
"strings",
".",
"Join",
"(",
"values",
",",
"\"",
"\"",
")",
"+",
"\"",
"\\\"",
"\"",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
"\n",
"}"
] | // 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 |
147,535 | 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",
"(",
"truetype",
".",
"NameIDFontFamily",
")",
"\n",
"if",
"len",
"(",
"name",
")",
"!=",
"0",
"{",
"family",
"=",
"fmt",
".",
"Sprintf",
"(",
"`'%s',%s`",
",",
"name",
",",
"family",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"family",
")",
"\n",
"}"
] | // 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 |
147,536 | 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",
".",
"FontSize",
"\n",
"fnc",
":=",
"s",
".",
"FontColor",
"\n\n",
"if",
"s",
".",
"ClassName",
"!=",
"\"",
"\"",
"{",
"var",
"classes",
"[",
"]",
"string",
"\n",
"classes",
"=",
"append",
"(",
"classes",
",",
"s",
".",
"ClassName",
")",
"\n",
"if",
"!",
"sc",
".",
"IsZero",
"(",
")",
"{",
"classes",
"=",
"append",
"(",
"classes",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"!",
"fc",
".",
"IsZero",
"(",
")",
"{",
"classes",
"=",
"append",
"(",
"classes",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"fs",
"!=",
"0",
"||",
"s",
".",
"Font",
"!=",
"nil",
"{",
"classes",
"=",
"append",
"(",
"classes",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\\"",
"\\\"",
"\"",
",",
"strings",
".",
"Join",
"(",
"classes",
",",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n\n",
"var",
"pieces",
"[",
"]",
"string",
"\n\n",
"if",
"sw",
"!=",
"0",
"{",
"pieces",
"=",
"append",
"(",
"pieces",
",",
"\"",
"\"",
"+",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"int",
"(",
"sw",
")",
")",
")",
"\n",
"}",
"else",
"{",
"pieces",
"=",
"append",
"(",
"pieces",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"!",
"sc",
".",
"IsZero",
"(",
")",
"{",
"pieces",
"=",
"append",
"(",
"pieces",
",",
"\"",
"\"",
"+",
"sc",
".",
"String",
"(",
")",
")",
"\n",
"}",
"else",
"{",
"pieces",
"=",
"append",
"(",
"pieces",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"!",
"fnc",
".",
"IsZero",
"(",
")",
"{",
"pieces",
"=",
"append",
"(",
"pieces",
",",
"\"",
"\"",
"+",
"fnc",
".",
"String",
"(",
")",
")",
"\n",
"}",
"else",
"if",
"!",
"fc",
".",
"IsZero",
"(",
")",
"{",
"pieces",
"=",
"append",
"(",
"pieces",
",",
"\"",
"\"",
"+",
"fc",
".",
"String",
"(",
")",
")",
"\n",
"}",
"else",
"{",
"pieces",
"=",
"append",
"(",
"pieces",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"fs",
"!=",
"0",
"{",
"pieces",
"=",
"append",
"(",
"pieces",
",",
"\"",
"\"",
"+",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"drawing",
".",
"PointsToPixels",
"(",
"c",
".",
"dpi",
",",
"fs",
")",
")",
")",
"\n",
"}",
"\n\n",
"if",
"s",
".",
"Font",
"!=",
"nil",
"{",
"pieces",
"=",
"append",
"(",
"pieces",
",",
"c",
".",
"getFontFace",
"(",
"s",
")",
")",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\\"",
"\\\"",
"\"",
",",
"strings",
".",
"Join",
"(",
"pieces",
",",
"\"",
"\"",
")",
")",
"\n",
"}"
] | // 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 |
147,537 | 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",
"=",
"append",
"(",
"values",
",",
"time",
".",
"Now",
"(",
")",
".",
"AddDate",
"(",
"0",
",",
"0",
",",
"-",
"day",
")",
")",
"\n",
"}",
"\n",
"return",
"values",
"\n",
"}"
] | // 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 |
147,538 | 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",
".",
"Time",
".",
"StartAndEnd",
"(",
"xdata",
"...",
")",
"\n",
"totalHours",
":=",
"util",
".",
"Time",
".",
"DiffHours",
"(",
"start",
",",
"end",
")",
"\n\n",
"finalTimes",
":=",
"ts",
".",
"Hours",
"(",
"start",
",",
"totalHours",
"+",
"1",
")",
"\n",
"finalValues",
":=",
"make",
"(",
"[",
"]",
"float64",
",",
"totalHours",
"+",
"1",
")",
"\n\n",
"var",
"hoursFromStart",
"int",
"\n",
"for",
"i",
",",
"xd",
":=",
"range",
"xdata",
"{",
"hoursFromStart",
"=",
"util",
".",
"Time",
".",
"DiffHours",
"(",
"start",
",",
"xd",
")",
"\n",
"finalValues",
"[",
"hoursFromStart",
"]",
"=",
"ydata",
"[",
"i",
"]",
"\n",
"}",
"\n\n",
"return",
"finalTimes",
",",
"finalValues",
"\n",
"}"
] | // 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 |
147,539 | 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",
"\n",
"for",
"_",
",",
"cmp",
":=",
"range",
"path",
".",
"Components",
"{",
"switch",
"cmp",
"{",
"case",
"MoveToComponent",
":",
"x",
",",
"y",
"=",
"path",
".",
"Points",
"[",
"i",
"]",
",",
"path",
".",
"Points",
"[",
"i",
"+",
"1",
"]",
"\n",
"startX",
",",
"startY",
"=",
"x",
",",
"y",
"\n",
"if",
"i",
"!=",
"0",
"{",
"flattener",
".",
"End",
"(",
")",
"\n",
"}",
"\n",
"flattener",
".",
"MoveTo",
"(",
"x",
",",
"y",
")",
"\n",
"i",
"+=",
"2",
"\n",
"case",
"LineToComponent",
":",
"x",
",",
"y",
"=",
"path",
".",
"Points",
"[",
"i",
"]",
",",
"path",
".",
"Points",
"[",
"i",
"+",
"1",
"]",
"\n",
"flattener",
".",
"LineTo",
"(",
"x",
",",
"y",
")",
"\n",
"flattener",
".",
"LineJoin",
"(",
")",
"\n",
"i",
"+=",
"2",
"\n",
"case",
"QuadCurveToComponent",
":",
"// we include the previous point for the start of the curve",
"TraceQuad",
"(",
"flattener",
",",
"path",
".",
"Points",
"[",
"i",
"-",
"2",
":",
"]",
",",
"0.5",
")",
"\n",
"x",
",",
"y",
"=",
"path",
".",
"Points",
"[",
"i",
"+",
"2",
"]",
",",
"path",
".",
"Points",
"[",
"i",
"+",
"3",
"]",
"\n",
"flattener",
".",
"LineTo",
"(",
"x",
",",
"y",
")",
"\n",
"i",
"+=",
"4",
"\n",
"case",
"CubicCurveToComponent",
":",
"TraceCubic",
"(",
"flattener",
",",
"path",
".",
"Points",
"[",
"i",
"-",
"2",
":",
"]",
",",
"0.5",
")",
"\n",
"x",
",",
"y",
"=",
"path",
".",
"Points",
"[",
"i",
"+",
"4",
"]",
",",
"path",
".",
"Points",
"[",
"i",
"+",
"5",
"]",
"\n",
"flattener",
".",
"LineTo",
"(",
"x",
",",
"y",
")",
"\n",
"i",
"+=",
"6",
"\n",
"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",
")",
"\n",
"flattener",
".",
"LineTo",
"(",
"x",
",",
"y",
")",
"\n",
"i",
"+=",
"6",
"\n",
"case",
"CloseComponent",
":",
"flattener",
".",
"LineTo",
"(",
"startX",
",",
"startY",
")",
"\n",
"flattener",
".",
"Close",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n",
"flattener",
".",
"End",
"(",
")",
"\n",
"}"
] | // 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 |
147,540 | 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 |
147,541 | 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 |
147,542 | 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",
"[",
"0",
"]",
"\n",
"}",
"\n",
"return",
"TickPositionUnderTick",
"\n",
"}",
"\n",
"return",
"xa",
".",
"TickPosition",
"\n",
"}"
] | // 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 |
147,543 | 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",
"}",
"else",
"if",
"typed",
",",
"isTyped",
":=",
"innerSeries",
".",
"(",
"ValueFormatterProvider",
")",
";",
"isTyped",
"{",
"_",
",",
"vf",
"=",
"typed",
".",
"GetValueFormatters",
"(",
")",
"\n",
"}",
"else",
"{",
"vf",
"=",
"FloatValueFormatter",
"\n",
"}",
"\n\n",
"var",
"firstValue",
"Value2",
"\n",
"if",
"typed",
",",
"isTyped",
":=",
"innerSeries",
".",
"(",
"FirstValuesProvider",
")",
";",
"isTyped",
"{",
"firstValue",
".",
"XValue",
",",
"firstValue",
".",
"YValue",
"=",
"typed",
".",
"GetFirstValues",
"(",
")",
"\n",
"firstValue",
".",
"Label",
"=",
"vf",
"(",
"firstValue",
".",
"YValue",
")",
"\n",
"}",
"else",
"{",
"firstValue",
".",
"XValue",
",",
"firstValue",
".",
"YValue",
"=",
"innerSeries",
".",
"GetValues",
"(",
"0",
")",
"\n",
"firstValue",
".",
"Label",
"=",
"vf",
"(",
"firstValue",
".",
"YValue",
")",
"\n",
"}",
"\n\n",
"var",
"seriesName",
"string",
"\n",
"var",
"seriesStyle",
"Style",
"\n",
"if",
"typed",
",",
"isTyped",
":=",
"innerSeries",
".",
"(",
"Series",
")",
";",
"isTyped",
"{",
"seriesName",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"typed",
".",
"GetName",
"(",
")",
")",
"\n",
"seriesStyle",
"=",
"typed",
".",
"GetStyle",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"AnnotationSeries",
"{",
"Name",
":",
"seriesName",
",",
"Style",
":",
"seriesStyle",
",",
"Annotations",
":",
"[",
"]",
"Value2",
"{",
"firstValue",
"}",
",",
"}",
"\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 |
147,544 | 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",
")",
"\n\n",
"return",
"Box",
"{",
"Top",
":",
"bc",
".",
"Background",
".",
"Padding",
".",
"GetTop",
"(",
"20",
")",
",",
"Left",
":",
"bc",
".",
"Background",
".",
"Padding",
".",
"GetLeft",
"(",
"20",
")",
",",
"Right",
":",
"bc",
".",
"GetWidth",
"(",
")",
"-",
"dpr",
",",
"Bottom",
":",
"bc",
".",
"GetHeight",
"(",
")",
"-",
"dpb",
",",
"}",
"\n",
"}"
] | // 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 |
147,545 | 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",
".",
"currentDash",
"=",
"0",
"\n",
"dasher",
".",
"dashOffset",
"=",
"dashOffset",
"\n",
"dasher",
".",
"next",
"=",
"flattener",
"\n",
"return",
"&",
"dasher",
"\n",
"}"
] | // 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 |
147,546 | 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 |
147,547 | 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",
"dasher",
".",
"distance",
"=",
"dasher",
".",
"dashOffset",
"\n",
"dasher",
".",
"currentDash",
"=",
"0",
"\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 |
147,548 | 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 |
147,549 | 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",
"}",
"\n",
"p",
".",
"appendToPath",
"(",
"LineToComponent",
",",
"x",
",",
"y",
")",
"\n",
"p",
".",
"x",
"=",
"x",
"\n",
"p",
".",
"y",
"=",
"y",
"\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 |
147,550 | 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",
",",
"0",
")",
"\n",
"}",
"\n",
"p",
".",
"appendToPath",
"(",
"QuadCurveToComponent",
",",
"cx",
",",
"cy",
",",
"x",
",",
"y",
")",
"\n",
"p",
".",
"x",
"=",
"x",
"\n",
"p",
".",
"y",
"=",
"y",
"\n",
"}"
] | // 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 |
147,551 | 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",
")",
")",
"\n",
"copy",
"(",
"dest",
".",
"Components",
",",
"p",
".",
"Components",
")",
"\n",
"dest",
".",
"Points",
"=",
"make",
"(",
"[",
"]",
"float64",
",",
"len",
"(",
"p",
".",
"Points",
")",
")",
"\n",
"copy",
"(",
"dest",
".",
"Points",
",",
"p",
".",
"Points",
")",
"\n",
"dest",
".",
"x",
",",
"dest",
".",
"y",
"=",
"p",
".",
"x",
",",
"p",
".",
"y",
"\n",
"return",
"dest",
"\n",
"}"
] | // 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 |
147,552 | 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 |
147,553 | 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",
":",
"s",
"+=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\"",
",",
"p",
".",
"Points",
"[",
"j",
"]",
",",
"p",
".",
"Points",
"[",
"j",
"+",
"1",
"]",
")",
"\n",
"j",
"=",
"j",
"+",
"2",
"\n",
"case",
"LineToComponent",
":",
"s",
"+=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\"",
",",
"p",
".",
"Points",
"[",
"j",
"]",
",",
"p",
".",
"Points",
"[",
"j",
"+",
"1",
"]",
")",
"\n",
"j",
"=",
"j",
"+",
"2",
"\n",
"case",
"QuadCurveToComponent",
":",
"s",
"+=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\"",
",",
"p",
".",
"Points",
"[",
"j",
"]",
",",
"p",
".",
"Points",
"[",
"j",
"+",
"1",
"]",
",",
"p",
".",
"Points",
"[",
"j",
"+",
"2",
"]",
",",
"p",
".",
"Points",
"[",
"j",
"+",
"3",
"]",
")",
"\n",
"j",
"=",
"j",
"+",
"4",
"\n",
"case",
"CubicCurveToComponent",
":",
"s",
"+=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\"",
",",
"p",
".",
"Points",
"[",
"j",
"]",
",",
"p",
".",
"Points",
"[",
"j",
"+",
"1",
"]",
",",
"p",
".",
"Points",
"[",
"j",
"+",
"2",
"]",
",",
"p",
".",
"Points",
"[",
"j",
"+",
"3",
"]",
",",
"p",
".",
"Points",
"[",
"j",
"+",
"4",
"]",
",",
"p",
".",
"Points",
"[",
"j",
"+",
"5",
"]",
")",
"\n",
"j",
"=",
"j",
"+",
"6",
"\n",
"case",
"ArcToComponent",
":",
"s",
"+=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\"",
",",
"p",
".",
"Points",
"[",
"j",
"]",
",",
"p",
".",
"Points",
"[",
"j",
"+",
"1",
"]",
",",
"p",
".",
"Points",
"[",
"j",
"+",
"2",
"]",
",",
"p",
".",
"Points",
"[",
"j",
"+",
"3",
"]",
",",
"p",
".",
"Points",
"[",
"j",
"+",
"4",
"]",
",",
"p",
".",
"Points",
"[",
"j",
"+",
"5",
"]",
")",
"\n",
"j",
"=",
"j",
"+",
"6",
"\n",
"case",
"CloseComponent",
":",
"s",
"+=",
"\"",
"\\n",
"\"",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"s",
"\n",
"}"
] | // 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 |
147,554 | 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",
"&&",
"b",
".",
"Bottom",
"==",
"0",
"\n",
"}"
] | // 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 |
147,555 | 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 |
147,556 | 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",
"]",
"\n",
"}",
"\n",
"return",
"0",
"\n",
"}",
"\n",
"return",
"b",
".",
"Top",
"\n",
"}"
] | // 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 |
147,557 | 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",
"]",
"\n",
"}",
"\n",
"return",
"0",
"\n",
"}",
"\n",
"return",
"b",
".",
"Left",
"\n",
"}"
] | // 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 |
147,558 | 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",
"]",
"\n",
"}",
"\n",
"return",
"0",
"\n",
"}",
"\n",
"return",
"b",
".",
"Right",
"\n",
"}"
] | // 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 |
147,559 | 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",
"]",
"\n",
"}",
"\n",
"return",
"0",
"\n",
"}",
"\n",
"return",
"b",
".",
"Bottom",
"\n",
"}"
] | // 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 |
147,560 | 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 |
147,561 | 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",
":",
"b",
".",
"Bottom",
",",
"}",
"\n",
"}"
] | // 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 |
147,562 | 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",
"||",
"b",
".",
"Right",
">",
"other",
".",
"Right",
"\n",
"}"
] | // 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 |
147,563 | 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",
".",
"MinInt",
"(",
"b",
".",
"Left",
",",
"other",
".",
"Left",
")",
",",
"Right",
":",
"util",
".",
"Math",
".",
"MaxInt",
"(",
"b",
".",
"Right",
",",
"other",
".",
"Right",
")",
",",
"Bottom",
":",
"util",
".",
"Math",
".",
"MaxInt",
"(",
"b",
".",
"Bottom",
",",
"other",
".",
"Bottom",
")",
",",
"}",
"\n",
"}"
] | // 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 |
147,564 | 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",
",",
"Bottom",
":",
"b",
".",
"Bottom",
"+",
"y",
",",
"}",
"\n",
"}"
] | // 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 |
147,565 | 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",
".",
"Top",
"}",
",",
"BottomRight",
":",
"Point",
"{",
"b",
".",
"Right",
",",
"b",
".",
"Bottom",
"}",
",",
"BottomLeft",
":",
"Point",
"{",
"b",
".",
"Left",
",",
"b",
".",
"Bottom",
"}",
",",
"}",
"\n",
"}"
] | // 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 |
147,566 | 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",
"(",
")",
"\n",
"}",
"\n\n",
"bw",
",",
"bh",
":=",
"float64",
"(",
"b",
".",
"Width",
"(",
")",
")",
",",
"float64",
"(",
"b",
".",
"Height",
"(",
")",
")",
"\n",
"bw2",
":=",
"int",
"(",
"bw",
")",
">>",
"1",
"\n",
"bh2",
":=",
"int",
"(",
"bh",
")",
">>",
"1",
"\n",
"if",
"oa",
">",
"ba",
"{",
"// ex. 16:9 vs. 4:3",
"var",
"noh2",
"int",
"\n",
"if",
"oa",
">",
"1.0",
"{",
"noh2",
"=",
"int",
"(",
"bw",
"/",
"oa",
")",
">>",
"1",
"\n",
"}",
"else",
"{",
"noh2",
"=",
"int",
"(",
"bh",
"*",
"oa",
")",
">>",
"1",
"\n",
"}",
"\n",
"return",
"Box",
"{",
"Top",
":",
"(",
"b",
".",
"Top",
"+",
"bh2",
")",
"-",
"noh2",
",",
"Left",
":",
"b",
".",
"Left",
",",
"Right",
":",
"b",
".",
"Right",
",",
"Bottom",
":",
"(",
"b",
".",
"Top",
"+",
"bh2",
")",
"+",
"noh2",
",",
"}",
"\n",
"}",
"\n",
"var",
"now2",
"int",
"\n",
"if",
"oa",
">",
"1.0",
"{",
"now2",
"=",
"int",
"(",
"bh",
"/",
"oa",
")",
">>",
"1",
"\n",
"}",
"else",
"{",
"now2",
"=",
"int",
"(",
"bw",
"*",
"oa",
")",
">>",
"1",
"\n",
"}",
"\n",
"return",
"Box",
"{",
"Top",
":",
"b",
".",
"Top",
",",
"Left",
":",
"(",
"b",
".",
"Left",
"+",
"bw2",
")",
"-",
"now2",
",",
"Right",
":",
"(",
"b",
".",
"Left",
"+",
"bw2",
")",
"+",
"now2",
",",
"Bottom",
":",
"b",
".",
"Bottom",
",",
"}",
"\n",
"}"
] | // 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 |
147,567 | 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",
".",
"Top",
")",
"\n",
"newBox",
".",
"Left",
"=",
"util",
".",
"Math",
".",
"MaxInt",
"(",
"newBox",
".",
"Left",
",",
"other",
".",
"Left",
")",
"\n",
"newBox",
".",
"Right",
"=",
"util",
".",
"Math",
".",
"MinInt",
"(",
"newBox",
".",
"Right",
",",
"other",
".",
"Right",
")",
"\n",
"newBox",
".",
"Bottom",
"=",
"util",
".",
"Math",
".",
"MinInt",
"(",
"newBox",
".",
"Bottom",
",",
"other",
".",
"Bottom",
")",
"\n\n",
"return",
"newBox",
"\n",
"}"
] | // 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 |
147,568 | 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",
"-",
"other",
".",
"Top",
"\n",
"newBox",
".",
"Top",
"=",
"b",
".",
"Top",
"+",
"delta",
"\n",
"}",
"\n\n",
"if",
"other",
".",
"Left",
"<",
"bounds",
".",
"Left",
"{",
"delta",
":=",
"bounds",
".",
"Left",
"-",
"other",
".",
"Left",
"\n",
"newBox",
".",
"Left",
"=",
"b",
".",
"Left",
"+",
"delta",
"\n",
"}",
"\n\n",
"if",
"other",
".",
"Right",
">",
"bounds",
".",
"Right",
"{",
"delta",
":=",
"other",
".",
"Right",
"-",
"bounds",
".",
"Right",
"\n",
"newBox",
".",
"Right",
"=",
"b",
".",
"Right",
"-",
"delta",
"\n",
"}",
"\n\n",
"if",
"other",
".",
"Bottom",
">",
"bounds",
".",
"Bottom",
"{",
"delta",
":=",
"other",
".",
"Bottom",
"-",
"bounds",
".",
"Bottom",
"\n",
"newBox",
".",
"Bottom",
"=",
"b",
".",
"Bottom",
"-",
"delta",
"\n",
"}",
"\n",
"return",
"newBox",
"\n",
"}"
] | // 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 |
147,569 | 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",
".",
"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",
")",
",",
"}",
"\n",
"}"
] | // 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 |
147,570 | 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",
")",
"\n\n",
"tlx",
",",
"tly",
":=",
"util",
".",
"Math",
".",
"RotateCoordinate",
"(",
"cx",
",",
"cy",
",",
"bc",
".",
"TopLeft",
".",
"X",
",",
"bc",
".",
"TopLeft",
".",
"Y",
",",
"thetaRadians",
")",
"\n",
"trx",
",",
"try",
":=",
"util",
".",
"Math",
".",
"RotateCoordinate",
"(",
"cx",
",",
"cy",
",",
"bc",
".",
"TopRight",
".",
"X",
",",
"bc",
".",
"TopRight",
".",
"Y",
",",
"thetaRadians",
")",
"\n",
"brx",
",",
"bry",
":=",
"util",
".",
"Math",
".",
"RotateCoordinate",
"(",
"cx",
",",
"cy",
",",
"bc",
".",
"BottomRight",
".",
"X",
",",
"bc",
".",
"BottomRight",
".",
"Y",
",",
"thetaRadians",
")",
"\n",
"blx",
",",
"bly",
":=",
"util",
".",
"Math",
".",
"RotateCoordinate",
"(",
"cx",
",",
"cy",
",",
"bc",
".",
"BottomLeft",
".",
"X",
",",
"bc",
".",
"BottomLeft",
".",
"Y",
",",
"thetaRadians",
")",
"\n\n",
"return",
"BoxCorners",
"{",
"TopLeft",
":",
"Point",
"{",
"tlx",
",",
"tly",
"}",
",",
"TopRight",
":",
"Point",
"{",
"trx",
",",
"try",
"}",
",",
"BottomRight",
":",
"Point",
"{",
"brx",
",",
"bry",
"}",
",",
"BottomLeft",
":",
"Point",
"{",
"blx",
",",
"bly",
"}",
",",
"}",
"\n",
"}"
] | // Rotate rotates the box. | [
"Rotate",
"rotates",
"the",
"box",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/box.go#L303-L319 |
147,571 | 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",
")",
"&&",
"bc",
".",
"BottomRight",
".",
"Equals",
"(",
"other",
".",
"BottomRight",
")",
"&&",
"bc",
".",
"BottomLeft",
".",
"Equals",
"(",
"other",
".",
"BottomLeft",
")",
"\n",
"}"
] | // 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 |
147,572 | 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",
"(",
"float64",
"(",
"p",
".",
"Y",
"-",
"other",
".",
"Y",
")",
",",
"2",
")",
"\n",
"return",
"math",
".",
"Pow",
"(",
"dx",
"+",
"dy",
",",
"0.5",
")",
"\n",
"}"
] | // 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 |
147,573 | wcharczuk/go-chart | box.go | Equals | func (p Point) Equals(other Point) bool {
return p.X == other.X && p.Y == other.Y
} | go | func (p Point) Equals(other Point) bool {
return p.X == other.X && p.Y == other.Y
} | [
"func",
"(",
"p",
"Point",
")",
"Equals",
"(",
"other",
"Point",
")",
"bool",
"{",
"return",
"p",
".",
"X",
"==",
"other",
".",
"X",
"&&",
"p",
".",
"Y",
"==",
"other",
".",
"Y",
"\n",
"}"
] | // Equals returns if a point equals another point. | [
"Equals",
"returns",
"if",
"a",
"point",
"equals",
"another",
"point",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/box.go#L346-L348 |
147,574 | wcharczuk/go-chart | tick.go | Swap | func (t Ticks) Swap(i, j int) {
t[i], t[j] = t[j], t[i]
} | go | func (t Ticks) Swap(i, j int) {
t[i], t[j] = t[j], t[i]
} | [
"func",
"(",
"t",
"Ticks",
")",
"Swap",
"(",
"i",
",",
"j",
"int",
")",
"{",
"t",
"[",
"i",
"]",
",",
"t",
"[",
"j",
"]",
"=",
"t",
"[",
"j",
"]",
",",
"t",
"[",
"i",
"]",
"\n",
"}"
] | // Swap swaps two elements. | [
"Swap",
"swaps",
"two",
"elements",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/tick.go#L31-L33 |
147,575 | wcharczuk/go-chart | tick.go | Less | func (t Ticks) Less(i, j int) bool {
return t[i].Value < t[j].Value
} | go | func (t Ticks) Less(i, j int) bool {
return t[i].Value < t[j].Value
} | [
"func",
"(",
"t",
"Ticks",
")",
"Less",
"(",
"i",
",",
"j",
"int",
")",
"bool",
"{",
"return",
"t",
"[",
"i",
"]",
".",
"Value",
"<",
"t",
"[",
"j",
"]",
".",
"Value",
"\n",
"}"
] | // Less returns if i's value is less than j's value. | [
"Less",
"returns",
"if",
"i",
"s",
"value",
"is",
"less",
"than",
"j",
"s",
"value",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/tick.go#L36-L38 |
147,576 | wcharczuk/go-chart | tick.go | String | func (t Ticks) String() string {
var values []string
for i, tick := range t {
values = append(values, fmt.Sprintf("[%d: %s]", i, tick.Label))
}
return strings.Join(values, ", ")
} | go | func (t Ticks) String() string {
var values []string
for i, tick := range t {
values = append(values, fmt.Sprintf("[%d: %s]", i, tick.Label))
}
return strings.Join(values, ", ")
} | [
"func",
"(",
"t",
"Ticks",
")",
"String",
"(",
")",
"string",
"{",
"var",
"values",
"[",
"]",
"string",
"\n",
"for",
"i",
",",
"tick",
":=",
"range",
"t",
"{",
"values",
"=",
"append",
"(",
"values",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"i",
",",
"tick",
".",
"Label",
")",
")",
"\n",
"}",
"\n",
"return",
"strings",
".",
"Join",
"(",
"values",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // String returns a string representation of the set of ticks. | [
"String",
"returns",
"a",
"string",
"representation",
"of",
"the",
"set",
"of",
"ticks",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/tick.go#L41-L47 |
147,577 | wcharczuk/go-chart | tick.go | GenerateContinuousTicks | func GenerateContinuousTicks(r Renderer, ra Range, isVertical bool, style Style, vf ValueFormatter) []Tick {
if vf == nil {
vf = FloatValueFormatter
}
var ticks []Tick
min, max := ra.GetMin(), ra.GetMax()
if ra.IsDescending() {
ticks = append(ticks, Tick{
Value: max,
Label: vf(max),
})
} else {
ticks = append(ticks, Tick{
Value: min,
Label: vf(min),
})
}
minLabel := vf(min)
style.GetTextOptions().WriteToRenderer(r)
labelBox := r.MeasureText(minLabel)
var tickSize float64
if isVertical {
tickSize = float64(labelBox.Height() + DefaultMinimumTickVerticalSpacing)
} else {
tickSize = float64(labelBox.Width() + DefaultMinimumTickHorizontalSpacing)
}
domain := float64(ra.GetDomain())
domainRemainder := domain - (tickSize * 2)
intermediateTickCount := int(math.Floor(float64(domainRemainder) / float64(tickSize)))
rangeDelta := math.Abs(max - min)
tickStep := rangeDelta / float64(intermediateTickCount)
roundTo := util.Math.GetRoundToForDelta(rangeDelta) / 10
intermediateTickCount = util.Math.MinInt(intermediateTickCount, DefaultTickCountSanityCheck)
for x := 1; x < intermediateTickCount; x++ {
var tickValue float64
if ra.IsDescending() {
tickValue = max - util.Math.RoundUp(tickStep*float64(x), roundTo)
} else {
tickValue = min + util.Math.RoundUp(tickStep*float64(x), roundTo)
}
ticks = append(ticks, Tick{
Value: tickValue,
Label: vf(tickValue),
})
}
if ra.IsDescending() {
ticks = append(ticks, Tick{
Value: min,
Label: vf(min),
})
} else {
ticks = append(ticks, Tick{
Value: max,
Label: vf(max),
})
}
return ticks
} | go | func GenerateContinuousTicks(r Renderer, ra Range, isVertical bool, style Style, vf ValueFormatter) []Tick {
if vf == nil {
vf = FloatValueFormatter
}
var ticks []Tick
min, max := ra.GetMin(), ra.GetMax()
if ra.IsDescending() {
ticks = append(ticks, Tick{
Value: max,
Label: vf(max),
})
} else {
ticks = append(ticks, Tick{
Value: min,
Label: vf(min),
})
}
minLabel := vf(min)
style.GetTextOptions().WriteToRenderer(r)
labelBox := r.MeasureText(minLabel)
var tickSize float64
if isVertical {
tickSize = float64(labelBox.Height() + DefaultMinimumTickVerticalSpacing)
} else {
tickSize = float64(labelBox.Width() + DefaultMinimumTickHorizontalSpacing)
}
domain := float64(ra.GetDomain())
domainRemainder := domain - (tickSize * 2)
intermediateTickCount := int(math.Floor(float64(domainRemainder) / float64(tickSize)))
rangeDelta := math.Abs(max - min)
tickStep := rangeDelta / float64(intermediateTickCount)
roundTo := util.Math.GetRoundToForDelta(rangeDelta) / 10
intermediateTickCount = util.Math.MinInt(intermediateTickCount, DefaultTickCountSanityCheck)
for x := 1; x < intermediateTickCount; x++ {
var tickValue float64
if ra.IsDescending() {
tickValue = max - util.Math.RoundUp(tickStep*float64(x), roundTo)
} else {
tickValue = min + util.Math.RoundUp(tickStep*float64(x), roundTo)
}
ticks = append(ticks, Tick{
Value: tickValue,
Label: vf(tickValue),
})
}
if ra.IsDescending() {
ticks = append(ticks, Tick{
Value: min,
Label: vf(min),
})
} else {
ticks = append(ticks, Tick{
Value: max,
Label: vf(max),
})
}
return ticks
} | [
"func",
"GenerateContinuousTicks",
"(",
"r",
"Renderer",
",",
"ra",
"Range",
",",
"isVertical",
"bool",
",",
"style",
"Style",
",",
"vf",
"ValueFormatter",
")",
"[",
"]",
"Tick",
"{",
"if",
"vf",
"==",
"nil",
"{",
"vf",
"=",
"FloatValueFormatter",
"\n",
"}",
"\n\n",
"var",
"ticks",
"[",
"]",
"Tick",
"\n",
"min",
",",
"max",
":=",
"ra",
".",
"GetMin",
"(",
")",
",",
"ra",
".",
"GetMax",
"(",
")",
"\n\n",
"if",
"ra",
".",
"IsDescending",
"(",
")",
"{",
"ticks",
"=",
"append",
"(",
"ticks",
",",
"Tick",
"{",
"Value",
":",
"max",
",",
"Label",
":",
"vf",
"(",
"max",
")",
",",
"}",
")",
"\n",
"}",
"else",
"{",
"ticks",
"=",
"append",
"(",
"ticks",
",",
"Tick",
"{",
"Value",
":",
"min",
",",
"Label",
":",
"vf",
"(",
"min",
")",
",",
"}",
")",
"\n",
"}",
"\n\n",
"minLabel",
":=",
"vf",
"(",
"min",
")",
"\n",
"style",
".",
"GetTextOptions",
"(",
")",
".",
"WriteToRenderer",
"(",
"r",
")",
"\n",
"labelBox",
":=",
"r",
".",
"MeasureText",
"(",
"minLabel",
")",
"\n\n",
"var",
"tickSize",
"float64",
"\n",
"if",
"isVertical",
"{",
"tickSize",
"=",
"float64",
"(",
"labelBox",
".",
"Height",
"(",
")",
"+",
"DefaultMinimumTickVerticalSpacing",
")",
"\n",
"}",
"else",
"{",
"tickSize",
"=",
"float64",
"(",
"labelBox",
".",
"Width",
"(",
")",
"+",
"DefaultMinimumTickHorizontalSpacing",
")",
"\n",
"}",
"\n\n",
"domain",
":=",
"float64",
"(",
"ra",
".",
"GetDomain",
"(",
")",
")",
"\n",
"domainRemainder",
":=",
"domain",
"-",
"(",
"tickSize",
"*",
"2",
")",
"\n",
"intermediateTickCount",
":=",
"int",
"(",
"math",
".",
"Floor",
"(",
"float64",
"(",
"domainRemainder",
")",
"/",
"float64",
"(",
"tickSize",
")",
")",
")",
"\n\n",
"rangeDelta",
":=",
"math",
".",
"Abs",
"(",
"max",
"-",
"min",
")",
"\n",
"tickStep",
":=",
"rangeDelta",
"/",
"float64",
"(",
"intermediateTickCount",
")",
"\n\n",
"roundTo",
":=",
"util",
".",
"Math",
".",
"GetRoundToForDelta",
"(",
"rangeDelta",
")",
"/",
"10",
"\n",
"intermediateTickCount",
"=",
"util",
".",
"Math",
".",
"MinInt",
"(",
"intermediateTickCount",
",",
"DefaultTickCountSanityCheck",
")",
"\n\n",
"for",
"x",
":=",
"1",
";",
"x",
"<",
"intermediateTickCount",
";",
"x",
"++",
"{",
"var",
"tickValue",
"float64",
"\n",
"if",
"ra",
".",
"IsDescending",
"(",
")",
"{",
"tickValue",
"=",
"max",
"-",
"util",
".",
"Math",
".",
"RoundUp",
"(",
"tickStep",
"*",
"float64",
"(",
"x",
")",
",",
"roundTo",
")",
"\n",
"}",
"else",
"{",
"tickValue",
"=",
"min",
"+",
"util",
".",
"Math",
".",
"RoundUp",
"(",
"tickStep",
"*",
"float64",
"(",
"x",
")",
",",
"roundTo",
")",
"\n",
"}",
"\n",
"ticks",
"=",
"append",
"(",
"ticks",
",",
"Tick",
"{",
"Value",
":",
"tickValue",
",",
"Label",
":",
"vf",
"(",
"tickValue",
")",
",",
"}",
")",
"\n",
"}",
"\n\n",
"if",
"ra",
".",
"IsDescending",
"(",
")",
"{",
"ticks",
"=",
"append",
"(",
"ticks",
",",
"Tick",
"{",
"Value",
":",
"min",
",",
"Label",
":",
"vf",
"(",
"min",
")",
",",
"}",
")",
"\n",
"}",
"else",
"{",
"ticks",
"=",
"append",
"(",
"ticks",
",",
"Tick",
"{",
"Value",
":",
"max",
",",
"Label",
":",
"vf",
"(",
"max",
")",
",",
"}",
")",
"\n",
"}",
"\n\n",
"return",
"ticks",
"\n",
"}"
] | // GenerateContinuousTicks generates a set of ticks. | [
"GenerateContinuousTicks",
"generates",
"a",
"set",
"of",
"ticks",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/tick.go#L50-L117 |
147,578 | wcharczuk/go-chart | matrix/matrix.go | New | func New(rows, cols int, values ...float64) *Matrix {
if len(values) == 0 {
return &Matrix{
stride: cols,
epsilon: DefaultEpsilon,
elements: make([]float64, rows*cols),
}
}
elems := make([]float64, rows*cols)
copy(elems, values)
return &Matrix{
stride: cols,
epsilon: DefaultEpsilon,
elements: elems,
}
} | go | func New(rows, cols int, values ...float64) *Matrix {
if len(values) == 0 {
return &Matrix{
stride: cols,
epsilon: DefaultEpsilon,
elements: make([]float64, rows*cols),
}
}
elems := make([]float64, rows*cols)
copy(elems, values)
return &Matrix{
stride: cols,
epsilon: DefaultEpsilon,
elements: elems,
}
} | [
"func",
"New",
"(",
"rows",
",",
"cols",
"int",
",",
"values",
"...",
"float64",
")",
"*",
"Matrix",
"{",
"if",
"len",
"(",
"values",
")",
"==",
"0",
"{",
"return",
"&",
"Matrix",
"{",
"stride",
":",
"cols",
",",
"epsilon",
":",
"DefaultEpsilon",
",",
"elements",
":",
"make",
"(",
"[",
"]",
"float64",
",",
"rows",
"*",
"cols",
")",
",",
"}",
"\n",
"}",
"\n",
"elems",
":=",
"make",
"(",
"[",
"]",
"float64",
",",
"rows",
"*",
"cols",
")",
"\n",
"copy",
"(",
"elems",
",",
"values",
")",
"\n",
"return",
"&",
"Matrix",
"{",
"stride",
":",
"cols",
",",
"epsilon",
":",
"DefaultEpsilon",
",",
"elements",
":",
"elems",
",",
"}",
"\n",
"}"
] | // New returns a new matrix. | [
"New",
"returns",
"a",
"new",
"matrix",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/matrix/matrix.go#L24-L39 |
147,579 | wcharczuk/go-chart | matrix/matrix.go | Identity | func Identity(order int) *Matrix {
m := New(order, order)
for i := 0; i < order; i++ {
m.Set(i, i, 1)
}
return m
} | go | func Identity(order int) *Matrix {
m := New(order, order)
for i := 0; i < order; i++ {
m.Set(i, i, 1)
}
return m
} | [
"func",
"Identity",
"(",
"order",
"int",
")",
"*",
"Matrix",
"{",
"m",
":=",
"New",
"(",
"order",
",",
"order",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"order",
";",
"i",
"++",
"{",
"m",
".",
"Set",
"(",
"i",
",",
"i",
",",
"1",
")",
"\n",
"}",
"\n",
"return",
"m",
"\n",
"}"
] | // Identity returns the identity matrix of a given order. | [
"Identity",
"returns",
"the",
"identity",
"matrix",
"of",
"a",
"given",
"order",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/matrix/matrix.go#L42-L48 |
147,580 | wcharczuk/go-chart | matrix/matrix.go | Ones | func Ones(rows, cols int) *Matrix {
ones := make([]float64, rows*cols)
for i := 0; i < (rows * cols); i++ {
ones[i] = 1
}
return &Matrix{
stride: cols,
epsilon: DefaultEpsilon,
elements: ones,
}
} | go | func Ones(rows, cols int) *Matrix {
ones := make([]float64, rows*cols)
for i := 0; i < (rows * cols); i++ {
ones[i] = 1
}
return &Matrix{
stride: cols,
epsilon: DefaultEpsilon,
elements: ones,
}
} | [
"func",
"Ones",
"(",
"rows",
",",
"cols",
"int",
")",
"*",
"Matrix",
"{",
"ones",
":=",
"make",
"(",
"[",
"]",
"float64",
",",
"rows",
"*",
"cols",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"(",
"rows",
"*",
"cols",
")",
";",
"i",
"++",
"{",
"ones",
"[",
"i",
"]",
"=",
"1",
"\n",
"}",
"\n\n",
"return",
"&",
"Matrix",
"{",
"stride",
":",
"cols",
",",
"epsilon",
":",
"DefaultEpsilon",
",",
"elements",
":",
"ones",
",",
"}",
"\n",
"}"
] | // Ones returns an matrix of ones. | [
"Ones",
"returns",
"an",
"matrix",
"of",
"ones",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/matrix/matrix.go#L56-L67 |
147,581 | wcharczuk/go-chart | matrix/matrix.go | Eye | func Eye(n int) *Matrix {
m := Zero(n, n)
for i := 0; i < len(m.elements); i += n + 1 {
m.elements[i] = 1
}
return m
} | go | func Eye(n int) *Matrix {
m := Zero(n, n)
for i := 0; i < len(m.elements); i += n + 1 {
m.elements[i] = 1
}
return m
} | [
"func",
"Eye",
"(",
"n",
"int",
")",
"*",
"Matrix",
"{",
"m",
":=",
"Zero",
"(",
"n",
",",
"n",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"m",
".",
"elements",
")",
";",
"i",
"+=",
"n",
"+",
"1",
"{",
"m",
".",
"elements",
"[",
"i",
"]",
"=",
"1",
"\n",
"}",
"\n",
"return",
"m",
"\n",
"}"
] | // Eye returns the eye matrix. | [
"Eye",
"returns",
"the",
"eye",
"matrix",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/matrix/matrix.go#L70-L76 |
147,582 | wcharczuk/go-chart | matrix/matrix.go | NewFromArrays | func NewFromArrays(a [][]float64) *Matrix {
rows := len(a)
if rows == 0 {
return nil
}
cols := len(a[0])
m := New(rows, cols)
for row := 0; row < rows; row++ {
for col := 0; col < cols; col++ {
m.Set(row, col, a[row][col])
}
}
return m
} | go | func NewFromArrays(a [][]float64) *Matrix {
rows := len(a)
if rows == 0 {
return nil
}
cols := len(a[0])
m := New(rows, cols)
for row := 0; row < rows; row++ {
for col := 0; col < cols; col++ {
m.Set(row, col, a[row][col])
}
}
return m
} | [
"func",
"NewFromArrays",
"(",
"a",
"[",
"]",
"[",
"]",
"float64",
")",
"*",
"Matrix",
"{",
"rows",
":=",
"len",
"(",
"a",
")",
"\n",
"if",
"rows",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"cols",
":=",
"len",
"(",
"a",
"[",
"0",
"]",
")",
"\n",
"m",
":=",
"New",
"(",
"rows",
",",
"cols",
")",
"\n",
"for",
"row",
":=",
"0",
";",
"row",
"<",
"rows",
";",
"row",
"++",
"{",
"for",
"col",
":=",
"0",
";",
"col",
"<",
"cols",
";",
"col",
"++",
"{",
"m",
".",
"Set",
"(",
"row",
",",
"col",
",",
"a",
"[",
"row",
"]",
"[",
"col",
"]",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"m",
"\n",
"}"
] | // NewFromArrays creates a matrix from a jagged array set. | [
"NewFromArrays",
"creates",
"a",
"matrix",
"from",
"a",
"jagged",
"array",
"set",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/matrix/matrix.go#L79-L92 |
147,583 | wcharczuk/go-chart | matrix/matrix.go | String | func (m *Matrix) String() string {
buffer := bytes.NewBuffer(nil)
rows, cols := m.Size()
for row := 0; row < rows; row++ {
for col := 0; col < cols; col++ {
buffer.WriteString(f64s(m.Get(row, col)))
buffer.WriteRune(' ')
}
buffer.WriteRune('\n')
}
return buffer.String()
} | go | func (m *Matrix) String() string {
buffer := bytes.NewBuffer(nil)
rows, cols := m.Size()
for row := 0; row < rows; row++ {
for col := 0; col < cols; col++ {
buffer.WriteString(f64s(m.Get(row, col)))
buffer.WriteRune(' ')
}
buffer.WriteRune('\n')
}
return buffer.String()
} | [
"func",
"(",
"m",
"*",
"Matrix",
")",
"String",
"(",
")",
"string",
"{",
"buffer",
":=",
"bytes",
".",
"NewBuffer",
"(",
"nil",
")",
"\n",
"rows",
",",
"cols",
":=",
"m",
".",
"Size",
"(",
")",
"\n\n",
"for",
"row",
":=",
"0",
";",
"row",
"<",
"rows",
";",
"row",
"++",
"{",
"for",
"col",
":=",
"0",
";",
"col",
"<",
"cols",
";",
"col",
"++",
"{",
"buffer",
".",
"WriteString",
"(",
"f64s",
"(",
"m",
".",
"Get",
"(",
"row",
",",
"col",
")",
")",
")",
"\n",
"buffer",
".",
"WriteRune",
"(",
"' '",
")",
"\n",
"}",
"\n",
"buffer",
".",
"WriteRune",
"(",
"'\\n'",
")",
"\n",
"}",
"\n",
"return",
"buffer",
".",
"String",
"(",
")",
"\n",
"}"
] | // String returns a string representation of the matrix. | [
"String",
"returns",
"a",
"string",
"representation",
"of",
"the",
"matrix",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/matrix/matrix.go#L102-L114 |
147,584 | wcharczuk/go-chart | matrix/matrix.go | WithEpsilon | func (m *Matrix) WithEpsilon(epsilon float64) *Matrix {
m.epsilon = epsilon
return m
} | go | func (m *Matrix) WithEpsilon(epsilon float64) *Matrix {
m.epsilon = epsilon
return m
} | [
"func",
"(",
"m",
"*",
"Matrix",
")",
"WithEpsilon",
"(",
"epsilon",
"float64",
")",
"*",
"Matrix",
"{",
"m",
".",
"epsilon",
"=",
"epsilon",
"\n",
"return",
"m",
"\n",
"}"
] | // WithEpsilon sets the epsilon on the matrix and returns a reference to the matrix. | [
"WithEpsilon",
"sets",
"the",
"epsilon",
"on",
"the",
"matrix",
"and",
"returns",
"a",
"reference",
"to",
"the",
"matrix",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/matrix/matrix.go#L122-L125 |
147,585 | wcharczuk/go-chart | matrix/matrix.go | Each | func (m *Matrix) Each(action func(row, col int, value float64)) {
rows, cols := m.Size()
for row := 0; row < rows; row++ {
for col := 0; col < cols; col++ {
action(row, col, m.Get(row, col))
}
}
} | go | func (m *Matrix) Each(action func(row, col int, value float64)) {
rows, cols := m.Size()
for row := 0; row < rows; row++ {
for col := 0; col < cols; col++ {
action(row, col, m.Get(row, col))
}
}
} | [
"func",
"(",
"m",
"*",
"Matrix",
")",
"Each",
"(",
"action",
"func",
"(",
"row",
",",
"col",
"int",
",",
"value",
"float64",
")",
")",
"{",
"rows",
",",
"cols",
":=",
"m",
".",
"Size",
"(",
")",
"\n",
"for",
"row",
":=",
"0",
";",
"row",
"<",
"rows",
";",
"row",
"++",
"{",
"for",
"col",
":=",
"0",
";",
"col",
"<",
"cols",
";",
"col",
"++",
"{",
"action",
"(",
"row",
",",
"col",
",",
"m",
".",
"Get",
"(",
"row",
",",
"col",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // Each applies the action to each element of the matrix in
// rows => cols order. | [
"Each",
"applies",
"the",
"action",
"to",
"each",
"element",
"of",
"the",
"matrix",
"in",
"rows",
"=",
">",
"cols",
"order",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/matrix/matrix.go#L129-L136 |
147,586 | wcharczuk/go-chart | matrix/matrix.go | Round | func (m *Matrix) Round() *Matrix {
rows, cols := m.Size()
for row := 0; row < rows; row++ {
for col := 0; col < cols; col++ {
m.Set(row, col, roundToEpsilon(m.Get(row, col), m.epsilon))
}
}
return m
} | go | func (m *Matrix) Round() *Matrix {
rows, cols := m.Size()
for row := 0; row < rows; row++ {
for col := 0; col < cols; col++ {
m.Set(row, col, roundToEpsilon(m.Get(row, col), m.epsilon))
}
}
return m
} | [
"func",
"(",
"m",
"*",
"Matrix",
")",
"Round",
"(",
")",
"*",
"Matrix",
"{",
"rows",
",",
"cols",
":=",
"m",
".",
"Size",
"(",
")",
"\n",
"for",
"row",
":=",
"0",
";",
"row",
"<",
"rows",
";",
"row",
"++",
"{",
"for",
"col",
":=",
"0",
";",
"col",
"<",
"cols",
";",
"col",
"++",
"{",
"m",
".",
"Set",
"(",
"row",
",",
"col",
",",
"roundToEpsilon",
"(",
"m",
".",
"Get",
"(",
"row",
",",
"col",
")",
",",
"m",
".",
"epsilon",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"m",
"\n",
"}"
] | // Round rounds all the values in a matrix to it epsilon,
// returning a reference to the original | [
"Round",
"rounds",
"all",
"the",
"values",
"in",
"a",
"matrix",
"to",
"it",
"epsilon",
"returning",
"a",
"reference",
"to",
"the",
"original"
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/matrix/matrix.go#L140-L148 |
147,587 | wcharczuk/go-chart | matrix/matrix.go | Arrays | func (m *Matrix) Arrays() [][]float64 {
rows, cols := m.Size()
a := make([][]float64, rows)
for row := 0; row < rows; row++ {
a[row] = make([]float64, cols)
for col := 0; col < cols; col++ {
a[row][col] = m.Get(row, col)
}
}
return a
} | go | func (m *Matrix) Arrays() [][]float64 {
rows, cols := m.Size()
a := make([][]float64, rows)
for row := 0; row < rows; row++ {
a[row] = make([]float64, cols)
for col := 0; col < cols; col++ {
a[row][col] = m.Get(row, col)
}
}
return a
} | [
"func",
"(",
"m",
"*",
"Matrix",
")",
"Arrays",
"(",
")",
"[",
"]",
"[",
"]",
"float64",
"{",
"rows",
",",
"cols",
":=",
"m",
".",
"Size",
"(",
")",
"\n",
"a",
":=",
"make",
"(",
"[",
"]",
"[",
"]",
"float64",
",",
"rows",
")",
"\n\n",
"for",
"row",
":=",
"0",
";",
"row",
"<",
"rows",
";",
"row",
"++",
"{",
"a",
"[",
"row",
"]",
"=",
"make",
"(",
"[",
"]",
"float64",
",",
"cols",
")",
"\n\n",
"for",
"col",
":=",
"0",
";",
"col",
"<",
"cols",
";",
"col",
"++",
"{",
"a",
"[",
"row",
"]",
"[",
"col",
"]",
"=",
"m",
".",
"Get",
"(",
"row",
",",
"col",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"a",
"\n",
"}"
] | // Arrays returns the matrix as a two dimensional jagged array. | [
"Arrays",
"returns",
"the",
"matrix",
"as",
"a",
"two",
"dimensional",
"jagged",
"array",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/matrix/matrix.go#L151-L163 |
147,588 | wcharczuk/go-chart | matrix/matrix.go | Size | func (m *Matrix) Size() (rows, cols int) {
rows = len(m.elements) / m.stride
cols = m.stride
return
} | go | func (m *Matrix) Size() (rows, cols int) {
rows = len(m.elements) / m.stride
cols = m.stride
return
} | [
"func",
"(",
"m",
"*",
"Matrix",
")",
"Size",
"(",
")",
"(",
"rows",
",",
"cols",
"int",
")",
"{",
"rows",
"=",
"len",
"(",
"m",
".",
"elements",
")",
"/",
"m",
".",
"stride",
"\n",
"cols",
"=",
"m",
".",
"stride",
"\n",
"return",
"\n",
"}"
] | // Size returns the dimensions of the matrix. | [
"Size",
"returns",
"the",
"dimensions",
"of",
"the",
"matrix",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/matrix/matrix.go#L166-L170 |
147,589 | wcharczuk/go-chart | matrix/matrix.go | IsSquare | func (m *Matrix) IsSquare() bool {
return m.stride == (len(m.elements) / m.stride)
} | go | func (m *Matrix) IsSquare() bool {
return m.stride == (len(m.elements) / m.stride)
} | [
"func",
"(",
"m",
"*",
"Matrix",
")",
"IsSquare",
"(",
")",
"bool",
"{",
"return",
"m",
".",
"stride",
"==",
"(",
"len",
"(",
"m",
".",
"elements",
")",
"/",
"m",
".",
"stride",
")",
"\n",
"}"
] | // IsSquare returns if the row count is equal to the column count. | [
"IsSquare",
"returns",
"if",
"the",
"row",
"count",
"is",
"equal",
"to",
"the",
"column",
"count",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/matrix/matrix.go#L173-L175 |
147,590 | wcharczuk/go-chart | matrix/matrix.go | IsSymmetric | func (m *Matrix) IsSymmetric() bool {
rows, cols := m.Size()
if rows != cols {
return false
}
for i := 0; i < rows; i++ {
for j := 0; j < i; j++ {
if m.Get(i, j) != m.Get(j, i) {
return false
}
}
}
return true
} | go | func (m *Matrix) IsSymmetric() bool {
rows, cols := m.Size()
if rows != cols {
return false
}
for i := 0; i < rows; i++ {
for j := 0; j < i; j++ {
if m.Get(i, j) != m.Get(j, i) {
return false
}
}
}
return true
} | [
"func",
"(",
"m",
"*",
"Matrix",
")",
"IsSymmetric",
"(",
")",
"bool",
"{",
"rows",
",",
"cols",
":=",
"m",
".",
"Size",
"(",
")",
"\n\n",
"if",
"rows",
"!=",
"cols",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"rows",
";",
"i",
"++",
"{",
"for",
"j",
":=",
"0",
";",
"j",
"<",
"i",
";",
"j",
"++",
"{",
"if",
"m",
".",
"Get",
"(",
"i",
",",
"j",
")",
"!=",
"m",
".",
"Get",
"(",
"j",
",",
"i",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] | // IsSymmetric returns if the matrix is symmetric about its diagonal. | [
"IsSymmetric",
"returns",
"if",
"the",
"matrix",
"is",
"symmetric",
"about",
"its",
"diagonal",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/matrix/matrix.go#L178-L193 |
147,591 | wcharczuk/go-chart | matrix/matrix.go | Get | func (m *Matrix) Get(row, col int) float64 {
index := (m.stride * row) + col
return m.elements[index]
} | go | func (m *Matrix) Get(row, col int) float64 {
index := (m.stride * row) + col
return m.elements[index]
} | [
"func",
"(",
"m",
"*",
"Matrix",
")",
"Get",
"(",
"row",
",",
"col",
"int",
")",
"float64",
"{",
"index",
":=",
"(",
"m",
".",
"stride",
"*",
"row",
")",
"+",
"col",
"\n",
"return",
"m",
".",
"elements",
"[",
"index",
"]",
"\n",
"}"
] | // Get returns the element at the given row, col. | [
"Get",
"returns",
"the",
"element",
"at",
"the",
"given",
"row",
"col",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/matrix/matrix.go#L196-L199 |
147,592 | wcharczuk/go-chart | matrix/matrix.go | Set | func (m *Matrix) Set(row, col int, val float64) {
index := (m.stride * row) + col
m.elements[index] = val
} | go | func (m *Matrix) Set(row, col int, val float64) {
index := (m.stride * row) + col
m.elements[index] = val
} | [
"func",
"(",
"m",
"*",
"Matrix",
")",
"Set",
"(",
"row",
",",
"col",
"int",
",",
"val",
"float64",
")",
"{",
"index",
":=",
"(",
"m",
".",
"stride",
"*",
"row",
")",
"+",
"col",
"\n",
"m",
".",
"elements",
"[",
"index",
"]",
"=",
"val",
"\n",
"}"
] | // Set sets a value. | [
"Set",
"sets",
"a",
"value",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/matrix/matrix.go#L202-L205 |
147,593 | wcharczuk/go-chart | matrix/matrix.go | Col | func (m *Matrix) Col(col int) Vector {
rows, _ := m.Size()
values := make([]float64, rows)
for row := 0; row < rows; row++ {
values[row] = m.Get(row, col)
}
return Vector(values)
} | go | func (m *Matrix) Col(col int) Vector {
rows, _ := m.Size()
values := make([]float64, rows)
for row := 0; row < rows; row++ {
values[row] = m.Get(row, col)
}
return Vector(values)
} | [
"func",
"(",
"m",
"*",
"Matrix",
")",
"Col",
"(",
"col",
"int",
")",
"Vector",
"{",
"rows",
",",
"_",
":=",
"m",
".",
"Size",
"(",
")",
"\n",
"values",
":=",
"make",
"(",
"[",
"]",
"float64",
",",
"rows",
")",
"\n",
"for",
"row",
":=",
"0",
";",
"row",
"<",
"rows",
";",
"row",
"++",
"{",
"values",
"[",
"row",
"]",
"=",
"m",
".",
"Get",
"(",
"row",
",",
"col",
")",
"\n",
"}",
"\n",
"return",
"Vector",
"(",
"values",
")",
"\n",
"}"
] | // Col returns a column of the matrix as a vector. | [
"Col",
"returns",
"a",
"column",
"of",
"the",
"matrix",
"as",
"a",
"vector",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/matrix/matrix.go#L208-L215 |
147,594 | wcharczuk/go-chart | matrix/matrix.go | Row | func (m *Matrix) Row(row int) Vector {
_, cols := m.Size()
values := make([]float64, cols)
for col := 0; col < cols; col++ {
values[col] = m.Get(row, col)
}
return Vector(values)
} | go | func (m *Matrix) Row(row int) Vector {
_, cols := m.Size()
values := make([]float64, cols)
for col := 0; col < cols; col++ {
values[col] = m.Get(row, col)
}
return Vector(values)
} | [
"func",
"(",
"m",
"*",
"Matrix",
")",
"Row",
"(",
"row",
"int",
")",
"Vector",
"{",
"_",
",",
"cols",
":=",
"m",
".",
"Size",
"(",
")",
"\n",
"values",
":=",
"make",
"(",
"[",
"]",
"float64",
",",
"cols",
")",
"\n",
"for",
"col",
":=",
"0",
";",
"col",
"<",
"cols",
";",
"col",
"++",
"{",
"values",
"[",
"col",
"]",
"=",
"m",
".",
"Get",
"(",
"row",
",",
"col",
")",
"\n",
"}",
"\n",
"return",
"Vector",
"(",
"values",
")",
"\n",
"}"
] | // Row returns a row of the matrix as a vector. | [
"Row",
"returns",
"a",
"row",
"of",
"the",
"matrix",
"as",
"a",
"vector",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/matrix/matrix.go#L218-L225 |
147,595 | wcharczuk/go-chart | matrix/matrix.go | SubMatrix | func (m *Matrix) SubMatrix(i, j, rows, cols int) *Matrix {
return &Matrix{
elements: m.elements[i*m.stride+j : i*m.stride+j+(rows-1)*m.stride+cols],
stride: m.stride,
epsilon: m.epsilon,
}
} | go | func (m *Matrix) SubMatrix(i, j, rows, cols int) *Matrix {
return &Matrix{
elements: m.elements[i*m.stride+j : i*m.stride+j+(rows-1)*m.stride+cols],
stride: m.stride,
epsilon: m.epsilon,
}
} | [
"func",
"(",
"m",
"*",
"Matrix",
")",
"SubMatrix",
"(",
"i",
",",
"j",
",",
"rows",
",",
"cols",
"int",
")",
"*",
"Matrix",
"{",
"return",
"&",
"Matrix",
"{",
"elements",
":",
"m",
".",
"elements",
"[",
"i",
"*",
"m",
".",
"stride",
"+",
"j",
":",
"i",
"*",
"m",
".",
"stride",
"+",
"j",
"+",
"(",
"rows",
"-",
"1",
")",
"*",
"m",
".",
"stride",
"+",
"cols",
"]",
",",
"stride",
":",
"m",
".",
"stride",
",",
"epsilon",
":",
"m",
".",
"epsilon",
",",
"}",
"\n",
"}"
] | // SubMatrix returns a sub matrix from a given outer matrix. | [
"SubMatrix",
"returns",
"a",
"sub",
"matrix",
"from",
"a",
"given",
"outer",
"matrix",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/matrix/matrix.go#L228-L234 |
147,596 | wcharczuk/go-chart | matrix/matrix.go | ScaleRow | func (m *Matrix) ScaleRow(row int, scale float64) {
startIndex := row * m.stride
for i := startIndex; i < m.stride; i++ {
m.elements[i] = m.elements[i] * scale
}
} | go | func (m *Matrix) ScaleRow(row int, scale float64) {
startIndex := row * m.stride
for i := startIndex; i < m.stride; i++ {
m.elements[i] = m.elements[i] * scale
}
} | [
"func",
"(",
"m",
"*",
"Matrix",
")",
"ScaleRow",
"(",
"row",
"int",
",",
"scale",
"float64",
")",
"{",
"startIndex",
":=",
"row",
"*",
"m",
".",
"stride",
"\n",
"for",
"i",
":=",
"startIndex",
";",
"i",
"<",
"m",
".",
"stride",
";",
"i",
"++",
"{",
"m",
".",
"elements",
"[",
"i",
"]",
"=",
"m",
".",
"elements",
"[",
"i",
"]",
"*",
"scale",
"\n",
"}",
"\n",
"}"
] | // ScaleRow applies a scale to an entire row. | [
"ScaleRow",
"applies",
"a",
"scale",
"to",
"an",
"entire",
"row",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/matrix/matrix.go#L237-L242 |
147,597 | wcharczuk/go-chart | matrix/matrix.go | SwapRows | func (m *Matrix) SwapRows(i, j int) {
var vi, vj float64
for col := 0; col < m.stride; col++ {
vi = m.Get(i, col)
vj = m.Get(j, col)
m.Set(i, col, vj)
m.Set(j, col, vi)
}
} | go | func (m *Matrix) SwapRows(i, j int) {
var vi, vj float64
for col := 0; col < m.stride; col++ {
vi = m.Get(i, col)
vj = m.Get(j, col)
m.Set(i, col, vj)
m.Set(j, col, vi)
}
} | [
"func",
"(",
"m",
"*",
"Matrix",
")",
"SwapRows",
"(",
"i",
",",
"j",
"int",
")",
"{",
"var",
"vi",
",",
"vj",
"float64",
"\n",
"for",
"col",
":=",
"0",
";",
"col",
"<",
"m",
".",
"stride",
";",
"col",
"++",
"{",
"vi",
"=",
"m",
".",
"Get",
"(",
"i",
",",
"col",
")",
"\n",
"vj",
"=",
"m",
".",
"Get",
"(",
"j",
",",
"col",
")",
"\n",
"m",
".",
"Set",
"(",
"i",
",",
"col",
",",
"vj",
")",
"\n",
"m",
".",
"Set",
"(",
"j",
",",
"col",
",",
"vi",
")",
"\n",
"}",
"\n",
"}"
] | // SwapRows swaps a row in the matrix in place. | [
"SwapRows",
"swaps",
"a",
"row",
"in",
"the",
"matrix",
"in",
"place",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/matrix/matrix.go#L255-L263 |
147,598 | wcharczuk/go-chart | matrix/matrix.go | Augment | func (m *Matrix) Augment(m2 *Matrix) (*Matrix, error) {
mr, mc := m.Size()
m2r, m2c := m2.Size()
if mr != m2r {
return nil, ErrDimensionMismatch
}
m3 := Zero(mr, mc+m2c)
for row := 0; row < mr; row++ {
for col := 0; col < mc; col++ {
m3.Set(row, col, m.Get(row, col))
}
for col := 0; col < m2c; col++ {
m3.Set(row, mc+col, m2.Get(row, col))
}
}
return m3, nil
} | go | func (m *Matrix) Augment(m2 *Matrix) (*Matrix, error) {
mr, mc := m.Size()
m2r, m2c := m2.Size()
if mr != m2r {
return nil, ErrDimensionMismatch
}
m3 := Zero(mr, mc+m2c)
for row := 0; row < mr; row++ {
for col := 0; col < mc; col++ {
m3.Set(row, col, m.Get(row, col))
}
for col := 0; col < m2c; col++ {
m3.Set(row, mc+col, m2.Get(row, col))
}
}
return m3, nil
} | [
"func",
"(",
"m",
"*",
"Matrix",
")",
"Augment",
"(",
"m2",
"*",
"Matrix",
")",
"(",
"*",
"Matrix",
",",
"error",
")",
"{",
"mr",
",",
"mc",
":=",
"m",
".",
"Size",
"(",
")",
"\n",
"m2r",
",",
"m2c",
":=",
"m2",
".",
"Size",
"(",
")",
"\n",
"if",
"mr",
"!=",
"m2r",
"{",
"return",
"nil",
",",
"ErrDimensionMismatch",
"\n",
"}",
"\n\n",
"m3",
":=",
"Zero",
"(",
"mr",
",",
"mc",
"+",
"m2c",
")",
"\n",
"for",
"row",
":=",
"0",
";",
"row",
"<",
"mr",
";",
"row",
"++",
"{",
"for",
"col",
":=",
"0",
";",
"col",
"<",
"mc",
";",
"col",
"++",
"{",
"m3",
".",
"Set",
"(",
"row",
",",
"col",
",",
"m",
".",
"Get",
"(",
"row",
",",
"col",
")",
")",
"\n",
"}",
"\n",
"for",
"col",
":=",
"0",
";",
"col",
"<",
"m2c",
";",
"col",
"++",
"{",
"m3",
".",
"Set",
"(",
"row",
",",
"mc",
"+",
"col",
",",
"m2",
".",
"Get",
"(",
"row",
",",
"col",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"m3",
",",
"nil",
"\n",
"}"
] | // Augment concatenates two matrices about the horizontal. | [
"Augment",
"concatenates",
"two",
"matrices",
"about",
"the",
"horizontal",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/matrix/matrix.go#L266-L283 |
147,599 | wcharczuk/go-chart | matrix/matrix.go | Copy | func (m *Matrix) Copy() *Matrix {
m2 := &Matrix{stride: m.stride, epsilon: m.epsilon, elements: make([]float64, len(m.elements))}
copy(m2.elements, m.elements)
return m2
} | go | func (m *Matrix) Copy() *Matrix {
m2 := &Matrix{stride: m.stride, epsilon: m.epsilon, elements: make([]float64, len(m.elements))}
copy(m2.elements, m.elements)
return m2
} | [
"func",
"(",
"m",
"*",
"Matrix",
")",
"Copy",
"(",
")",
"*",
"Matrix",
"{",
"m2",
":=",
"&",
"Matrix",
"{",
"stride",
":",
"m",
".",
"stride",
",",
"epsilon",
":",
"m",
".",
"epsilon",
",",
"elements",
":",
"make",
"(",
"[",
"]",
"float64",
",",
"len",
"(",
"m",
".",
"elements",
")",
")",
"}",
"\n",
"copy",
"(",
"m2",
".",
"elements",
",",
"m",
".",
"elements",
")",
"\n",
"return",
"m2",
"\n",
"}"
] | // Copy returns a duplicate of a given matrix. | [
"Copy",
"returns",
"a",
"duplicate",
"of",
"a",
"given",
"matrix",
"."
] | 9852fce5a172598e72d16f4306f0f17a53d94eb4 | https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/matrix/matrix.go#L286-L290 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.