thatll do for now

main
bel 2024-02-14 08:58:38 -07:00
parent 9dc35a8a80
commit 9af98c5924
2 changed files with 22 additions and 8 deletions

View File

@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"log"
"net/url"
"os"
"slices"
@ -12,7 +13,8 @@ import (
)
type Config struct {
Data Data
Data Data
Output url.URL
}
type Data struct {
@ -35,6 +37,9 @@ func newConfig() (Config, error) {
}
result.Data.Weight.Floor = 12
result.Data.Weight.Range = 20
result.Output = url.URL{Scheme: "file", Path: "/tmp/f"}
result.Data.Title = os.Getenv("TITLE")
result.Data.Subtitle = os.Getenv("SUBTITLE")
if js := os.Getenv("POINTS_JSON"); js == "" {
} else if err := json.Unmarshal([]byte(js), &result.Data.Points); err != nil {
@ -74,8 +79,12 @@ func newConfig() (Config, error) {
return result, fmt.Errorf("found negative weight floor %d", result.Data.Weight.Floor)
}
result.Data.Title = os.Getenv("TITLE")
result.Data.Subtitle = os.Getenv("SUBTITLE")
if s := os.Getenv("OUTPUT"); s == "" {
} else if u, err := url.Parse(s); err != nil {
return result, fmt.Errorf("failed to parse $OUTPUT (%s): %w", s, err)
} else {
result.Output = *u
}
return result, nil
}

15
main.go
View File

@ -1,7 +1,9 @@
package main
import (
"bytes"
"context"
"fmt"
"log"
"os"
"os/signal"
@ -50,12 +52,15 @@ func run(ctx context.Context) error {
}))
scatter.SetXAxis(xs).
AddSeries(y, ys)
f, _ := os.Create("/tmp/f")
defer f.Close()
if err := scatter.Render(f); err != nil {
buff := bytes.NewBuffer(nil)
if err := scatter.Render(buff); err != nil {
return err
}
log.Println("firefox /tmp/f")
return nil
switch config.Output.Scheme {
case "file":
return os.WriteFile(config.Output.Path, buff.Bytes(), os.ModePerm)
}
return fmt.Errorf("not impl output scheme: %s", config.Output.Scheme)
}