Skip to content

Commit 5f42a58

Browse files
author
Will Charczuk
committed
mostly working
1 parent 26eaa1d commit 5f42a58

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+897
-620
lines changed

_examples/custom_padding/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
2727
},
2828
Series: []chart.Series{
2929
chart.ContinuousSeries{
30-
XValues: seq.Range(1.0, 100.0),
30+
XValues: SeqRange(1.0, 100.0),
3131
YValues: seq.RandomValuesWithMax(100, 512),
3232
},
3333
},
@@ -50,7 +50,7 @@ func drawChartDefault(res http.ResponseWriter, req *http.Request) {
5050
},
5151
Series: []chart.Series{
5252
chart.ContinuousSeries{
53-
XValues: seq.Range(1.0, 100.0),
53+
XValues: SeqRange(1.0, 100.0),
5454
YValues: seq.RandomValuesWithMax(100, 512),
5555
},
5656
},

_examples/linear_regression/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
1616

1717
mainSeries := chart.ContinuousSeries{
1818
Name: "A test series",
19-
XValues: seq.Range(1.0, 100.0), //generates a []float64 from 1.0 to 100.0 in 1.0 step increments, or 100 elements.
19+
XValues: SeqRange(1.0, 100.0), //generates a []float64 from 1.0 to 100.0 in 1.0 step increments, or 100 elements.
2020
YValues: seq.RandomValuesWithMax(100, 100), //generates a []float64 randomly from 0 to 100 with 100 elements.
2121
}
2222

