Skip to content
Permalink
Browse files

Update: #18 remove packr dependency and update docs

  • Loading branch information...
chenjiandongx committed May 5, 2019
1 parent 87d1c65 commit 7f6a637dc31b893629f3439476ff277e82165505
Showing with 39 additions and 3 deletions.
  1. +17 −1 datasets/datasets.go
  2. +1 −2 docs/docs/themes.md
  3. +21 −0 templates/templates.go
@@ -2,7 +2,9 @@ package datasets

import (
"encoding/json"
"io/ioutil"
"log"
"net/http"

"github.com/gobuffalo/packr"
)
@@ -13,9 +15,23 @@ var Coordinates map[string][2]float32
func init() {
box := packr.NewBox(".")
maps, err := box.Find("map_filename.json")
json.Unmarshal(maps, &MapFileNames)
if err == nil {
json.Unmarshal(maps, &MapFileNames)
}

coordinates, err := box.Find("coordinates.json")
if err == nil {
json.Unmarshal(coordinates, &Coordinates)
}
}

func LoadAssets(loader http.FileSystem) {
fMaps, err := loader.Open("map_filename.json")
maps, err := ioutil.ReadAll(fMaps)
json.Unmarshal(maps, &MapFileNames)

fCoordinates, err := loader.Open("coordinates.json")
coordinates, err := ioutil.ReadAll(fCoordinates)
json.Unmarshal(coordinates, &Coordinates)

if err != nil {
@@ -19,7 +19,6 @@ import (
"time"
"github.com/chenjiandongx/go-echarts/charts"
"github.com/chenjiandongx/go-echarts/common"
)
var nameItems = []string{"衬衫", "牛仔裤", "运动裤", "袜子", "冲锋衣", "羊毛衫"}
@@ -38,7 +37,7 @@ func main() {
bar := charts.NewBar()
bar.SetGlobalOptions(
charts.TitleOpts{Title: "Theme-Walden"},
charts.InitOpts{Theme: common.ThemeType.Walden},
charts.InitOpts{Theme: charts.ThemeType.Walden},
charts.ToolboxOpts{Show: true},
)
bar.AddXAxis(nameItems).
@@ -1,7 +1,9 @@
package templates

import (
"io/ioutil"
"log"
"net/http"

"github.com/gobuffalo/packr"
)
@@ -18,7 +20,26 @@ func init() {
PageTpl, err = box.FindString("page.html")
RoutersTpl, err = box.FindString("routers.html")

if err != nil {
log.Printf("packr load templates error: %v", err)
}
}


func LoadTemplates(loader http.FileSystem) {
var err error
BaseTpl, err = _bytesToString(loader.Open("base.html"))
ChartTpl, err = _bytesToString(loader.Open("chart.html"))
HeaderTpl, err = _bytesToString(loader.Open("header.html"))
PageTpl, err = _bytesToString(loader.Open("page.html"))
RoutersTpl, err = _bytesToString(loader.Open("routers.html"))

if err != nil {
log.Fatal(err)
}
}

func _bytesToString(file http.File, err error) (string, error){
content, err := ioutil.ReadAll(file)
return string(content), err
}

0 comments on commit 7f6a637

Please sign in to comment.
You can’t perform that action at this time.