1
0
mirror of https://shylinux.com/x/icebergs synced 2025-06-26 18:37:29 +08:00
This commit is contained in:
harveyshao 2022-11-04 23:15:07 +08:00
parent 7ce4da96ef
commit 1dea5983e1
4 changed files with 32 additions and 75 deletions

View File

@ -58,14 +58,10 @@ func (g *Group) Get(group string) *ice.Message { return g.list[group] }
func (g *Group) Join(arg ...string) string {
args := []string{}
for i := 0; i < len(arg); i += 2 {
for i := 0; i < len(arg)-1; i += 2 {
if arg[i] == "" {
continue
}
if i == len(arg)-1 {
args = append(args, arg[i])
continue
}
args = append(args, kit.Format(`%s="%s"`, arg[i], arg[i+1]))
}
return kit.Join(args, ice.SP)
@ -91,6 +87,10 @@ func (g *Group) EchoText(group string, x, y int, text string, arg ...string) *ic
func (g *Group) EchoTexts(group string, x, y int, text string, arg ...string) *ice.Message {
m := g.Get(group)
float := kit.Int(kit.Select("2", "7", kit.Contains(m.Option(ice.MSG_USERUA), "iPhone")))
if strings.Contains(m.Option(ice.MSG_USERUA), "Chrome") || strings.Contains(m.Option(ice.MSG_USERUA), "Mobile") {
} else {
float += 4
}
return g.EchoText(group, x, y+float, text, arg...)
}
func (g *Group) DefsArrow(group string, height, width int, arg ...string) *ice.Message { // name

View File

@ -57,7 +57,6 @@ func (c *Chain) draw(m *ice.Message, root ice.Map, x, y int, p *Block, gs *wiki.
meta := kit.GetMeta(root)
item := p.Fork(m, kit.Format(meta[mdb.TEXT]))
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 {
@ -70,7 +69,7 @@ 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)
}
if m.Option(SHOW_BLOCK) == ice.TRUE {
gs.EchoRect(RECT, item.GetHeight(), item.GetWidth(), item.x+item.MarginX/2, item.y+item.MarginY/2, "4", "4", item.RectData)
gs.EchoRect(RECT, item.GetHeight(), item.GetWidth(), item.x+item.MarginX/2, item.y+item.MarginY/2)
} else {
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)
}
@ -95,7 +94,7 @@ const CHAIN = "chain"
func init() {
wiki.AddChart(CHAIN, func(m *ice.Message) wiki.Chart {
m.Option(wiki.FONT_SIZE, "16")
m.Option(wiki.FONT_SIZE, "18")
m.Option(wiki.MARGINX, "60")
m.Option(wiki.MARGINY, "20")
m.Option(wiki.PADDING, "10")

View File

@ -1,8 +1,6 @@
package chart
import (
"strings"
ice "shylinux.com/x/icebergs"
"shylinux.com/x/icebergs/base/lex"
"shylinux.com/x/icebergs/base/nfs"
@ -62,23 +60,9 @@ func (s *Label) Draw(m *ice.Message, x, y int) wiki.Chart {
}
if m.Option(HIDE_BLOCK) != ice.TRUE {
args := []string{"4", "4"}
if mod := kit.Int(m.Option("order.mod")); mod != 0 && i%mod == 0 {
args = append(args, wiki.FILL, m.Option("order.bg"))
}
gs.EchoRect(RECT, item.GetHeight(), item.GetWidth(), left+item.MarginX/2, top+item.MarginY/2, args...)
}
args := []string{}
if mod := kit.Int(m.Option("order.mod")); mod != 0 && i%mod == 0 {
args = append(args, wiki.STROKE, m.Option("order.fg"))
args = append(args, wiki.FILL, m.Option("order.fg"))
}
if strings.Contains(m.Option(ice.MSG_USERUA), "Chrome") || strings.Contains(m.Option(ice.MSG_USERUA), "Mobile") {
gs.EchoTexts(TEXT, left+item.GetWidths()/2, top+item.GetHeights()/2, item.Text, args...)
} else {
gs.EchoTexts(TEXT, left+item.GetWidths()/2, top+item.GetHeights()/2+4, item.Text, args...)
gs.EchoRect(RECT, item.GetHeight(), item.GetWidth(), left+item.MarginX/2, top+item.MarginY/2)
}
gs.EchoTexts(TEXT, left+item.GetWidths()/2, top+item.GetHeights()/2, item.Text)
if left += item.GetWidths(); item.GetHeights() > height {
height = item.GetHeights()

View File

@ -4,7 +4,6 @@ import (
ice "shylinux.com/x/icebergs"
"shylinux.com/x/icebergs/base/cli"
"shylinux.com/x/icebergs/base/lex"
"shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/nfs"
"shylinux.com/x/icebergs/core/wiki"
kit "shylinux.com/x/toolkits"
@ -21,23 +20,19 @@ type Sequence struct {
func (s *Sequence) push(m *ice.Message, list string, arg ...ice.Any) ice.Map {
node, node_list := kit.Dict(arg...), kit.Int(list)
s.list[node_list] = append(s.list[node_list], node)
// _max := kit.Max(len(s.list[node_list])-1, s.pos[node_list])
_max := kit.Max(len(s.list[node_list])-1, s.max)
node[ORDER], s.pos[node_list] = _max, _max+1
return node
}
func (s *Sequence) Init(m *ice.Message, arg ...string) wiki.Chart {
(&s.Block).Init(m)
// 解析数据
m.Option(lex.SPLIT_BLOCK, ice.SP)
m.Cmd(lex.SPLIT, "", kit.Dict(nfs.CAT_CONTENT, arg[0]), func(ls []string, data ice.Map) []string {
if len(s.head) == 0 { // 添加标题
m.Cmd(lex.SPLIT, "", kit.Dict(lex.SPLIT_BLOCK, ice.SP, nfs.CAT_CONTENT, arg[0]), func(ls []string) {
if len(s.head) == 0 {
s.head, s.pos = ls, make([]int, len(ls))
for i := 0; i < len(ls); i++ {
s.list = append(s.list, []ice.Map{})
}
return ls
return
}
from_node := s.push(m, ls[0])
@ -49,13 +44,11 @@ func (s *Sequence) Init(m *ice.Message, arg ...string) wiki.Chart {
list[ls[i+1]] = to_node
step++
// 层级
_max := kit.Max(kit.Int(from_node[ORDER]), kit.Int(to_node[ORDER]), s.max)
s.pos[kit.Int(ls[i-1])], s.pos[kit.Int(ls[i+1])] = _max+1, _max+1
from_node[ORDER], to_node[ORDER] = _max, _max
// 连接
from_node[mdb.TEXT], from_node[mdb.NEXT] = kit.Format("%d.%d %s", s.max+1, step, ls[i]), ls[i+1]
from_node[TEXT], from_node[NEXT] = kit.Format("%d.%d %s", s.max+1, step, ls[i]), ls[i+1]
to_node[ECHO], to_node[PREV] = "", ls[i-1]
} else {
from_node[ECHO], from_node[PREV] = ls[i], ls[i+1]
@ -63,10 +56,9 @@ func (s *Sequence) Init(m *ice.Message, arg ...string) wiki.Chart {
from_node = to_node
}
s.max++
return ls
return
})
// 计算尺寸
width := 0
for _, v := range s.head {
width += s.Block.GetWidths(v)
@ -80,11 +72,7 @@ func (s *Sequence) Draw(m *ice.Message, x, y int) wiki.Chart {
wiki.AddGroupOption(m, TITLE, wiki.FILL, m.Option(wiki.STROKE))
wiki.AddGroupOption(m, TEXT, wiki.FILL, m.Option(wiki.STROKE))
wiki.AddGroupOption(m, ECHO, wiki.FILL, m.Option(wiki.STROKE))
defer func() { // 输出
gs.Dump(m, HEAD).Dump(m, TITLE).Dump(m, LINE)
gs.Dump(m, RECT).Dump(m, NEXT).Dump(m, PREV)
gs.Dump(m, TEXT).Dump(m, ECHO)
}()
defer gs.DumpAll(m, HEAD, TITLE, LINE, RECT, NEXT, PREV, TEXT, ECHO)
rect_width := kit.Int(gs.Option(RECT, wiki.WIDTH))
rect_height := kit.Int(gs.Option(RECT, wiki.HEIGHT))
@ -95,39 +83,36 @@ func (s *Sequence) Draw(m *ice.Message, x, y int) wiki.Chart {
gs.DefsArrow(NEXT, arrow_height, arrow_width, NEXT)
gs.DefsArrow(PREV, arrow_height, arrow_width, PREV)
height := s.Height
s.Block.Height, s.Block.Width = 0, 0
line_pos := make([]int, len(s.list))
for i := range s.list { // 标题
s.Block.Text = s.head[i]
gs.EchoRect(HEAD, s.Block.GetHeight(), s.Block.GetWidth(), x+s.Block.MarginX/2, y+s.Block.MarginY/2)
gs.EchoTexts(TITLE, x+s.Block.GetWidths()/2, y+s.Block.GetHeights()/2, s.head[i])
line_pos[i], x = x+s.Block.GetWidths()/2, x+s.Block.GetWidths()
}
y += s.Block.GetHeight() + s.MarginY/2
for _, x := range line_pos { // 竖线
gs.EchoLine(LINE, x, y, x, height-s.MarginY/2)
line_pos, height := make([]int, len(s.list)), 0
for i, head := range s.head {
item := s.Fork(m, head)
pos := x + item.GetWidths()/2
gs.EchoLine(LINE, pos, item.GetHeight()+item.MarginY/2, pos, s.Height-s.MarginY/2)
gs.EchoRect(HEAD, item.GetHeight(), item.GetWidth(), x+item.MarginX/2, y+item.MarginY/2)
gs.EchoTexts(TITLE, pos, y+item.GetHeights()/2, head)
height = item.GetHeight() + item.MarginY/2
line_pos[i], x = pos, x+item.GetWidths()
}
y += height
for i, x := range line_pos {
for _, v := range s.list[i] {
pos := kit.Int(v[ORDER])
gs.EchoRect(RECT, rect_height, rect_width, x-rect_width/2, y+pos*(rect_height+s.MarginY)+s.MarginY, "2", "2")
gs.EchoRect(RECT, rect_height, rect_width, x-rect_width/2, y+pos*(rect_height+s.MarginY)+s.MarginY, "0", "0")
yy := y + pos*(rect_height+s.MarginY) + s.MarginY + rect_height/4
if kit.Format(v[mdb.NEXT]) != "" { // 请求
xx := line_pos[kit.Int(v[mdb.NEXT])]
if kit.Format(v[NEXT]) != "" {
xx := line_pos[kit.Int(v[NEXT])]
if x < xx {
gs.EchoArrowLine(NEXT, x+rect_width/2, yy, xx-rect_width/2-arrow_width, yy, NEXT)
} else {
gs.EchoArrowLine(NEXT, x-rect_width/2, yy, xx+rect_width/2+arrow_width, yy, NEXT)
}
gs.EchoText(TEXT, (x+xx)/2, yy-text_size/2, kit.Format(v[mdb.TEXT]))
gs.EchoText(TEXT, (x+xx)/2, yy-text_size/2, kit.Format(v[TEXT]))
}
yy += rect_height / 2
if kit.Format(v[PREV]) != "" { // 响应
if kit.Format(v[PREV]) != "" {
xx := line_pos[kit.Int(v[PREV])]
if x < xx {
gs.EchoArrowLine(PREV, x+rect_width/2, yy, xx-rect_width/2-arrow_width, yy, PREV)
@ -157,26 +142,15 @@ const SEQUENCE = "sequence"
func init() {
wiki.AddChart(SEQUENCE, func(m *ice.Message) wiki.Chart {
m.Option(wiki.STROKE_WIDTH, "1")
m.Option(wiki.MARGINX, "40")
m.Option(wiki.MARGINY, "40")
m.Option(wiki.STROKE_WIDTH, "1")
switch m.Option("topic") {
case cli.WHITE:
m.Option(wiki.STROKE, cli.BLACK)
m.Option(wiki.FILL, cli.WHITE)
case cli.BLACK:
m.Option(wiki.STROKE, cli.WHITE)
m.Option(wiki.FILL, cli.BLACK)
default:
m.Option(wiki.STROKE, cli.BLACK)
m.Option(wiki.FILL, cli.WHITE)
}
wiki.AddGroupOption(m, LINE, wiki.STROKE_DASHARRAY, "20 4 4 4")
wiki.AddGroupOption(m, RECT, wiki.HEIGHT, "40", wiki.WIDTH, "14")
wiki.AddGroupOption(m, PREV, wiki.STROKE_DASHARRAY, "10 2")
wiki.AddGroupOption(m, TEXT, wiki.FONT_SIZE, "16")
wiki.AddGroupOption(m, ECHO, wiki.FONT_SIZE, "12")
wiki.AddGroupOption(m, ARROW, wiki.HEIGHT, "8", wiki.WIDTH, "18", wiki.FILL, cli.GLASS)
wiki.AddGroupOption(m, ARROW, wiki.HEIGHT, "6", wiki.WIDTH, "12", wiki.FILL, cli.GLASS)
return &Sequence{}
})
}