mirror of
https://shylinux.com/x/icebergs
synced 2025-04-26 01:24:05 +08:00
opt chart.go
This commit is contained in:
parent
b0346ea915
commit
7b9ada65ac
@ -55,6 +55,11 @@ func _split_list(m *ice.Message, file string, arg ...string) ice.Map {
|
||||
switch cb := m.OptionCB(SPLIT).(type) {
|
||||
case func(int, []string) []string:
|
||||
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:
|
||||
ls = cb(deep, ls, data)
|
||||
case func([]string, ice.Map) []string:
|
||||
|
@ -4,8 +4,6 @@ import (
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
@ -36,14 +34,10 @@ func (item *Item) Push(str string, arg ice.Any) *Item {
|
||||
return item
|
||||
}
|
||||
func (item *Item) Dump(m *ice.Message) *ice.Message {
|
||||
m.Echo(kit.Join(item.list, ice.SP), item.args...)
|
||||
m.Echo(ice.NL)
|
||||
return m
|
||||
return m.Echo(kit.Join(item.list, ice.SP), item.args...).Echo(ice.NL)
|
||||
}
|
||||
|
||||
type Group struct {
|
||||
list ice.Messages
|
||||
}
|
||||
type Group struct{ list ice.Messages }
|
||||
|
||||
func NewGroup(m *ice.Message, arg ...string) *Group {
|
||||
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 {
|
||||
return g.Get(group).Echo(str, arg...)
|
||||
}
|
||||
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) EchoPath(group string, str string, arg ...ice.Any) *ice.Message {
|
||||
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 {
|
||||
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 {
|
||||
if text == "" {
|
||||
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>")
|
||||
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 {
|
||||
Init(*ice.Message, ...string) Chart
|
||||
Data(*ice.Message, ice.Any) Chart
|
||||
Draw(*ice.Message, int, int) Chart
|
||||
|
||||
Data(*ice.Message, ice.Any) Chart
|
||||
GetHeight(...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 _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_FAMILY, "monospace")
|
||||
m.Option(STROKE_WIDTH, "2")
|
||||
chart := chart_list[kind](m)
|
||||
|
||||
// 解析参数
|
||||
for i := 0; i < len(arg)-1; i++ {
|
||||
m.Option(arg[i], arg[i+1])
|
||||
}
|
||||
m.Option(FILL, kit.Select(m.Option(FILL), m.Option(BG)))
|
||||
m.Option(STROKE, kit.Select(m.Option(STROKE), m.Option(FG)))
|
||||
|
||||
// 计算尺寸
|
||||
chart.Init(m, text)
|
||||
m.Option(WIDTH, chart.GetWidth())
|
||||
m.Option(HEIGHT, chart.GetHeight())
|
||||
|
||||
// 渲染引擎
|
||||
_wiki_template(m, "", text, arg...)
|
||||
defer m.Echo("</svg>")
|
||||
defer m.RenderResult()
|
||||
chart.Draw(m, 0, 0)
|
||||
m.RenderResult()
|
||||
}
|
||||
|
||||
const (
|
||||
@ -188,18 +176,15 @@ const (
|
||||
const CHART = "chart"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{Commands: ice.Commands{
|
||||
CHART: {Name: "chart type=label,chain,sequence auto text", Help: "图表", Hand: func(m *ice.Message, arg ...string) {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
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 {
|
||||
_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">`,
|
||||
)},
|
||||
}})
|
||||
})
|
||||
}
|
||||
|
@ -10,21 +10,22 @@ import (
|
||||
)
|
||||
|
||||
type Block struct {
|
||||
Text string
|
||||
FontSize int
|
||||
FontColor string
|
||||
BackGround string
|
||||
Text string
|
||||
|
||||
TextData string
|
||||
RectData string
|
||||
|
||||
Padding int
|
||||
MarginX int
|
||||
MarginY int
|
||||
FontSize int
|
||||
Padding int
|
||||
MarginX int
|
||||
MarginY int
|
||||
|
||||
Height int
|
||||
Width int
|
||||
x, y int
|
||||
|
||||
FontColor string
|
||||
BackGround string
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
})
|
||||
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)
|
||||
})
|
||||
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 {
|
||||
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.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)
|
||||
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 {
|
||||
if b.Height != 0 {
|
||||
|
@ -12,105 +12,93 @@ import (
|
||||
|
||||
type Chain struct {
|
||||
data ice.Map
|
||||
gs *wiki.Group
|
||||
Block
|
||||
}
|
||||
|
||||
func (c *Chain) Init(m *ice.Message, arg ...string) wiki.Chart {
|
||||
(&c.Block).Init(m)
|
||||
|
||||
m.Option(nfs.CAT_CONTENT, arg[0])
|
||||
m.Option(lex.SPLIT_BLOCK, ice.SP)
|
||||
max, stack := 0, kit.List(kit.Dict("_deep", -1, "width", "0"))
|
||||
m.OptionCB(lex.SPLIT, func(deep int, ls []string, data ice.Map) []string {
|
||||
for deep <= kit.Int(kit.Value(stack[len(stack)-1], "_deep")) {
|
||||
const _DEEP = "_deep"
|
||||
stack, max := kit.List(kit.Dict(_DEEP, -1, wiki.WIDTH, "0")), 0
|
||||
last := func(key string) int { return kit.Int(kit.Value(stack[len(stack)-1], key)) }
|
||||
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) {
|
||||
for deep <= last(_DEEP) {
|
||||
stack = stack[:len(stack)-1]
|
||||
}
|
||||
width := kit.Int(kit.Value(stack[len(stack)-1], "width")) + c.GetWidths(ls[0])
|
||||
stack = append(stack, kit.Dict("_deep", deep, "width", width))
|
||||
if width > max {
|
||||
width := last(wiki.WIDTH) + c.GetWidths(ls[0])
|
||||
if stack = append(stack, kit.Dict(_DEEP, deep, wiki.WIDTH, width)); width > max {
|
||||
max = width
|
||||
}
|
||||
return ls
|
||||
c.data = root
|
||||
})
|
||||
c.data = lex.Split(m, "", mdb.TEXT)
|
||||
|
||||
c.Height, c.Width = c.size(m, c.data)*c.GetHeights(), max
|
||||
c.Height, c.Width = c.height(m, c.data)*c.GetHeights(), max
|
||||
return c
|
||||
}
|
||||
func (c *Chain) Draw(m *ice.Message, x, y int) wiki.Chart {
|
||||
c.gs = wiki.NewGroup(m, SHIP, RECT, LINE, TEXT)
|
||||
wiki.AddGroupOption(m, LINE, wiki.STROKE, c.gs.Option(SHIP, wiki.STROKE))
|
||||
wiki.AddGroupOption(m, TEXT, wiki.FILL, m.Option(wiki.STROKE), wiki.STROKE_WIDTH, "1")
|
||||
defer func() { c.gs.Dump(m, SHIP).Dump(m, RECT).Dump(m, LINE).Dump(m, TEXT) }()
|
||||
gs := wiki.NewGroup(m, SHIP, LINE, RECT, TEXT)
|
||||
wiki.AddGroupOption(m, LINE, wiki.STROKE, gs.Option(SHIP, wiki.STROKE))
|
||||
wiki.AddGroupOption(m, TEXT, wiki.FILL, m.Option(wiki.STROKE))
|
||||
defer gs.DumpAll(m, SHIP, LINE, RECT, TEXT)
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
func (c *Chain) size(m *ice.Message, root ice.Map) (height int) {
|
||||
func (c *Chain) height(m *ice.Message, root ice.Map) (height int) {
|
||||
meta := kit.GetMeta(root)
|
||||
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 {
|
||||
height = 1
|
||||
}
|
||||
meta[wiki.HEIGHT] = 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)
|
||||
|
||||
item := &Block{FontSize: p.FontSize, Padding: p.Padding, MarginX: p.MarginX, MarginY: p.MarginY}
|
||||
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.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)
|
||||
}
|
||||
|
||||
// 文本
|
||||
c.gs.EchoTexts(TEXT, item.x+item.GetWidths()/2, item.y+item.GetHeights()/2, kit.Format(meta[mdb.TEXT]))
|
||||
|
||||
if p != nil && p.y != 0 { // 连线
|
||||
if p != nil && p.y != 0 {
|
||||
padding := item.GetHeights() / 2
|
||||
if m.Option(SHOW_BLOCK) == ice.TRUE {
|
||||
x1, y1 := p.x+p.GetWidths()-(p.MarginX+item.MarginX)/4, p.y+p.GetHeights()/2
|
||||
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)
|
||||
padding = 0
|
||||
}
|
||||
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()
|
||||
if kit.Fetch(root[mdb.LIST], func(index int, value ice.Map) {
|
||||
h += c.draw(m, value, x, y+h, item)
|
||||
}); h == 0 {
|
||||
if kit.Fetch(root[mdb.LIST], func(value ice.Map) { h += c.draw(m, value, x, y+h, item, gs) }); h == 0 {
|
||||
return item.GetHeights()
|
||||
}
|
||||
return h
|
||||
}
|
||||
|
||||
const (
|
||||
SHOW_BLOCK = "show-block"
|
||||
|
||||
SHIP = "ship"
|
||||
LINE = "line"
|
||||
RECT = "rect"
|
||||
TEXT = "text"
|
||||
)
|
||||
const CHAIN = "chain"
|
||||
|
||||
func init() {
|
||||
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.STROKE_WIDTH, "2")
|
||||
m.Option(wiki.PADDING, "6")
|
||||
m.Option(wiki.MARGINY, "4")
|
||||
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, TEXT, wiki.STROKE_WIDTH, "1")
|
||||
return &Chain{}
|
||||
})
|
||||
}
|
||||
|
@ -5,88 +5,74 @@ import (
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"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"
|
||||
)
|
||||
|
||||
type Label struct {
|
||||
data [][]string
|
||||
max map[int]int
|
||||
data [][]string
|
||||
Block
|
||||
}
|
||||
|
||||
func (l *Label) Init(m *ice.Message, arg ...string) wiki.Chart {
|
||||
(&l.Block).Init(m)
|
||||
|
||||
// 解析数据
|
||||
l.max = map[int]int{}
|
||||
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)
|
||||
|
||||
func (s *Label) Init(m *ice.Message, arg ...string) wiki.Chart {
|
||||
(&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) {
|
||||
s.data = append(s.data, ls)
|
||||
for i, v := range ls {
|
||||
switch data := kit.Parse(nil, "", kit.Split(v)...).(type) {
|
||||
case ice.Map:
|
||||
v = kit.Select("", data[mdb.TEXT])
|
||||
}
|
||||
if w := l.GetWidth(v); w > l.max[i] {
|
||||
l.max[i] = w
|
||||
if w := s.GetWidth(kit.SplitWord(v)[0]); w > s.max[i] {
|
||||
s.max[i] = w
|
||||
}
|
||||
}
|
||||
return ls
|
||||
})
|
||||
|
||||
// 计算尺寸
|
||||
l.Height = len(l.data) * l.GetHeights()
|
||||
for _, v := range l.max {
|
||||
l.Width += v + l.MarginX
|
||||
s.Height = len(s.data) * s.GetHeights()
|
||||
for _, v := range s.max {
|
||||
s.Width += v + s.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)
|
||||
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
|
||||
for _, line := range l.data {
|
||||
left := x
|
||||
for _, line := range s.data {
|
||||
left, height := x, 0
|
||||
for i, text := range line {
|
||||
item := s.Fork(m)
|
||||
|
||||
// 数据
|
||||
item = &Block{FontSize: l.FontSize, Padding: l.Padding, MarginX: l.MarginX, MarginY: l.MarginY}
|
||||
switch data := kit.Parse(nil, "", kit.Split(text)...).(type) {
|
||||
case ice.Map:
|
||||
item.Init(m, kit.Select(text, data[mdb.TEXT])).Data(m, data)
|
||||
default:
|
||||
item.Init(m, text)
|
||||
ls := kit.SplitWord(text)
|
||||
if item.Init(m, ls[0]); len(ls) > 1 {
|
||||
data := kit.Dict()
|
||||
for i := 1; i < len(ls)-1; i += 2 {
|
||||
kit.Value(data, ls[i], ls[i+1])
|
||||
}
|
||||
item.Data(m, data)
|
||||
}
|
||||
|
||||
// 尺寸
|
||||
switch m.Option(COMPACT) {
|
||||
case "max":
|
||||
item.Width = l.Width/len(line) - l.MarginX
|
||||
case ice.TRUE:
|
||||
case "max":
|
||||
item.Width = s.Width/len(line) - s.MarginX
|
||||
default:
|
||||
item.Width = l.max[i]
|
||||
item.Width = s.max[i]
|
||||
}
|
||||
|
||||
// 输出
|
||||
if m.Option(SHOW_BLOCK) == ice.TRUE {
|
||||
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, "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...)
|
||||
}
|
||||
|
||||
args := []string{}
|
||||
if mod := kit.Int(m.Option("order.mod")); mod != 0 && i%mod == 0 {
|
||||
args = append(args, "stroke", m.Option("order.fg"))
|
||||
args = append(args, "fill", m.Option("order.fg"))
|
||||
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...)
|
||||
@ -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...)
|
||||
}
|
||||
|
||||
left += item.GetWidths()
|
||||
if left += item.GetWidths(); item.GetHeights() > height {
|
||||
height = item.GetHeights()
|
||||
}
|
||||
}
|
||||
top += item.GetHeights()
|
||||
top += height
|
||||
}
|
||||
return l
|
||||
return s
|
||||
}
|
||||
|
||||
const (
|
||||
SHOW_BLOCK = "show-block"
|
||||
HIDE_BLOCK = "hide-block"
|
||||
COMPACT = "compact"
|
||||
)
|
||||
const LABEL = "label"
|
||||
|
||||
func init() {
|
||||
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.FONT_FAMILY, m.Option(wiki.FONT_FAMILY))
|
||||
return &Label{}
|
||||
})
|
||||
}
|
||||
|
@ -147,11 +147,8 @@ const (
|
||||
const (
|
||||
HEAD = "head"
|
||||
TITLE = "title"
|
||||
LINE = "line"
|
||||
RECT = "rect"
|
||||
NEXT = "next"
|
||||
PREV = "prev"
|
||||
TEXT = "text"
|
||||
ECHO = "echo"
|
||||
ARROW = "arrow"
|
||||
)
|
||||
|
@ -23,7 +23,7 @@ func init() {
|
||||
}
|
||||
}},
|
||||
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) {
|
||||
m.Cmd(nfs.PUSH, path.Join(m.Config(nfs.PATH), arg[0]), kit.Join(arg[1:], ice.FS)+ice.NL)
|
||||
|
@ -18,14 +18,11 @@ func init() {
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
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>")
|
||||
defer m.Echo("</body></html>")
|
||||
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) {
|
||||
if !_wiki_list(m, kit.Select(nfs.PWD, arg, 0)) {
|
||||
_wiki_show(m, arg[0])
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
"time"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/tcp"
|
||||
@ -46,6 +47,7 @@ func init() {
|
||||
}
|
||||
case nfs.JSON:
|
||||
m.Echo(kit.Formats(kit.UnMarshal(arg[1])))
|
||||
ctx.DisplayStoryJSON(m)
|
||||
case web.HTTP:
|
||||
u, _ := url.Parse(arg[1])
|
||||
m.Push(tcp.PROTO, u.Scheme)
|
||||
|
@ -73,7 +73,7 @@ func init() {
|
||||
web.Index.Register(Index, &web.Frame{},
|
||||
TITLE, BRIEF, REFER, SPARK, FIELD, PARSE,
|
||||
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)
|
||||
}
|
||||
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) {
|
||||
add("", key)
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
@ -1,5 +1,8 @@
|
||||
wiki.shy
|
||||
wiki.go
|
||||
feel.go
|
||||
draw.go
|
||||
data.go
|
||||
word.go
|
||||
|
||||
title.go
|
||||
@ -9,14 +12,9 @@ spark.go
|
||||
field.go
|
||||
parse.go
|
||||
|
||||
order.go
|
||||
table.go
|
||||
chart.go
|
||||
image.go
|
||||
video.go
|
||||
audio.go
|
||||
|
||||
feel.go
|
||||
draw.go
|
||||
data.go
|
||||
|
||||
order.go
|
||||
table.go
|
||||
chart.go
|
||||
|
Loading…
x
Reference in New Issue
Block a user