Helper API refactor (#40)
* api cleaup * updates * wtf * updates * snapshot. * tweaks * snapshot * api tweaks. * updates * updates * updates * changes. * updates * updates * sequence => seq * dont need to use curl, just using wget * fixing examples
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 22 KiB |
|
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 11 KiB |
|
|
@ -20,12 +20,18 @@ func drawLargeChart(res http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
numSeriesInt64 = int64(1)
|
||||
}
|
||||
if numSeriesInt64 == 0 {
|
||||
numSeriesInt64 = 1
|
||||
}
|
||||
numSeries := int(numSeriesInt64)
|
||||
|
||||
numValuesInt64, err := strconv.ParseInt(r.FormValue("values"), 10, 64)
|
||||
if err != nil {
|
||||
numValuesInt64 = int64(100)
|
||||
}
|
||||
if numValuesInt64 == 0 {
|
||||
numValuesInt64 = int64(100)
|
||||
}
|
||||
numValues := int(numValuesInt64)
|
||||
|
||||
series := make([]chart.Series, numSeries)
|
||||
|
|
|
|||
BIN
_examples/benchmark_line_charts/output.png
Normal file
|
After Width: | Height: | Size: 68 KiB |
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
|
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
"github.com/wcharczuk/go-chart"
|
||||
"github.com/wcharczuk/go-chart/drawing"
|
||||
"github.com/wcharczuk/go-chart/seq"
|
||||
)
|
||||
|
||||
func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||
|
|
@ -30,8 +31,8 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
|||
},
|
||||
Series: []chart.Series{
|
||||
chart.ContinuousSeries{
|
||||
XValues: chart.Sequence.Float64(1.0, 100.0),
|
||||
YValues: chart.Sequence.Random(100.0, 256.0),
|
||||
XValues: seq.Range(1.0, 100.0),
|
||||
YValues: seq.RandomValuesWithMax(100, 512),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
@ -57,8 +58,8 @@ func drawChartDefault(res http.ResponseWriter, req *http.Request) {
|
|||
},
|
||||
Series: []chart.Series{
|
||||
chart.ContinuousSeries{
|
||||
XValues: chart.Sequence.Float64(1.0, 100.0),
|
||||
YValues: chart.Sequence.Random(100.0, 256.0),
|
||||
XValues: seq.Range(1.0, 100.0),
|
||||
YValues: seq.RandomValuesWithMax(100, 512),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
Before Width: | Height: | Size: 64 KiB After Width: | Height: | Size: 66 KiB |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 11 KiB |
BIN
_examples/descending/output.png
Normal file
|
After Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 24 KiB |
|
|
@ -4,19 +4,20 @@ import (
|
|||
"net/http"
|
||||
|
||||
"github.com/wcharczuk/go-chart"
|
||||
"github.com/wcharczuk/go-chart/seq"
|
||||
)
|
||||
|
||||
func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||
|
||||
/*
|
||||
In this example we add a new type of series, a `SimpleMovingAverageSeries` that takes another series as a required argument.
|
||||
InnerSeries only needs to implement `ValueProvider`, so really you could chain `SimpleMovingAverageSeries` together if you wanted.
|
||||
InnerSeries only needs to implement `ValuesProvider`, so really you could chain `SimpleMovingAverageSeries` together if you wanted.
|
||||
*/
|
||||
|
||||
mainSeries := chart.ContinuousSeries{
|
||||
Name: "A test series",
|
||||
XValues: chart.Sequence.Float64(1.0, 100.0), //generates a []float64 from 1.0 to 100.0 in 1.0 step increments, or 100 elements.
|
||||
YValues: chart.Sequence.Random(100, 100), //generates a []float64 randomly from 0 to 100 with 100 elements.
|
||||
XValues: seq.Range(1.0, 100.0), //generates a []float64 from 1.0 to 100.0 in 1.0 step increments, or 100 elements.
|
||||
YValues: seq.RandomValuesWithAverage(100, 100), //generates a []float64 randomly from 0 to 100 with 100 elements.
|
||||
}
|
||||
|
||||
// note we create a LinearRegressionSeries series by assignin the inner series.
|
||||
|
|
|
|||
|
|
@ -4,13 +4,15 @@ import (
|
|||
"net/http"
|
||||
|
||||
"github.com/wcharczuk/go-chart"
|
||||
"github.com/wcharczuk/go-chart/seq"
|
||||
"github.com/wcharczuk/go-chart/util"
|
||||
)
|
||||
|
||||
func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||
start := chart.Date.Date(2016, 7, 01, chart.Date.Eastern())
|
||||
end := chart.Date.Date(2016, 07, 21, chart.Date.Eastern())
|
||||
xv := chart.Sequence.MarketHours(start, end, chart.NYSEOpen, chart.NYSEClose, chart.Date.IsNYSEHoliday)
|
||||
yv := chart.Sequence.RandomWithAverage(len(xv), 200, 10)
|
||||
start := util.Date.Date(2016, 7, 01, util.Date.Eastern())
|
||||
end := util.Date.Date(2016, 07, 21, util.Date.Eastern())
|
||||
xv := seq.Time.MarketHours(start, end, util.NYSEOpen(), util.NYSEClose(), util.Date.IsNYSEHoliday)
|
||||
yv := seq.New(seq.NewRandom().WithLen(len(xv)).WithAverage(200).WithScale(10)).Array()
|
||||
|
||||
graph := chart.Chart{
|
||||
XAxis: chart.XAxis{
|
||||
|
|
@ -18,9 +20,9 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
|||
TickPosition: chart.TickPositionBetweenTicks,
|
||||
ValueFormatter: chart.TimeHourValueFormatter,
|
||||
Range: &chart.MarketHoursRange{
|
||||
MarketOpen: chart.NYSEOpen,
|
||||
MarketClose: chart.NYSEClose,
|
||||
HolidayProvider: chart.Date.IsNYSEHoliday,
|
||||
MarketOpen: util.NYSEOpen(),
|
||||
MarketClose: util.NYSEClose(),
|
||||
HolidayProvider: util.Date.IsNYSEHoliday,
|
||||
},
|
||||
},
|
||||
YAxis: chart.YAxis{
|
||||
|
|
|
|||
|
|
@ -4,13 +4,14 @@ import (
|
|||
"net/http"
|
||||
|
||||
"github.com/wcharczuk/go-chart"
|
||||
"github.com/wcharczuk/go-chart/seq"
|
||||
)
|
||||
|
||||
func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||
mainSeries := chart.ContinuousSeries{
|
||||
Name: "A test series",
|
||||
XValues: chart.Sequence.Float64(1.0, 100.0),
|
||||
YValues: chart.Sequence.RandomWithAverage(100, 100, 50),
|
||||
XValues: seq.Range(1.0, 100.0),
|
||||
YValues: seq.New(seq.NewRandom().WithLen(100).WithAverage(100).WithScale(50)).Array(),
|
||||
}
|
||||
|
||||
minSeries := &chart.MinSeries{
|
||||
|
|
|
|||
|
Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 34 KiB |
|
|
@ -4,19 +4,20 @@ import (
|
|||
"net/http"
|
||||
|
||||
"github.com/wcharczuk/go-chart"
|
||||
"github.com/wcharczuk/go-chart/seq"
|
||||
)
|
||||
|
||||
func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||
|
||||
/*
|
||||
In this example we add a new type of series, a `PolynomialRegressionSeries` that takes another series as a required argument.
|
||||
InnerSeries only needs to implement `ValueProvider`, so really you could chain `PolynomialRegressionSeries` together if you wanted.
|
||||
InnerSeries only needs to implement `ValuesProvider`, so really you could chain `PolynomialRegressionSeries` together if you wanted.
|
||||
*/
|
||||
|
||||
mainSeries := chart.ContinuousSeries{
|
||||
Name: "A test series",
|
||||
XValues: chart.Sequence.Float64(1.0, 100.0), //generates a []float64 from 1.0 to 100.0 in 1.0 step increments, or 100 elements.
|
||||
YValues: chart.Sequence.Random(100, 100), //generates a []float64 randomly from 0 to 100 with 100 elements.
|
||||
XValues: seq.Range(1.0, 100.0), //generates a []float64 from 1.0 to 100.0 in 1.0 step increments, or 100 elements.
|
||||
YValues: seq.RandomValuesWithAverage(100, 100), //generates a []float64 randomly from 0 to 100 with 100 elements.
|
||||
}
|
||||
|
||||
polyRegSeries := &chart.PolynomialRegressionSeries{
|
||||
|
|
|
|||
BIN
_examples/poly_regression/output.png
Normal file
|
After Width: | Height: | Size: 54 KiB |
|
|
@ -8,6 +8,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/wcharczuk/go-chart"
|
||||
util "github.com/wcharczuk/go-chart/util"
|
||||
)
|
||||
|
||||
func parseInt(str string) int {
|
||||
|
|
@ -23,7 +24,7 @@ func parseFloat64(str string) float64 {
|
|||
func readData() ([]time.Time, []float64) {
|
||||
var xvalues []time.Time
|
||||
var yvalues []float64
|
||||
err := chart.File.ReadByLines("requests.csv", func(line string) {
|
||||
err := util.File.ReadByLines("requests.csv", func(line string) error {
|
||||
parts := strings.Split(line, ",")
|
||||
year := parseInt(parts[0])
|
||||
month := parseInt(parts[1])
|
||||
|
|
@ -32,6 +33,7 @@ func readData() ([]time.Time, []float64) {
|
|||
elapsedMillis := parseFloat64(parts[4])
|
||||
xvalues = append(xvalues, time.Date(year, time.Month(month), day, hour, 0, 0, 0, time.UTC))
|
||||
yvalues = append(yvalues, elapsedMillis)
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
|
|
@ -41,12 +43,12 @@ func readData() ([]time.Time, []float64) {
|
|||
|
||||
func releases() []chart.GridLine {
|
||||
return []chart.GridLine{
|
||||
{Value: chart.Time.ToFloat64(time.Date(2016, 8, 1, 9, 30, 0, 0, time.UTC))},
|
||||
{Value: chart.Time.ToFloat64(time.Date(2016, 8, 2, 9, 30, 0, 0, time.UTC))},
|
||||
{Value: chart.Time.ToFloat64(time.Date(2016, 8, 2, 15, 30, 0, 0, time.UTC))},
|
||||
{Value: chart.Time.ToFloat64(time.Date(2016, 8, 4, 9, 30, 0, 0, time.UTC))},
|
||||
{Value: chart.Time.ToFloat64(time.Date(2016, 8, 5, 9, 30, 0, 0, time.UTC))},
|
||||
{Value: chart.Time.ToFloat64(time.Date(2016, 8, 6, 9, 30, 0, 0, time.UTC))},
|
||||
{Value: util.Time.ToFloat64(time.Date(2016, 8, 1, 9, 30, 0, 0, time.UTC))},
|
||||
{Value: util.Time.ToFloat64(time.Date(2016, 8, 2, 9, 30, 0, 0, time.UTC))},
|
||||
{Value: util.Time.ToFloat64(time.Date(2016, 8, 2, 15, 30, 0, 0, time.UTC))},
|
||||
{Value: util.Time.ToFloat64(time.Date(2016, 8, 4, 9, 30, 0, 0, time.UTC))},
|
||||
{Value: util.Time.ToFloat64(time.Date(2016, 8, 5, 9, 30, 0, 0, time.UTC))},
|
||||
{Value: util.Time.ToFloat64(time.Date(2016, 8, 6, 9, 30, 0, 0, time.UTC))},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -125,8 +127,8 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
|||
|
||||
graph.Elements = []chart.Renderable{chart.LegendThin(&graph)}
|
||||
|
||||
res.Header().Set("Content-Type", chart.ContentTypeSVG)
|
||||
graph.Render(chart.SVG, res)
|
||||
res.Header().Set("Content-Type", chart.ContentTypePNG)
|
||||
graph.Render(chart.PNG, res)
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import (
|
|||
|
||||
"github.com/wcharczuk/go-chart"
|
||||
"github.com/wcharczuk/go-chart/drawing"
|
||||
"github.com/wcharczuk/go-chart/seq"
|
||||
)
|
||||
|
||||
func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||
|
|
@ -25,8 +26,8 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
|||
DotWidth: 5,
|
||||
DotColorProvider: viridisByY,
|
||||
},
|
||||
XValues: chart.Sequence.Random(128, 1024),
|
||||
YValues: chart.Sequence.Random(128, 1024),
|
||||
XValues: seq.Range(0, 127),
|
||||
YValues: seq.New(seq.NewRandom().WithLen(128).WithMax(1024)).Array(),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
@ -50,8 +51,8 @@ func unit(res http.ResponseWriter, req *http.Request) {
|
|||
},
|
||||
Series: []chart.Series{
|
||||
chart.ContinuousSeries{
|
||||
XValues: chart.Sequence.Float64(0, 4, 1),
|
||||
YValues: chart.Sequence.Float64(0, 4, 1),
|
||||
XValues: seq.RangeWithStep(0, 4, 1),
|
||||
YValues: seq.RangeWithStep(0, 4, 1),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 26 KiB |
|
|
@ -4,19 +4,15 @@ import (
|
|||
"net/http"
|
||||
|
||||
"github.com/wcharczuk/go-chart"
|
||||
"github.com/wcharczuk/go-chart/seq"
|
||||
)
|
||||
|
||||
func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||
|
||||
/*
|
||||
In this example we add a new type of series, a `SimpleMovingAverageSeries` that takes another series as a required argument.
|
||||
InnerSeries only needs to implement `ValueProvider`, so really you could chain `SimpleMovingAverageSeries` together if you wanted.
|
||||
*/
|
||||
|
||||
mainSeries := chart.ContinuousSeries{
|
||||
Name: "A test series",
|
||||
XValues: chart.Sequence.Float64(1.0, 100.0), //generates a []float64 from 1.0 to 100.0 in 1.0 step increments, or 100 elements.
|
||||
YValues: chart.Sequence.Random(100, 100), //generates a []float64 randomly from 0 to 100 with 100 elements.
|
||||
XValues: seq.Range(1.0, 100.0), //generates a []float64 from 1.0 to 100.0 in 1.0 step increments, or 100 elements.
|
||||
YValues: seq.RandomValuesWithMax(100, 100), //generates a []float64 randomly from 0 to 100 with 100 elements.
|
||||
}
|
||||
|
||||
// note we create a SimpleMovingAverage series by assignin the inner series.
|
||||
|
|
|
|||
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
BIN
_examples/text_rotation/output.png
Normal file
|
After Width: | Height: | Size: 8.6 KiB |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
|
|
@ -5,6 +5,7 @@ import (
|
|||
"net/http"
|
||||
|
||||
"github.com/wcharczuk/go-chart"
|
||||
util "github.com/wcharczuk/go-chart/util"
|
||||
)
|
||||
|
||||
func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||
|
|
@ -23,7 +24,7 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
|||
TickPosition: chart.TickPositionBetweenTicks,
|
||||
ValueFormatter: func(v interface{}) string {
|
||||
typed := v.(float64)
|
||||
typedDate := chart.Time.FromFloat64(typed)
|
||||
typedDate := util.Time.FromFloat64(typed)
|
||||
return fmt.Sprintf("%d-%d\n%d", typedDate.Month(), typedDate.Day(), typedDate.Year())
|
||||
},
|
||||
},
|
||||
|
|
|
|||
|
Before Width: | Height: | Size: 37 KiB After Width: | Height: | Size: 36 KiB |
|
|
@ -4,8 +4,8 @@ import (
|
|||
"bytes"
|
||||
"log"
|
||||
"os"
|
||||
//"time"
|
||||
"github.com/wcharczuk/go-chart" //exposes "chart"
|
||||
|
||||
"github.com/wcharczuk/go-chart"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
@ -18,8 +18,6 @@ func main() {
|
|||
Style: chart.Style{
|
||||
Show: true,
|
||||
},
|
||||
|
||||
//XValues: []time.Time{time.Unix(3*b,0),time.Unix(4*b,0),time.Unix(5*b,0),time.Unix(6*b,0),time.Unix(7*b,0),time.Unix(8*b,0),time.Unix(9*b,0),time.Unix(10*b,0)},
|
||||
XValues: []float64{10 * b, 20 * b, 30 * b, 40 * b, 50 * b, 60 * b, 70 * b, 80 * b},
|
||||
YValues: []float64{1.0, 2.0, 30.0, 4.0, 50.0, 6.0, 7.0, 88.0},
|
||||
}
|
||||
|
|
|
|||