Skip to content
Permalink
Browse files

move data types into the datatypes package (#14)

* fix typo

* move data types into the datatypes package
  • Loading branch information...
yuankunzhang authored and chenjiandongx committed Apr 5, 2019
1 parent 74c7db0 commit 882021cb207c1d69b5db83c1ef3d61860d409f79
Showing with 57 additions and 52 deletions.
  1. +1 āˆ’1 README.md
  2. +4 āˆ’5 charts/base.go
  3. +3 āˆ’2 charts/funnel.go
  4. +3 āˆ’2 charts/gauge.go
  5. +3 āˆ’2 charts/geo.go
  6. +3 āˆ’2 charts/map.go
  7. +3 āˆ’2 charts/page.go
  8. +3 āˆ’2 charts/pie.go
  9. +3 āˆ’2 charts/wordcloud.go
  10. +0 āˆ’32 common/structures.go
  11. +7 āˆ’0 datatypes/namevalue.go
  12. +24 āˆ’0 datatypes/orderedset.go
@@ -42,7 +42,7 @@ $ go get -u github.com/chenjiandongx/go-echarts/...
* Visualize your data in 25+ different ways.
* Highly configurable chart options.
* Detailed documentation and a rich collection of examples.
* Visualization your geographical data with 400+ maps.
* Visualize your geographical data with 400+ maps.

### šŸ“ Usage

@@ -1,9 +1,8 @@
package charts

import (
"github.com/chenjiandongx/go-echarts/datatypes"
"regexp"

"github.com/chenjiandongx/go-echarts/common"
)

type globalOptser interface {
@@ -32,7 +31,7 @@ func (InitOpts) markGlobal() {}

// AssetsOpts contains options for static assets.
type AssetsOpts struct {
JSAssets, CSSAssets common.OrderedSet
JSAssets, CSSAssets datatypes.OrderedSet
}

// åˆå§‹åŒ–é™ę€čµ„ęŗé…ē½®é”¹
@@ -43,8 +42,8 @@ func (opt *AssetsOpts) initAssetsOpts() {

// åˆå§‹åŒ–é™ę€čµ„ęŗé…ē½®é”¹
func (opt *AssetsOpts) initAssetsOptsWithoutArg() {
opt.JSAssets.InitWithoutArg()
opt.CSSAssets.InitWithoutArg()
opt.JSAssets.Init()
opt.CSSAssets.Init()
}

// čæ”å›žčµ„ęŗåˆ—č”Ø
@@ -1,6 +1,7 @@
package charts

import (
"github.com/chenjiandongx/go-echarts/datatypes"
"io"

"github.com/chenjiandongx/go-echarts/common"
@@ -23,9 +24,9 @@ func NewFunnel(routers ...RouterOpts) *Funnel {

// Add adds new data sets.
func (c *Funnel) Add(name string, data map[string]interface{}, options ...seriesOptser) *Funnel {
nvs := make([]common.NameValueItem, 0)
nvs := make([]datatypes.NameValueItem, 0)
for k, v := range data {
nvs = append(nvs, common.NameValueItem{Name: k, Value: v})
nvs = append(nvs, datatypes.NameValueItem{Name: k, Value: v})
}
series := singleSeries{Name: name, Type: common.ChartType.Funnel, Data: nvs}
series.setSingleSeriesOpts(options...)
@@ -1,6 +1,7 @@
package charts

import (
"github.com/chenjiandongx/go-echarts/datatypes"
"io"

"github.com/chenjiandongx/go-echarts/common"
@@ -23,9 +24,9 @@ func NewGauge(routers ...RouterOpts) *Gauge {

// Add adds new data sets.
func (c *Gauge) Add(name string, data map[string]interface{}, options ...seriesOptser) *Gauge {
nvs := make([]common.NameValueItem, 0)
nvs := make([]datatypes.NameValueItem, 0)
for k, v := range data {
nvs = append(nvs, common.NameValueItem{Name: k, Value: v})
nvs = append(nvs, datatypes.NameValueItem{Name: k, Value: v})
}
series := singleSeries{Name: name, Type: common.ChartType.Gauge, Data: nvs}
series.setSingleSeriesOpts(options...)
@@ -2,6 +2,7 @@ package charts

import (
"fmt"
"github.com/chenjiandongx/go-echarts/datatypes"
"io"
"log"

@@ -43,9 +44,9 @@ func NewGeo(mapType string, routers ...RouterOpts) *Geo {
// common.ChartType.EffectScatter
// common.ChartType.HeatMap
func (c *Geo) Add(name, geoType string, data map[string]float32, options ...seriesOptser) *Geo {
nvs := make([]common.NameValueItem, 0)
nvs := make([]datatypes.NameValueItem, 0)
for k, v := range data {
nvs = append(nvs, common.NameValueItem{Name: k, Value: c.extendValue(k, v)})
nvs = append(nvs, datatypes.NameValueItem{Name: k, Value: c.extendValue(k, v)})
}
series := singleSeries{Name: name, Type: geoType, Data: nvs, CoordSystem: common.ChartType.Geo}
series.setSingleSeriesOpts(options...)
@@ -1,6 +1,7 @@
package charts

import (
"github.com/chenjiandongx/go-echarts/datatypes"
"io"

"github.com/chenjiandongx/go-echarts/common"
@@ -28,9 +29,9 @@ func NewMap(mapType string, routers ...RouterOpts) *Map {

// Add adds new data sets.
func (c *Map) Add(name string, data map[string]float32, options ...seriesOptser) *Map {
nvs := make([]common.NameValueItem, 0)
nvs := make([]datatypes.NameValueItem, 0)
for k, v := range data {
nvs = append(nvs, common.NameValueItem{Name: k, Value: v})
nvs = append(nvs, datatypes.NameValueItem{Name: k, Value: v})
}
series := singleSeries{Name: name, Type: common.ChartType.Map, MapType: c.mapType, Data: nvs}
series.setSingleSeriesOpts(options...)
@@ -1,6 +1,7 @@
package charts

import (
"github.com/chenjiandongx/go-echarts/datatypes"
"io"
"log"

@@ -20,7 +21,7 @@ type Page struct {
Charts []interface{}
Routers

unusedStr common.OrderedSet
unusedStr datatypes.OrderedSet
}

// NewPage creates a new page.
@@ -30,7 +31,7 @@ func NewPage(routers ...RouterOpts) *Page {
page.Routers = append(page.Routers, routers[i])
}
page.AssetsOpts.initAssetsOptsWithoutArg()
page.unusedStr.InitWithoutArg()
page.unusedStr.Init()
return page
}

@@ -1,6 +1,7 @@
package charts

import (
"github.com/chenjiandongx/go-echarts/datatypes"
"io"

"github.com/chenjiandongx/go-echarts/common"
@@ -53,9 +54,9 @@ func NewPie(routers ...RouterOpts) *Pie {

// Add adds new data sets.
func (c *Pie) Add(name string, data map[string]interface{}, options ...seriesOptser) *Pie {
nvs := make([]common.NameValueItem, 0)
nvs := make([]datatypes.NameValueItem, 0)
for k, v := range data {
nvs = append(nvs, common.NameValueItem{Name: k, Value: v})
nvs = append(nvs, datatypes.NameValueItem{Name: k, Value: v})
}
series := singleSeries{Name: name, Type: common.ChartType.Pie, Data: nvs}
series.setSingleSeriesOpts(options...)
@@ -1,6 +1,7 @@
package charts

import (
"github.com/chenjiandongx/go-echarts/datatypes"
"io"

"github.com/chenjiandongx/go-echarts/common"
@@ -50,9 +51,9 @@ func NewWordCloud(routers ...RouterOpts) *WordCloud {

// Add adds new data sets.
func (c *WordCloud) Add(name string, data map[string]interface{}, options ...seriesOptser) *WordCloud {
nvs := make([]common.NameValueItem, 0)
nvs := make([]datatypes.NameValueItem, 0)
for k, v := range data {
nvs = append(nvs, common.NameValueItem{Name: k, Value: v})
nvs = append(nvs, datatypes.NameValueItem{Name: k, Value: v})
}
series := singleSeries{Name: name, Type: common.ChartType.WordCloud, Data: nvs}
series.setSingleSeriesOpts(options...)

This file was deleted.

@@ -0,0 +1,7 @@
package datatypes

// NameValueItem represents a data type with a name and a value.
type NameValueItem struct {
Name string `json:"name"`
Value interface{} `json:"value"`
}
@@ -0,0 +1,24 @@
package datatypes

// OrderedSet represents an ordered set.
// TODO: make it a true **Ordered** set.
type OrderedSet struct {
filter map[string]bool
Values []string
}

// Init creates a new OrderedSet instance, and adds any given items into this set.
func (o *OrderedSet) Init(items ...string) {
o.filter = make(map[string]bool)
for _, item := range items {
o.Add(item)
}
}

// Add adds a new item into the ordered set.
func (o *OrderedSet) Add(item string) {
if !o.filter[item] {
o.filter[item] = true
o.Values = append(o.Values, item)
}
}

0 comments on commit 882021c

Please sign in to comment.
You canā€™t perform that action at this time.