mirror of
				https://github.com/taigrr/wtf
				synced 2025-01-18 04:03:14 -08:00 
			
		
		
		
	Merge pull request #227 from BillKeenan/createBarConfig
added length of bar to bargraph config
This commit is contained in:
		
						commit
						b7d99fe74d
					
				@ -11,11 +11,12 @@ wtf:
 | 
				
			|||||||
  mods:
 | 
					  mods:
 | 
				
			||||||
    bargraph:
 | 
					    bargraph:
 | 
				
			||||||
      enabled: true
 | 
					      enabled: true
 | 
				
			||||||
      graphIcon: "🍎"
 | 
					      starChar: "👿"
 | 
				
			||||||
 | 
					      stars: 25
 | 
				
			||||||
      position:
 | 
					      position:
 | 
				
			||||||
        top: 2
 | 
					        top: 3
 | 
				
			||||||
        left: 0
 | 
					        left: 0
 | 
				
			||||||
        height: 2
 | 
					        height: 1
 | 
				
			||||||
        width: 2
 | 
					        width: 2
 | 
				
			||||||
      refreshInterval: 30
 | 
					      refreshInterval: 30
 | 
				
			||||||
      updateInterval: 15
 | 
					      updateInterval: 15
 | 
				
			||||||
 | 
				
			|||||||
@ -50,8 +50,7 @@ func MakeGraph(widget *Widget) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	icon := wtf.Config.UString("wtf.mods.bargraph.graphIcon", "✭ ")
 | 
						widget.BarGraph.BuildBars(stats[:])
 | 
				
			||||||
	widget.BarGraph.BuildBars(20, icon, stats[:])
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -11,9 +11,10 @@ import (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
//BarGraph lets make graphs
 | 
					//BarGraph lets make graphs
 | 
				
			||||||
type BarGraph struct {
 | 
					type BarGraph struct {
 | 
				
			||||||
	enabled   bool
 | 
						enabled     bool
 | 
				
			||||||
	focusable bool
 | 
						focusable   bool
 | 
				
			||||||
 | 
						starChar    string
 | 
				
			||||||
 | 
						maxStars    int
 | 
				
			||||||
	Name        string
 | 
						Name        string
 | 
				
			||||||
	RefreshedAt time.Time
 | 
						RefreshedAt time.Time
 | 
				
			||||||
	RefreshInt  int
 | 
						RefreshInt  int
 | 
				
			||||||
@ -27,9 +28,10 @@ type BarGraph struct {
 | 
				
			|||||||
// NewBarGraph initialize your fancy new graph
 | 
					// NewBarGraph initialize your fancy new graph
 | 
				
			||||||
func NewBarGraph(name string, configKey string, focusable bool) BarGraph {
 | 
					func NewBarGraph(name string, configKey string, focusable bool) BarGraph {
 | 
				
			||||||
	widget := BarGraph{
 | 
						widget := BarGraph{
 | 
				
			||||||
		enabled:   Config.UBool(fmt.Sprintf("wtf.mods.%s.enabled", configKey), false),
 | 
							enabled:    Config.UBool(fmt.Sprintf("wtf.mods.%s.enabled", configKey), false),
 | 
				
			||||||
		focusable: focusable,
 | 
							focusable:  focusable,
 | 
				
			||||||
 | 
							starChar:   Config.UString(fmt.Sprintf("wtf.mods.%s.graphIcon", configKey), name),
 | 
				
			||||||
 | 
							maxStars:   Config.UInt(fmt.Sprintf("wtf.mods.%s.graphStars", configKey), 20),
 | 
				
			||||||
		Name:       Config.UString(fmt.Sprintf("wtf.mods.%s.title", configKey), name),
 | 
							Name:       Config.UString(fmt.Sprintf("wtf.mods.%s.title", configKey), name),
 | 
				
			||||||
		RefreshInt: Config.UInt(fmt.Sprintf("wtf.mods.%s.refreshInterval", configKey)),
 | 
							RefreshInt: Config.UInt(fmt.Sprintf("wtf.mods.%s.refreshInterval", configKey)),
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@ -99,7 +101,7 @@ func (widget *BarGraph) addView() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// BuildBars will build a string of * to represent your data of [time][value]
 | 
					// BuildBars will build a string of * to represent your data of [time][value]
 | 
				
			||||||
// time should be passed as a int64
 | 
					// time should be passed as a int64
 | 
				
			||||||
func (widget *BarGraph) BuildBars(maxStars int, starChar string, data [][2]int64) {
 | 
					func (widget *BarGraph) BuildBars(data [][2]int64) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var buffer bytes.Buffer
 | 
						var buffer bytes.Buffer
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -136,7 +138,7 @@ func (widget *BarGraph) BuildBars(maxStars int, starChar string, data [][2]int64
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// each number = how many stars?
 | 
						// each number = how many stars?
 | 
				
			||||||
	var starRatio = float64(maxStars) / float64((maxValue - minValue))
 | 
						var starRatio = float64(widget.maxStars) / float64((maxValue - minValue))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	//build the stars
 | 
						//build the stars
 | 
				
			||||||
	for i := range data {
 | 
						for i := range data {
 | 
				
			||||||
@ -149,7 +151,7 @@ func (widget *BarGraph) BuildBars(maxStars int, starChar string, data [][2]int64
 | 
				
			|||||||
			starCount = 1
 | 
								starCount = 1
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		//build the actual string
 | 
							//build the actual string
 | 
				
			||||||
		var stars = strings.Repeat(starChar, starCount)
 | 
							var stars = strings.Repeat(widget.starChar, starCount)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		//parse the time
 | 
							//parse the time
 | 
				
			||||||
		var t = time.Unix(int64(data[i][1]/1000), 0)
 | 
							var t = time.Unix(int64(data[i][1]/1000), 0)
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user