_examples/min_max/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
func drawChart(res http.ResponseWriter, req *http.Request) {
1111
mainSeries := chart.ContinuousSeries{
1212
Name: "A test series",
13-
XValues: seq.Range(1.0, 100.0),
13+
XValues: SeqRange(1.0, 100.0),
1414
YValues: seq.New(seq.NewRandom().WithLen(100).WithMax(150).WithMin(50)).Array(),
1515
}
1616

_examples/poly_regression/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
1616

1717
mainSeries := chart.ContinuousSeries{
1818
Name: "A test series",
19-
XValues: seq.Range(1.0, 100.0), //generates a []float64 from 1.0 to 100.0 in 1.0 step increments, or 100 elements.
19+
XValues: SeqRange(1.0, 100.0), //generates a []float64 from 1.0 to 100.0 in 1.0 step increments, or 100 elements.
2020
YValues: seq.RandomValuesWithMax(100, 100), //generates a []float64 randomly from 0 to 100 with 100 elements.
2121
}
2222

_examples/request_timings/main.go

Lines changed: 68 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55
"net/http"
66
"strconv"
7-
"strings"
87
"time"
98

109
chart "github.com/wcharczuk/go-chart"
@@ -24,7 +23,7 @@ func readData() ([]time.Time, []float64) {
2423
var xvalues []time.Time
2524
var yvalues []float64
2625
err := chart.ReadLines("requests.csv", func(line string) error {
27-
parts := strings.Split(line, ",")
26+
parts := chart.SplitCSV(line)
2827
year := parseInt(parts[0])
2928
month := parseInt(parts[1])
3029
day := parseInt(parts[2])
@@ -51,84 +50,84 @@ func releases() []chart.GridLine {
5150
}
5251
}
5352

54-
func drawChart(res http.ResponseWriter, req *http.Request) {
55-
xvalues, yvalues := readData()
56-
mainSeries := chart.TimeSeries{
57-
Name: "Prod Request Timings",
58-
Style: chart.Style{
59-
Show: true,
60-
StrokeColor: chart.ColorBlue,
61-
FillColor: chart.ColorBlue.WithAlpha(100),
62-
},
63-
XValues: xvalues,
64-
YValues: yvalues,
65-
}
53+
func drawChart(log chart.Logger) http.HandlerFunc {
54+
return func(res http.ResponseWriter, req *http.Request) {
55+
xvalues, yvalues := readData()
56+
mainSeries := chart.TimeSeries{
57+
Name: "Prod Request Timings",
58+
Style: chart.Style{
59+
StrokeColor: chart.ColorBlue,
60+
FillColor: chart.ColorBlue.WithAlpha(100),
61+
},
62+
XValues: xvalues,
63+
YValues: yvalues,
64+
}
6665

67-
linreg := &chart.LinearRegressionSeries{
68-
Name: "Linear Regression",
69-
Style: chart.Style{
70-
Show: true,
71-
StrokeColor: chart.ColorAlternateBlue,
72-
StrokeDashArray: []float64{5.0, 5.0},
73-
},
74-
InnerSeries: mainSeries,
75-
}
66+
linreg := &chart.LinearRegressionSeries{
67+
Name: "Linear Regression",
68+
Style: chart.Style{
69+
StrokeColor: chart.ColorAlternateBlue,
70+
StrokeDashArray: []float64{5.0, 5.0},
71+
},
72+
InnerSeries: mainSeries,
73+
}
7674

77-
sma := &chart.SMASeries{
78-
Name: "SMA",
79-
Style: chart.Style{
80-
Show: true,
81-
StrokeColor: chart.ColorRed,
82-
StrokeDashArray: []float64{5.0, 5.0},
83-
},
84-
InnerSeries: mainSeries,
85-
}
75+
sma := &chart.SMASeries{
76+
Name: "SMA",
77+
Style: chart.Style{
78+
StrokeColor: chart.ColorRed,
79+
StrokeDashArray: []float64{5.0, 5.0},
80+
},
81+
InnerSeries: mainSeries,
82+
}
8683

87-
graph := chart.Chart{
88-
Width: 1280,
89-
Height: 720,
90-
Background: chart.Style{
91-
Padding: chart.Box{
92-
Top: 50,
84+
graph := chart.Chart{
85+
Log: log,
86+
Width: 1280,
87+
Height: 720,
88+
Background: chart.Style{
89+
Padding: chart.Box{
90+
Top: 50,
91+
},
9392
},
94-
},
95-
YAxis: chart.YAxis{
96-
Name: "Elapsed Millis",
97-
NameStyle: chart.StyleShow(),
98-
Style: chart.StyleShow(),
99-
TickStyle: chart.Style{
100-
TextRotationDegrees: 45.0,
93+
YAxis: chart.YAxis{
94+
Name: "Elapsed Millis",
95+
TickStyle: chart.Style{
96+
TextRotationDegrees: 45.0,
97+
},
98+
ValueFormatter: func(v interface{}) string {
99+
return fmt.Sprintf("%d ms", int(v.(float64)))
100+
},
101101
},
102-
ValueFormatter: func(v interface{}) string {
103-
return fmt.Sprintf("%d ms", int(v.(float64)))
102+
XAxis: chart.XAxis{
103+
ValueFormatter: chart.TimeHourValueFormatter,
104+
GridMajorStyle: chart.Style{
105+
StrokeColor: chart.ColorAlternateGray,
106+
StrokeWidth: 1.0,
107+
},
108+
GridLines: releases(),
104109
},
105-
},
106-
XAxis: chart.XAxis{
107-
Style: chart.StyleShow(),
108-
ValueFormatter: chart.TimeHourValueFormatter,
109-
GridMajorStyle: chart.Style{
110-
Show: true,
111-
StrokeColor: chart.ColorAlternateGray,
112-
StrokeWidth: 1.0,
110+
Series: []chart.Series{
111+
mainSeries,
112+
linreg,
113+
chart.LastValueAnnotation(linreg),
114+
sma,
115+
chart.LastValueAnnotation(sma),
113116
},
114-
GridLines: releases(),
115-
},
116-
Series: []chart.Series{
117-
mainSeries,
118-
linreg,
119-
chart.LastValueAnnotation(linreg),
120-
sma,
121-
chart.LastValueAnnotation(sma),
122-
},
123-
}
117+
}
124118

125-
graph.Elements = []chart.Renderable{chart.LegendThin(&graph)}
119+
graph.Elements = []chart.Renderable{chart.LegendThin(&graph)}
126120

127-
res.Header().Set("Content-Type", chart.ContentTypePNG)
128-
graph.Render(chart.PNG, res)
121+
res.Header().Set("Content-Type", chart.ContentTypePNG)
122+
if err := graph.Render(chart.PNG, res); err != nil {
123+
log.Err(err)
124+
}
125+
}
129126
}
130127

131128
func main() {
132-
http.HandleFunc("/", drawChart)
129+
log := chart.NewLogger()
130+
log.Infof("listening on :8080")
131+
http.HandleFunc("/", drawChart(log))
133132
http.ListenAndServe(":8080", nil)
134133
}

_examples/scatter/main.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ import (
66

77
_ "net/http/pprof"
88

9-
"github.com/wcharczuk/go-chart"
9+
chart "github.com/wcharczuk/go-chart"
1010
"github.com/wcharczuk/go-chart/drawing"
11-
"github.com/wcharczuk/go-chart/seq"
1211
)
1312

1413
func drawChart(res http.ResponseWriter, req *http.Request) {
@@ -26,8 +25,8 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
2625
DotWidth: 5,
2726
DotColorProvider: viridisByY,
2827
},
29-
XValues: seq.Range(0, 127),
30-
YValues: seq.New(seq.NewRandom().WithLen(128).WithMax(1024)).Array(),
28+
XValues: chart.SeqRange(0, 127),
29+
YValues: chart.NewSeq(chart.NewSeqRandom().WithLen(128).WithMax(1024)).Values(),
3130
},
3231
},
3332
}
@@ -51,8 +50,8 @@ func unit(res http.ResponseWriter, req *http.Request) {
5150
},
5251
Series: []chart.Series{
5352
chart.ContinuousSeries{
54-
XValues: seq.RangeWithStep(0, 4, 1),
55-
YValues: seq.RangeWithStep(0, 4, 1),
53+
XValues: chart.SeqRangeWithStep(0, 4, 1),
54+
YValues: chart.SeqRangeWithStep(0, 4, 1),
5655
},
5756
},
5857
}

_examples/simple_moving_average/main.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@ package main
33
import (
44
"net/http"
55

6-
"github.com/wcharczuk/go-chart"
7-
"github.com/wcharczuk/go-chart/seq"
6+
chart "github.com/wcharczuk/go-chart"
87
)
98

109
func drawChart(res http.ResponseWriter, req *http.Request) {
1110

1211
mainSeries := chart.ContinuousSeries{
1312
Name: "A test series",
14-
XValues: seq.Range(1.0, 100.0), //generates a []float64 from 1.0 to 100.0 in 1.0 step increments, or 100 elements.
15-
YValues: seq.RandomValuesWithMax(100, 100), //generates a []float64 randomly from 0 to 100 with 100 elements.
13+
XValues: chart.SeqRange(1.0, 100.0), //generates a []float64 from 1.0 to 100.0 in 1.0 step increments, or 100 elements.
14+
YValues: chart.SeqRandomValuesWithMax(100, 100), //generates a []float64 randomly from 0 to 100 with 100 elements.
1615
}
1716

1817
// note we create a SimpleMovingAverage series by assignin the inner series.

_examples/stacked_bar/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"log"
66
"net/http"
77

8-
"github.com/wcharczuk/go-chart"
8+
chart "github.com/wcharczuk/go-chart"
99
)
1010

1111
func drawChart(res http.ResponseWriter, req *http.Request) {

_examples/stock_analysis/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"net/http"
55
"time"
66

7-
"github.com/wcharczuk/go-chart"
7+
chart "github.com/wcharczuk/go-chart"
88
"github.com/wcharczuk/go-chart/drawing"
99
)
1010

_examples/text_rotation/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package main
33
import (
44
"net/http"
55

6-
"github.com/wcharczuk/go-chart"
6+
chart "github.com/wcharczuk/go-chart"
77
"github.com/wcharczuk/go-chart/drawing"
88
)
99

0 commit comments

Comments
 (0)