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,400
rs/zerolog
event.go
MACAddr
func (e *Event) MACAddr(key string, ha net.HardwareAddr) *Event { if e == nil { return e } e.buf = enc.AppendMACAddr(enc.AppendKey(e.buf, key), ha) return e }
go
func (e *Event) MACAddr(key string, ha net.HardwareAddr) *Event { if e == nil { return e } e.buf = enc.AppendMACAddr(enc.AppendKey(e.buf, key), ha) return e }
[ "func", "(", "e", "*", "Event", ")", "MACAddr", "(", "key", "string", ",", "ha", "net", ".", "HardwareAddr", ")", "*", "Event", "{", "if", "e", "==", "nil", "{", "return", "e", "\n", "}", "\n", "e", ".", "buf", "=", "enc", ".", "AppendMACAddr", "(", "enc", ".", "AppendKey", "(", "e", ".", "buf", ",", "key", ")", ",", "ha", ")", "\n", "return", "e", "\n", "}" ]
// MACAddr adds MAC address to the event
[ "MACAddr", "adds", "MAC", "address", "to", "the", "event" ]
acf3980132bfcdc48638724e6e3d9e5749b85999
https://github.com/rs/zerolog/blob/acf3980132bfcdc48638724e6e3d9e5749b85999/event.go#L698-L704
147,401
rs/zerolog
internal/json/bytes.go
AppendHex
func (Encoder) AppendHex(dst, s []byte) []byte { dst = append(dst, '"') for _, v := range s { dst = append(dst, hex[v>>4], hex[v&0x0f]) } return append(dst, '"') }
go
func (Encoder) AppendHex(dst, s []byte) []byte { dst = append(dst, '"') for _, v := range s { dst = append(dst, hex[v>>4], hex[v&0x0f]) } return append(dst, '"') }
[ "func", "(", "Encoder", ")", "AppendHex", "(", "dst", ",", "s", "[", "]", "byte", ")", "[", "]", "byte", "{", "dst", "=", "append", "(", "dst", ",", "'\"'", ")", "\n", "for", "_", ",", "v", ":=", "range", "s", "{", "dst", "=", "append", "(", "dst", ",", "hex", "[", "v", ">>", "4", "]", ",", "hex", "[", "v", "&", "0x0f", "]", ")", "\n", "}", "\n", "return", "append", "(", "dst", ",", "'\"'", ")", "\n", "}" ]
// AppendHex encodes the input bytes to a hex string and appends // the encoded string to the input byte slice. // // The operation loops though each byte and encodes it as hex using // the hex lookup table.
[ "AppendHex", "encodes", "the", "input", "bytes", "to", "a", "hex", "string", "and", "appends", "the", "encoded", "string", "to", "the", "input", "byte", "slice", ".", "The", "operation", "loops", "though", "each", "byte", "and", "encodes", "it", "as", "hex", "using", "the", "hex", "lookup", "table", "." ]
acf3980132bfcdc48638724e6e3d9e5749b85999
https://github.com/rs/zerolog/blob/acf3980132bfcdc48638724e6e3d9e5749b85999/internal/json/bytes.go#L23-L29
147,402
rs/zerolog
array.go
Arr
func Arr() *Array { a := arrayPool.Get().(*Array) a.buf = a.buf[:0] return a }
go
func Arr() *Array { a := arrayPool.Get().(*Array) a.buf = a.buf[:0] return a }
[ "func", "Arr", "(", ")", "*", "Array", "{", "a", ":=", "arrayPool", ".", "Get", "(", ")", ".", "(", "*", "Array", ")", "\n", "a", ".", "buf", "=", "a", ".", "buf", "[", ":", "0", "]", "\n", "return", "a", "\n", "}" ]
// Arr creates an array to be added to an Event or Context.
[ "Arr", "creates", "an", "array", "to", "be", "added", "to", "an", "Event", "or", "Context", "." ]
acf3980132bfcdc48638724e6e3d9e5749b85999
https://github.com/rs/zerolog/blob/acf3980132bfcdc48638724e6e3d9e5749b85999/array.go#L38-L42
147,403
rs/zerolog
array.go
Object
func (a *Array) Object(obj LogObjectMarshaler) *Array { e := Dict() obj.MarshalZerologObject(e) e.buf = enc.AppendEndMarker(e.buf) a.buf = append(enc.AppendArrayDelim(a.buf), e.buf...) putEvent(e) return a }
go
func (a *Array) Object(obj LogObjectMarshaler) *Array { e := Dict() obj.MarshalZerologObject(e) e.buf = enc.AppendEndMarker(e.buf) a.buf = append(enc.AppendArrayDelim(a.buf), e.buf...) putEvent(e) return a }
[ "func", "(", "a", "*", "Array", ")", "Object", "(", "obj", "LogObjectMarshaler", ")", "*", "Array", "{", "e", ":=", "Dict", "(", ")", "\n", "obj", ".", "MarshalZerologObject", "(", "e", ")", "\n", "e", ".", "buf", "=", "enc", ".", "AppendEndMarker", "(", "e", ".", "buf", ")", "\n", "a", ".", "buf", "=", "append", "(", "enc", ".", "AppendArrayDelim", "(", "a", ".", "buf", ")", ",", "e", ".", "buf", "...", ")", "\n", "putEvent", "(", "e", ")", "\n", "return", "a", "\n", "}" ]
// Object marshals an object that implement the LogObjectMarshaler // interface and append append it to the array.
[ "Object", "marshals", "an", "object", "that", "implement", "the", "LogObjectMarshaler", "interface", "and", "append", "append", "it", "to", "the", "array", "." ]
acf3980132bfcdc48638724e6e3d9e5749b85999
https://github.com/rs/zerolog/blob/acf3980132bfcdc48638724e6e3d9e5749b85999/array.go#L61-L68
147,404
rs/zerolog
array.go
Str
func (a *Array) Str(val string) *Array { a.buf = enc.AppendString(enc.AppendArrayDelim(a.buf), val) return a }
go
func (a *Array) Str(val string) *Array { a.buf = enc.AppendString(enc.AppendArrayDelim(a.buf), val) return a }
[ "func", "(", "a", "*", "Array", ")", "Str", "(", "val", "string", ")", "*", "Array", "{", "a", ".", "buf", "=", "enc", ".", "AppendString", "(", "enc", ".", "AppendArrayDelim", "(", "a", ".", "buf", ")", ",", "val", ")", "\n", "return", "a", "\n", "}" ]
// Str append append the val as a string to the array.
[ "Str", "append", "append", "the", "val", "as", "a", "string", "to", "the", "array", "." ]
acf3980132bfcdc48638724e6e3d9e5749b85999
https://github.com/rs/zerolog/blob/acf3980132bfcdc48638724e6e3d9e5749b85999/array.go#L71-L74
147,405
rs/zerolog
array.go
Bytes
func (a *Array) Bytes(val []byte) *Array { a.buf = enc.AppendBytes(enc.AppendArrayDelim(a.buf), val) return a }
go
func (a *Array) Bytes(val []byte) *Array { a.buf = enc.AppendBytes(enc.AppendArrayDelim(a.buf), val) return a }
[ "func", "(", "a", "*", "Array", ")", "Bytes", "(", "val", "[", "]", "byte", ")", "*", "Array", "{", "a", ".", "buf", "=", "enc", ".", "AppendBytes", "(", "enc", ".", "AppendArrayDelim", "(", "a", ".", "buf", ")", ",", "val", ")", "\n", "return", "a", "\n", "}" ]
// Bytes append append the val as a string to the array.
[ "Bytes", "append", "append", "the", "val", "as", "a", "string", "to", "the", "array", "." ]
acf3980132bfcdc48638724e6e3d9e5749b85999
https://github.com/rs/zerolog/blob/acf3980132bfcdc48638724e6e3d9e5749b85999/array.go#L77-L80
147,406
rs/zerolog
array.go
Hex
func (a *Array) Hex(val []byte) *Array { a.buf = enc.AppendHex(enc.AppendArrayDelim(a.buf), val) return a }
go
func (a *Array) Hex(val []byte) *Array { a.buf = enc.AppendHex(enc.AppendArrayDelim(a.buf), val) return a }
[ "func", "(", "a", "*", "Array", ")", "Hex", "(", "val", "[", "]", "byte", ")", "*", "Array", "{", "a", ".", "buf", "=", "enc", ".", "AppendHex", "(", "enc", ".", "AppendArrayDelim", "(", "a", ".", "buf", ")", ",", "val", ")", "\n", "return", "a", "\n", "}" ]
// Hex append append the val as a hex string to the array.
[ "Hex", "append", "append", "the", "val", "as", "a", "hex", "string", "to", "the", "array", "." ]
acf3980132bfcdc48638724e6e3d9e5749b85999
https://github.com/rs/zerolog/blob/acf3980132bfcdc48638724e6e3d9e5749b85999/array.go#L83-L86
147,407
rs/zerolog
array.go
Err
func (a *Array) Err(err error) *Array { marshaled := ErrorMarshalFunc(err) switch m := marshaled.(type) { case LogObjectMarshaler: e := newEvent(nil, 0) e.buf = e.buf[:0] e.appendObject(m) a.buf = append(enc.AppendArrayDelim(a.buf), e.buf...) putEvent(e) case error: a.buf = enc.AppendString(enc.AppendArrayDelim(a.buf), m.Error()) case string: a.buf = enc.AppendString(enc.AppendArrayDelim(a.buf), m) default: a.buf = enc.AppendInterface(enc.AppendArrayDelim(a.buf), m) } return a }
go
func (a *Array) Err(err error) *Array { marshaled := ErrorMarshalFunc(err) switch m := marshaled.(type) { case LogObjectMarshaler: e := newEvent(nil, 0) e.buf = e.buf[:0] e.appendObject(m) a.buf = append(enc.AppendArrayDelim(a.buf), e.buf...) putEvent(e) case error: a.buf = enc.AppendString(enc.AppendArrayDelim(a.buf), m.Error()) case string: a.buf = enc.AppendString(enc.AppendArrayDelim(a.buf), m) default: a.buf = enc.AppendInterface(enc.AppendArrayDelim(a.buf), m) } return a }
[ "func", "(", "a", "*", "Array", ")", "Err", "(", "err", "error", ")", "*", "Array", "{", "marshaled", ":=", "ErrorMarshalFunc", "(", "err", ")", "\n", "switch", "m", ":=", "marshaled", ".", "(", "type", ")", "{", "case", "LogObjectMarshaler", ":", "e", ":=", "newEvent", "(", "nil", ",", "0", ")", "\n", "e", ".", "buf", "=", "e", ".", "buf", "[", ":", "0", "]", "\n", "e", ".", "appendObject", "(", "m", ")", "\n", "a", ".", "buf", "=", "append", "(", "enc", ".", "AppendArrayDelim", "(", "a", ".", "buf", ")", ",", "e", ".", "buf", "...", ")", "\n", "putEvent", "(", "e", ")", "\n", "case", "error", ":", "a", ".", "buf", "=", "enc", ".", "AppendString", "(", "enc", ".", "AppendArrayDelim", "(", "a", ".", "buf", ")", ",", "m", ".", "Error", "(", ")", ")", "\n", "case", "string", ":", "a", ".", "buf", "=", "enc", ".", "AppendString", "(", "enc", ".", "AppendArrayDelim", "(", "a", ".", "buf", ")", ",", "m", ")", "\n", "default", ":", "a", ".", "buf", "=", "enc", ".", "AppendInterface", "(", "enc", ".", "AppendArrayDelim", "(", "a", ".", "buf", ")", ",", "m", ")", "\n", "}", "\n\n", "return", "a", "\n", "}" ]
// Err serializes and appends the err to the array.
[ "Err", "serializes", "and", "appends", "the", "err", "to", "the", "array", "." ]
acf3980132bfcdc48638724e6e3d9e5749b85999
https://github.com/rs/zerolog/blob/acf3980132bfcdc48638724e6e3d9e5749b85999/array.go#L89-L107
147,408
rs/zerolog
array.go
Bool
func (a *Array) Bool(b bool) *Array { a.buf = enc.AppendBool(enc.AppendArrayDelim(a.buf), b) return a }
go
func (a *Array) Bool(b bool) *Array { a.buf = enc.AppendBool(enc.AppendArrayDelim(a.buf), b) return a }
[ "func", "(", "a", "*", "Array", ")", "Bool", "(", "b", "bool", ")", "*", "Array", "{", "a", ".", "buf", "=", "enc", ".", "AppendBool", "(", "enc", ".", "AppendArrayDelim", "(", "a", ".", "buf", ")", ",", "b", ")", "\n", "return", "a", "\n", "}" ]
// Bool append append the val as a bool to the array.
[ "Bool", "append", "append", "the", "val", "as", "a", "bool", "to", "the", "array", "." ]
acf3980132bfcdc48638724e6e3d9e5749b85999
https://github.com/rs/zerolog/blob/acf3980132bfcdc48638724e6e3d9e5749b85999/array.go#L110-L113
147,409
rs/zerolog
array.go
Int
func (a *Array) Int(i int) *Array { a.buf = enc.AppendInt(enc.AppendArrayDelim(a.buf), i) return a }
go
func (a *Array) Int(i int) *Array { a.buf = enc.AppendInt(enc.AppendArrayDelim(a.buf), i) return a }
[ "func", "(", "a", "*", "Array", ")", "Int", "(", "i", "int", ")", "*", "Array", "{", "a", ".", "buf", "=", "enc", ".", "AppendInt", "(", "enc", ".", "AppendArrayDelim", "(", "a", ".", "buf", ")", ",", "i", ")", "\n", "return", "a", "\n", "}" ]
// Int append append i as a int to the array.
[ "Int", "append", "append", "i", "as", "a", "int", "to", "the", "array", "." ]
acf3980132bfcdc48638724e6e3d9e5749b85999
https://github.com/rs/zerolog/blob/acf3980132bfcdc48638724e6e3d9e5749b85999/array.go#L116-L119
147,410
rs/zerolog
array.go
Int8
func (a *Array) Int8(i int8) *Array { a.buf = enc.AppendInt8(enc.AppendArrayDelim(a.buf), i) return a }
go
func (a *Array) Int8(i int8) *Array { a.buf = enc.AppendInt8(enc.AppendArrayDelim(a.buf), i) return a }
[ "func", "(", "a", "*", "Array", ")", "Int8", "(", "i", "int8", ")", "*", "Array", "{", "a", ".", "buf", "=", "enc", ".", "AppendInt8", "(", "enc", ".", "AppendArrayDelim", "(", "a", ".", "buf", ")", ",", "i", ")", "\n", "return", "a", "\n", "}" ]
// Int8 append append i as a int8 to the array.
[ "Int8", "append", "append", "i", "as", "a", "int8", "to", "the", "array", "." ]
acf3980132bfcdc48638724e6e3d9e5749b85999
https://github.com/rs/zerolog/blob/acf3980132bfcdc48638724e6e3d9e5749b85999/array.go#L122-L125
147,411
rs/zerolog
array.go
Int16
func (a *Array) Int16(i int16) *Array { a.buf = enc.AppendInt16(enc.AppendArrayDelim(a.buf), i) return a }
go
func (a *Array) Int16(i int16) *Array { a.buf = enc.AppendInt16(enc.AppendArrayDelim(a.buf), i) return a }
[ "func", "(", "a", "*", "Array", ")", "Int16", "(", "i", "int16", ")", "*", "Array", "{", "a", ".", "buf", "=", "enc", ".", "AppendInt16", "(", "enc", ".", "AppendArrayDelim", "(", "a", ".", "buf", ")", ",", "i", ")", "\n", "return", "a", "\n", "}" ]
// Int16 append append i as a int16 to the array.
[ "Int16", "append", "append", "i", "as", "a", "int16", "to", "the", "array", "." ]
acf3980132bfcdc48638724e6e3d9e5749b85999
https://github.com/rs/zerolog/blob/acf3980132bfcdc48638724e6e3d9e5749b85999/array.go#L128-L131
147,412
rs/zerolog
array.go
Int32
func (a *Array) Int32(i int32) *Array { a.buf = enc.AppendInt32(enc.AppendArrayDelim(a.buf), i) return a }
go
func (a *Array) Int32(i int32) *Array { a.buf = enc.AppendInt32(enc.AppendArrayDelim(a.buf), i) return a }
[ "func", "(", "a", "*", "Array", ")", "Int32", "(", "i", "int32", ")", "*", "Array", "{", "a", ".", "buf", "=", "enc", ".", "AppendInt32", "(", "enc", ".", "AppendArrayDelim", "(", "a", ".", "buf", ")", ",", "i", ")", "\n", "return", "a", "\n", "}" ]
// Int32 append append i as a int32 to the array.
[ "Int32", "append", "append", "i", "as", "a", "int32", "to", "the", "array", "." ]
acf3980132bfcdc48638724e6e3d9e5749b85999
https://github.com/rs/zerolog/blob/acf3980132bfcdc48638724e6e3d9e5749b85999/array.go#L134-L137
147,413
rs/zerolog
array.go
Int64
func (a *Array) Int64(i int64) *Array { a.buf = enc.AppendInt64(enc.AppendArrayDelim(a.buf), i) return a }
go
func (a *Array) Int64(i int64) *Array { a.buf = enc.AppendInt64(enc.AppendArrayDelim(a.buf), i) return a }
[ "func", "(", "a", "*", "Array", ")", "Int64", "(", "i", "int64", ")", "*", "Array", "{", "a", ".", "buf", "=", "enc", ".", "AppendInt64", "(", "enc", ".", "AppendArrayDelim", "(", "a", ".", "buf", ")", ",", "i", ")", "\n", "return", "a", "\n", "}" ]
// Int64 append append i as a int64 to the array.
[ "Int64", "append", "append", "i", "as", "a", "int64", "to", "the", "array", "." ]
acf3980132bfcdc48638724e6e3d9e5749b85999
https://github.com/rs/zerolog/blob/acf3980132bfcdc48638724e6e3d9e5749b85999/array.go#L140-L143
147,414
rs/zerolog
array.go
Uint
func (a *Array) Uint(i uint) *Array { a.buf = enc.AppendUint(enc.AppendArrayDelim(a.buf), i) return a }
go
func (a *Array) Uint(i uint) *Array { a.buf = enc.AppendUint(enc.AppendArrayDelim(a.buf), i) return a }
[ "func", "(", "a", "*", "Array", ")", "Uint", "(", "i", "uint", ")", "*", "Array", "{", "a", ".", "buf", "=", "enc", ".", "AppendUint", "(", "enc", ".", "AppendArrayDelim", "(", "a", ".", "buf", ")", ",", "i", ")", "\n", "return", "a", "\n", "}" ]
// Uint append append i as a uint to the array.
[ "Uint", "append", "append", "i", "as", "a", "uint", "to", "the", "array", "." ]
acf3980132bfcdc48638724e6e3d9e5749b85999
https://github.com/rs/zerolog/blob/acf3980132bfcdc48638724e6e3d9e5749b85999/array.go#L146-L149
147,415
rs/zerolog
array.go
Uint8
func (a *Array) Uint8(i uint8) *Array { a.buf = enc.AppendUint8(enc.AppendArrayDelim(a.buf), i) return a }
go
func (a *Array) Uint8(i uint8) *Array { a.buf = enc.AppendUint8(enc.AppendArrayDelim(a.buf), i) return a }
[ "func", "(", "a", "*", "Array", ")", "Uint8", "(", "i", "uint8", ")", "*", "Array", "{", "a", ".", "buf", "=", "enc", ".", "AppendUint8", "(", "enc", ".", "AppendArrayDelim", "(", "a", ".", "buf", ")", ",", "i", ")", "\n", "return", "a", "\n", "}" ]
// Uint8 append append i as a uint8 to the array.
[ "Uint8", "append", "append", "i", "as", "a", "uint8", "to", "the", "array", "." ]
acf3980132bfcdc48638724e6e3d9e5749b85999
https://github.com/rs/zerolog/blob/acf3980132bfcdc48638724e6e3d9e5749b85999/array.go#L152-L155
147,416
rs/zerolog
array.go
Uint16
func (a *Array) Uint16(i uint16) *Array { a.buf = enc.AppendUint16(enc.AppendArrayDelim(a.buf), i) return a }
go
func (a *Array) Uint16(i uint16) *Array { a.buf = enc.AppendUint16(enc.AppendArrayDelim(a.buf), i) return a }
[ "func", "(", "a", "*", "Array", ")", "Uint16", "(", "i", "uint16", ")", "*", "Array", "{", "a", ".", "buf", "=", "enc", ".", "AppendUint16", "(", "enc", ".", "AppendArrayDelim", "(", "a", ".", "buf", ")", ",", "i", ")", "\n", "return", "a", "\n", "}" ]
// Uint16 append append i as a uint16 to the array.
[ "Uint16", "append", "append", "i", "as", "a", "uint16", "to", "the", "array", "." ]
acf3980132bfcdc48638724e6e3d9e5749b85999
https://github.com/rs/zerolog/blob/acf3980132bfcdc48638724e6e3d9e5749b85999/array.go#L158-L161
147,417
rs/zerolog
array.go
Uint32
func (a *Array) Uint32(i uint32) *Array { a.buf = enc.AppendUint32(enc.AppendArrayDelim(a.buf), i) return a }
go
func (a *Array) Uint32(i uint32) *Array { a.buf = enc.AppendUint32(enc.AppendArrayDelim(a.buf), i) return a }
[ "func", "(", "a", "*", "Array", ")", "Uint32", "(", "i", "uint32", ")", "*", "Array", "{", "a", ".", "buf", "=", "enc", ".", "AppendUint32", "(", "enc", ".", "AppendArrayDelim", "(", "a", ".", "buf", ")", ",", "i", ")", "\n", "return", "a", "\n", "}" ]
// Uint32 append append i as a uint32 to the array.
[ "Uint32", "append", "append", "i", "as", "a", "uint32", "to", "the", "array", "." ]
acf3980132bfcdc48638724e6e3d9e5749b85999
https://github.com/rs/zerolog/blob/acf3980132bfcdc48638724e6e3d9e5749b85999/array.go#L164-L167
147,418
rs/zerolog
array.go
Uint64
func (a *Array) Uint64(i uint64) *Array { a.buf = enc.AppendUint64(enc.AppendArrayDelim(a.buf), i) return a }
go
func (a *Array) Uint64(i uint64) *Array { a.buf = enc.AppendUint64(enc.AppendArrayDelim(a.buf), i) return a }
[ "func", "(", "a", "*", "Array", ")", "Uint64", "(", "i", "uint64", ")", "*", "Array", "{", "a", ".", "buf", "=", "enc", ".", "AppendUint64", "(", "enc", ".", "AppendArrayDelim", "(", "a", ".", "buf", ")", ",", "i", ")", "\n", "return", "a", "\n", "}" ]
// Uint64 append append i as a uint64 to the array.
[ "Uint64", "append", "append", "i", "as", "a", "uint64", "to", "the", "array", "." ]
acf3980132bfcdc48638724e6e3d9e5749b85999
https://github.com/rs/zerolog/blob/acf3980132bfcdc48638724e6e3d9e5749b85999/array.go#L170-L173
147,419
rs/zerolog
array.go
Float32
func (a *Array) Float32(f float32) *Array { a.buf = enc.AppendFloat32(enc.AppendArrayDelim(a.buf), f) return a }
go
func (a *Array) Float32(f float32) *Array { a.buf = enc.AppendFloat32(enc.AppendArrayDelim(a.buf), f) return a }
[ "func", "(", "a", "*", "Array", ")", "Float32", "(", "f", "float32", ")", "*", "Array", "{", "a", ".", "buf", "=", "enc", ".", "AppendFloat32", "(", "enc", ".", "AppendArrayDelim", "(", "a", ".", "buf", ")", ",", "f", ")", "\n", "return", "a", "\n", "}" ]
// Float32 append append f as a float32 to the array.
[ "Float32", "append", "append", "f", "as", "a", "float32", "to", "the", "array", "." ]
acf3980132bfcdc48638724e6e3d9e5749b85999
https://github.com/rs/zerolog/blob/acf3980132bfcdc48638724e6e3d9e5749b85999/array.go#L176-L179
147,420
rs/zerolog
array.go
Float64
func (a *Array) Float64(f float64) *Array { a.buf = enc.AppendFloat64(enc.AppendArrayDelim(a.buf), f) return a }
go
func (a *Array) Float64(f float64) *Array { a.buf = enc.AppendFloat64(enc.AppendArrayDelim(a.buf), f) return a }
[ "func", "(", "a", "*", "Array", ")", "Float64", "(", "f", "float64", ")", "*", "Array", "{", "a", ".", "buf", "=", "enc", ".", "AppendFloat64", "(", "enc", ".", "AppendArrayDelim", "(", "a", ".", "buf", ")", ",", "f", ")", "\n", "return", "a", "\n", "}" ]
// Float64 append append f as a float64 to the array.
[ "Float64", "append", "append", "f", "as", "a", "float64", "to", "the", "array", "." ]
acf3980132bfcdc48638724e6e3d9e5749b85999
https://github.com/rs/zerolog/blob/acf3980132bfcdc48638724e6e3d9e5749b85999/array.go#L182-L185
147,421
rs/zerolog
array.go
Time
func (a *Array) Time(t time.Time) *Array { a.buf = enc.AppendTime(enc.AppendArrayDelim(a.buf), t, TimeFieldFormat) return a }
go
func (a *Array) Time(t time.Time) *Array { a.buf = enc.AppendTime(enc.AppendArrayDelim(a.buf), t, TimeFieldFormat) return a }
[ "func", "(", "a", "*", "Array", ")", "Time", "(", "t", "time", ".", "Time", ")", "*", "Array", "{", "a", ".", "buf", "=", "enc", ".", "AppendTime", "(", "enc", ".", "AppendArrayDelim", "(", "a", ".", "buf", ")", ",", "t", ",", "TimeFieldFormat", ")", "\n", "return", "a", "\n", "}" ]
// Time append append t formated as string using zerolog.TimeFieldFormat.
[ "Time", "append", "append", "t", "formated", "as", "string", "using", "zerolog", ".", "TimeFieldFormat", "." ]
acf3980132bfcdc48638724e6e3d9e5749b85999
https://github.com/rs/zerolog/blob/acf3980132bfcdc48638724e6e3d9e5749b85999/array.go#L188-L191
147,422
rs/zerolog
array.go
Dur
func (a *Array) Dur(d time.Duration) *Array { a.buf = enc.AppendDuration(enc.AppendArrayDelim(a.buf), d, DurationFieldUnit, DurationFieldInteger) return a }
go
func (a *Array) Dur(d time.Duration) *Array { a.buf = enc.AppendDuration(enc.AppendArrayDelim(a.buf), d, DurationFieldUnit, DurationFieldInteger) return a }
[ "func", "(", "a", "*", "Array", ")", "Dur", "(", "d", "time", ".", "Duration", ")", "*", "Array", "{", "a", ".", "buf", "=", "enc", ".", "AppendDuration", "(", "enc", ".", "AppendArrayDelim", "(", "a", ".", "buf", ")", ",", "d", ",", "DurationFieldUnit", ",", "DurationFieldInteger", ")", "\n", "return", "a", "\n", "}" ]
// Dur append append d to the array.
[ "Dur", "append", "append", "d", "to", "the", "array", "." ]
acf3980132bfcdc48638724e6e3d9e5749b85999
https://github.com/rs/zerolog/blob/acf3980132bfcdc48638724e6e3d9e5749b85999/array.go#L194-L197
147,423
rs/zerolog
array.go
Interface
func (a *Array) Interface(i interface{}) *Array { if obj, ok := i.(LogObjectMarshaler); ok { return a.Object(obj) } a.buf = enc.AppendInterface(enc.AppendArrayDelim(a.buf), i) return a }
go
func (a *Array) Interface(i interface{}) *Array { if obj, ok := i.(LogObjectMarshaler); ok { return a.Object(obj) } a.buf = enc.AppendInterface(enc.AppendArrayDelim(a.buf), i) return a }
[ "func", "(", "a", "*", "Array", ")", "Interface", "(", "i", "interface", "{", "}", ")", "*", "Array", "{", "if", "obj", ",", "ok", ":=", "i", ".", "(", "LogObjectMarshaler", ")", ";", "ok", "{", "return", "a", ".", "Object", "(", "obj", ")", "\n", "}", "\n", "a", ".", "buf", "=", "enc", ".", "AppendInterface", "(", "enc", ".", "AppendArrayDelim", "(", "a", ".", "buf", ")", ",", "i", ")", "\n", "return", "a", "\n", "}" ]
// Interface append append i marshaled using reflection.
[ "Interface", "append", "append", "i", "marshaled", "using", "reflection", "." ]
acf3980132bfcdc48638724e6e3d9e5749b85999
https://github.com/rs/zerolog/blob/acf3980132bfcdc48638724e6e3d9e5749b85999/array.go#L200-L206
147,424
rs/zerolog
array.go
IPAddr
func (a *Array) IPAddr(ip net.IP) *Array { a.buf = enc.AppendIPAddr(enc.AppendArrayDelim(a.buf), ip) return a }
go
func (a *Array) IPAddr(ip net.IP) *Array { a.buf = enc.AppendIPAddr(enc.AppendArrayDelim(a.buf), ip) return a }
[ "func", "(", "a", "*", "Array", ")", "IPAddr", "(", "ip", "net", ".", "IP", ")", "*", "Array", "{", "a", ".", "buf", "=", "enc", ".", "AppendIPAddr", "(", "enc", ".", "AppendArrayDelim", "(", "a", ".", "buf", ")", ",", "ip", ")", "\n", "return", "a", "\n", "}" ]
// IPAddr adds IPv4 or IPv6 address to the array
[ "IPAddr", "adds", "IPv4", "or", "IPv6", "address", "to", "the", "array" ]
acf3980132bfcdc48638724e6e3d9e5749b85999
https://github.com/rs/zerolog/blob/acf3980132bfcdc48638724e6e3d9e5749b85999/array.go#L209-L212
147,425
rs/zerolog
internal/json/string.go
AppendStrings
func (e Encoder) AppendStrings(dst []byte, vals []string) []byte { if len(vals) == 0 { return append(dst, '[', ']') } dst = append(dst, '[') dst = e.AppendString(dst, vals[0]) if len(vals) > 1 { for _, val := range vals[1:] { dst = e.AppendString(append(dst, ','), val) } } dst = append(dst, ']') return dst }
go
func (e Encoder) AppendStrings(dst []byte, vals []string) []byte { if len(vals) == 0 { return append(dst, '[', ']') } dst = append(dst, '[') dst = e.AppendString(dst, vals[0]) if len(vals) > 1 { for _, val := range vals[1:] { dst = e.AppendString(append(dst, ','), val) } } dst = append(dst, ']') return dst }
[ "func", "(", "e", "Encoder", ")", "AppendStrings", "(", "dst", "[", "]", "byte", ",", "vals", "[", "]", "string", ")", "[", "]", "byte", "{", "if", "len", "(", "vals", ")", "==", "0", "{", "return", "append", "(", "dst", ",", "'['", ",", "']'", ")", "\n", "}", "\n", "dst", "=", "append", "(", "dst", ",", "'['", ")", "\n", "dst", "=", "e", ".", "AppendString", "(", "dst", ",", "vals", "[", "0", "]", ")", "\n", "if", "len", "(", "vals", ")", ">", "1", "{", "for", "_", ",", "val", ":=", "range", "vals", "[", "1", ":", "]", "{", "dst", "=", "e", ".", "AppendString", "(", "append", "(", "dst", ",", "','", ")", ",", "val", ")", "\n", "}", "\n", "}", "\n", "dst", "=", "append", "(", "dst", ",", "']'", ")", "\n", "return", "dst", "\n", "}" ]
// AppendStrings encodes the input strings to json and // appends the encoded string list to the input byte slice.
[ "AppendStrings", "encodes", "the", "input", "strings", "to", "json", "and", "appends", "the", "encoded", "string", "list", "to", "the", "input", "byte", "slice", "." ]
acf3980132bfcdc48638724e6e3d9e5749b85999
https://github.com/rs/zerolog/blob/acf3980132bfcdc48638724e6e3d9e5749b85999/internal/json/string.go#L17-L30
147,426
rs/zerolog
internal/json/string.go
AppendString
func (Encoder) AppendString(dst []byte, s string) []byte { // Start with a double quote. dst = append(dst, '"') // Loop through each character in the string. for i := 0; i < len(s); i++ { // Check if the character needs encoding. Control characters, slashes, // and the double quote need json encoding. Bytes above the ascii // boundary needs utf8 encoding. if !noEscapeTable[s[i]] { // We encountered a character that needs to be encoded. Switch // to complex version of the algorithm. dst = appendStringComplex(dst, s, i) return append(dst, '"') } } // The string has no need for encoding an therefore is directly // appended to the byte slice. dst = append(dst, s...) // End with a double quote return append(dst, '"') }
go
func (Encoder) AppendString(dst []byte, s string) []byte { // Start with a double quote. dst = append(dst, '"') // Loop through each character in the string. for i := 0; i < len(s); i++ { // Check if the character needs encoding. Control characters, slashes, // and the double quote need json encoding. Bytes above the ascii // boundary needs utf8 encoding. if !noEscapeTable[s[i]] { // We encountered a character that needs to be encoded. Switch // to complex version of the algorithm. dst = appendStringComplex(dst, s, i) return append(dst, '"') } } // The string has no need for encoding an therefore is directly // appended to the byte slice. dst = append(dst, s...) // End with a double quote return append(dst, '"') }
[ "func", "(", "Encoder", ")", "AppendString", "(", "dst", "[", "]", "byte", ",", "s", "string", ")", "[", "]", "byte", "{", "// Start with a double quote.", "dst", "=", "append", "(", "dst", ",", "'\"'", ")", "\n", "// Loop through each character in the string.", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "s", ")", ";", "i", "++", "{", "// Check if the character needs encoding. Control characters, slashes,", "// and the double quote need json encoding. Bytes above the ascii", "// boundary needs utf8 encoding.", "if", "!", "noEscapeTable", "[", "s", "[", "i", "]", "]", "{", "// We encountered a character that needs to be encoded. Switch", "// to complex version of the algorithm.", "dst", "=", "appendStringComplex", "(", "dst", ",", "s", ",", "i", ")", "\n", "return", "append", "(", "dst", ",", "'\"'", ")", "\n", "}", "\n", "}", "\n", "// The string has no need for encoding an therefore is directly", "// appended to the byte slice.", "dst", "=", "append", "(", "dst", ",", "s", "...", ")", "\n", "// End with a double quote", "return", "append", "(", "dst", ",", "'\"'", ")", "\n", "}" ]
// AppendString encodes the input string to json and appends // the encoded string to the input byte slice. // // The operation loops though each byte in the string looking // for characters that need json or utf8 encoding. If the string // does not need encoding, then the string is appended in it's // entirety to the byte slice. // If we encounter a byte that does need encoding, switch up // the operation and perform a byte-by-byte read-encode-append.
[ "AppendString", "encodes", "the", "input", "string", "to", "json", "and", "appends", "the", "encoded", "string", "to", "the", "input", "byte", "slice", ".", "The", "operation", "loops", "though", "each", "byte", "in", "the", "string", "looking", "for", "characters", "that", "need", "json", "or", "utf8", "encoding", ".", "If", "the", "string", "does", "not", "need", "encoding", "then", "the", "string", "is", "appended", "in", "it", "s", "entirety", "to", "the", "byte", "slice", ".", "If", "we", "encounter", "a", "byte", "that", "does", "need", "encoding", "switch", "up", "the", "operation", "and", "perform", "a", "byte", "-", "by", "-", "byte", "read", "-", "encode", "-", "append", "." ]
acf3980132bfcdc48638724e6e3d9e5749b85999
https://github.com/rs/zerolog/blob/acf3980132bfcdc48638724e6e3d9e5749b85999/internal/json/string.go#L41-L61
147,427
rs/zerolog
internal/json/string.go
appendStringComplex
func appendStringComplex(dst []byte, s string, i int) []byte { start := 0 for i < len(s) { b := s[i] if b >= utf8.RuneSelf { r, size := utf8.DecodeRuneInString(s[i:]) if r == utf8.RuneError && size == 1 { // In case of error, first append previous simple characters to // the byte slice if any and append a remplacement character code // in place of the invalid sequence. if start < i { dst = append(dst, s[start:i]...) } dst = append(dst, `\ufffd`...) i += size start = i continue } i += size continue } if noEscapeTable[b] { i++ continue } // We encountered a character that needs to be encoded. // Let's append the previous simple characters to the byte slice // and switch our operation to read and encode the remainder // characters byte-by-byte. if start < i { dst = append(dst, s[start:i]...) } switch b { case '"', '\\': dst = append(dst, '\\', b) case '\b': dst = append(dst, '\\', 'b') case '\f': dst = append(dst, '\\', 'f') case '\n': dst = append(dst, '\\', 'n') case '\r': dst = append(dst, '\\', 'r') case '\t': dst = append(dst, '\\', 't') default: dst = append(dst, '\\', 'u', '0', '0', hex[b>>4], hex[b&0xF]) } i++ start = i } if start < len(s) { dst = append(dst, s[start:]...) } return dst }
go
func appendStringComplex(dst []byte, s string, i int) []byte { start := 0 for i < len(s) { b := s[i] if b >= utf8.RuneSelf { r, size := utf8.DecodeRuneInString(s[i:]) if r == utf8.RuneError && size == 1 { // In case of error, first append previous simple characters to // the byte slice if any and append a remplacement character code // in place of the invalid sequence. if start < i { dst = append(dst, s[start:i]...) } dst = append(dst, `\ufffd`...) i += size start = i continue } i += size continue } if noEscapeTable[b] { i++ continue } // We encountered a character that needs to be encoded. // Let's append the previous simple characters to the byte slice // and switch our operation to read and encode the remainder // characters byte-by-byte. if start < i { dst = append(dst, s[start:i]...) } switch b { case '"', '\\': dst = append(dst, '\\', b) case '\b': dst = append(dst, '\\', 'b') case '\f': dst = append(dst, '\\', 'f') case '\n': dst = append(dst, '\\', 'n') case '\r': dst = append(dst, '\\', 'r') case '\t': dst = append(dst, '\\', 't') default: dst = append(dst, '\\', 'u', '0', '0', hex[b>>4], hex[b&0xF]) } i++ start = i } if start < len(s) { dst = append(dst, s[start:]...) } return dst }
[ "func", "appendStringComplex", "(", "dst", "[", "]", "byte", ",", "s", "string", ",", "i", "int", ")", "[", "]", "byte", "{", "start", ":=", "0", "\n", "for", "i", "<", "len", "(", "s", ")", "{", "b", ":=", "s", "[", "i", "]", "\n", "if", "b", ">=", "utf8", ".", "RuneSelf", "{", "r", ",", "size", ":=", "utf8", ".", "DecodeRuneInString", "(", "s", "[", "i", ":", "]", ")", "\n", "if", "r", "==", "utf8", ".", "RuneError", "&&", "size", "==", "1", "{", "// In case of error, first append previous simple characters to", "// the byte slice if any and append a remplacement character code", "// in place of the invalid sequence.", "if", "start", "<", "i", "{", "dst", "=", "append", "(", "dst", ",", "s", "[", "start", ":", "i", "]", "...", ")", "\n", "}", "\n", "dst", "=", "append", "(", "dst", ",", "`\\ufffd`", "...", ")", "\n", "i", "+=", "size", "\n", "start", "=", "i", "\n", "continue", "\n", "}", "\n", "i", "+=", "size", "\n", "continue", "\n", "}", "\n", "if", "noEscapeTable", "[", "b", "]", "{", "i", "++", "\n", "continue", "\n", "}", "\n", "// We encountered a character that needs to be encoded.", "// Let's append the previous simple characters to the byte slice", "// and switch our operation to read and encode the remainder", "// characters byte-by-byte.", "if", "start", "<", "i", "{", "dst", "=", "append", "(", "dst", ",", "s", "[", "start", ":", "i", "]", "...", ")", "\n", "}", "\n", "switch", "b", "{", "case", "'\"'", ",", "'\\\\'", ":", "dst", "=", "append", "(", "dst", ",", "'\\\\'", ",", "b", ")", "\n", "case", "'\\b'", ":", "dst", "=", "append", "(", "dst", ",", "'\\\\'", ",", "'b'", ")", "\n", "case", "'\\f'", ":", "dst", "=", "append", "(", "dst", ",", "'\\\\'", ",", "'f'", ")", "\n", "case", "'\\n'", ":", "dst", "=", "append", "(", "dst", ",", "'\\\\'", ",", "'n'", ")", "\n", "case", "'\\r'", ":", "dst", "=", "append", "(", "dst", ",", "'\\\\'", ",", "'r'", ")", "\n", "case", "'\\t'", ":", "dst", "=", "append", "(", "dst", ",", "'\\\\'", ",", "'t'", ")", "\n", "default", ":", "dst", "=", "append", "(", "dst", ",", "'\\\\'", ",", "'u'", ",", "'0'", ",", "'0'", ",", "hex", "[", "b", ">>", "4", "]", ",", "hex", "[", "b", "&", "0xF", "]", ")", "\n", "}", "\n", "i", "++", "\n", "start", "=", "i", "\n", "}", "\n", "if", "start", "<", "len", "(", "s", ")", "{", "dst", "=", "append", "(", "dst", ",", "s", "[", "start", ":", "]", "...", ")", "\n", "}", "\n", "return", "dst", "\n", "}" ]
// appendStringComplex is used by appendString to take over an in // progress JSON string encoding that encountered a character that needs // to be encoded.
[ "appendStringComplex", "is", "used", "by", "appendString", "to", "take", "over", "an", "in", "progress", "JSON", "string", "encoding", "that", "encountered", "a", "character", "that", "needs", "to", "be", "encoded", "." ]
acf3980132bfcdc48638724e6e3d9e5749b85999
https://github.com/rs/zerolog/blob/acf3980132bfcdc48638724e6e3d9e5749b85999/internal/json/string.go#L66-L121
147,428
rs/zerolog
diode/internal/diodes/poller.go
WithPollingInterval
func WithPollingInterval(interval time.Duration) PollerConfigOption { return PollerConfigOption(func(c *Poller) { c.interval = interval }) }
go
func WithPollingInterval(interval time.Duration) PollerConfigOption { return PollerConfigOption(func(c *Poller) { c.interval = interval }) }
[ "func", "WithPollingInterval", "(", "interval", "time", ".", "Duration", ")", "PollerConfigOption", "{", "return", "PollerConfigOption", "(", "func", "(", "c", "*", "Poller", ")", "{", "c", ".", "interval", "=", "interval", "\n", "}", ")", "\n", "}" ]
// WithPollingInterval sets the interval at which the diode is queried // for new data. The default is 10ms.
[ "WithPollingInterval", "sets", "the", "interval", "at", "which", "the", "diode", "is", "queried", "for", "new", "data", ".", "The", "default", "is", "10ms", "." ]
acf3980132bfcdc48638724e6e3d9e5749b85999
https://github.com/rs/zerolog/blob/acf3980132bfcdc48638724e6e3d9e5749b85999/diode/internal/diodes/poller.go#L26-L30
147,429
rs/zerolog
diode/internal/diodes/poller.go
NewPoller
func NewPoller(d Diode, opts ...PollerConfigOption) *Poller { p := &Poller{ Diode: d, interval: 10 * time.Millisecond, ctx: context.Background(), } for _, o := range opts { o(p) } return p }
go
func NewPoller(d Diode, opts ...PollerConfigOption) *Poller { p := &Poller{ Diode: d, interval: 10 * time.Millisecond, ctx: context.Background(), } for _, o := range opts { o(p) } return p }
[ "func", "NewPoller", "(", "d", "Diode", ",", "opts", "...", "PollerConfigOption", ")", "*", "Poller", "{", "p", ":=", "&", "Poller", "{", "Diode", ":", "d", ",", "interval", ":", "10", "*", "time", ".", "Millisecond", ",", "ctx", ":", "context", ".", "Background", "(", ")", ",", "}", "\n\n", "for", "_", ",", "o", ":=", "range", "opts", "{", "o", "(", "p", ")", "\n", "}", "\n\n", "return", "p", "\n", "}" ]
// NewPoller returns a new Poller that wraps the given diode.
[ "NewPoller", "returns", "a", "new", "Poller", "that", "wraps", "the", "given", "diode", "." ]
acf3980132bfcdc48638724e6e3d9e5749b85999
https://github.com/rs/zerolog/blob/acf3980132bfcdc48638724e6e3d9e5749b85999/diode/internal/diodes/poller.go#L42-L54
147,430
rs/zerolog
diode/internal/diodes/poller.go
Next
func (p *Poller) Next() GenericDataType { for { data, ok := p.Diode.TryNext() if !ok { if p.isDone() { return nil } time.Sleep(p.interval) continue } return data } }
go
func (p *Poller) Next() GenericDataType { for { data, ok := p.Diode.TryNext() if !ok { if p.isDone() { return nil } time.Sleep(p.interval) continue } return data } }
[ "func", "(", "p", "*", "Poller", ")", "Next", "(", ")", "GenericDataType", "{", "for", "{", "data", ",", "ok", ":=", "p", ".", "Diode", ".", "TryNext", "(", ")", "\n", "if", "!", "ok", "{", "if", "p", ".", "isDone", "(", ")", "{", "return", "nil", "\n", "}", "\n\n", "time", ".", "Sleep", "(", "p", ".", "interval", ")", "\n", "continue", "\n", "}", "\n", "return", "data", "\n", "}", "\n", "}" ]
// Next polls the diode until data is available or until the context is done. // If the context is done, then nil will be returned.
[ "Next", "polls", "the", "diode", "until", "data", "is", "available", "or", "until", "the", "context", "is", "done", ".", "If", "the", "context", "is", "done", "then", "nil", "will", "be", "returned", "." ]
acf3980132bfcdc48638724e6e3d9e5749b85999
https://github.com/rs/zerolog/blob/acf3980132bfcdc48638724e6e3d9e5749b85999/diode/internal/diodes/poller.go#L58-L71
147,431
rs/zerolog
diode/internal/diodes/one_to_one.go
NewOneToOne
func NewOneToOne(size int, alerter Alerter) *OneToOne { if alerter == nil { alerter = AlertFunc(func(int) {}) } return &OneToOne{ buffer: make([]unsafe.Pointer, size), alerter: alerter, } }
go
func NewOneToOne(size int, alerter Alerter) *OneToOne { if alerter == nil { alerter = AlertFunc(func(int) {}) } return &OneToOne{ buffer: make([]unsafe.Pointer, size), alerter: alerter, } }
[ "func", "NewOneToOne", "(", "size", "int", ",", "alerter", "Alerter", ")", "*", "OneToOne", "{", "if", "alerter", "==", "nil", "{", "alerter", "=", "AlertFunc", "(", "func", "(", "int", ")", "{", "}", ")", "\n", "}", "\n\n", "return", "&", "OneToOne", "{", "buffer", ":", "make", "(", "[", "]", "unsafe", ".", "Pointer", ",", "size", ")", ",", "alerter", ":", "alerter", ",", "}", "\n", "}" ]
// NewOneToOne creates a new diode is meant to be used by a single reader and // a single writer. The alerter is invoked on the read's go-routine. It is // called when it notices that the writer go-routine has passed it and wrote // over data. A nil can be used to ignore alerts.
[ "NewOneToOne", "creates", "a", "new", "diode", "is", "meant", "to", "be", "used", "by", "a", "single", "reader", "and", "a", "single", "writer", ".", "The", "alerter", "is", "invoked", "on", "the", "read", "s", "go", "-", "routine", ".", "It", "is", "called", "when", "it", "notices", "that", "the", "writer", "go", "-", "routine", "has", "passed", "it", "and", "wrote", "over", "data", ".", "A", "nil", "can", "be", "used", "to", "ignore", "alerts", "." ]
acf3980132bfcdc48638724e6e3d9e5749b85999
https://github.com/rs/zerolog/blob/acf3980132bfcdc48638724e6e3d9e5749b85999/diode/internal/diodes/one_to_one.go#L44-L53
147,432
rs/zerolog
internal/json/base.go
AppendKey
func (e Encoder) AppendKey(dst []byte, key string) []byte { if len(dst) > 1 && dst[len(dst)-1] != '{' { dst = append(dst, ',') } dst = e.AppendString(dst, key) return append(dst, ':') }
go
func (e Encoder) AppendKey(dst []byte, key string) []byte { if len(dst) > 1 && dst[len(dst)-1] != '{' { dst = append(dst, ',') } dst = e.AppendString(dst, key) return append(dst, ':') }
[ "func", "(", "e", "Encoder", ")", "AppendKey", "(", "dst", "[", "]", "byte", ",", "key", "string", ")", "[", "]", "byte", "{", "if", "len", "(", "dst", ")", ">", "1", "&&", "dst", "[", "len", "(", "dst", ")", "-", "1", "]", "!=", "'{'", "{", "dst", "=", "append", "(", "dst", ",", "','", ")", "\n", "}", "\n", "dst", "=", "e", ".", "AppendString", "(", "dst", ",", "key", ")", "\n", "return", "append", "(", "dst", ",", "':'", ")", "\n", "}" ]
// AppendKey appends a new key to the output JSON.
[ "AppendKey", "appends", "a", "new", "key", "to", "the", "output", "JSON", "." ]
acf3980132bfcdc48638724e6e3d9e5749b85999
https://github.com/rs/zerolog/blob/acf3980132bfcdc48638724e6e3d9e5749b85999/internal/json/base.go#L6-L12
147,433
rs/zerolog
internal/json/time.go
AppendTime
func (e Encoder) AppendTime(dst []byte, t time.Time, format string) []byte { switch format { case timeFormatUnix: return e.AppendInt64(dst, t.Unix()) case timeFormatUnixMs: return e.AppendInt64(dst, t.UnixNano()/1000000) } return append(t.AppendFormat(append(dst, '"'), format), '"') }
go
func (e Encoder) AppendTime(dst []byte, t time.Time, format string) []byte { switch format { case timeFormatUnix: return e.AppendInt64(dst, t.Unix()) case timeFormatUnixMs: return e.AppendInt64(dst, t.UnixNano()/1000000) } return append(t.AppendFormat(append(dst, '"'), format), '"') }
[ "func", "(", "e", "Encoder", ")", "AppendTime", "(", "dst", "[", "]", "byte", ",", "t", "time", ".", "Time", ",", "format", "string", ")", "[", "]", "byte", "{", "switch", "format", "{", "case", "timeFormatUnix", ":", "return", "e", ".", "AppendInt64", "(", "dst", ",", "t", ".", "Unix", "(", ")", ")", "\n", "case", "timeFormatUnixMs", ":", "return", "e", ".", "AppendInt64", "(", "dst", ",", "t", ".", "UnixNano", "(", ")", "/", "1000000", ")", "\n", "}", "\n", "return", "append", "(", "t", ".", "AppendFormat", "(", "append", "(", "dst", ",", "'\"'", ")", ",", "format", ")", ",", "'\"'", ")", "\n", "}" ]
// AppendTime formats the input time with the given format // and appends the encoded string to the input byte slice.
[ "AppendTime", "formats", "the", "input", "time", "with", "the", "given", "format", "and", "appends", "the", "encoded", "string", "to", "the", "input", "byte", "slice", "." ]
acf3980132bfcdc48638724e6e3d9e5749b85999
https://github.com/rs/zerolog/blob/acf3980132bfcdc48638724e6e3d9e5749b85999/internal/json/time.go#L16-L24
147,434
rs/zerolog
internal/json/time.go
AppendTimes
func (Encoder) AppendTimes(dst []byte, vals []time.Time, format string) []byte { switch format { case timeFormatUnix: return appendUnixTimes(dst, vals) case timeFormatUnixMs: return appendUnixMsTimes(dst, vals) } if len(vals) == 0 { return append(dst, '[', ']') } dst = append(dst, '[') dst = append(vals[0].AppendFormat(append(dst, '"'), format), '"') if len(vals) > 1 { for _, t := range vals[1:] { dst = append(t.AppendFormat(append(dst, ',', '"'), format), '"') } } dst = append(dst, ']') return dst }
go
func (Encoder) AppendTimes(dst []byte, vals []time.Time, format string) []byte { switch format { case timeFormatUnix: return appendUnixTimes(dst, vals) case timeFormatUnixMs: return appendUnixMsTimes(dst, vals) } if len(vals) == 0 { return append(dst, '[', ']') } dst = append(dst, '[') dst = append(vals[0].AppendFormat(append(dst, '"'), format), '"') if len(vals) > 1 { for _, t := range vals[1:] { dst = append(t.AppendFormat(append(dst, ',', '"'), format), '"') } } dst = append(dst, ']') return dst }
[ "func", "(", "Encoder", ")", "AppendTimes", "(", "dst", "[", "]", "byte", ",", "vals", "[", "]", "time", ".", "Time", ",", "format", "string", ")", "[", "]", "byte", "{", "switch", "format", "{", "case", "timeFormatUnix", ":", "return", "appendUnixTimes", "(", "dst", ",", "vals", ")", "\n", "case", "timeFormatUnixMs", ":", "return", "appendUnixMsTimes", "(", "dst", ",", "vals", ")", "\n", "}", "\n", "if", "len", "(", "vals", ")", "==", "0", "{", "return", "append", "(", "dst", ",", "'['", ",", "']'", ")", "\n", "}", "\n", "dst", "=", "append", "(", "dst", ",", "'['", ")", "\n", "dst", "=", "append", "(", "vals", "[", "0", "]", ".", "AppendFormat", "(", "append", "(", "dst", ",", "'\"'", ")", ",", "format", ")", ",", "'\"'", ")", "\n", "if", "len", "(", "vals", ")", ">", "1", "{", "for", "_", ",", "t", ":=", "range", "vals", "[", "1", ":", "]", "{", "dst", "=", "append", "(", "t", ".", "AppendFormat", "(", "append", "(", "dst", ",", "','", ",", "'\"'", ")", ",", "format", ")", ",", "'\"'", ")", "\n", "}", "\n", "}", "\n", "dst", "=", "append", "(", "dst", ",", "']'", ")", "\n", "return", "dst", "\n", "}" ]
// AppendTimes converts the input times with the given format // and appends the encoded string list to the input byte slice.
[ "AppendTimes", "converts", "the", "input", "times", "with", "the", "given", "format", "and", "appends", "the", "encoded", "string", "list", "to", "the", "input", "byte", "slice", "." ]
acf3980132bfcdc48638724e6e3d9e5749b85999
https://github.com/rs/zerolog/blob/acf3980132bfcdc48638724e6e3d9e5749b85999/internal/json/time.go#L28-L47
147,435
rs/zerolog
internal/json/time.go
AppendDurations
func (e Encoder) AppendDurations(dst []byte, vals []time.Duration, unit time.Duration, useInt bool) []byte { if len(vals) == 0 { return append(dst, '[', ']') } dst = append(dst, '[') dst = e.AppendDuration(dst, vals[0], unit, useInt) if len(vals) > 1 { for _, d := range vals[1:] { dst = e.AppendDuration(append(dst, ','), d, unit, useInt) } } dst = append(dst, ']') return dst }
go
func (e Encoder) AppendDurations(dst []byte, vals []time.Duration, unit time.Duration, useInt bool) []byte { if len(vals) == 0 { return append(dst, '[', ']') } dst = append(dst, '[') dst = e.AppendDuration(dst, vals[0], unit, useInt) if len(vals) > 1 { for _, d := range vals[1:] { dst = e.AppendDuration(append(dst, ','), d, unit, useInt) } } dst = append(dst, ']') return dst }
[ "func", "(", "e", "Encoder", ")", "AppendDurations", "(", "dst", "[", "]", "byte", ",", "vals", "[", "]", "time", ".", "Duration", ",", "unit", "time", ".", "Duration", ",", "useInt", "bool", ")", "[", "]", "byte", "{", "if", "len", "(", "vals", ")", "==", "0", "{", "return", "append", "(", "dst", ",", "'['", ",", "']'", ")", "\n", "}", "\n", "dst", "=", "append", "(", "dst", ",", "'['", ")", "\n", "dst", "=", "e", ".", "AppendDuration", "(", "dst", ",", "vals", "[", "0", "]", ",", "unit", ",", "useInt", ")", "\n", "if", "len", "(", "vals", ")", ">", "1", "{", "for", "_", ",", "d", ":=", "range", "vals", "[", "1", ":", "]", "{", "dst", "=", "e", ".", "AppendDuration", "(", "append", "(", "dst", ",", "','", ")", ",", "d", ",", "unit", ",", "useInt", ")", "\n", "}", "\n", "}", "\n", "dst", "=", "append", "(", "dst", ",", "']'", ")", "\n", "return", "dst", "\n", "}" ]
// AppendDurations formats the input durations with the given unit & format // and appends the encoded string list to the input byte slice.
[ "AppendDurations", "formats", "the", "input", "durations", "with", "the", "given", "unit", "&", "format", "and", "appends", "the", "encoded", "string", "list", "to", "the", "input", "byte", "slice", "." ]
acf3980132bfcdc48638724e6e3d9e5749b85999
https://github.com/rs/zerolog/blob/acf3980132bfcdc48638724e6e3d9e5749b85999/internal/json/time.go#L90-L103
147,436
rs/zerolog
pkgerrors/stacktrace.go
Write
func (s *state) Write(b []byte) (n int, err error) { s.b = b return len(b), nil }
go
func (s *state) Write(b []byte) (n int, err error) { s.b = b return len(b), nil }
[ "func", "(", "s", "*", "state", ")", "Write", "(", "b", "[", "]", "byte", ")", "(", "n", "int", ",", "err", "error", ")", "{", "s", ".", "b", "=", "b", "\n", "return", "len", "(", "b", ")", ",", "nil", "\n", "}" ]
// Write implement fmt.Formatter interface.
[ "Write", "implement", "fmt", ".", "Formatter", "interface", "." ]
acf3980132bfcdc48638724e6e3d9e5749b85999
https://github.com/rs/zerolog/blob/acf3980132bfcdc48638724e6e3d9e5749b85999/pkgerrors/stacktrace.go#L18-L21
147,437
rs/zerolog
hlog/hlog.go
NewHandler
func NewHandler(log zerolog.Logger) func(http.Handler) http.Handler { return func(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { // Create a copy of the logger (including internal context slice) // to prevent data race when using UpdateContext. l := log.With().Logger() r = r.WithContext(l.WithContext(r.Context())) next.ServeHTTP(w, r) }) } }
go
func NewHandler(log zerolog.Logger) func(http.Handler) http.Handler { return func(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { // Create a copy of the logger (including internal context slice) // to prevent data race when using UpdateContext. l := log.With().Logger() r = r.WithContext(l.WithContext(r.Context())) next.ServeHTTP(w, r) }) } }
[ "func", "NewHandler", "(", "log", "zerolog", ".", "Logger", ")", "func", "(", "http", ".", "Handler", ")", "http", ".", "Handler", "{", "return", "func", "(", "next", "http", ".", "Handler", ")", "http", ".", "Handler", "{", "return", "http", ".", "HandlerFunc", "(", "func", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "// Create a copy of the logger (including internal context slice)", "// to prevent data race when using UpdateContext.", "l", ":=", "log", ".", "With", "(", ")", ".", "Logger", "(", ")", "\n", "r", "=", "r", ".", "WithContext", "(", "l", ".", "WithContext", "(", "r", ".", "Context", "(", ")", ")", ")", "\n", "next", ".", "ServeHTTP", "(", "w", ",", "r", ")", "\n", "}", ")", "\n", "}", "\n", "}" ]
// NewHandler injects log into requests context.
[ "NewHandler", "injects", "log", "into", "requests", "context", "." ]
acf3980132bfcdc48638724e6e3d9e5749b85999
https://github.com/rs/zerolog/blob/acf3980132bfcdc48638724e6e3d9e5749b85999/hlog/hlog.go#L23-L33
147,438
rs/zerolog
hlog/hlog.go
RequestHandler
func RequestHandler(fieldKey string) func(next http.Handler) http.Handler { return func(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { log := zerolog.Ctx(r.Context()) log.UpdateContext(func(c zerolog.Context) zerolog.Context { return c.Str(fieldKey, r.Method+" "+r.URL.String()) }) next.ServeHTTP(w, r) }) } }
go
func RequestHandler(fieldKey string) func(next http.Handler) http.Handler { return func(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { log := zerolog.Ctx(r.Context()) log.UpdateContext(func(c zerolog.Context) zerolog.Context { return c.Str(fieldKey, r.Method+" "+r.URL.String()) }) next.ServeHTTP(w, r) }) } }
[ "func", "RequestHandler", "(", "fieldKey", "string", ")", "func", "(", "next", "http", ".", "Handler", ")", "http", ".", "Handler", "{", "return", "func", "(", "next", "http", ".", "Handler", ")", "http", ".", "Handler", "{", "return", "http", ".", "HandlerFunc", "(", "func", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "log", ":=", "zerolog", ".", "Ctx", "(", "r", ".", "Context", "(", ")", ")", "\n", "log", ".", "UpdateContext", "(", "func", "(", "c", "zerolog", ".", "Context", ")", "zerolog", ".", "Context", "{", "return", "c", ".", "Str", "(", "fieldKey", ",", "r", ".", "Method", "+", "\"", "\"", "+", "r", ".", "URL", ".", "String", "(", ")", ")", "\n", "}", ")", "\n", "next", ".", "ServeHTTP", "(", "w", ",", "r", ")", "\n", "}", ")", "\n", "}", "\n", "}" ]
// RequestHandler adds the request method and URL as a field to the context's logger // using fieldKey as field key.
[ "RequestHandler", "adds", "the", "request", "method", "and", "URL", "as", "a", "field", "to", "the", "context", "s", "logger", "using", "fieldKey", "as", "field", "key", "." ]
acf3980132bfcdc48638724e6e3d9e5749b85999
https://github.com/rs/zerolog/blob/acf3980132bfcdc48638724e6e3d9e5749b85999/hlog/hlog.go#L65-L75
147,439
rs/zerolog
hlog/hlog.go
RemoteAddrHandler
func RemoteAddrHandler(fieldKey string) func(next http.Handler) http.Handler { return func(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if host, _, err := net.SplitHostPort(r.RemoteAddr); err == nil { log := zerolog.Ctx(r.Context()) log.UpdateContext(func(c zerolog.Context) zerolog.Context { return c.Str(fieldKey, host) }) } next.ServeHTTP(w, r) }) } }
go
func RemoteAddrHandler(fieldKey string) func(next http.Handler) http.Handler { return func(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if host, _, err := net.SplitHostPort(r.RemoteAddr); err == nil { log := zerolog.Ctx(r.Context()) log.UpdateContext(func(c zerolog.Context) zerolog.Context { return c.Str(fieldKey, host) }) } next.ServeHTTP(w, r) }) } }
[ "func", "RemoteAddrHandler", "(", "fieldKey", "string", ")", "func", "(", "next", "http", ".", "Handler", ")", "http", ".", "Handler", "{", "return", "func", "(", "next", "http", ".", "Handler", ")", "http", ".", "Handler", "{", "return", "http", ".", "HandlerFunc", "(", "func", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "if", "host", ",", "_", ",", "err", ":=", "net", ".", "SplitHostPort", "(", "r", ".", "RemoteAddr", ")", ";", "err", "==", "nil", "{", "log", ":=", "zerolog", ".", "Ctx", "(", "r", ".", "Context", "(", ")", ")", "\n", "log", ".", "UpdateContext", "(", "func", "(", "c", "zerolog", ".", "Context", ")", "zerolog", ".", "Context", "{", "return", "c", ".", "Str", "(", "fieldKey", ",", "host", ")", "\n", "}", ")", "\n", "}", "\n", "next", ".", "ServeHTTP", "(", "w", ",", "r", ")", "\n", "}", ")", "\n", "}", "\n", "}" ]
// RemoteAddrHandler adds the request's remote address as a field to the context's logger // using fieldKey as field key.
[ "RemoteAddrHandler", "adds", "the", "request", "s", "remote", "address", "as", "a", "field", "to", "the", "context", "s", "logger", "using", "fieldKey", "as", "field", "key", "." ]
acf3980132bfcdc48638724e6e3d9e5749b85999
https://github.com/rs/zerolog/blob/acf3980132bfcdc48638724e6e3d9e5749b85999/hlog/hlog.go#L79-L91
147,440
rs/zerolog
hlog/hlog.go
UserAgentHandler
func UserAgentHandler(fieldKey string) func(next http.Handler) http.Handler { return func(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if ua := r.Header.Get("User-Agent"); ua != "" { log := zerolog.Ctx(r.Context()) log.UpdateContext(func(c zerolog.Context) zerolog.Context { return c.Str(fieldKey, ua) }) } next.ServeHTTP(w, r) }) } }
go
func UserAgentHandler(fieldKey string) func(next http.Handler) http.Handler { return func(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if ua := r.Header.Get("User-Agent"); ua != "" { log := zerolog.Ctx(r.Context()) log.UpdateContext(func(c zerolog.Context) zerolog.Context { return c.Str(fieldKey, ua) }) } next.ServeHTTP(w, r) }) } }
[ "func", "UserAgentHandler", "(", "fieldKey", "string", ")", "func", "(", "next", "http", ".", "Handler", ")", "http", ".", "Handler", "{", "return", "func", "(", "next", "http", ".", "Handler", ")", "http", ".", "Handler", "{", "return", "http", ".", "HandlerFunc", "(", "func", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "if", "ua", ":=", "r", ".", "Header", ".", "Get", "(", "\"", "\"", ")", ";", "ua", "!=", "\"", "\"", "{", "log", ":=", "zerolog", ".", "Ctx", "(", "r", ".", "Context", "(", ")", ")", "\n", "log", ".", "UpdateContext", "(", "func", "(", "c", "zerolog", ".", "Context", ")", "zerolog", ".", "Context", "{", "return", "c", ".", "Str", "(", "fieldKey", ",", "ua", ")", "\n", "}", ")", "\n", "}", "\n", "next", ".", "ServeHTTP", "(", "w", ",", "r", ")", "\n", "}", ")", "\n", "}", "\n", "}" ]
// UserAgentHandler adds the request's user-agent as a field to the context's logger // using fieldKey as field key.
[ "UserAgentHandler", "adds", "the", "request", "s", "user", "-", "agent", "as", "a", "field", "to", "the", "context", "s", "logger", "using", "fieldKey", "as", "field", "key", "." ]
acf3980132bfcdc48638724e6e3d9e5749b85999
https://github.com/rs/zerolog/blob/acf3980132bfcdc48638724e6e3d9e5749b85999/hlog/hlog.go#L95-L107
147,441
rs/zerolog
hlog/hlog.go
IDFromRequest
func IDFromRequest(r *http.Request) (id xid.ID, ok bool) { if r == nil { return } return IDFromCtx(r.Context()) }
go
func IDFromRequest(r *http.Request) (id xid.ID, ok bool) { if r == nil { return } return IDFromCtx(r.Context()) }
[ "func", "IDFromRequest", "(", "r", "*", "http", ".", "Request", ")", "(", "id", "xid", ".", "ID", ",", "ok", "bool", ")", "{", "if", "r", "==", "nil", "{", "return", "\n", "}", "\n", "return", "IDFromCtx", "(", "r", ".", "Context", "(", ")", ")", "\n", "}" ]
// IDFromRequest returns the unique id associated to the request if any.
[ "IDFromRequest", "returns", "the", "unique", "id", "associated", "to", "the", "request", "if", "any", "." ]
acf3980132bfcdc48638724e6e3d9e5749b85999
https://github.com/rs/zerolog/blob/acf3980132bfcdc48638724e6e3d9e5749b85999/hlog/hlog.go#L128-L133
147,442
rs/zerolog
hlog/hlog.go
AccessHandler
func AccessHandler(f func(r *http.Request, status, size int, duration time.Duration)) func(next http.Handler) http.Handler { return func(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { start := time.Now() lw := mutil.WrapWriter(w) next.ServeHTTP(lw, r) f(r, lw.Status(), lw.BytesWritten(), time.Since(start)) }) } }
go
func AccessHandler(f func(r *http.Request, status, size int, duration time.Duration)) func(next http.Handler) http.Handler { return func(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { start := time.Now() lw := mutil.WrapWriter(w) next.ServeHTTP(lw, r) f(r, lw.Status(), lw.BytesWritten(), time.Since(start)) }) } }
[ "func", "AccessHandler", "(", "f", "func", "(", "r", "*", "http", ".", "Request", ",", "status", ",", "size", "int", ",", "duration", "time", ".", "Duration", ")", ")", "func", "(", "next", "http", ".", "Handler", ")", "http", ".", "Handler", "{", "return", "func", "(", "next", "http", ".", "Handler", ")", "http", ".", "Handler", "{", "return", "http", ".", "HandlerFunc", "(", "func", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "start", ":=", "time", ".", "Now", "(", ")", "\n", "lw", ":=", "mutil", ".", "WrapWriter", "(", "w", ")", "\n", "next", ".", "ServeHTTP", "(", "lw", ",", "r", ")", "\n", "f", "(", "r", ",", "lw", ".", "Status", "(", ")", ",", "lw", ".", "BytesWritten", "(", ")", ",", "time", ".", "Since", "(", "start", ")", ")", "\n", "}", ")", "\n", "}", "\n", "}" ]
// AccessHandler returns a handler that call f after each request.
[ "AccessHandler", "returns", "a", "handler", "that", "call", "f", "after", "each", "request", "." ]
acf3980132bfcdc48638724e6e3d9e5749b85999
https://github.com/rs/zerolog/blob/acf3980132bfcdc48638724e6e3d9e5749b85999/hlog/hlog.go#L175-L184
147,443
rebuy-de/aws-nuke
cmd/queue.go
List
func (i *Item) List() ([]resources.Resource, error) { listers := resources.GetListers() return listers[i.Type](i.Region.Session) }
go
func (i *Item) List() ([]resources.Resource, error) { listers := resources.GetListers() return listers[i.Type](i.Region.Session) }
[ "func", "(", "i", "*", "Item", ")", "List", "(", ")", "(", "[", "]", "resources", ".", "Resource", ",", "error", ")", "{", "listers", ":=", "resources", ".", "GetListers", "(", ")", "\n", "return", "listers", "[", "i", ".", "Type", "]", "(", "i", ".", "Region", ".", "Session", ")", "\n", "}" ]
// List gets all resource items of the same resource type like the Item.
[ "List", "gets", "all", "resource", "items", "of", "the", "same", "resource", "type", "like", "the", "Item", "." ]
21582790b6806fd775aba073b0bbc27a111a15f0
https://github.com/rebuy-de/aws-nuke/blob/21582790b6806fd775aba073b0bbc27a111a15f0/cmd/queue.go#L51-L54
147,444
wcharczuk/go-chart
util/math.go
Max
func (m mathUtil) Max(values ...float64) float64 { if len(values) == 0 { return 0 } max := values[0] for _, v := range values { if max < v { max = v } } return max }
go
func (m mathUtil) Max(values ...float64) float64 { if len(values) == 0 { return 0 } max := values[0] for _, v := range values { if max < v { max = v } } return max }
[ "func", "(", "m", "mathUtil", ")", "Max", "(", "values", "...", "float64", ")", "float64", "{", "if", "len", "(", "values", ")", "==", "0", "{", "return", "0", "\n", "}", "\n", "max", ":=", "values", "[", "0", "]", "\n", "for", "_", ",", "v", ":=", "range", "values", "{", "if", "max", "<", "v", "{", "max", "=", "v", "\n", "}", "\n", "}", "\n", "return", "max", "\n", "}" ]
// Max returns the maximum value of a group of floats.
[ "Max", "returns", "the", "maximum", "value", "of", "a", "group", "of", "floats", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/util/math.go#L29-L40
147,445
wcharczuk/go-chart
util/math.go
MinAndMax
func (m mathUtil) MinAndMax(values ...float64) (min float64, max float64) { if len(values) == 0 { return } min = values[0] max = values[0] for _, v := range values[1:] { if max < v { max = v } if min > v { min = v } } return }
go
func (m mathUtil) MinAndMax(values ...float64) (min float64, max float64) { if len(values) == 0 { return } min = values[0] max = values[0] for _, v := range values[1:] { if max < v { max = v } if min > v { min = v } } return }
[ "func", "(", "m", "mathUtil", ")", "MinAndMax", "(", "values", "...", "float64", ")", "(", "min", "float64", ",", "max", "float64", ")", "{", "if", "len", "(", "values", ")", "==", "0", "{", "return", "\n", "}", "\n", "min", "=", "values", "[", "0", "]", "\n", "max", "=", "values", "[", "0", "]", "\n", "for", "_", ",", "v", ":=", "range", "values", "[", "1", ":", "]", "{", "if", "max", "<", "v", "{", "max", "=", "v", "\n", "}", "\n", "if", "min", ">", "v", "{", "min", "=", "v", "\n", "}", "\n", "}", "\n", "return", "\n", "}" ]
// MinAndMax returns both the min and max in one pass.
[ "MinAndMax", "returns", "both", "the", "min", "and", "max", "in", "one", "pass", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/util/math.go#L43-L58
147,446
wcharczuk/go-chart
util/math.go
GetRoundToForDelta
func (m mathUtil) GetRoundToForDelta(delta float64) float64 { startingDeltaBound := math.Pow(10.0, 10.0) for cursor := startingDeltaBound; cursor > 0; cursor /= 10.0 { if delta > cursor { return cursor / 10.0 } } return 0.0 }
go
func (m mathUtil) GetRoundToForDelta(delta float64) float64 { startingDeltaBound := math.Pow(10.0, 10.0) for cursor := startingDeltaBound; cursor > 0; cursor /= 10.0 { if delta > cursor { return cursor / 10.0 } } return 0.0 }
[ "func", "(", "m", "mathUtil", ")", "GetRoundToForDelta", "(", "delta", "float64", ")", "float64", "{", "startingDeltaBound", ":=", "math", ".", "Pow", "(", "10.0", ",", "10.0", ")", "\n", "for", "cursor", ":=", "startingDeltaBound", ";", "cursor", ">", "0", ";", "cursor", "/=", "10.0", "{", "if", "delta", ">", "cursor", "{", "return", "cursor", "/", "10.0", "\n", "}", "\n", "}", "\n\n", "return", "0.0", "\n", "}" ]
// GetRoundToForDelta returns a `roundTo` value for a given delta.
[ "GetRoundToForDelta", "returns", "a", "roundTo", "value", "for", "a", "given", "delta", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/util/math.go#L61-L70
147,447
wcharczuk/go-chart
util/math.go
RoundUp
func (m mathUtil) RoundUp(value, roundTo float64) float64 { if roundTo < 0.000000000000001 { return value } d1 := math.Ceil(value / roundTo) return d1 * roundTo }
go
func (m mathUtil) RoundUp(value, roundTo float64) float64 { if roundTo < 0.000000000000001 { return value } d1 := math.Ceil(value / roundTo) return d1 * roundTo }
[ "func", "(", "m", "mathUtil", ")", "RoundUp", "(", "value", ",", "roundTo", "float64", ")", "float64", "{", "if", "roundTo", "<", "0.000000000000001", "{", "return", "value", "\n", "}", "\n", "d1", ":=", "math", ".", "Ceil", "(", "value", "/", "roundTo", ")", "\n", "return", "d1", "*", "roundTo", "\n", "}" ]
// RoundUp rounds up to a given roundTo value.
[ "RoundUp", "rounds", "up", "to", "a", "given", "roundTo", "value", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/util/math.go#L73-L79
147,448
wcharczuk/go-chart
util/math.go
RoundDown
func (m mathUtil) RoundDown(value, roundTo float64) float64 { if roundTo < 0.000000000000001 { return value } d1 := math.Floor(value / roundTo) return d1 * roundTo }
go
func (m mathUtil) RoundDown(value, roundTo float64) float64 { if roundTo < 0.000000000000001 { return value } d1 := math.Floor(value / roundTo) return d1 * roundTo }
[ "func", "(", "m", "mathUtil", ")", "RoundDown", "(", "value", ",", "roundTo", "float64", ")", "float64", "{", "if", "roundTo", "<", "0.000000000000001", "{", "return", "value", "\n", "}", "\n", "d1", ":=", "math", ".", "Floor", "(", "value", "/", "roundTo", ")", "\n", "return", "d1", "*", "roundTo", "\n", "}" ]
// RoundDown rounds down to a given roundTo value.
[ "RoundDown", "rounds", "down", "to", "a", "given", "roundTo", "value", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/util/math.go#L82-L88
147,449
wcharczuk/go-chart
util/math.go
MinInt
func (m mathUtil) MinInt(values ...int) int { min := math.MaxInt32 for _, v := range values { if v < min { min = v } } return min }
go
func (m mathUtil) MinInt(values ...int) int { min := math.MaxInt32 for _, v := range values { if v < min { min = v } } return min }
[ "func", "(", "m", "mathUtil", ")", "MinInt", "(", "values", "...", "int", ")", "int", "{", "min", ":=", "math", ".", "MaxInt32", "\n", "for", "_", ",", "v", ":=", "range", "values", "{", "if", "v", "<", "min", "{", "min", "=", "v", "\n", "}", "\n", "}", "\n", "return", "min", "\n", "}" ]
// MinInt returns the minimum of a set of integers.
[ "MinInt", "returns", "the", "minimum", "of", "a", "set", "of", "integers", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/util/math.go#L106-L114
147,450
wcharczuk/go-chart
util/math.go
MaxInt
func (m mathUtil) MaxInt(values ...int) int { max := math.MinInt32 for _, v := range values { if v > max { max = v } } return max }
go
func (m mathUtil) MaxInt(values ...int) int { max := math.MinInt32 for _, v := range values { if v > max { max = v } } return max }
[ "func", "(", "m", "mathUtil", ")", "MaxInt", "(", "values", "...", "int", ")", "int", "{", "max", ":=", "math", ".", "MinInt32", "\n", "for", "_", ",", "v", ":=", "range", "values", "{", "if", "v", ">", "max", "{", "max", "=", "v", "\n", "}", "\n", "}", "\n", "return", "max", "\n", "}" ]
// MaxInt returns the maximum of a set of integers.
[ "MaxInt", "returns", "the", "maximum", "of", "a", "set", "of", "integers", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/util/math.go#L117-L125
147,451
wcharczuk/go-chart
util/math.go
Mean
func (m mathUtil) Mean(values ...float64) float64 { return m.Sum(values...) / float64(len(values)) }
go
func (m mathUtil) Mean(values ...float64) float64 { return m.Sum(values...) / float64(len(values)) }
[ "func", "(", "m", "mathUtil", ")", "Mean", "(", "values", "...", "float64", ")", "float64", "{", "return", "m", ".", "Sum", "(", "values", "...", ")", "/", "float64", "(", "len", "(", "values", ")", ")", "\n", "}" ]
// Mean returns the mean of a set of values
[ "Mean", "returns", "the", "mean", "of", "a", "set", "of", "values" ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/util/math.go#L144-L146
147,452
wcharczuk/go-chart
util/math.go
MeanInt
func (m mathUtil) MeanInt(values ...int) int { return m.SumInt(values...) / len(values) }
go
func (m mathUtil) MeanInt(values ...int) int { return m.SumInt(values...) / len(values) }
[ "func", "(", "m", "mathUtil", ")", "MeanInt", "(", "values", "...", "int", ")", "int", "{", "return", "m", ".", "SumInt", "(", "values", "...", ")", "/", "len", "(", "values", ")", "\n", "}" ]
// MeanInt returns the mean of a set of integer values.
[ "MeanInt", "returns", "the", "mean", "of", "a", "set", "of", "integer", "values", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/util/math.go#L149-L151
147,453
wcharczuk/go-chart
util/math.go
Sum
func (m mathUtil) Sum(values ...float64) float64 { var total float64 for _, v := range values { total += v } return total }
go
func (m mathUtil) Sum(values ...float64) float64 { var total float64 for _, v := range values { total += v } return total }
[ "func", "(", "m", "mathUtil", ")", "Sum", "(", "values", "...", "float64", ")", "float64", "{", "var", "total", "float64", "\n", "for", "_", ",", "v", ":=", "range", "values", "{", "total", "+=", "v", "\n", "}", "\n", "return", "total", "\n", "}" ]
// Sum sums a set of values.
[ "Sum", "sums", "a", "set", "of", "values", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/util/math.go#L154-L160
147,454
wcharczuk/go-chart
util/math.go
SumInt
func (m mathUtil) SumInt(values ...int) int { var total int for _, v := range values { total += v } return total }
go
func (m mathUtil) SumInt(values ...int) int { var total int for _, v := range values { total += v } return total }
[ "func", "(", "m", "mathUtil", ")", "SumInt", "(", "values", "...", "int", ")", "int", "{", "var", "total", "int", "\n", "for", "_", ",", "v", ":=", "range", "values", "{", "total", "+=", "v", "\n", "}", "\n", "return", "total", "\n", "}" ]
// SumInt sums a set of values.
[ "SumInt", "sums", "a", "set", "of", "values", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/util/math.go#L163-L169
147,455
wcharczuk/go-chart
util/math.go
RadiansToDegrees
func (m mathUtil) RadiansToDegrees(value float64) float64 { return math.Mod(value, _2pi) * _r2d }
go
func (m mathUtil) RadiansToDegrees(value float64) float64 { return math.Mod(value, _2pi) * _r2d }
[ "func", "(", "m", "mathUtil", ")", "RadiansToDegrees", "(", "value", "float64", ")", "float64", "{", "return", "math", ".", "Mod", "(", "value", ",", "_2pi", ")", "*", "_r2d", "\n", "}" ]
// RadiansToDegrees translates a radian value to a degree value.
[ "RadiansToDegrees", "translates", "a", "radian", "value", "to", "a", "degree", "value", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/util/math.go#L186-L188
147,456
wcharczuk/go-chart
util/math.go
RadianAdd
func (m mathUtil) RadianAdd(base, delta float64) float64 { value := base + delta if value > _2pi { return math.Mod(value, _2pi) } else if value < 0 { return math.Mod(_2pi+value, _2pi) } return value }
go
func (m mathUtil) RadianAdd(base, delta float64) float64 { value := base + delta if value > _2pi { return math.Mod(value, _2pi) } else if value < 0 { return math.Mod(_2pi+value, _2pi) } return value }
[ "func", "(", "m", "mathUtil", ")", "RadianAdd", "(", "base", ",", "delta", "float64", ")", "float64", "{", "value", ":=", "base", "+", "delta", "\n", "if", "value", ">", "_2pi", "{", "return", "math", ".", "Mod", "(", "value", ",", "_2pi", ")", "\n", "}", "else", "if", "value", "<", "0", "{", "return", "math", ".", "Mod", "(", "_2pi", "+", "value", ",", "_2pi", ")", "\n", "}", "\n", "return", "value", "\n", "}" ]
// RadianAdd adds a delta to a base in radians.
[ "RadianAdd", "adds", "a", "delta", "to", "a", "base", "in", "radians", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/util/math.go#L196-L204
147,457
wcharczuk/go-chart
util/math.go
DegreesAdd
func (m mathUtil) DegreesAdd(baseDegrees, deltaDegrees float64) float64 { value := baseDegrees + deltaDegrees if value > _2pi { return math.Mod(value, 360.0) } else if value < 0 { return math.Mod(360.0+value, 360.0) } return value }
go
func (m mathUtil) DegreesAdd(baseDegrees, deltaDegrees float64) float64 { value := baseDegrees + deltaDegrees if value > _2pi { return math.Mod(value, 360.0) } else if value < 0 { return math.Mod(360.0+value, 360.0) } return value }
[ "func", "(", "m", "mathUtil", ")", "DegreesAdd", "(", "baseDegrees", ",", "deltaDegrees", "float64", ")", "float64", "{", "value", ":=", "baseDegrees", "+", "deltaDegrees", "\n", "if", "value", ">", "_2pi", "{", "return", "math", ".", "Mod", "(", "value", ",", "360.0", ")", "\n", "}", "else", "if", "value", "<", "0", "{", "return", "math", ".", "Mod", "(", "360.0", "+", "value", ",", "360.0", ")", "\n", "}", "\n", "return", "value", "\n", "}" ]
// DegreesAdd adds a delta to a base in radians.
[ "DegreesAdd", "adds", "a", "delta", "to", "a", "base", "in", "radians", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/util/math.go#L207-L215
147,458
wcharczuk/go-chart
util/math.go
CirclePoint
func (m mathUtil) CirclePoint(cx, cy int, radius, thetaRadians float64) (x, y int) { x = cx + int(radius*math.Sin(thetaRadians)) y = cy - int(radius*math.Cos(thetaRadians)) return }
go
func (m mathUtil) CirclePoint(cx, cy int, radius, thetaRadians float64) (x, y int) { x = cx + int(radius*math.Sin(thetaRadians)) y = cy - int(radius*math.Cos(thetaRadians)) return }
[ "func", "(", "m", "mathUtil", ")", "CirclePoint", "(", "cx", ",", "cy", "int", ",", "radius", ",", "thetaRadians", "float64", ")", "(", "x", ",", "y", "int", ")", "{", "x", "=", "cx", "+", "int", "(", "radius", "*", "math", ".", "Sin", "(", "thetaRadians", ")", ")", "\n", "y", "=", "cy", "-", "int", "(", "radius", "*", "math", ".", "Cos", "(", "thetaRadians", ")", ")", "\n", "return", "\n", "}" ]
// CirclePoint returns the absolute position of a circle diameter point given // by the radius and the theta.
[ "CirclePoint", "returns", "the", "absolute", "position", "of", "a", "circle", "diameter", "point", "given", "by", "the", "radius", "and", "the", "theta", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/util/math.go#L224-L228
147,459
wcharczuk/go-chart
seq/seq.go
Array
func (s Seq) Array() (output []float64) { if s.Len() == 0 { return } output = make([]float64, s.Len()) for i := 0; i < s.Len(); i++ { output[i] = s.GetValue(i) } return }
go
func (s Seq) Array() (output []float64) { if s.Len() == 0 { return } output = make([]float64, s.Len()) for i := 0; i < s.Len(); i++ { output[i] = s.GetValue(i) } return }
[ "func", "(", "s", "Seq", ")", "Array", "(", ")", "(", "output", "[", "]", "float64", ")", "{", "if", "s", ".", "Len", "(", ")", "==", "0", "{", "return", "\n", "}", "\n\n", "output", "=", "make", "(", "[", "]", "float64", ",", "s", ".", "Len", "(", ")", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "s", ".", "Len", "(", ")", ";", "i", "++", "{", "output", "[", "i", "]", "=", "s", ".", "GetValue", "(", "i", ")", "\n", "}", "\n", "return", "\n", "}" ]
// Array enumerates the seq into a slice.
[ "Array", "enumerates", "the", "seq", "into", "a", "slice", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/seq/seq.go#L30-L40
147,460
wcharczuk/go-chart
seq/seq.go
Each
func (s Seq) Each(mapfn func(int, float64)) { for i := 0; i < s.Len(); i++ { mapfn(i, s.GetValue(i)) } }
go
func (s Seq) Each(mapfn func(int, float64)) { for i := 0; i < s.Len(); i++ { mapfn(i, s.GetValue(i)) } }
[ "func", "(", "s", "Seq", ")", "Each", "(", "mapfn", "func", "(", "int", ",", "float64", ")", ")", "{", "for", "i", ":=", "0", ";", "i", "<", "s", ".", "Len", "(", ")", ";", "i", "++", "{", "mapfn", "(", "i", ",", "s", ".", "GetValue", "(", "i", ")", ")", "\n", "}", "\n", "}" ]
// Each applies the `mapfn` to all values in the value provider.
[ "Each", "applies", "the", "mapfn", "to", "all", "values", "in", "the", "value", "provider", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/seq/seq.go#L43-L47
147,461
wcharczuk/go-chart
seq/seq.go
Map
func (s Seq) Map(mapfn func(i int, v float64) float64) Seq { output := make([]float64, s.Len()) for i := 0; i < s.Len(); i++ { mapfn(i, s.GetValue(i)) } return Seq{Array(output)} }
go
func (s Seq) Map(mapfn func(i int, v float64) float64) Seq { output := make([]float64, s.Len()) for i := 0; i < s.Len(); i++ { mapfn(i, s.GetValue(i)) } return Seq{Array(output)} }
[ "func", "(", "s", "Seq", ")", "Map", "(", "mapfn", "func", "(", "i", "int", ",", "v", "float64", ")", "float64", ")", "Seq", "{", "output", ":=", "make", "(", "[", "]", "float64", ",", "s", ".", "Len", "(", ")", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "s", ".", "Len", "(", ")", ";", "i", "++", "{", "mapfn", "(", "i", ",", "s", ".", "GetValue", "(", "i", ")", ")", "\n", "}", "\n", "return", "Seq", "{", "Array", "(", "output", ")", "}", "\n", "}" ]
// Map applies the `mapfn` to all values in the value provider, // returning a new seq.
[ "Map", "applies", "the", "mapfn", "to", "all", "values", "in", "the", "value", "provider", "returning", "a", "new", "seq", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/seq/seq.go#L51-L57
147,462
wcharczuk/go-chart
seq/seq.go
FoldRight
func (s Seq) FoldRight(mapfn func(i int, v0, v float64) float64) (v0 float64) { if s.Len() == 0 { return 0 } if s.Len() == 1 { return s.GetValue(0) } v0 = s.GetValue(s.Len() - 1) for i := s.Len() - 2; i >= 0; i-- { v0 = mapfn(i, v0, s.GetValue(i)) } return }
go
func (s Seq) FoldRight(mapfn func(i int, v0, v float64) float64) (v0 float64) { if s.Len() == 0 { return 0 } if s.Len() == 1 { return s.GetValue(0) } v0 = s.GetValue(s.Len() - 1) for i := s.Len() - 2; i >= 0; i-- { v0 = mapfn(i, v0, s.GetValue(i)) } return }
[ "func", "(", "s", "Seq", ")", "FoldRight", "(", "mapfn", "func", "(", "i", "int", ",", "v0", ",", "v", "float64", ")", "float64", ")", "(", "v0", "float64", ")", "{", "if", "s", ".", "Len", "(", ")", "==", "0", "{", "return", "0", "\n", "}", "\n\n", "if", "s", ".", "Len", "(", ")", "==", "1", "{", "return", "s", ".", "GetValue", "(", "0", ")", "\n", "}", "\n\n", "v0", "=", "s", ".", "GetValue", "(", "s", ".", "Len", "(", ")", "-", "1", ")", "\n", "for", "i", ":=", "s", ".", "Len", "(", ")", "-", "2", ";", "i", ">=", "0", ";", "i", "--", "{", "v0", "=", "mapfn", "(", "i", ",", "v0", ",", "s", ".", "GetValue", "(", "i", ")", ")", "\n", "}", "\n", "return", "\n", "}" ]
// FoldRight collapses a seq from right to left.
[ "FoldRight", "collapses", "a", "seq", "from", "right", "to", "left", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/seq/seq.go#L77-L91
147,463
wcharczuk/go-chart
seq/seq.go
Min
func (s Seq) Min() float64 { if s.Len() == 0 { return 0 } min := s.GetValue(0) var value float64 for i := 1; i < s.Len(); i++ { value = s.GetValue(i) if value < min { min = value } } return min }
go
func (s Seq) Min() float64 { if s.Len() == 0 { return 0 } min := s.GetValue(0) var value float64 for i := 1; i < s.Len(); i++ { value = s.GetValue(i) if value < min { min = value } } return min }
[ "func", "(", "s", "Seq", ")", "Min", "(", ")", "float64", "{", "if", "s", ".", "Len", "(", ")", "==", "0", "{", "return", "0", "\n", "}", "\n", "min", ":=", "s", ".", "GetValue", "(", "0", ")", "\n", "var", "value", "float64", "\n", "for", "i", ":=", "1", ";", "i", "<", "s", ".", "Len", "(", ")", ";", "i", "++", "{", "value", "=", "s", ".", "GetValue", "(", "i", ")", "\n", "if", "value", "<", "min", "{", "min", "=", "value", "\n", "}", "\n", "}", "\n", "return", "min", "\n", "}" ]
// Min returns the minimum value in the seq.
[ "Min", "returns", "the", "minimum", "value", "in", "the", "seq", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/seq/seq.go#L94-L107
147,464
wcharczuk/go-chart
seq/seq.go
Max
func (s Seq) Max() float64 { if s.Len() == 0 { return 0 } max := s.GetValue(0) var value float64 for i := 1; i < s.Len(); i++ { value = s.GetValue(i) if value > max { max = value } } return max }
go
func (s Seq) Max() float64 { if s.Len() == 0 { return 0 } max := s.GetValue(0) var value float64 for i := 1; i < s.Len(); i++ { value = s.GetValue(i) if value > max { max = value } } return max }
[ "func", "(", "s", "Seq", ")", "Max", "(", ")", "float64", "{", "if", "s", ".", "Len", "(", ")", "==", "0", "{", "return", "0", "\n", "}", "\n", "max", ":=", "s", ".", "GetValue", "(", "0", ")", "\n", "var", "value", "float64", "\n", "for", "i", ":=", "1", ";", "i", "<", "s", ".", "Len", "(", ")", ";", "i", "++", "{", "value", "=", "s", ".", "GetValue", "(", "i", ")", "\n", "if", "value", ">", "max", "{", "max", "=", "value", "\n", "}", "\n", "}", "\n", "return", "max", "\n", "}" ]
// Max returns the maximum value in the seq.
[ "Max", "returns", "the", "maximum", "value", "in", "the", "seq", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/seq/seq.go#L110-L123
147,465
wcharczuk/go-chart
seq/seq.go
MinMax
func (s Seq) MinMax() (min, max float64) { if s.Len() == 0 { return } min = s.GetValue(0) max = min var value float64 for i := 1; i < s.Len(); i++ { value = s.GetValue(i) if value < min { min = value } if value > max { max = value } } return }
go
func (s Seq) MinMax() (min, max float64) { if s.Len() == 0 { return } min = s.GetValue(0) max = min var value float64 for i := 1; i < s.Len(); i++ { value = s.GetValue(i) if value < min { min = value } if value > max { max = value } } return }
[ "func", "(", "s", "Seq", ")", "MinMax", "(", ")", "(", "min", ",", "max", "float64", ")", "{", "if", "s", ".", "Len", "(", ")", "==", "0", "{", "return", "\n", "}", "\n", "min", "=", "s", ".", "GetValue", "(", "0", ")", "\n", "max", "=", "min", "\n", "var", "value", "float64", "\n", "for", "i", ":=", "1", ";", "i", "<", "s", ".", "Len", "(", ")", ";", "i", "++", "{", "value", "=", "s", ".", "GetValue", "(", "i", ")", "\n", "if", "value", "<", "min", "{", "min", "=", "value", "\n", "}", "\n", "if", "value", ">", "max", "{", "max", "=", "value", "\n", "}", "\n", "}", "\n", "return", "\n", "}" ]
// MinMax returns the minimum and the maximum in one pass.
[ "MinMax", "returns", "the", "minimum", "and", "the", "maximum", "in", "one", "pass", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/seq/seq.go#L126-L143
147,466
wcharczuk/go-chart
seq/seq.go
Sort
func (s Seq) Sort() Seq { if s.Len() == 0 { return s } values := s.Array() sort.Float64s(values) return Seq{Provider: Array(values)} }
go
func (s Seq) Sort() Seq { if s.Len() == 0 { return s } values := s.Array() sort.Float64s(values) return Seq{Provider: Array(values)} }
[ "func", "(", "s", "Seq", ")", "Sort", "(", ")", "Seq", "{", "if", "s", ".", "Len", "(", ")", "==", "0", "{", "return", "s", "\n", "}", "\n", "values", ":=", "s", ".", "Array", "(", ")", "\n", "sort", ".", "Float64s", "(", "values", ")", "\n", "return", "Seq", "{", "Provider", ":", "Array", "(", "values", ")", "}", "\n", "}" ]
// Sort returns the seq sorted in ascending order. // This fully enumerates the seq.
[ "Sort", "returns", "the", "seq", "sorted", "in", "ascending", "order", ".", "This", "fully", "enumerates", "the", "seq", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/seq/seq.go#L147-L154
147,467
wcharczuk/go-chart
seq/seq.go
Median
func (s Seq) Median() (median float64) { l := s.Len() if l == 0 { return } sorted := s.Sort() if l%2 == 0 { v0 := sorted.GetValue(l/2 - 1) v1 := sorted.GetValue(l/2 + 1) median = (v0 + v1) / 2 } else { median = float64(sorted.GetValue(l << 1)) } return }
go
func (s Seq) Median() (median float64) { l := s.Len() if l == 0 { return } sorted := s.Sort() if l%2 == 0 { v0 := sorted.GetValue(l/2 - 1) v1 := sorted.GetValue(l/2 + 1) median = (v0 + v1) / 2 } else { median = float64(sorted.GetValue(l << 1)) } return }
[ "func", "(", "s", "Seq", ")", "Median", "(", ")", "(", "median", "float64", ")", "{", "l", ":=", "s", ".", "Len", "(", ")", "\n", "if", "l", "==", "0", "{", "return", "\n", "}", "\n\n", "sorted", ":=", "s", ".", "Sort", "(", ")", "\n", "if", "l", "%", "2", "==", "0", "{", "v0", ":=", "sorted", ".", "GetValue", "(", "l", "/", "2", "-", "1", ")", "\n", "v1", ":=", "sorted", ".", "GetValue", "(", "l", "/", "2", "+", "1", ")", "\n", "median", "=", "(", "v0", "+", "v1", ")", "/", "2", "\n", "}", "else", "{", "median", "=", "float64", "(", "sorted", ".", "GetValue", "(", "l", "<<", "1", ")", ")", "\n", "}", "\n\n", "return", "\n", "}" ]
// Median returns the median or middle value in the sorted seq.
[ "Median", "returns", "the", "median", "or", "middle", "value", "in", "the", "sorted", "seq", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/seq/seq.go#L157-L173
147,468
wcharczuk/go-chart
seq/seq.go
Sum
func (s Seq) Sum() (accum float64) { if s.Len() == 0 { return 0 } for i := 0; i < s.Len(); i++ { accum += s.GetValue(i) } return }
go
func (s Seq) Sum() (accum float64) { if s.Len() == 0 { return 0 } for i := 0; i < s.Len(); i++ { accum += s.GetValue(i) } return }
[ "func", "(", "s", "Seq", ")", "Sum", "(", ")", "(", "accum", "float64", ")", "{", "if", "s", ".", "Len", "(", ")", "==", "0", "{", "return", "0", "\n", "}", "\n\n", "for", "i", ":=", "0", ";", "i", "<", "s", ".", "Len", "(", ")", ";", "i", "++", "{", "accum", "+=", "s", ".", "GetValue", "(", "i", ")", "\n", "}", "\n", "return", "\n", "}" ]
// Sum adds all the elements of a series together.
[ "Sum", "adds", "all", "the", "elements", "of", "a", "series", "together", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/seq/seq.go#L176-L185
147,469
wcharczuk/go-chart
seq/seq.go
Average
func (s Seq) Average() float64 { if s.Len() == 0 { return 0 } return s.Sum() / float64(s.Len()) }
go
func (s Seq) Average() float64 { if s.Len() == 0 { return 0 } return s.Sum() / float64(s.Len()) }
[ "func", "(", "s", "Seq", ")", "Average", "(", ")", "float64", "{", "if", "s", ".", "Len", "(", ")", "==", "0", "{", "return", "0", "\n", "}", "\n\n", "return", "s", ".", "Sum", "(", ")", "/", "float64", "(", "s", ".", "Len", "(", ")", ")", "\n", "}" ]
// Average returns the float average of the values in the buffer.
[ "Average", "returns", "the", "float", "average", "of", "the", "values", "in", "the", "buffer", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/seq/seq.go#L188-L194
147,470
wcharczuk/go-chart
seq/seq.go
Variance
func (s Seq) Variance() float64 { if s.Len() == 0 { return 0 } m := s.Average() var variance, v float64 for i := 0; i < s.Len(); i++ { v = s.GetValue(i) variance += (v - m) * (v - m) } return variance / float64(s.Len()) }
go
func (s Seq) Variance() float64 { if s.Len() == 0 { return 0 } m := s.Average() var variance, v float64 for i := 0; i < s.Len(); i++ { v = s.GetValue(i) variance += (v - m) * (v - m) } return variance / float64(s.Len()) }
[ "func", "(", "s", "Seq", ")", "Variance", "(", ")", "float64", "{", "if", "s", ".", "Len", "(", ")", "==", "0", "{", "return", "0", "\n", "}", "\n\n", "m", ":=", "s", ".", "Average", "(", ")", "\n", "var", "variance", ",", "v", "float64", "\n", "for", "i", ":=", "0", ";", "i", "<", "s", ".", "Len", "(", ")", ";", "i", "++", "{", "v", "=", "s", ".", "GetValue", "(", "i", ")", "\n", "variance", "+=", "(", "v", "-", "m", ")", "*", "(", "v", "-", "m", ")", "\n", "}", "\n\n", "return", "variance", "/", "float64", "(", "s", ".", "Len", "(", ")", ")", "\n", "}" ]
// Variance computes the variance of the buffer.
[ "Variance", "computes", "the", "variance", "of", "the", "buffer", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/seq/seq.go#L197-L210
147,471
wcharczuk/go-chart
seq/seq.go
StdDev
func (s Seq) StdDev() float64 { if s.Len() == 0 { return 0 } return math.Pow(s.Variance(), 0.5) }
go
func (s Seq) StdDev() float64 { if s.Len() == 0 { return 0 } return math.Pow(s.Variance(), 0.5) }
[ "func", "(", "s", "Seq", ")", "StdDev", "(", ")", "float64", "{", "if", "s", ".", "Len", "(", ")", "==", "0", "{", "return", "0", "\n", "}", "\n\n", "return", "math", ".", "Pow", "(", "s", ".", "Variance", "(", ")", ",", "0.5", ")", "\n", "}" ]
// StdDev returns the standard deviation.
[ "StdDev", "returns", "the", "standard", "deviation", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/seq/seq.go#L213-L219
147,472
wcharczuk/go-chart
seq/seq.go
Percentile
func (s Seq) Percentile(percent float64) (percentile float64) { l := s.Len() if l == 0 { return 0 } if percent < 0 || percent > 1.0 { panic("percent out of range [0.0, 1.0)") } sorted := s.Sort() index := percent * float64(l) if index == float64(int64(index)) { i := f64i(index) ci := sorted.GetValue(i - 1) c := sorted.GetValue(i) percentile = (ci + c) / 2.0 } else { i := f64i(index) percentile = sorted.GetValue(i) } return percentile }
go
func (s Seq) Percentile(percent float64) (percentile float64) { l := s.Len() if l == 0 { return 0 } if percent < 0 || percent > 1.0 { panic("percent out of range [0.0, 1.0)") } sorted := s.Sort() index := percent * float64(l) if index == float64(int64(index)) { i := f64i(index) ci := sorted.GetValue(i - 1) c := sorted.GetValue(i) percentile = (ci + c) / 2.0 } else { i := f64i(index) percentile = sorted.GetValue(i) } return percentile }
[ "func", "(", "s", "Seq", ")", "Percentile", "(", "percent", "float64", ")", "(", "percentile", "float64", ")", "{", "l", ":=", "s", ".", "Len", "(", ")", "\n", "if", "l", "==", "0", "{", "return", "0", "\n", "}", "\n\n", "if", "percent", "<", "0", "||", "percent", ">", "1.0", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n\n", "sorted", ":=", "s", ".", "Sort", "(", ")", "\n", "index", ":=", "percent", "*", "float64", "(", "l", ")", "\n", "if", "index", "==", "float64", "(", "int64", "(", "index", ")", ")", "{", "i", ":=", "f64i", "(", "index", ")", "\n", "ci", ":=", "sorted", ".", "GetValue", "(", "i", "-", "1", ")", "\n", "c", ":=", "sorted", ".", "GetValue", "(", "i", ")", "\n", "percentile", "=", "(", "ci", "+", "c", ")", "/", "2.0", "\n", "}", "else", "{", "i", ":=", "f64i", "(", "index", ")", "\n", "percentile", "=", "sorted", ".", "GetValue", "(", "i", ")", "\n", "}", "\n\n", "return", "percentile", "\n", "}" ]
//Percentile finds the relative standing in a slice of floats. // `percent` should be given on the interval [0,1.0).
[ "Percentile", "finds", "the", "relative", "standing", "in", "a", "slice", "of", "floats", ".", "percent", "should", "be", "given", "on", "the", "interval", "[", "0", "1", ".", "0", ")", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/seq/seq.go#L223-L246
147,473
wcharczuk/go-chart
polynomial_regression_series.go
GetValues
func (prs *PolynomialRegressionSeries) GetValues(index int) (x, y float64) { if prs.InnerSeries == nil || prs.InnerSeries.Len() == 0 { return } if prs.coeffs == nil { coeffs, err := prs.computeCoefficients() if err != nil { panic(err) } prs.coeffs = coeffs } offset := prs.GetOffset() effectiveIndex := util.Math.MinInt(index+offset, prs.InnerSeries.Len()) x, y = prs.InnerSeries.GetValues(effectiveIndex) y = prs.apply(x) return }
go
func (prs *PolynomialRegressionSeries) GetValues(index int) (x, y float64) { if prs.InnerSeries == nil || prs.InnerSeries.Len() == 0 { return } if prs.coeffs == nil { coeffs, err := prs.computeCoefficients() if err != nil { panic(err) } prs.coeffs = coeffs } offset := prs.GetOffset() effectiveIndex := util.Math.MinInt(index+offset, prs.InnerSeries.Len()) x, y = prs.InnerSeries.GetValues(effectiveIndex) y = prs.apply(x) return }
[ "func", "(", "prs", "*", "PolynomialRegressionSeries", ")", "GetValues", "(", "index", "int", ")", "(", "x", ",", "y", "float64", ")", "{", "if", "prs", ".", "InnerSeries", "==", "nil", "||", "prs", ".", "InnerSeries", ".", "Len", "(", ")", "==", "0", "{", "return", "\n", "}", "\n\n", "if", "prs", ".", "coeffs", "==", "nil", "{", "coeffs", ",", "err", ":=", "prs", ".", "computeCoefficients", "(", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "prs", ".", "coeffs", "=", "coeffs", "\n", "}", "\n\n", "offset", ":=", "prs", ".", "GetOffset", "(", ")", "\n", "effectiveIndex", ":=", "util", ".", "Math", ".", "MinInt", "(", "index", "+", "offset", ",", "prs", ".", "InnerSeries", ".", "Len", "(", ")", ")", "\n", "x", ",", "y", "=", "prs", ".", "InnerSeries", ".", "GetValues", "(", "effectiveIndex", ")", "\n", "y", "=", "prs", ".", "apply", "(", "x", ")", "\n", "return", "\n", "}" ]
// GetValues returns the series value for a given index.
[ "GetValues", "returns", "the", "series", "value", "for", "a", "given", "index", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/polynomial_regression_series.go#L91-L109
147,474
wcharczuk/go-chart
polynomial_regression_series.go
GetFirstValues
func (prs *PolynomialRegressionSeries) GetFirstValues() (x, y float64) { if prs.InnerSeries == nil || prs.InnerSeries.Len() == 0 { return } if prs.coeffs == nil { coeffs, err := prs.computeCoefficients() if err != nil { panic(err) } prs.coeffs = coeffs } x, y = prs.InnerSeries.GetValues(0) y = prs.apply(x) return }
go
func (prs *PolynomialRegressionSeries) GetFirstValues() (x, y float64) { if prs.InnerSeries == nil || prs.InnerSeries.Len() == 0 { return } if prs.coeffs == nil { coeffs, err := prs.computeCoefficients() if err != nil { panic(err) } prs.coeffs = coeffs } x, y = prs.InnerSeries.GetValues(0) y = prs.apply(x) return }
[ "func", "(", "prs", "*", "PolynomialRegressionSeries", ")", "GetFirstValues", "(", ")", "(", "x", ",", "y", "float64", ")", "{", "if", "prs", ".", "InnerSeries", "==", "nil", "||", "prs", ".", "InnerSeries", ".", "Len", "(", ")", "==", "0", "{", "return", "\n", "}", "\n", "if", "prs", ".", "coeffs", "==", "nil", "{", "coeffs", ",", "err", ":=", "prs", ".", "computeCoefficients", "(", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "prs", ".", "coeffs", "=", "coeffs", "\n", "}", "\n", "x", ",", "y", "=", "prs", ".", "InnerSeries", ".", "GetValues", "(", "0", ")", "\n", "y", "=", "prs", ".", "apply", "(", "x", ")", "\n", "return", "\n", "}" ]
// GetFirstValues computes the first poly regression value.
[ "GetFirstValues", "computes", "the", "first", "poly", "regression", "value", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/polynomial_regression_series.go#L112-L126
147,475
wcharczuk/go-chart
polynomial_regression_series.go
GetLastValues
func (prs *PolynomialRegressionSeries) GetLastValues() (x, y float64) { if prs.InnerSeries == nil || prs.InnerSeries.Len() == 0 { return } if prs.coeffs == nil { coeffs, err := prs.computeCoefficients() if err != nil { panic(err) } prs.coeffs = coeffs } endIndex := prs.GetEndIndex() x, y = prs.InnerSeries.GetValues(endIndex) y = prs.apply(x) return }
go
func (prs *PolynomialRegressionSeries) GetLastValues() (x, y float64) { if prs.InnerSeries == nil || prs.InnerSeries.Len() == 0 { return } if prs.coeffs == nil { coeffs, err := prs.computeCoefficients() if err != nil { panic(err) } prs.coeffs = coeffs } endIndex := prs.GetEndIndex() x, y = prs.InnerSeries.GetValues(endIndex) y = prs.apply(x) return }
[ "func", "(", "prs", "*", "PolynomialRegressionSeries", ")", "GetLastValues", "(", ")", "(", "x", ",", "y", "float64", ")", "{", "if", "prs", ".", "InnerSeries", "==", "nil", "||", "prs", ".", "InnerSeries", ".", "Len", "(", ")", "==", "0", "{", "return", "\n", "}", "\n", "if", "prs", ".", "coeffs", "==", "nil", "{", "coeffs", ",", "err", ":=", "prs", ".", "computeCoefficients", "(", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "prs", ".", "coeffs", "=", "coeffs", "\n", "}", "\n", "endIndex", ":=", "prs", ".", "GetEndIndex", "(", ")", "\n", "x", ",", "y", "=", "prs", ".", "InnerSeries", ".", "GetValues", "(", "endIndex", ")", "\n", "y", "=", "prs", ".", "apply", "(", "x", ")", "\n", "return", "\n", "}" ]
// GetLastValues computes the last poly regression value.
[ "GetLastValues", "computes", "the", "last", "poly", "regression", "value", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/polynomial_regression_series.go#L129-L144
147,476
wcharczuk/go-chart
jet.go
Jet
func Jet(v, vmin, vmax float64) drawing.Color { c := drawing.Color{R: 0xff, G: 0xff, B: 0xff, A: 0xff} // white var dv float64 if v < vmin { v = vmin } if v > vmax { v = vmax } dv = vmax - vmin if v < (vmin + 0.25*dv) { c.R = 0 c.G = drawing.ColorChannelFromFloat(4 * (v - vmin) / dv) } else if v < (vmin + 0.5*dv) { c.R = 0 c.B = drawing.ColorChannelFromFloat(1 + 4*(vmin+0.25*dv-v)/dv) } else if v < (vmin + 0.75*dv) { c.R = drawing.ColorChannelFromFloat(4 * (v - vmin - 0.5*dv) / dv) c.B = 0 } else { c.G = drawing.ColorChannelFromFloat(1 + 4*(vmin+0.75*dv-v)/dv) c.B = 0 } return c }
go
func Jet(v, vmin, vmax float64) drawing.Color { c := drawing.Color{R: 0xff, G: 0xff, B: 0xff, A: 0xff} // white var dv float64 if v < vmin { v = vmin } if v > vmax { v = vmax } dv = vmax - vmin if v < (vmin + 0.25*dv) { c.R = 0 c.G = drawing.ColorChannelFromFloat(4 * (v - vmin) / dv) } else if v < (vmin + 0.5*dv) { c.R = 0 c.B = drawing.ColorChannelFromFloat(1 + 4*(vmin+0.25*dv-v)/dv) } else if v < (vmin + 0.75*dv) { c.R = drawing.ColorChannelFromFloat(4 * (v - vmin - 0.5*dv) / dv) c.B = 0 } else { c.G = drawing.ColorChannelFromFloat(1 + 4*(vmin+0.75*dv-v)/dv) c.B = 0 } return c }
[ "func", "Jet", "(", "v", ",", "vmin", ",", "vmax", "float64", ")", "drawing", ".", "Color", "{", "c", ":=", "drawing", ".", "Color", "{", "R", ":", "0xff", ",", "G", ":", "0xff", ",", "B", ":", "0xff", ",", "A", ":", "0xff", "}", "// white", "\n", "var", "dv", "float64", "\n\n", "if", "v", "<", "vmin", "{", "v", "=", "vmin", "\n", "}", "\n", "if", "v", ">", "vmax", "{", "v", "=", "vmax", "\n", "}", "\n", "dv", "=", "vmax", "-", "vmin", "\n\n", "if", "v", "<", "(", "vmin", "+", "0.25", "*", "dv", ")", "{", "c", ".", "R", "=", "0", "\n", "c", ".", "G", "=", "drawing", ".", "ColorChannelFromFloat", "(", "4", "*", "(", "v", "-", "vmin", ")", "/", "dv", ")", "\n", "}", "else", "if", "v", "<", "(", "vmin", "+", "0.5", "*", "dv", ")", "{", "c", ".", "R", "=", "0", "\n", "c", ".", "B", "=", "drawing", ".", "ColorChannelFromFloat", "(", "1", "+", "4", "*", "(", "vmin", "+", "0.25", "*", "dv", "-", "v", ")", "/", "dv", ")", "\n", "}", "else", "if", "v", "<", "(", "vmin", "+", "0.75", "*", "dv", ")", "{", "c", ".", "R", "=", "drawing", ".", "ColorChannelFromFloat", "(", "4", "*", "(", "v", "-", "vmin", "-", "0.5", "*", "dv", ")", "/", "dv", ")", "\n", "c", ".", "B", "=", "0", "\n", "}", "else", "{", "c", ".", "G", "=", "drawing", ".", "ColorChannelFromFloat", "(", "1", "+", "4", "*", "(", "vmin", "+", "0.75", "*", "dv", "-", "v", ")", "/", "dv", ")", "\n", "c", ".", "B", "=", "0", "\n", "}", "\n\n", "return", "c", "\n", "}" ]
// Jet is a color map provider based on matlab's jet color map.
[ "Jet", "is", "a", "color", "map", "provider", "based", "on", "matlab", "s", "jet", "color", "map", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/jet.go#L6-L33
147,477
wcharczuk/go-chart
drawing/color.go
ColorFromHex
func ColorFromHex(hex string) Color { var c Color if len(hex) == 3 { c.R = parseHex(string(hex[0])) * 0x11 c.G = parseHex(string(hex[1])) * 0x11 c.B = parseHex(string(hex[2])) * 0x11 } else { c.R = parseHex(string(hex[0:2])) c.G = parseHex(string(hex[2:4])) c.B = parseHex(string(hex[4:6])) } c.A = 255 return c }
go
func ColorFromHex(hex string) Color { var c Color if len(hex) == 3 { c.R = parseHex(string(hex[0])) * 0x11 c.G = parseHex(string(hex[1])) * 0x11 c.B = parseHex(string(hex[2])) * 0x11 } else { c.R = parseHex(string(hex[0:2])) c.G = parseHex(string(hex[2:4])) c.B = parseHex(string(hex[4:6])) } c.A = 255 return c }
[ "func", "ColorFromHex", "(", "hex", "string", ")", "Color", "{", "var", "c", "Color", "\n", "if", "len", "(", "hex", ")", "==", "3", "{", "c", ".", "R", "=", "parseHex", "(", "string", "(", "hex", "[", "0", "]", ")", ")", "*", "0x11", "\n", "c", ".", "G", "=", "parseHex", "(", "string", "(", "hex", "[", "1", "]", ")", ")", "*", "0x11", "\n", "c", ".", "B", "=", "parseHex", "(", "string", "(", "hex", "[", "2", "]", ")", ")", "*", "0x11", "\n", "}", "else", "{", "c", ".", "R", "=", "parseHex", "(", "string", "(", "hex", "[", "0", ":", "2", "]", ")", ")", "\n", "c", ".", "G", "=", "parseHex", "(", "string", "(", "hex", "[", "2", ":", "4", "]", ")", ")", "\n", "c", ".", "B", "=", "parseHex", "(", "string", "(", "hex", "[", "4", ":", "6", "]", ")", ")", "\n", "}", "\n", "c", ".", "A", "=", "255", "\n", "return", "c", "\n", "}" ]
// ColorFromHex returns a color from a css hex code.
[ "ColorFromHex", "returns", "a", "color", "from", "a", "css", "hex", "code", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/color.go#L34-L47
147,478
wcharczuk/go-chart
drawing/color.go
ColorFromAlphaMixedRGBA
func ColorFromAlphaMixedRGBA(r, g, b, a uint32) Color { fa := float64(a) / 255.0 var c Color c.R = uint8(float64(r) / fa) c.G = uint8(float64(g) / fa) c.B = uint8(float64(b) / fa) c.A = uint8(a | (a >> 8)) return c }
go
func ColorFromAlphaMixedRGBA(r, g, b, a uint32) Color { fa := float64(a) / 255.0 var c Color c.R = uint8(float64(r) / fa) c.G = uint8(float64(g) / fa) c.B = uint8(float64(b) / fa) c.A = uint8(a | (a >> 8)) return c }
[ "func", "ColorFromAlphaMixedRGBA", "(", "r", ",", "g", ",", "b", ",", "a", "uint32", ")", "Color", "{", "fa", ":=", "float64", "(", "a", ")", "/", "255.0", "\n", "var", "c", "Color", "\n", "c", ".", "R", "=", "uint8", "(", "float64", "(", "r", ")", "/", "fa", ")", "\n", "c", ".", "G", "=", "uint8", "(", "float64", "(", "g", ")", "/", "fa", ")", "\n", "c", ".", "B", "=", "uint8", "(", "float64", "(", "b", ")", "/", "fa", ")", "\n", "c", ".", "A", "=", "uint8", "(", "a", "|", "(", "a", ">>", "8", ")", ")", "\n", "return", "c", "\n", "}" ]
// ColorFromAlphaMixedRGBA returns the system alpha mixed rgba values.
[ "ColorFromAlphaMixedRGBA", "returns", "the", "system", "alpha", "mixed", "rgba", "values", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/color.go#L50-L58
147,479
wcharczuk/go-chart
drawing/color.go
RGBA
func (c Color) RGBA() (r, g, b, a uint32) { fa := float64(c.A) / 255.0 r = uint32(float64(uint32(c.R)) * fa) r |= r << 8 g = uint32(float64(uint32(c.G)) * fa) g |= g << 8 b = uint32(float64(uint32(c.B)) * fa) b |= b << 8 a = uint32(c.A) a |= a << 8 return }
go
func (c Color) RGBA() (r, g, b, a uint32) { fa := float64(c.A) / 255.0 r = uint32(float64(uint32(c.R)) * fa) r |= r << 8 g = uint32(float64(uint32(c.G)) * fa) g |= g << 8 b = uint32(float64(uint32(c.B)) * fa) b |= b << 8 a = uint32(c.A) a |= a << 8 return }
[ "func", "(", "c", "Color", ")", "RGBA", "(", ")", "(", "r", ",", "g", ",", "b", ",", "a", "uint32", ")", "{", "fa", ":=", "float64", "(", "c", ".", "A", ")", "/", "255.0", "\n", "r", "=", "uint32", "(", "float64", "(", "uint32", "(", "c", ".", "R", ")", ")", "*", "fa", ")", "\n", "r", "|=", "r", "<<", "8", "\n", "g", "=", "uint32", "(", "float64", "(", "uint32", "(", "c", ".", "G", ")", ")", "*", "fa", ")", "\n", "g", "|=", "g", "<<", "8", "\n", "b", "=", "uint32", "(", "float64", "(", "uint32", "(", "c", ".", "B", ")", ")", "*", "fa", ")", "\n", "b", "|=", "b", "<<", "8", "\n", "a", "=", "uint32", "(", "c", ".", "A", ")", "\n", "a", "|=", "a", "<<", "8", "\n", "return", "\n", "}" ]
// RGBA returns the color as a pre-alpha mixed color set.
[ "RGBA", "returns", "the", "color", "as", "a", "pre", "-", "alpha", "mixed", "color", "set", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/color.go#L71-L82
147,480
wcharczuk/go-chart
drawing/color.go
IsZero
func (c Color) IsZero() bool { return c.R == 0 && c.G == 0 && c.B == 0 && c.A == 0 }
go
func (c Color) IsZero() bool { return c.R == 0 && c.G == 0 && c.B == 0 && c.A == 0 }
[ "func", "(", "c", "Color", ")", "IsZero", "(", ")", "bool", "{", "return", "c", ".", "R", "==", "0", "&&", "c", ".", "G", "==", "0", "&&", "c", ".", "B", "==", "0", "&&", "c", ".", "A", "==", "0", "\n", "}" ]
// IsZero returns if the color has been set or not.
[ "IsZero", "returns", "if", "the", "color", "has", "been", "set", "or", "not", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/color.go#L85-L87
147,481
wcharczuk/go-chart
drawing/color.go
WithAlpha
func (c Color) WithAlpha(a uint8) Color { return Color{ R: c.R, G: c.G, B: c.B, A: a, } }
go
func (c Color) WithAlpha(a uint8) Color { return Color{ R: c.R, G: c.G, B: c.B, A: a, } }
[ "func", "(", "c", "Color", ")", "WithAlpha", "(", "a", "uint8", ")", "Color", "{", "return", "Color", "{", "R", ":", "c", ".", "R", ",", "G", ":", "c", ".", "G", ",", "B", ":", "c", ".", "B", ",", "A", ":", "a", ",", "}", "\n", "}" ]
// WithAlpha returns a copy of the color with a given alpha.
[ "WithAlpha", "returns", "a", "copy", "of", "the", "color", "with", "a", "given", "alpha", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/color.go#L95-L102
147,482
wcharczuk/go-chart
drawing/color.go
Equals
func (c Color) Equals(other Color) bool { return c.R == other.R && c.G == other.G && c.B == other.B && c.A == other.A }
go
func (c Color) Equals(other Color) bool { return c.R == other.R && c.G == other.G && c.B == other.B && c.A == other.A }
[ "func", "(", "c", "Color", ")", "Equals", "(", "other", "Color", ")", "bool", "{", "return", "c", ".", "R", "==", "other", ".", "R", "&&", "c", ".", "G", "==", "other", ".", "G", "&&", "c", ".", "B", "==", "other", ".", "B", "&&", "c", ".", "A", "==", "other", ".", "A", "\n", "}" ]
// Equals returns true if the color equals another.
[ "Equals", "returns", "true", "if", "the", "color", "equals", "another", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/color.go#L105-L110
147,483
wcharczuk/go-chart
drawing/color.go
AverageWith
func (c Color) AverageWith(other Color) Color { return Color{ R: (c.R + other.R) >> 1, G: (c.G + other.G) >> 1, B: (c.B + other.B) >> 1, A: c.A, } }
go
func (c Color) AverageWith(other Color) Color { return Color{ R: (c.R + other.R) >> 1, G: (c.G + other.G) >> 1, B: (c.B + other.B) >> 1, A: c.A, } }
[ "func", "(", "c", "Color", ")", "AverageWith", "(", "other", "Color", ")", "Color", "{", "return", "Color", "{", "R", ":", "(", "c", ".", "R", "+", "other", ".", "R", ")", ">>", "1", ",", "G", ":", "(", "c", ".", "G", "+", "other", ".", "G", ")", ">>", "1", ",", "B", ":", "(", "c", ".", "B", "+", "other", ".", "B", ")", ">>", "1", ",", "A", ":", "c", ".", "A", ",", "}", "\n", "}" ]
// AverageWith averages two colors.
[ "AverageWith", "averages", "two", "colors", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/color.go#L113-L120
147,484
wcharczuk/go-chart
drawing/color.go
String
func (c Color) String() string { fa := float64(c.A) / float64(255) return fmt.Sprintf("rgba(%v,%v,%v,%.1f)", c.R, c.G, c.B, fa) }
go
func (c Color) String() string { fa := float64(c.A) / float64(255) return fmt.Sprintf("rgba(%v,%v,%v,%.1f)", c.R, c.G, c.B, fa) }
[ "func", "(", "c", "Color", ")", "String", "(", ")", "string", "{", "fa", ":=", "float64", "(", "c", ".", "A", ")", "/", "float64", "(", "255", ")", "\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "c", ".", "R", ",", "c", ".", "G", ",", "c", ".", "B", ",", "fa", ")", "\n", "}" ]
// String returns a css string representation of the color.
[ "String", "returns", "a", "css", "string", "representation", "of", "the", "color", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/color.go#L123-L126
147,485
wcharczuk/go-chart
annotation_series.go
Measure
func (as AnnotationSeries) Measure(r Renderer, canvasBox Box, xrange, yrange Range, defaults Style) Box { box := Box{ Top: math.MaxInt32, Left: math.MaxInt32, Right: 0, Bottom: 0, } if as.Style.IsZero() || as.Style.Show { seriesStyle := as.Style.InheritFrom(as.annotationStyleDefaults(defaults)) for _, a := range as.Annotations { style := a.Style.InheritFrom(seriesStyle) lx := canvasBox.Left + xrange.Translate(a.XValue) ly := canvasBox.Bottom - yrange.Translate(a.YValue) ab := Draw.MeasureAnnotation(r, canvasBox, style, lx, ly, a.Label) box.Top = util.Math.MinInt(box.Top, ab.Top) box.Left = util.Math.MinInt(box.Left, ab.Left) box.Right = util.Math.MaxInt(box.Right, ab.Right) box.Bottom = util.Math.MaxInt(box.Bottom, ab.Bottom) } } return box }
go
func (as AnnotationSeries) Measure(r Renderer, canvasBox Box, xrange, yrange Range, defaults Style) Box { box := Box{ Top: math.MaxInt32, Left: math.MaxInt32, Right: 0, Bottom: 0, } if as.Style.IsZero() || as.Style.Show { seriesStyle := as.Style.InheritFrom(as.annotationStyleDefaults(defaults)) for _, a := range as.Annotations { style := a.Style.InheritFrom(seriesStyle) lx := canvasBox.Left + xrange.Translate(a.XValue) ly := canvasBox.Bottom - yrange.Translate(a.YValue) ab := Draw.MeasureAnnotation(r, canvasBox, style, lx, ly, a.Label) box.Top = util.Math.MinInt(box.Top, ab.Top) box.Left = util.Math.MinInt(box.Left, ab.Left) box.Right = util.Math.MaxInt(box.Right, ab.Right) box.Bottom = util.Math.MaxInt(box.Bottom, ab.Bottom) } } return box }
[ "func", "(", "as", "AnnotationSeries", ")", "Measure", "(", "r", "Renderer", ",", "canvasBox", "Box", ",", "xrange", ",", "yrange", "Range", ",", "defaults", "Style", ")", "Box", "{", "box", ":=", "Box", "{", "Top", ":", "math", ".", "MaxInt32", ",", "Left", ":", "math", ".", "MaxInt32", ",", "Right", ":", "0", ",", "Bottom", ":", "0", ",", "}", "\n", "if", "as", ".", "Style", ".", "IsZero", "(", ")", "||", "as", ".", "Style", ".", "Show", "{", "seriesStyle", ":=", "as", ".", "Style", ".", "InheritFrom", "(", "as", ".", "annotationStyleDefaults", "(", "defaults", ")", ")", "\n", "for", "_", ",", "a", ":=", "range", "as", ".", "Annotations", "{", "style", ":=", "a", ".", "Style", ".", "InheritFrom", "(", "seriesStyle", ")", "\n", "lx", ":=", "canvasBox", ".", "Left", "+", "xrange", ".", "Translate", "(", "a", ".", "XValue", ")", "\n", "ly", ":=", "canvasBox", ".", "Bottom", "-", "yrange", ".", "Translate", "(", "a", ".", "YValue", ")", "\n", "ab", ":=", "Draw", ".", "MeasureAnnotation", "(", "r", ",", "canvasBox", ",", "style", ",", "lx", ",", "ly", ",", "a", ".", "Label", ")", "\n", "box", ".", "Top", "=", "util", ".", "Math", ".", "MinInt", "(", "box", ".", "Top", ",", "ab", ".", "Top", ")", "\n", "box", ".", "Left", "=", "util", ".", "Math", ".", "MinInt", "(", "box", ".", "Left", ",", "ab", ".", "Left", ")", "\n", "box", ".", "Right", "=", "util", ".", "Math", ".", "MaxInt", "(", "box", ".", "Right", ",", "ab", ".", "Right", ")", "\n", "box", ".", "Bottom", "=", "util", ".", "Math", ".", "MaxInt", "(", "box", ".", "Bottom", ",", "ab", ".", "Bottom", ")", "\n", "}", "\n", "}", "\n", "return", "box", "\n", "}" ]
// Measure returns a bounds box of the series.
[ "Measure", "returns", "a", "bounds", "box", "of", "the", "series", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/annotation_series.go#L51-L72
147,486
wcharczuk/go-chart
annotation_series.go
Render
func (as AnnotationSeries) Render(r Renderer, canvasBox Box, xrange, yrange Range, defaults Style) { if as.Style.IsZero() || as.Style.Show { seriesStyle := as.Style.InheritFrom(as.annotationStyleDefaults(defaults)) for _, a := range as.Annotations { style := a.Style.InheritFrom(seriesStyle) lx := canvasBox.Left + xrange.Translate(a.XValue) ly := canvasBox.Bottom - yrange.Translate(a.YValue) Draw.Annotation(r, canvasBox, style, lx, ly, a.Label) } } }
go
func (as AnnotationSeries) Render(r Renderer, canvasBox Box, xrange, yrange Range, defaults Style) { if as.Style.IsZero() || as.Style.Show { seriesStyle := as.Style.InheritFrom(as.annotationStyleDefaults(defaults)) for _, a := range as.Annotations { style := a.Style.InheritFrom(seriesStyle) lx := canvasBox.Left + xrange.Translate(a.XValue) ly := canvasBox.Bottom - yrange.Translate(a.YValue) Draw.Annotation(r, canvasBox, style, lx, ly, a.Label) } } }
[ "func", "(", "as", "AnnotationSeries", ")", "Render", "(", "r", "Renderer", ",", "canvasBox", "Box", ",", "xrange", ",", "yrange", "Range", ",", "defaults", "Style", ")", "{", "if", "as", ".", "Style", ".", "IsZero", "(", ")", "||", "as", ".", "Style", ".", "Show", "{", "seriesStyle", ":=", "as", ".", "Style", ".", "InheritFrom", "(", "as", ".", "annotationStyleDefaults", "(", "defaults", ")", ")", "\n", "for", "_", ",", "a", ":=", "range", "as", ".", "Annotations", "{", "style", ":=", "a", ".", "Style", ".", "InheritFrom", "(", "seriesStyle", ")", "\n", "lx", ":=", "canvasBox", ".", "Left", "+", "xrange", ".", "Translate", "(", "a", ".", "XValue", ")", "\n", "ly", ":=", "canvasBox", ".", "Bottom", "-", "yrange", ".", "Translate", "(", "a", ".", "YValue", ")", "\n", "Draw", ".", "Annotation", "(", "r", ",", "canvasBox", ",", "style", ",", "lx", ",", "ly", ",", "a", ".", "Label", ")", "\n", "}", "\n", "}", "\n", "}" ]
// Render draws the series.
[ "Render", "draws", "the", "series", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/annotation_series.go#L75-L85
147,487
wcharczuk/go-chart
drawing/line.go
PolylineBresenham
func PolylineBresenham(img draw.Image, c color.Color, s ...float64) { for i := 2; i < len(s); i += 2 { Bresenham(img, c, int(s[i-2]+0.5), int(s[i-1]+0.5), int(s[i]+0.5), int(s[i+1]+0.5)) } }
go
func PolylineBresenham(img draw.Image, c color.Color, s ...float64) { for i := 2; i < len(s); i += 2 { Bresenham(img, c, int(s[i-2]+0.5), int(s[i-1]+0.5), int(s[i]+0.5), int(s[i+1]+0.5)) } }
[ "func", "PolylineBresenham", "(", "img", "draw", ".", "Image", ",", "c", "color", ".", "Color", ",", "s", "...", "float64", ")", "{", "for", "i", ":=", "2", ";", "i", "<", "len", "(", "s", ")", ";", "i", "+=", "2", "{", "Bresenham", "(", "img", ",", "c", ",", "int", "(", "s", "[", "i", "-", "2", "]", "+", "0.5", ")", ",", "int", "(", "s", "[", "i", "-", "1", "]", "+", "0.5", ")", ",", "int", "(", "s", "[", "i", "]", "+", "0.5", ")", ",", "int", "(", "s", "[", "i", "+", "1", "]", "+", "0.5", ")", ")", "\n", "}", "\n", "}" ]
// PolylineBresenham draws a polyline to an image
[ "PolylineBresenham", "draws", "a", "polyline", "to", "an", "image" ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/line.go#L9-L13
147,488
wcharczuk/go-chart
drawing/matrix.go
Transform
func (tr Matrix) Transform(points []float64) { for i, j := 0, 1; j < len(points); i, j = i+2, j+2 { x := points[i] y := points[j] points[i] = x*tr[0] + y*tr[2] + tr[4] points[j] = x*tr[1] + y*tr[3] + tr[5] } }
go
func (tr Matrix) Transform(points []float64) { for i, j := 0, 1; j < len(points); i, j = i+2, j+2 { x := points[i] y := points[j] points[i] = x*tr[0] + y*tr[2] + tr[4] points[j] = x*tr[1] + y*tr[3] + tr[5] } }
[ "func", "(", "tr", "Matrix", ")", "Transform", "(", "points", "[", "]", "float64", ")", "{", "for", "i", ",", "j", ":=", "0", ",", "1", ";", "j", "<", "len", "(", "points", ")", ";", "i", ",", "j", "=", "i", "+", "2", ",", "j", "+", "2", "{", "x", ":=", "points", "[", "i", "]", "\n", "y", ":=", "points", "[", "j", "]", "\n", "points", "[", "i", "]", "=", "x", "*", "tr", "[", "0", "]", "+", "y", "*", "tr", "[", "2", "]", "+", "tr", "[", "4", "]", "\n", "points", "[", "j", "]", "=", "x", "*", "tr", "[", "1", "]", "+", "y", "*", "tr", "[", "3", "]", "+", "tr", "[", "5", "]", "\n", "}", "\n", "}" ]
// Transform applies the transformation matrix to points. It modify the points passed in parameter.
[ "Transform", "applies", "the", "transformation", "matrix", "to", "points", ".", "It", "modify", "the", "points", "passed", "in", "parameter", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/matrix.go#L20-L27
147,489
wcharczuk/go-chart
drawing/matrix.go
TransformPoint
func (tr Matrix) TransformPoint(x, y float64) (xres, yres float64) { xres = x*tr[0] + y*tr[2] + tr[4] yres = x*tr[1] + y*tr[3] + tr[5] return xres, yres }
go
func (tr Matrix) TransformPoint(x, y float64) (xres, yres float64) { xres = x*tr[0] + y*tr[2] + tr[4] yres = x*tr[1] + y*tr[3] + tr[5] return xres, yres }
[ "func", "(", "tr", "Matrix", ")", "TransformPoint", "(", "x", ",", "y", "float64", ")", "(", "xres", ",", "yres", "float64", ")", "{", "xres", "=", "x", "*", "tr", "[", "0", "]", "+", "y", "*", "tr", "[", "2", "]", "+", "tr", "[", "4", "]", "\n", "yres", "=", "x", "*", "tr", "[", "1", "]", "+", "y", "*", "tr", "[", "3", "]", "+", "tr", "[", "5", "]", "\n", "return", "xres", ",", "yres", "\n", "}" ]
// TransformPoint applies the transformation matrix to point. It returns the point the transformed point.
[ "TransformPoint", "applies", "the", "transformation", "matrix", "to", "point", ".", "It", "returns", "the", "point", "the", "transformed", "point", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/matrix.go#L30-L34
147,490
wcharczuk/go-chart
drawing/matrix.go
TransformRectangle
func (tr Matrix) TransformRectangle(x0, y0, x2, y2 float64) (nx0, ny0, nx2, ny2 float64) { points := []float64{x0, y0, x2, y0, x2, y2, x0, y2} tr.Transform(points) points[0], points[2] = minMax(points[0], points[2]) points[4], points[6] = minMax(points[4], points[6]) points[1], points[3] = minMax(points[1], points[3]) points[5], points[7] = minMax(points[5], points[7]) nx0 = math.Min(points[0], points[4]) ny0 = math.Min(points[1], points[5]) nx2 = math.Max(points[2], points[6]) ny2 = math.Max(points[3], points[7]) return nx0, ny0, nx2, ny2 }
go
func (tr Matrix) TransformRectangle(x0, y0, x2, y2 float64) (nx0, ny0, nx2, ny2 float64) { points := []float64{x0, y0, x2, y0, x2, y2, x0, y2} tr.Transform(points) points[0], points[2] = minMax(points[0], points[2]) points[4], points[6] = minMax(points[4], points[6]) points[1], points[3] = minMax(points[1], points[3]) points[5], points[7] = minMax(points[5], points[7]) nx0 = math.Min(points[0], points[4]) ny0 = math.Min(points[1], points[5]) nx2 = math.Max(points[2], points[6]) ny2 = math.Max(points[3], points[7]) return nx0, ny0, nx2, ny2 }
[ "func", "(", "tr", "Matrix", ")", "TransformRectangle", "(", "x0", ",", "y0", ",", "x2", ",", "y2", "float64", ")", "(", "nx0", ",", "ny0", ",", "nx2", ",", "ny2", "float64", ")", "{", "points", ":=", "[", "]", "float64", "{", "x0", ",", "y0", ",", "x2", ",", "y0", ",", "x2", ",", "y2", ",", "x0", ",", "y2", "}", "\n", "tr", ".", "Transform", "(", "points", ")", "\n", "points", "[", "0", "]", ",", "points", "[", "2", "]", "=", "minMax", "(", "points", "[", "0", "]", ",", "points", "[", "2", "]", ")", "\n", "points", "[", "4", "]", ",", "points", "[", "6", "]", "=", "minMax", "(", "points", "[", "4", "]", ",", "points", "[", "6", "]", ")", "\n", "points", "[", "1", "]", ",", "points", "[", "3", "]", "=", "minMax", "(", "points", "[", "1", "]", ",", "points", "[", "3", "]", ")", "\n", "points", "[", "5", "]", ",", "points", "[", "7", "]", "=", "minMax", "(", "points", "[", "5", "]", ",", "points", "[", "7", "]", ")", "\n\n", "nx0", "=", "math", ".", "Min", "(", "points", "[", "0", "]", ",", "points", "[", "4", "]", ")", "\n", "ny0", "=", "math", ".", "Min", "(", "points", "[", "1", "]", ",", "points", "[", "5", "]", ")", "\n", "nx2", "=", "math", ".", "Max", "(", "points", "[", "2", "]", ",", "points", "[", "6", "]", ")", "\n", "ny2", "=", "math", ".", "Max", "(", "points", "[", "3", "]", ",", "points", "[", "7", "]", ")", "\n", "return", "nx0", ",", "ny0", ",", "nx2", ",", "ny2", "\n", "}" ]
// TransformRectangle applies the transformation matrix to the rectangle represented by the min and the max point of the rectangle
[ "TransformRectangle", "applies", "the", "transformation", "matrix", "to", "the", "rectangle", "represented", "by", "the", "min", "and", "the", "max", "point", "of", "the", "rectangle" ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/matrix.go#L44-L57
147,491
wcharczuk/go-chart
drawing/matrix.go
InverseTransform
func (tr Matrix) InverseTransform(points []float64) { d := tr.Determinant() // matrix determinant for i, j := 0, 1; j < len(points); i, j = i+2, j+2 { x := points[i] y := points[j] points[i] = ((x-tr[4])*tr[3] - (y-tr[5])*tr[2]) / d points[j] = ((y-tr[5])*tr[0] - (x-tr[4])*tr[1]) / d } }
go
func (tr Matrix) InverseTransform(points []float64) { d := tr.Determinant() // matrix determinant for i, j := 0, 1; j < len(points); i, j = i+2, j+2 { x := points[i] y := points[j] points[i] = ((x-tr[4])*tr[3] - (y-tr[5])*tr[2]) / d points[j] = ((y-tr[5])*tr[0] - (x-tr[4])*tr[1]) / d } }
[ "func", "(", "tr", "Matrix", ")", "InverseTransform", "(", "points", "[", "]", "float64", ")", "{", "d", ":=", "tr", ".", "Determinant", "(", ")", "// matrix determinant", "\n", "for", "i", ",", "j", ":=", "0", ",", "1", ";", "j", "<", "len", "(", "points", ")", ";", "i", ",", "j", "=", "i", "+", "2", ",", "j", "+", "2", "{", "x", ":=", "points", "[", "i", "]", "\n", "y", ":=", "points", "[", "j", "]", "\n", "points", "[", "i", "]", "=", "(", "(", "x", "-", "tr", "[", "4", "]", ")", "*", "tr", "[", "3", "]", "-", "(", "y", "-", "tr", "[", "5", "]", ")", "*", "tr", "[", "2", "]", ")", "/", "d", "\n", "points", "[", "j", "]", "=", "(", "(", "y", "-", "tr", "[", "5", "]", ")", "*", "tr", "[", "0", "]", "-", "(", "x", "-", "tr", "[", "4", "]", ")", "*", "tr", "[", "1", "]", ")", "/", "d", "\n", "}", "\n", "}" ]
// InverseTransform applies the transformation inverse matrix to the rectangle represented by the min and the max point of the rectangle
[ "InverseTransform", "applies", "the", "transformation", "inverse", "matrix", "to", "the", "rectangle", "represented", "by", "the", "min", "and", "the", "max", "point", "of", "the", "rectangle" ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/matrix.go#L60-L68
147,492
wcharczuk/go-chart
drawing/matrix.go
InverseTransformPoint
func (tr Matrix) InverseTransformPoint(x, y float64) (xres, yres float64) { d := tr.Determinant() // matrix determinant xres = ((x-tr[4])*tr[3] - (y-tr[5])*tr[2]) / d yres = ((y-tr[5])*tr[0] - (x-tr[4])*tr[1]) / d return xres, yres }
go
func (tr Matrix) InverseTransformPoint(x, y float64) (xres, yres float64) { d := tr.Determinant() // matrix determinant xres = ((x-tr[4])*tr[3] - (y-tr[5])*tr[2]) / d yres = ((y-tr[5])*tr[0] - (x-tr[4])*tr[1]) / d return xres, yres }
[ "func", "(", "tr", "Matrix", ")", "InverseTransformPoint", "(", "x", ",", "y", "float64", ")", "(", "xres", ",", "yres", "float64", ")", "{", "d", ":=", "tr", ".", "Determinant", "(", ")", "// matrix determinant", "\n", "xres", "=", "(", "(", "x", "-", "tr", "[", "4", "]", ")", "*", "tr", "[", "3", "]", "-", "(", "y", "-", "tr", "[", "5", "]", ")", "*", "tr", "[", "2", "]", ")", "/", "d", "\n", "yres", "=", "(", "(", "y", "-", "tr", "[", "5", "]", ")", "*", "tr", "[", "0", "]", "-", "(", "x", "-", "tr", "[", "4", "]", ")", "*", "tr", "[", "1", "]", ")", "/", "d", "\n", "return", "xres", ",", "yres", "\n", "}" ]
// InverseTransformPoint applies the transformation inverse matrix to point. It returns the point the transformed point.
[ "InverseTransformPoint", "applies", "the", "transformation", "inverse", "matrix", "to", "point", ".", "It", "returns", "the", "point", "the", "transformed", "point", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/matrix.go#L71-L76
147,493
wcharczuk/go-chart
drawing/matrix.go
NewRotationMatrix
func NewRotationMatrix(angle float64) Matrix { c := math.Cos(angle) s := math.Sin(angle) return Matrix{c, s, -s, c, 0, 0} }
go
func NewRotationMatrix(angle float64) Matrix { c := math.Cos(angle) s := math.Sin(angle) return Matrix{c, s, -s, c, 0, 0} }
[ "func", "NewRotationMatrix", "(", "angle", "float64", ")", "Matrix", "{", "c", ":=", "math", ".", "Cos", "(", "angle", ")", "\n", "s", ":=", "math", ".", "Sin", "(", "angle", ")", "\n", "return", "Matrix", "{", "c", ",", "s", ",", "-", "s", ",", "c", ",", "0", ",", "0", "}", "\n", "}" ]
// NewRotationMatrix creates a rotation transformation matrix. angle is in radian
[ "NewRotationMatrix", "creates", "a", "rotation", "transformation", "matrix", ".", "angle", "is", "in", "radian" ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/matrix.go#L105-L109
147,494
wcharczuk/go-chart
drawing/matrix.go
NewMatrixFromRects
func NewMatrixFromRects(rectangle1, rectangle2 [4]float64) Matrix { xScale := (rectangle2[2] - rectangle2[0]) / (rectangle1[2] - rectangle1[0]) yScale := (rectangle2[3] - rectangle2[1]) / (rectangle1[3] - rectangle1[1]) xOffset := rectangle2[0] - (rectangle1[0] * xScale) yOffset := rectangle2[1] - (rectangle1[1] * yScale) return Matrix{xScale, 0, 0, yScale, xOffset, yOffset} }
go
func NewMatrixFromRects(rectangle1, rectangle2 [4]float64) Matrix { xScale := (rectangle2[2] - rectangle2[0]) / (rectangle1[2] - rectangle1[0]) yScale := (rectangle2[3] - rectangle2[1]) / (rectangle1[3] - rectangle1[1]) xOffset := rectangle2[0] - (rectangle1[0] * xScale) yOffset := rectangle2[1] - (rectangle1[1] * yScale) return Matrix{xScale, 0, 0, yScale, xOffset, yOffset} }
[ "func", "NewMatrixFromRects", "(", "rectangle1", ",", "rectangle2", "[", "4", "]", "float64", ")", "Matrix", "{", "xScale", ":=", "(", "rectangle2", "[", "2", "]", "-", "rectangle2", "[", "0", "]", ")", "/", "(", "rectangle1", "[", "2", "]", "-", "rectangle1", "[", "0", "]", ")", "\n", "yScale", ":=", "(", "rectangle2", "[", "3", "]", "-", "rectangle2", "[", "1", "]", ")", "/", "(", "rectangle1", "[", "3", "]", "-", "rectangle1", "[", "1", "]", ")", "\n", "xOffset", ":=", "rectangle2", "[", "0", "]", "-", "(", "rectangle1", "[", "0", "]", "*", "xScale", ")", "\n", "yOffset", ":=", "rectangle2", "[", "1", "]", "-", "(", "rectangle1", "[", "1", "]", "*", "yScale", ")", "\n", "return", "Matrix", "{", "xScale", ",", "0", ",", "0", ",", "yScale", ",", "xOffset", ",", "yOffset", "}", "\n", "}" ]
// NewMatrixFromRects creates a transformation matrix, combining a scale and a translation, that transform rectangle1 into rectangle2.
[ "NewMatrixFromRects", "creates", "a", "transformation", "matrix", "combining", "a", "scale", "and", "a", "translation", "that", "transform", "rectangle1", "into", "rectangle2", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/matrix.go#L112-L118
147,495
wcharczuk/go-chart
drawing/matrix.go
Inverse
func (tr *Matrix) Inverse() { d := tr.Determinant() // matrix determinant tr0, tr1, tr2, tr3, tr4, tr5 := tr[0], tr[1], tr[2], tr[3], tr[4], tr[5] tr[0] = tr3 / d tr[1] = -tr1 / d tr[2] = -tr2 / d tr[3] = tr0 / d tr[4] = (tr2*tr5 - tr3*tr4) / d tr[5] = (tr1*tr4 - tr0*tr5) / d }
go
func (tr *Matrix) Inverse() { d := tr.Determinant() // matrix determinant tr0, tr1, tr2, tr3, tr4, tr5 := tr[0], tr[1], tr[2], tr[3], tr[4], tr[5] tr[0] = tr3 / d tr[1] = -tr1 / d tr[2] = -tr2 / d tr[3] = tr0 / d tr[4] = (tr2*tr5 - tr3*tr4) / d tr[5] = (tr1*tr4 - tr0*tr5) / d }
[ "func", "(", "tr", "*", "Matrix", ")", "Inverse", "(", ")", "{", "d", ":=", "tr", ".", "Determinant", "(", ")", "// matrix determinant", "\n", "tr0", ",", "tr1", ",", "tr2", ",", "tr3", ",", "tr4", ",", "tr5", ":=", "tr", "[", "0", "]", ",", "tr", "[", "1", "]", ",", "tr", "[", "2", "]", ",", "tr", "[", "3", "]", ",", "tr", "[", "4", "]", ",", "tr", "[", "5", "]", "\n", "tr", "[", "0", "]", "=", "tr3", "/", "d", "\n", "tr", "[", "1", "]", "=", "-", "tr1", "/", "d", "\n", "tr", "[", "2", "]", "=", "-", "tr2", "/", "d", "\n", "tr", "[", "3", "]", "=", "tr0", "/", "d", "\n", "tr", "[", "4", "]", "=", "(", "tr2", "*", "tr5", "-", "tr3", "*", "tr4", ")", "/", "d", "\n", "tr", "[", "5", "]", "=", "(", "tr1", "*", "tr4", "-", "tr0", "*", "tr5", ")", "/", "d", "\n", "}" ]
// Inverse computes the inverse matrix
[ "Inverse", "computes", "the", "inverse", "matrix" ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/matrix.go#L121-L130
147,496
wcharczuk/go-chart
drawing/matrix.go
Copy
func (tr Matrix) Copy() Matrix { var result Matrix copy(result[:], tr[:]) return result }
go
func (tr Matrix) Copy() Matrix { var result Matrix copy(result[:], tr[:]) return result }
[ "func", "(", "tr", "Matrix", ")", "Copy", "(", ")", "Matrix", "{", "var", "result", "Matrix", "\n", "copy", "(", "result", "[", ":", "]", ",", "tr", "[", ":", "]", ")", "\n", "return", "result", "\n", "}" ]
// Copy copies the matrix.
[ "Copy", "copies", "the", "matrix", "." ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/matrix.go#L133-L137
147,497
wcharczuk/go-chart
drawing/matrix.go
Compose
func (tr *Matrix) Compose(trToCompose Matrix) { tr0, tr1, tr2, tr3, tr4, tr5 := tr[0], tr[1], tr[2], tr[3], tr[4], tr[5] tr[0] = trToCompose[0]*tr0 + trToCompose[1]*tr2 tr[1] = trToCompose[1]*tr3 + trToCompose[0]*tr1 tr[2] = trToCompose[2]*tr0 + trToCompose[3]*tr2 tr[3] = trToCompose[3]*tr3 + trToCompose[2]*tr1 tr[4] = trToCompose[4]*tr0 + trToCompose[5]*tr2 + tr4 tr[5] = trToCompose[5]*tr3 + trToCompose[4]*tr1 + tr5 }
go
func (tr *Matrix) Compose(trToCompose Matrix) { tr0, tr1, tr2, tr3, tr4, tr5 := tr[0], tr[1], tr[2], tr[3], tr[4], tr[5] tr[0] = trToCompose[0]*tr0 + trToCompose[1]*tr2 tr[1] = trToCompose[1]*tr3 + trToCompose[0]*tr1 tr[2] = trToCompose[2]*tr0 + trToCompose[3]*tr2 tr[3] = trToCompose[3]*tr3 + trToCompose[2]*tr1 tr[4] = trToCompose[4]*tr0 + trToCompose[5]*tr2 + tr4 tr[5] = trToCompose[5]*tr3 + trToCompose[4]*tr1 + tr5 }
[ "func", "(", "tr", "*", "Matrix", ")", "Compose", "(", "trToCompose", "Matrix", ")", "{", "tr0", ",", "tr1", ",", "tr2", ",", "tr3", ",", "tr4", ",", "tr5", ":=", "tr", "[", "0", "]", ",", "tr", "[", "1", "]", ",", "tr", "[", "2", "]", ",", "tr", "[", "3", "]", ",", "tr", "[", "4", "]", ",", "tr", "[", "5", "]", "\n", "tr", "[", "0", "]", "=", "trToCompose", "[", "0", "]", "*", "tr0", "+", "trToCompose", "[", "1", "]", "*", "tr2", "\n", "tr", "[", "1", "]", "=", "trToCompose", "[", "1", "]", "*", "tr3", "+", "trToCompose", "[", "0", "]", "*", "tr1", "\n", "tr", "[", "2", "]", "=", "trToCompose", "[", "2", "]", "*", "tr0", "+", "trToCompose", "[", "3", "]", "*", "tr2", "\n", "tr", "[", "3", "]", "=", "trToCompose", "[", "3", "]", "*", "tr3", "+", "trToCompose", "[", "2", "]", "*", "tr1", "\n", "tr", "[", "4", "]", "=", "trToCompose", "[", "4", "]", "*", "tr0", "+", "trToCompose", "[", "5", "]", "*", "tr2", "+", "tr4", "\n", "tr", "[", "5", "]", "=", "trToCompose", "[", "5", "]", "*", "tr3", "+", "trToCompose", "[", "4", "]", "*", "tr1", "+", "tr5", "\n", "}" ]
// Compose multiplies trToConcat x tr
[ "Compose", "multiplies", "trToConcat", "x", "tr" ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/matrix.go#L140-L148
147,498
wcharczuk/go-chart
drawing/matrix.go
Scale
func (tr *Matrix) Scale(sx, sy float64) { tr[0] = sx * tr[0] tr[1] = sx * tr[1] tr[2] = sy * tr[2] tr[3] = sy * tr[3] }
go
func (tr *Matrix) Scale(sx, sy float64) { tr[0] = sx * tr[0] tr[1] = sx * tr[1] tr[2] = sy * tr[2] tr[3] = sy * tr[3] }
[ "func", "(", "tr", "*", "Matrix", ")", "Scale", "(", "sx", ",", "sy", "float64", ")", "{", "tr", "[", "0", "]", "=", "sx", "*", "tr", "[", "0", "]", "\n", "tr", "[", "1", "]", "=", "sx", "*", "tr", "[", "1", "]", "\n", "tr", "[", "2", "]", "=", "sy", "*", "tr", "[", "2", "]", "\n", "tr", "[", "3", "]", "=", "sy", "*", "tr", "[", "3", "]", "\n", "}" ]
// Scale adds a scale to the matrix
[ "Scale", "adds", "a", "scale", "to", "the", "matrix" ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/matrix.go#L151-L156
147,499
wcharczuk/go-chart
drawing/matrix.go
Translate
func (tr *Matrix) Translate(tx, ty float64) { tr[4] = tx*tr[0] + ty*tr[2] + tr[4] tr[5] = ty*tr[3] + tx*tr[1] + tr[5] }
go
func (tr *Matrix) Translate(tx, ty float64) { tr[4] = tx*tr[0] + ty*tr[2] + tr[4] tr[5] = ty*tr[3] + tx*tr[1] + tr[5] }
[ "func", "(", "tr", "*", "Matrix", ")", "Translate", "(", "tx", ",", "ty", "float64", ")", "{", "tr", "[", "4", "]", "=", "tx", "*", "tr", "[", "0", "]", "+", "ty", "*", "tr", "[", "2", "]", "+", "tr", "[", "4", "]", "\n", "tr", "[", "5", "]", "=", "ty", "*", "tr", "[", "3", "]", "+", "tx", "*", "tr", "[", "1", "]", "+", "tr", "[", "5", "]", "\n", "}" ]
// Translate adds a translation to the matrix
[ "Translate", "adds", "a", "translation", "to", "the", "matrix" ]
9852fce5a172598e72d16f4306f0f17a53d94eb4
https://github.com/wcharczuk/go-chart/blob/9852fce5a172598e72d16f4306f0f17a53d94eb4/drawing/matrix.go#L159-L162