1
0
mirror of https://shylinux.com/x/icebergs synced 2025-04-26 09:34:05 +08:00

opt chart.go

This commit is contained in:
harveyshao 2022-11-04 16:25:39 +08:00
parent b0346ea915
commit 7b9ada65ac
11 changed files with 144 additions and 168 deletions

View File

@ -55,6 +55,11 @@ func _split_list(m *ice.Message, file string, arg ...string) ice.Map {
switch cb := m.OptionCB(SPLIT).(type) { switch cb := m.OptionCB(SPLIT).(type) {
case func(int, []string) []string: case func(int, []string) []string:
ls = cb(deep, ls) ls = cb(deep, ls)
case func(int, []string, ice.Map, ice.List):
case func(int, []string, ice.Map, ice.Map):
root, _ := kit.Value(list[0], "list.0").(ice.Map)
cb(deep, ls, data, root)
case func(int, []string, ice.Map) []string: case func(int, []string, ice.Map) []string:
ls = cb(deep, ls, data) ls = cb(deep, ls, data)
case func([]string, ice.Map) []string: case func([]string, ice.Map) []string:

View File

@ -4,8 +4,6 @@ import (
"strings" "strings"
ice "shylinux.com/x/icebergs" ice "shylinux.com/x/icebergs"
"shylinux.com/x/icebergs/base/cli"
"shylinux.com/x/icebergs/base/nfs"
kit "shylinux.com/x/toolkits" kit "shylinux.com/x/toolkits"
) )
@ -36,14 +34,10 @@ func (item *Item) Push(str string, arg ice.Any) *Item {
return item return item
} }
func (item *Item) Dump(m *ice.Message) *ice.Message { func (item *Item) Dump(m *ice.Message) *ice.Message {
m.Echo(kit.Join(item.list, ice.SP), item.args...) return m.Echo(kit.Join(item.list, ice.SP), item.args...).Echo(ice.NL)
m.Echo(ice.NL)
return m
} }
type Group struct { type Group struct{ list ice.Messages }
list ice.Messages
}
func NewGroup(m *ice.Message, arg ...string) *Group { func NewGroup(m *ice.Message, arg ...string) *Group {
g := &Group{list: ice.Messages{}} g := &Group{list: ice.Messages{}}
@ -75,12 +69,15 @@ func (g *Group) Join(arg ...string) string {
func (g *Group) Echo(group string, str string, arg ...ice.Any) *ice.Message { func (g *Group) Echo(group string, str string, arg ...ice.Any) *ice.Message {
return g.Get(group).Echo(str, arg...) return g.Get(group).Echo(str, arg...)
} }
func (g *Group) EchoRect(group string, height, width, x, y int, arg ...string) *ice.Message { // rx ry func (g *Group) EchoPath(group string, str string, arg ...ice.Any) *ice.Message {
return g.Echo(group, `<rect height=%d width=%d rx=%s ry=%s x=%d y=%d %s/>`, height, width, kit.Select("4", arg, 0), kit.Select("4", arg, 1), x, y, g.Join(kit.Slice(arg, 2)...)) return g.Echo(group, `<path d="%s"></path>`, kit.Format(str, arg...))
} }
func (g *Group) EchoLine(group string, x1, y1, x2, y2 int) *ice.Message { func (g *Group) EchoLine(group string, x1, y1, x2, y2 int) *ice.Message {
return g.Echo(group, "<line x1=%d y1=%d x2=%d y2=%d></line>", x1, y1, x2, y2) return g.Echo(group, "<line x1=%d y1=%d x2=%d y2=%d></line>", x1, y1, x2, y2)
} }
func (g *Group) EchoRect(group string, height, width, x, y int, arg ...string) *ice.Message { // rx ry
return g.Echo(group, `<rect height=%d width=%d rx=%s ry=%s x=%d y=%d %s/>`, height, width, kit.Select("4", arg, 0), kit.Select("4", arg, 1), x, y, g.Join(kit.Slice(arg, 2)...))
}
func (g *Group) EchoText(group string, x, y int, text string, arg ...string) *ice.Message { func (g *Group) EchoText(group string, x, y int, text string, arg ...string) *ice.Message {
if text == "" { if text == "" {
return g.Get(group) return g.Get(group)
@ -115,12 +112,17 @@ func (g *Group) Dump(m *ice.Message, group string, arg ...string) *Group {
item.Echo(">").Dump(m).Copy(g.Get(group)).Echo("</g>") item.Echo(">").Dump(m).Copy(g.Get(group)).Echo("</g>")
return g return g
} }
func (g *Group) DumpAll(m *ice.Message, group ...string) *Group {
for _, grp := range group {
g.Dump(m, grp)
}
return g
}
type Chart interface { type Chart interface {
Init(*ice.Message, ...string) Chart Init(*ice.Message, ...string) Chart
Data(*ice.Message, ice.Any) Chart
Draw(*ice.Message, int, int) Chart Draw(*ice.Message, int, int) Chart
Data(*ice.Message, ice.Any) Chart
GetHeight(...string) int GetHeight(...string) int
GetWidth(...string) int GetWidth(...string) int
} }
@ -130,37 +132,23 @@ var chart_list = map[string]func(m *ice.Message) Chart{}
func AddChart(name string, hand func(m *ice.Message) Chart) { chart_list[name] = hand } func AddChart(name string, hand func(m *ice.Message) Chart) { chart_list[name] = hand }
func _chart_show(m *ice.Message, kind, text string, arg ...string) { func _chart_show(m *ice.Message, kind, text string, arg ...string) {
// 默认参数
m.Option(STROKE_WIDTH, "2")
switch m.Option("topic") {
case "black":
m.Option(STROKE, cli.YELLOW)
m.Option(FILL, cli.YELLOW)
default:
m.Option(STROKE, cli.BLUE)
m.Option(FILL, cli.YELLOW)
}
m.Option(FONT_SIZE, "24") m.Option(FONT_SIZE, "24")
m.Option(FONT_FAMILY, "monospace") m.Option(STROKE_WIDTH, "2")
chart := chart_list[kind](m) chart := chart_list[kind](m)
// 解析参数
for i := 0; i < len(arg)-1; i++ { for i := 0; i < len(arg)-1; i++ {
m.Option(arg[i], arg[i+1]) m.Option(arg[i], arg[i+1])
} }
m.Option(FILL, kit.Select(m.Option(FILL), m.Option(BG))) m.Option(FILL, kit.Select(m.Option(FILL), m.Option(BG)))
m.Option(STROKE, kit.Select(m.Option(STROKE), m.Option(FG))) m.Option(STROKE, kit.Select(m.Option(STROKE), m.Option(FG)))
// 计算尺寸
chart.Init(m, text) chart.Init(m, text)
m.Option(WIDTH, chart.GetWidth()) m.Option(WIDTH, chart.GetWidth())
m.Option(HEIGHT, chart.GetHeight()) m.Option(HEIGHT, chart.GetHeight())
// 渲染引擎
_wiki_template(m, "", text, arg...) _wiki_template(m, "", text, arg...)
defer m.Echo("</svg>") defer m.Echo("</svg>")
defer m.RenderResult()
chart.Draw(m, 0, 0) chart.Draw(m, 0, 0)
m.RenderResult()
} }
const ( const (
@ -188,18 +176,15 @@ const (
const CHART = "chart" const CHART = "chart"
func init() { func init() {
Index.Merge(&ice.Context{Commands: ice.Commands{ Index.MergeCommands(ice.Commands{
CHART: {Name: "chart type=label,chain,sequence auto text", Help: "图表", Hand: func(m *ice.Message, arg ...string) { CHART: {Name: "chart type=label,chain,sequence auto text", Help: "图表", Actions: WordAction(
`<svg xmlns="http://www.w3.org/2000/svg" vertion="1.1"
{{.OptionTemplate}} {{.OptionKV "height,width,font-size,font-family,stroke-width,stroke,fill"}}
text-anchor="middle" dominant-baseline="middle">`,
), Hand: func(m *ice.Message, arg ...string) {
if len(arg) > 1 { if len(arg) > 1 {
_chart_show(m, arg[0], strings.TrimSpace(arg[1]), arg[2:]...) _chart_show(m, arg[0], strings.TrimSpace(arg[1]), arg[2:]...)
} }
}}, }},
}, Configs: ice.Configs{ })
CHART: {Name: CHART, Help: "图表", Value: kit.Data(
nfs.TEMPLATE, `<svg xmlns="http://www.w3.org/2000/svg" vertion="1.1"
{{.OptionTemplate}} data-index="{{.Option "index"}}" height="{{.Option "height"}}" width="{{.Option "width"}}"
stroke-width="{{.Option "stroke-width"}}" stroke="{{.Option "stroke"}}" fill="{{.Option "fill"}}"
font-size="{{.Option "font-size"}}" font-family="{{.Option "font-family"}}" text-anchor="middle" dominant-baseline="middle">`,
)},
}})
} }

View File

@ -10,21 +10,22 @@ import (
) )
type Block struct { type Block struct {
Text string Text string
FontSize int
FontColor string
BackGround string
TextData string TextData string
RectData string RectData string
Padding int FontSize int
MarginX int Padding int
MarginY int MarginX int
MarginY int
Height int Height int
Width int Width int
x, y int x, y int
FontColor string
BackGround string
} }
func (b *Block) Init(m *ice.Message, arg ...string) wiki.Chart { func (b *Block) Init(m *ice.Message, arg ...string) wiki.Chart {
@ -48,7 +49,7 @@ func (b *Block) Data(m *ice.Message, meta ice.Any) wiki.Chart {
b.RectData += kit.Format("%s='%s' ", wiki.FILL, value) b.RectData += kit.Format("%s='%s' ", wiki.FILL, value)
} }
}) })
kit.Fetch(kit.Value(meta, "data"), func(key string, value string) { kit.Fetch(kit.Value(meta, "text"), 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) {
@ -58,7 +59,7 @@ func (b *Block) Data(m *ice.Message, meta ice.Any) wiki.Chart {
} }
func (b *Block) Draw(m *ice.Message, x, y int) wiki.Chart { func (b *Block) Draw(m *ice.Message, x, y int) wiki.Chart {
float := kit.Int(kit.Select("2", "7", strings.Contains(m.Option(ice.MSG_USERUA), "iPhone"))) float := kit.Int(kit.Select("2", "7", strings.Contains(m.Option(ice.MSG_USERUA), "iPhone")))
if m.Option(SHOW_BLOCK) == ice.TRUE { if m.Option(HIDE_BLOCK) != ice.TRUE {
item := wiki.NewItem([]string{`<rect height="%d" width="%d" rx="4" ry="4" x="%d" y="%d"`}, b.GetHeight(), b.GetWidth(), x+b.MarginX/2, y+b.MarginY/2) item := wiki.NewItem([]string{`<rect height="%d" width="%d" rx="4" ry="4" x="%d" y="%d"`}, b.GetHeight(), b.GetWidth(), x+b.MarginX/2, y+b.MarginY/2)
item.Push(`fill="%s"`, b.BackGround).Push(`%v`, b.RectData).Echo("/>").Dump(m) item.Push(`fill="%s"`, b.BackGround).Push(`%v`, b.RectData).Echo("/>").Dump(m)
} }
@ -68,6 +69,9 @@ func (b *Block) Draw(m *ice.Message, x, y int) wiki.Chart {
item.Push(`stroke="%s"`, b.FontColor).Push(`fill="%s"`, b.FontColor).Push("%v", b.TextData).Push(`>%v</text>`, b.Text).Dump(m) item.Push(`stroke="%s"`, b.FontColor).Push(`fill="%s"`, b.FontColor).Push("%v", b.TextData).Push(`>%v</text>`, b.Text).Dump(m)
return b return b
} }
func (b *Block) Fork(m *ice.Message, arg ...string) *Block {
return &Block{Text: kit.Select("", arg, 0), FontSize: b.FontSize, Padding: b.Padding, MarginX: b.MarginX, MarginY: b.MarginY}
}
func (b *Block) GetHeight(str ...string) int { func (b *Block) GetHeight(str ...string) int {
if b.Height != 0 { if b.Height != 0 {

View File

@ -12,105 +12,93 @@ import (
type Chain struct { type Chain struct {
data ice.Map data ice.Map
gs *wiki.Group
Block Block
} }
func (c *Chain) Init(m *ice.Message, arg ...string) wiki.Chart { func (c *Chain) Init(m *ice.Message, arg ...string) wiki.Chart {
(&c.Block).Init(m) (&c.Block).Init(m)
const _DEEP = "_deep"
m.Option(nfs.CAT_CONTENT, arg[0]) stack, max := kit.List(kit.Dict(_DEEP, -1, wiki.WIDTH, "0")), 0
m.Option(lex.SPLIT_BLOCK, ice.SP) last := func(key string) int { return kit.Int(kit.Value(stack[len(stack)-1], key)) }
max, stack := 0, kit.List(kit.Dict("_deep", -1, "width", "0")) m.Cmd(lex.SPLIT, "", mdb.TEXT, kit.Dict(lex.SPLIT_BLOCK, ice.SP, nfs.CAT_CONTENT, arg[0]), func(deep int, ls []string, data, root ice.Map) {
m.OptionCB(lex.SPLIT, func(deep int, ls []string, data ice.Map) []string { for deep <= last(_DEEP) {
for deep <= kit.Int(kit.Value(stack[len(stack)-1], "_deep")) {
stack = stack[:len(stack)-1] stack = stack[:len(stack)-1]
} }
width := kit.Int(kit.Value(stack[len(stack)-1], "width")) + c.GetWidths(ls[0]) width := last(wiki.WIDTH) + c.GetWidths(ls[0])
stack = append(stack, kit.Dict("_deep", deep, "width", width)) if stack = append(stack, kit.Dict(_DEEP, deep, wiki.WIDTH, width)); width > max {
if width > max {
max = width max = width
} }
return ls c.data = root
}) })
c.data = lex.Split(m, "", mdb.TEXT) c.Height, c.Width = c.height(m, c.data)*c.GetHeights(), max
c.Height, c.Width = c.size(m, c.data)*c.GetHeights(), max
return c return c
} }
func (c *Chain) Draw(m *ice.Message, x, y int) wiki.Chart { func (c *Chain) Draw(m *ice.Message, x, y int) wiki.Chart {
c.gs = wiki.NewGroup(m, SHIP, RECT, LINE, TEXT) gs := wiki.NewGroup(m, SHIP, LINE, RECT, TEXT)
wiki.AddGroupOption(m, LINE, wiki.STROKE, c.gs.Option(SHIP, wiki.STROKE)) wiki.AddGroupOption(m, LINE, wiki.STROKE, gs.Option(SHIP, wiki.STROKE))
wiki.AddGroupOption(m, TEXT, wiki.FILL, m.Option(wiki.STROKE), wiki.STROKE_WIDTH, "1") wiki.AddGroupOption(m, TEXT, wiki.FILL, m.Option(wiki.STROKE))
defer func() { c.gs.Dump(m, SHIP).Dump(m, RECT).Dump(m, LINE).Dump(m, TEXT) }() defer gs.DumpAll(m, SHIP, LINE, RECT, TEXT)
c.Height, c.Width = 0, 0 c.Height, c.Width = 0, 0
c.draw(m, c.data, x, y, &c.Block) c.draw(m, c.data, x, y, &c.Block, gs)
return c return c
} }
func (c *Chain) height(m *ice.Message, root ice.Map) (height int) {
func (c *Chain) size(m *ice.Message, root ice.Map) (height int) {
meta := kit.GetMeta(root) meta := kit.GetMeta(root)
if list, ok := root[mdb.LIST].([]ice.Any); ok && len(list) > 0 { if list, ok := root[mdb.LIST].([]ice.Any); ok && len(list) > 0 {
kit.Fetch(root[mdb.LIST], func(index int, value ice.Map) { height += c.size(m, value) }) kit.Fetch(root[mdb.LIST], func(index int, value ice.Map) { height += c.height(m, value) })
} else { } else {
height = 1 height = 1
} }
meta[wiki.HEIGHT] = height meta[wiki.HEIGHT] = height
return height return height
} }
func (c *Chain) draw(m *ice.Message, root ice.Map, x, y int, p *Block) int { func (c *Chain) draw(m *ice.Message, root ice.Map, x, y int, p *Block, gs *wiki.Group) int {
meta := kit.GetMeta(root) meta := kit.GetMeta(root)
item := p.Fork(m, kit.Format(meta[mdb.TEXT]))
item := &Block{FontSize: p.FontSize, Padding: p.Padding, MarginX: p.MarginX, MarginY: p.MarginY}
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
item.Text = kit.Format(meta[mdb.TEXT])
if m.Option(SHOW_BLOCK) == ice.TRUE { // 方框
c.gs.EchoRect(RECT, item.GetHeight(), item.GetWidth(), item.x+item.MarginX/2, item.y+item.MarginY/2)
} else { // 横线
c.gs.EchoLine(LINE, item.x+item.MarginX/2, item.y+item.GetHeight()+item.Padding/2, item.x+item.GetWidths()-item.MarginX/2, item.y+item.GetHeight()+item.Padding/2)
}
// 文本 if p != nil && p.y != 0 {
c.gs.EchoTexts(TEXT, item.x+item.GetWidths()/2, item.y+item.GetHeights()/2, kit.Format(meta[mdb.TEXT])) padding := item.GetHeights() / 2
if p != nil && p.y != 0 { // 连线
if m.Option(SHOW_BLOCK) == ice.TRUE { if m.Option(SHOW_BLOCK) == ice.TRUE {
x1, y1 := p.x+p.GetWidths()-(p.MarginX+item.MarginX)/4, p.y+p.GetHeights()/2 padding = 0
x4, y4 := item.x+(p.MarginX+item.MarginX)/4, item.y+item.GetHeights()/2
c.gs.Echo(SHIP, `<path d="M %d,%d Q %d,%d %d,%d T %d %d"></path>`, x1, y1, x1+(x4-x1)/4, y1, x1+(x4-x1)/2, y1+(y4-y1)/2, x4, y4)
} else {
x1, y1 := p.x+p.GetWidths()-(p.MarginX+item.MarginX)/4, p.y+p.GetHeight()+item.Padding/2
x4, y4 := item.x+(p.MarginX+item.MarginX)/4, item.y+item.GetHeight()+item.Padding/2
c.gs.Echo(SHIP, `<path d="M %d,%d Q %d,%d %d,%d T %d %d"></path>`, x1, y1, x1+(x4-x1)/4, y1, x1+(x4-x1)/2, y1+(y4-y1)/2, x4, y4)
} }
x4, y4 := item.x+(p.MarginX+item.MarginX)/4, item.y+item.GetHeights()/2+padding
x1, y1 := p.x+p.GetWidths()-(p.MarginX+item.MarginX)/4, p.y+p.GetHeights()/2+padding
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)
} 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.EchoTexts(TEXT, item.x+item.GetWidths()/2, item.y+item.GetHeights()/2, item.Text)
// 递归
h, x := 0, x+item.GetWidths() h, x := 0, x+item.GetWidths()
if kit.Fetch(root[mdb.LIST], func(index int, value ice.Map) { if kit.Fetch(root[mdb.LIST], func(value ice.Map) { h += c.draw(m, value, x, y+h, item, gs) }); h == 0 {
h += c.draw(m, value, x, y+h, item)
}); h == 0 {
return item.GetHeights() return item.GetHeights()
} }
return h return h
} }
const ( const (
SHOW_BLOCK = "show-block"
SHIP = "ship" SHIP = "ship"
LINE = "line"
RECT = "rect"
TEXT = "text"
) )
const CHAIN = "chain" 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.FILL, "")
m.Option(wiki.STROKE, "")
m.Option(wiki.FONT_SIZE, "16") m.Option(wiki.FONT_SIZE, "16")
m.Option(wiki.STROKE_WIDTH, "2")
m.Option(wiki.PADDING, "6")
m.Option(wiki.MARGINY, "4")
m.Option(wiki.MARGINX, "40") m.Option(wiki.MARGINX, "40")
m.Option(wiki.MARGINY, "4")
m.Option(wiki.PADDING, "6")
wiki.AddGroupOption(m, SHIP, wiki.FILL, cli.GLASS) wiki.AddGroupOption(m, SHIP, wiki.FILL, cli.GLASS)
wiki.AddGroupOption(m, TEXT, wiki.STROKE_WIDTH, "1")
return &Chain{} return &Chain{}
}) })
} }

View File

@ -5,88 +5,74 @@ import (
ice "shylinux.com/x/icebergs" ice "shylinux.com/x/icebergs"
"shylinux.com/x/icebergs/base/lex" "shylinux.com/x/icebergs/base/lex"
"shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/nfs" "shylinux.com/x/icebergs/base/nfs"
"shylinux.com/x/icebergs/core/wiki" "shylinux.com/x/icebergs/core/wiki"
kit "shylinux.com/x/toolkits" kit "shylinux.com/x/toolkits"
) )
type Label struct { type Label struct {
data [][]string
max map[int]int max map[int]int
data [][]string
Block Block
} }
func (l *Label) Init(m *ice.Message, arg ...string) wiki.Chart { func (s *Label) Init(m *ice.Message, arg ...string) wiki.Chart {
(&l.Block).Init(m) (&s.Block).Init(m)
s.max = map[int]int{}
// 解析数据 m.Cmd(lex.SPLIT, "", kit.Dict(lex.SPLIT_BLOCK, ice.SP, nfs.CAT_CONTENT, arg[0]), func(ls []string) {
l.max = map[int]int{} s.data = append(s.data, ls)
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 {
l.data = append(l.data, ls)
for i, v := range ls { for i, v := range ls {
switch data := kit.Parse(nil, "", kit.Split(v)...).(type) { if w := s.GetWidth(kit.SplitWord(v)[0]); w > s.max[i] {
case ice.Map: s.max[i] = w
v = kit.Select("", data[mdb.TEXT])
}
if w := l.GetWidth(v); w > l.max[i] {
l.max[i] = w
} }
} }
return ls
}) })
s.Height = len(s.data) * s.GetHeights()
// 计算尺寸 for _, v := range s.max {
l.Height = len(l.data) * l.GetHeights() s.Width += v + s.MarginX
for _, v := range l.max {
l.Width += v + l.MarginX
} }
return l return s
} }
func (l *Label) Draw(m *ice.Message, x, y int) wiki.Chart { func (s *Label) Draw(m *ice.Message, x, y int) wiki.Chart {
gs := wiki.NewGroup(m, RECT, TEXT) gs := wiki.NewGroup(m, RECT, TEXT)
wiki.AddGroupOption(m, TEXT, wiki.FILL, m.Option(wiki.STROKE)) wiki.AddGroupOption(m, TEXT, wiki.FILL, m.Option(wiki.STROKE))
defer func() { gs.Dump(m, RECT).Dump(m, TEXT) }() defer gs.DumpAll(m, RECT, TEXT)
var item *Block
top := y top := y
for _, line := range l.data { for _, line := range s.data {
left := x left, height := x, 0
for i, text := range line { for i, text := range line {
item := s.Fork(m)
// 数据 ls := kit.SplitWord(text)
item = &Block{FontSize: l.FontSize, Padding: l.Padding, MarginX: l.MarginX, MarginY: l.MarginY} if item.Init(m, ls[0]); len(ls) > 1 {
switch data := kit.Parse(nil, "", kit.Split(text)...).(type) { data := kit.Dict()
case ice.Map: for i := 1; i < len(ls)-1; i += 2 {
item.Init(m, kit.Select(text, data[mdb.TEXT])).Data(m, data) kit.Value(data, ls[i], ls[i+1])
default: }
item.Init(m, text) item.Data(m, data)
} }
// 尺寸
switch m.Option(COMPACT) { switch m.Option(COMPACT) {
case "max":
item.Width = l.Width/len(line) - l.MarginX
case ice.TRUE: case ice.TRUE:
case "max":
item.Width = s.Width/len(line) - s.MarginX
default: default:
item.Width = l.max[i] item.Width = s.max[i]
} }
// 输出 if m.Option(HIDE_BLOCK) != ice.TRUE {
if m.Option(SHOW_BLOCK) == ice.TRUE {
args := []string{"4", "4"} args := []string{"4", "4"}
if mod := kit.Int(m.Option("order.mod")); mod != 0 && i%mod == 0 { if mod := kit.Int(m.Option("order.mod")); mod != 0 && i%mod == 0 {
args = append(args, "fill", m.Option("order.bg")) 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...) gs.EchoRect(RECT, item.GetHeight(), item.GetWidth(), left+item.MarginX/2, top+item.MarginY/2, args...)
} }
args := []string{} args := []string{}
if mod := kit.Int(m.Option("order.mod")); mod != 0 && i%mod == 0 { if mod := kit.Int(m.Option("order.mod")); mod != 0 && i%mod == 0 {
args = append(args, "stroke", m.Option("order.fg")) args = append(args, wiki.STROKE, m.Option("order.fg"))
args = append(args, "fill", 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") { 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...) gs.EchoTexts(TEXT, left+item.GetWidths()/2, top+item.GetHeights()/2, item.Text, args...)
@ -94,25 +80,24 @@ func (l *Label) Draw(m *ice.Message, x, y int) wiki.Chart {
gs.EchoTexts(TEXT, left+item.GetWidths()/2, top+item.GetHeights()/2+4, item.Text, args...) gs.EchoTexts(TEXT, left+item.GetWidths()/2, top+item.GetHeights()/2+4, item.Text, args...)
} }
left += item.GetWidths() if left += item.GetWidths(); item.GetHeights() > height {
height = item.GetHeights()
}
} }
top += item.GetHeights() top += height
} }
return l return s
} }
const ( const (
SHOW_BLOCK = "show-block" HIDE_BLOCK = "hide-block"
COMPACT = "compact" COMPACT = "compact"
) )
const LABEL = "label" const LABEL = "label"
func init() { func init() {
wiki.AddChart(LABEL, func(m *ice.Message) wiki.Chart { wiki.AddChart(LABEL, func(m *ice.Message) wiki.Chart {
m.Option(SHOW_BLOCK, ice.TRUE)
wiki.AddGroupOption(m, TEXT, wiki.FILL, m.Option(wiki.STROKE))
wiki.AddGroupOption(m, TEXT, wiki.STROKE_WIDTH, "1") wiki.AddGroupOption(m, TEXT, wiki.STROKE_WIDTH, "1")
wiki.AddGroupOption(m, TEXT, wiki.FONT_FAMILY, m.Option(wiki.FONT_FAMILY))
return &Label{} return &Label{}
}) })
} }

View File

@ -147,11 +147,8 @@ const (
const ( const (
HEAD = "head" HEAD = "head"
TITLE = "title" TITLE = "title"
LINE = "line"
RECT = "rect"
NEXT = "next" NEXT = "next"
PREV = "prev" PREV = "prev"
TEXT = "text"
ECHO = "echo" ECHO = "echo"
ARROW = "arrow" ARROW = "arrow"
) )

View File

@ -23,7 +23,7 @@ func init() {
} }
}}, }},
mdb.CREATE: {Name: "create path fields value", Hand: func(m *ice.Message, arg ...string) { mdb.CREATE: {Name: "create path fields value", Hand: func(m *ice.Message, arg ...string) {
m.Cmd("", nfs.SAVE, m.Option(nfs.PATH), kit.Join(kit.Split(m.Option("fields")), ice.FS)+ice.NL+kit.Join(kit.Split(m.Option("value")))+ice.NL) m.Cmd("", nfs.SAVE, m.Option(nfs.PATH), kit.Join(kit.Split(m.Option("fields")), ice.FS)+ice.NL+kit.Join(kit.Split(m.Option(mdb.VALUE)))+ice.NL)
}}, }},
nfs.PUSH: {Name: "push path record", Help: "添加", Hand: func(m *ice.Message, arg ...string) { nfs.PUSH: {Name: "push path record", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
m.Cmd(nfs.PUSH, path.Join(m.Config(nfs.PATH), arg[0]), kit.Join(arg[1:], ice.FS)+ice.NL) m.Cmd(nfs.PUSH, path.Join(m.Config(nfs.PATH), arg[0]), kit.Join(arg[1:], ice.FS)+ice.NL)

View File

@ -18,14 +18,11 @@ func init() {
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
m.Cmd(mdb.RENDER, mdb.CREATE, mdb.TYPE, nfs.SVG, mdb.NAME, m.PrefixKey()) m.Cmd(mdb.RENDER, mdb.CREATE, mdb.TYPE, nfs.SVG, mdb.NAME, m.PrefixKey())
}}, }},
mdb.RENDER: {Name: "render", Help: "渲染", Hand: func(m *ice.Message, arg ...string) { mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) {
m.Echo("<html><body>") m.Echo("<html><body>")
defer m.Echo("</body></html>") defer m.Echo("</body></html>")
m.Cmdy(nfs.CAT, path.Join(arg[2], arg[1])) m.Cmdy(nfs.CAT, path.Join(arg[2], arg[1]))
}}, }},
nfs.SAVE: {Name: "save", Help: "保存", Hand: func(m *ice.Message, arg ...string) {
_wiki_save(m, arg[0], m.Option(nfs.CONTENT))
}},
}, WikiAction("", nfs.SVG), ctx.CmdAction()), Hand: func(m *ice.Message, arg ...string) { }, WikiAction("", nfs.SVG), ctx.CmdAction()), Hand: func(m *ice.Message, arg ...string) {
if !_wiki_list(m, kit.Select(nfs.PWD, arg, 0)) { if !_wiki_list(m, kit.Select(nfs.PWD, arg, 0)) {
_wiki_show(m, arg[0]) _wiki_show(m, arg[0])

View File

@ -9,6 +9,7 @@ import (
"time" "time"
ice "shylinux.com/x/icebergs" ice "shylinux.com/x/icebergs"
"shylinux.com/x/icebergs/base/ctx"
"shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/nfs" "shylinux.com/x/icebergs/base/nfs"
"shylinux.com/x/icebergs/base/tcp" "shylinux.com/x/icebergs/base/tcp"
@ -46,6 +47,7 @@ func init() {
} }
case nfs.JSON: case nfs.JSON:
m.Echo(kit.Formats(kit.UnMarshal(arg[1]))) m.Echo(kit.Formats(kit.UnMarshal(arg[1])))
ctx.DisplayStoryJSON(m)
case web.HTTP: case web.HTTP:
u, _ := url.Parse(arg[1]) u, _ := url.Parse(arg[1])
m.Push(tcp.PROTO, u.Scheme) m.Push(tcp.PROTO, u.Scheme)

View File

@ -73,7 +73,7 @@ func init() {
web.Index.Register(Index, &web.Frame{}, web.Index.Register(Index, &web.Frame{},
TITLE, BRIEF, REFER, SPARK, FIELD, PARSE, TITLE, BRIEF, REFER, SPARK, FIELD, PARSE,
ORDER, TABLE, CHART, IMAGE, VIDEO, AUDIO, ORDER, TABLE, CHART, IMAGE, VIDEO, AUDIO,
FEEL, DRAW, WORD, DATA, FEEL, DRAW, DATA, WORD,
) )
} }
@ -101,10 +101,25 @@ func (m *Message) OptionTemplate() string {
add("data-", key) add("data-", key)
} }
kit.Fetch(m.Optionv(mdb.EXTRA), func(key string, value string) { kit.Fetch(m.Optionv(mdb.EXTRA), func(key string, value string) {
add("data-", key) switch key {
case PADDING:
return
}
if !strings.Contains(key, "-") {
add("data-", key)
}
}) })
for _, key := range kit.Split(ctx.STYLE) { for _, key := range kit.Split(ctx.STYLE) {
add("", key) add("", key)
} }
return kit.Join(res, ice.SP) return kit.Join(res, ice.SP)
} }
func (m *Message) OptionKV(key ...string) string {
res := []string{}
for _, k := range kit.Split(kit.Join(key)) {
if m.Option(k) != "" {
res = append(res, kit.Format("%s='%s'", k, m.Option(k)))
}
}
return kit.Join(res, ice.SP)
}

View File

@ -1,5 +1,8 @@
wiki.shy wiki.shy
wiki.go wiki.go
feel.go
draw.go
data.go
word.go word.go
title.go title.go
@ -9,14 +12,9 @@ spark.go
field.go field.go
parse.go parse.go
order.go
table.go
chart.go
image.go image.go
video.go video.go
audio.go audio.go
order.go
feel.go table.go
draw.go chart.go
data.go