forked from x/icebergs
opt chart.go
This commit is contained in:
parent
7b9ada65ac
commit
7ce4da96ef
@ -58,10 +58,14 @@ func (g *Group) Get(group string) *ice.Message { return g.list[group] }
|
|||||||
|
|
||||||
func (g *Group) Join(arg ...string) string {
|
func (g *Group) Join(arg ...string) string {
|
||||||
args := []string{}
|
args := []string{}
|
||||||
for i := 0; i < len(arg)-1; i += 2 {
|
for i := 0; i < len(arg); i += 2 {
|
||||||
if arg[i] == "" {
|
if arg[i] == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if i == len(arg)-1 {
|
||||||
|
args = append(args, arg[i])
|
||||||
|
continue
|
||||||
|
}
|
||||||
args = append(args, kit.Format(`%s="%s"`, arg[i], arg[i+1]))
|
args = append(args, kit.Format(`%s="%s"`, arg[i], arg[i+1]))
|
||||||
}
|
}
|
||||||
return kit.Join(args, ice.SP)
|
return kit.Join(args, ice.SP)
|
||||||
|
@ -44,12 +44,12 @@ func (b *Block) Data(m *ice.Message, meta ice.Any) wiki.Chart {
|
|||||||
kit.Fetch(meta, func(key string, value string) {
|
kit.Fetch(meta, func(key string, value string) {
|
||||||
switch key {
|
switch key {
|
||||||
case wiki.FG:
|
case wiki.FG:
|
||||||
b.TextData += kit.Format("%s='%s' ", wiki.FILL, value)
|
b.TextData += kit.Format("%s='%s' %s='%s'", wiki.FILL, value, wiki.STROKE, value)
|
||||||
case wiki.BG:
|
case wiki.BG:
|
||||||
b.RectData += kit.Format("%s='%s' ", wiki.FILL, value)
|
b.RectData += kit.Format("%s='%s' ", wiki.FILL, value)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
kit.Fetch(kit.Value(meta, "text"), func(key string, value string) {
|
kit.Fetch(kit.Value(meta, "data"), func(key string, value string) {
|
||||||
b.TextData += kit.Format("%s='%s' ", key, value)
|
b.TextData += kit.Format("%s='%s' ", key, value)
|
||||||
})
|
})
|
||||||
kit.Fetch(kit.Value(meta, "rect"), func(key string, value string) {
|
kit.Fetch(kit.Value(meta, "rect"), func(key string, value string) {
|
||||||
|
@ -57,9 +57,11 @@ func (c *Chain) draw(m *ice.Message, root ice.Map, x, y int, p *Block, gs *wiki.
|
|||||||
meta := kit.GetMeta(root)
|
meta := kit.GetMeta(root)
|
||||||
item := p.Fork(m, kit.Format(meta[mdb.TEXT]))
|
item := p.Fork(m, kit.Format(meta[mdb.TEXT]))
|
||||||
item.x, item.y = x, y+(kit.Int(meta[wiki.HEIGHT])-1)*c.GetHeights()/2
|
item.x, item.y = x, y+(kit.Int(meta[wiki.HEIGHT])-1)*c.GetHeights()/2
|
||||||
|
m.Debug("what %#v", meta)
|
||||||
|
item.Data(m, meta)
|
||||||
|
|
||||||
if p != nil && p.y != 0 {
|
if p != nil && p.y != 0 {
|
||||||
padding := item.GetHeights() / 2
|
padding := item.GetHeight() / 2
|
||||||
if m.Option(SHOW_BLOCK) == ice.TRUE {
|
if m.Option(SHOW_BLOCK) == ice.TRUE {
|
||||||
padding = 0
|
padding = 0
|
||||||
}
|
}
|
||||||
@ -68,11 +70,11 @@ func (c *Chain) draw(m *ice.Message, root ice.Map, x, y int, p *Block, gs *wiki.
|
|||||||
gs.EchoPath(SHIP, "M %d,%d Q %d,%d %d,%d T %d %d", x1, y1, x1+(x4-x1)/4, y1, x1+(x4-x1)/2, y1+(y4-y1)/2, x4, y4)
|
gs.EchoPath(SHIP, "M %d,%d Q %d,%d %d,%d T %d %d", x1, y1, x1+(x4-x1)/4, y1, x1+(x4-x1)/2, y1+(y4-y1)/2, x4, y4)
|
||||||
}
|
}
|
||||||
if m.Option(SHOW_BLOCK) == ice.TRUE {
|
if m.Option(SHOW_BLOCK) == ice.TRUE {
|
||||||
gs.EchoRect(RECT, item.GetHeight(), item.GetWidth(), item.x+item.MarginX/2, item.y+item.MarginY/2)
|
gs.EchoRect(RECT, item.GetHeight(), item.GetWidth(), item.x+item.MarginX/2, item.y+item.MarginY/2, "4", "4", item.RectData)
|
||||||
} else {
|
} else {
|
||||||
gs.EchoLine(LINE, item.x+item.MarginX/2, item.y+item.GetHeights(), item.x+item.GetWidths()-item.MarginX/2, item.y+item.GetHeights())
|
gs.EchoLine(LINE, item.x+item.MarginX/2, item.y+item.GetHeights()-item.MarginY/2, item.x+item.GetWidths()-item.MarginX/2, item.y+item.GetHeights()-item.MarginY/2)
|
||||||
}
|
}
|
||||||
gs.EchoTexts(TEXT, item.x+item.GetWidths()/2, item.y+item.GetHeights()/2, item.Text)
|
gs.EchoTexts(TEXT, item.x+item.GetWidths()/2, item.y+item.GetHeights()/2, item.Text, item.TextData)
|
||||||
|
|
||||||
h, x := 0, x+item.GetWidths()
|
h, x := 0, x+item.GetWidths()
|
||||||
if kit.Fetch(root[mdb.LIST], func(value ice.Map) { h += c.draw(m, value, x, y+h, item, gs) }); h == 0 {
|
if kit.Fetch(root[mdb.LIST], func(value ice.Map) { h += c.draw(m, value, x, y+h, item, gs) }); h == 0 {
|
||||||
@ -94,9 +96,9 @@ const CHAIN = "chain"
|
|||||||
func init() {
|
func init() {
|
||||||
wiki.AddChart(CHAIN, func(m *ice.Message) wiki.Chart {
|
wiki.AddChart(CHAIN, func(m *ice.Message) wiki.Chart {
|
||||||
m.Option(wiki.FONT_SIZE, "16")
|
m.Option(wiki.FONT_SIZE, "16")
|
||||||
m.Option(wiki.MARGINX, "40")
|
m.Option(wiki.MARGINX, "60")
|
||||||
m.Option(wiki.MARGINY, "4")
|
m.Option(wiki.MARGINY, "20")
|
||||||
m.Option(wiki.PADDING, "6")
|
m.Option(wiki.PADDING, "10")
|
||||||
wiki.AddGroupOption(m, SHIP, wiki.FILL, cli.GLASS)
|
wiki.AddGroupOption(m, SHIP, wiki.FILL, cli.GLASS)
|
||||||
wiki.AddGroupOption(m, TEXT, wiki.STROKE_WIDTH, "1")
|
wiki.AddGroupOption(m, TEXT, wiki.STROKE_WIDTH, "1")
|
||||||
return &Chain{}
|
return &Chain{}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user