tweaks
This commit is contained in:
parent
2c9a9218e5
commit
046daf94fb
6 changed files with 13 additions and 8 deletions
|
@ -23,7 +23,7 @@ func parseFloat64(str string) float64 {
|
||||||
func readData() ([]time.Time, []float64) {
|
func readData() ([]time.Time, []float64) {
|
||||||
var xvalues []time.Time
|
var xvalues []time.Time
|
||||||
var yvalues []float64
|
var yvalues []float64
|
||||||
chart.File.ReadByLines("requests.csv", func(line string) {
|
err := chart.File.ReadByLines("requests.csv", func(line string) {
|
||||||
parts := strings.Split(line, ",")
|
parts := strings.Split(line, ",")
|
||||||
year := parseInt(parts[0])
|
year := parseInt(parts[0])
|
||||||
month := parseInt(parts[1])
|
month := parseInt(parts[1])
|
||||||
|
@ -33,6 +33,9 @@ func readData() ([]time.Time, []float64) {
|
||||||
xvalues = append(xvalues, time.Date(year, time.Month(month), day, hour, 0, 0, 0, time.UTC))
|
xvalues = append(xvalues, time.Date(year, time.Month(month), day, hour, 0, 0, 0, time.UTC))
|
||||||
yvalues = append(yvalues, elapsedMillis)
|
yvalues = append(yvalues, elapsedMillis)
|
||||||
})
|
})
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err.Error())
|
||||||
|
}
|
||||||
return xvalues, yvalues
|
return xvalues, yvalues
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/wcharczuk/go-chart"
|
"github.com/wcharczuk/go-chart"
|
||||||
"github.com/wcharczuk/go-chart/drawing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func drawChart(res http.ResponseWriter, req *http.Request) {
|
func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||||
|
@ -17,7 +16,6 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||||
Show: true,
|
Show: true,
|
||||||
StrokeWidth: chart.Disabled,
|
StrokeWidth: chart.Disabled,
|
||||||
DotWidth: 3,
|
DotWidth: 3,
|
||||||
DotColor: drawing.ColorRed,
|
|
||||||
},
|
},
|
||||||
XValues: chart.Sequence.Random(32, 1024),
|
XValues: chart.Sequence.Random(32, 1024),
|
||||||
YValues: chart.Sequence.Random(32, 1024),
|
YValues: chart.Sequence.Random(32, 1024),
|
||||||
|
|
1
chart.go
1
chart.go
|
@ -513,6 +513,7 @@ func (c Chart) styleDefaultsCanvas() Style {
|
||||||
func (c Chart) styleDefaultsSeries(seriesIndex int) Style {
|
func (c Chart) styleDefaultsSeries(seriesIndex int) Style {
|
||||||
strokeColor := GetDefaultColor(seriesIndex)
|
strokeColor := GetDefaultColor(seriesIndex)
|
||||||
return Style{
|
return Style{
|
||||||
|
DotColor: strokeColor,
|
||||||
StrokeColor: strokeColor,
|
StrokeColor: strokeColor,
|
||||||
StrokeWidth: DefaultSeriesLineWidth,
|
StrokeWidth: DefaultSeriesLineWidth,
|
||||||
Font: c.GetFont(),
|
Font: c.GetFont(),
|
||||||
|
|
1
draw.go
1
draw.go
|
@ -52,6 +52,7 @@ func (d draw) LineSeries(r Renderer, canvasBox Box, xrange, yrange Range, style
|
||||||
y = cb - yrange.Translate(vy)
|
y = cb - yrange.Translate(vy)
|
||||||
r.LineTo(x, y)
|
r.LineTo(x, y)
|
||||||
}
|
}
|
||||||
|
r.Stroke()
|
||||||
}
|
}
|
||||||
|
|
||||||
if style.ShouldDrawDot() {
|
if style.ShouldDrawDot() {
|
||||||
|
|
|
@ -49,7 +49,9 @@ func (lrs LinearRegressionSeries) GetWindow() int {
|
||||||
|
|
||||||
// GetEndIndex returns the effective window end.
|
// GetEndIndex returns the effective window end.
|
||||||
func (lrs LinearRegressionSeries) GetEndIndex() int {
|
func (lrs LinearRegressionSeries) GetEndIndex() int {
|
||||||
return Math.MinInt(lrs.GetOffset()+(lrs.Len()), (lrs.InnerSeries.Len() - 1))
|
offset := lrs.GetOffset() + lrs.Len()
|
||||||
|
innerSeriesLastIndex := lrs.InnerSeries.Len() - 1
|
||||||
|
return Math.MinInt(offset, innerSeriesLastIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetOffset returns the data offset.
|
// GetOffset returns the data offset.
|
||||||
|
@ -62,7 +64,7 @@ func (lrs LinearRegressionSeries) GetOffset() int {
|
||||||
|
|
||||||
// GetValue gets a value at a given index.
|
// GetValue gets a value at a given index.
|
||||||
func (lrs *LinearRegressionSeries) GetValue(index int) (x, y float64) {
|
func (lrs *LinearRegressionSeries) GetValue(index int) (x, y float64) {
|
||||||
if lrs.InnerSeries == nil {
|
if lrs.InnerSeries == nil || lrs.InnerSeries.Len() == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if lrs.m == 0 && lrs.b == 0 {
|
if lrs.m == 0 && lrs.b == 0 {
|
||||||
|
@ -78,7 +80,7 @@ func (lrs *LinearRegressionSeries) GetValue(index int) (x, y float64) {
|
||||||
// GetLastValue computes the last moving average value but walking back window size samples,
|
// GetLastValue computes the last moving average value but walking back window size samples,
|
||||||
// and recomputing the last moving average chunk.
|
// and recomputing the last moving average chunk.
|
||||||
func (lrs *LinearRegressionSeries) GetLastValue() (x, y float64) {
|
func (lrs *LinearRegressionSeries) GetLastValue() (x, y float64) {
|
||||||
if lrs.InnerSeries == nil {
|
if lrs.InnerSeries == nil || lrs.InnerSeries.Len() == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if lrs.m == 0 && lrs.b == 0 {
|
if lrs.m == 0 && lrs.b == 0 {
|
||||||
|
|
|
@ -50,7 +50,7 @@ func (sma SMASeries) GetPeriod(defaults ...int) int {
|
||||||
|
|
||||||
// GetValue gets a value at a given index.
|
// GetValue gets a value at a given index.
|
||||||
func (sma SMASeries) GetValue(index int) (x, y float64) {
|
func (sma SMASeries) GetValue(index int) (x, y float64) {
|
||||||
if sma.InnerSeries == nil {
|
if sma.InnerSeries == nil || sma.InnerSeries.Len() == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
px, _ := sma.InnerSeries.GetValue(index)
|
px, _ := sma.InnerSeries.GetValue(index)
|
||||||
|
@ -62,7 +62,7 @@ func (sma SMASeries) GetValue(index int) (x, y float64) {
|
||||||
// GetLastValue computes the last moving average value but walking back window size samples,
|
// GetLastValue computes the last moving average value but walking back window size samples,
|
||||||
// and recomputing the last moving average chunk.
|
// and recomputing the last moving average chunk.
|
||||||
func (sma SMASeries) GetLastValue() (x, y float64) {
|
func (sma SMASeries) GetLastValue() (x, y float64) {
|
||||||
if sma.InnerSeries == nil {
|
if sma.InnerSeries == nil || sma.InnerSeries.Len() == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
seriesLen := sma.InnerSeries.Len()
|
seriesLen := sma.InnerSeries.Len()
|
||||||
|
|
Loading…
Reference in a new issue