1
0
forked from x/volcanos

opt draw.js

This commit is contained in:
harveyshao 2022-07-05 23:49:44 +08:00
parent 63308b4ea5
commit 1e42313ffc
7 changed files with 182 additions and 185 deletions

View File

@ -278,7 +278,8 @@ Volcanos(chat.ONAPPEND, {help: "渲染引擎", list: [], _init: function(can, me
return can.Update(event, can.Input(cmds, silent), cb, silent) return can.Update(event, can.Input(cmds, silent), cb, silent)
}, can._outputs && can._outputs.push(table), table.sup = can, table._msg = msg }, can._outputs && can._outputs.push(table), table.sup = can, table._msg = msg
table._args = can.base.ParseURL(table._display), table._trans = can.base.Copy(table._trans||{}, can.core.Value(table, "onaction._trans")) table.Conf(table._args = can.base.ParseURL(table._display))
table._trans = can.base.Copy(table._trans||{}, can.core.Value(table, "onaction._trans"))
if (table.onimport && can.base.isArray(table.onimport.list) && table.onimport.list.length > 0) { if (table.onimport && can.base.isArray(table.onimport.list) && table.onimport.list.length > 0) {
can.onmotion.clear(can, can._option), can.onappend._option(can, {inputs: table.onimport.list}) can.onmotion.clear(can, can._option), can.onappend._option(can, {inputs: table.onimport.list})
} }

View File

@ -1,95 +1,95 @@
Volcanos("misc", {help: "通信协议", Message: function(event, can) { var msg = {} Volcanos("misc", {help: "通信协议", Message: function(event, can) { var msg = {}
var proto = {_event: event, _can: can, var proto = {_event: event, _can: can,
RunAction: function(event, sub, cmds, meta) { var msg = can.request(event); meta = meta || sub&&sub.onaction || {} RunAction: function(event, sub, cmds, meta) { var msg = can.request(event); meta = meta || sub&&sub.onaction || {}
if (msg.Option(ice.MSG_HANDLE) == ice.TRUE) { return } if (msg.Option(ice.MSG_HANDLE) == ice.TRUE) { return }
if (cmds && cmds[0] == ctx.ACTION && can.base.isFunc(meta[cmds[1]])) { event = event._event||event if (cmds && cmds[0] == ctx.ACTION && can.base.isFunc(meta[cmds[1]])) { event = event._event||event
return msg.Option(ice.MSG_HANDLE, ice.TRUE), can.core.CallFunc(meta[cmds[1]], {event: event, can: sub, msg: msg, button: cmds[1], cmd: cmds[1]}), true return msg.Option(ice.MSG_HANDLE, ice.TRUE), can.core.CallFunc(meta[cmds[1]], {event: event, can: sub, msg: msg, button: cmds[1], cmd: cmds[1]}), true
}
return false
},
Display: function(file) { msg.Option(ice.MSG_DISPLAY, file) },
DisplayStory: function(file) { msg.Option(ice.MSG_DISPLAY, "/plugin/story/"+file) },
OptionStatus: function() { return msg.Option(ice.MSG_STATUS) },
OptionProcess: function() { return msg.Option(ice.MSG_PROCESS) },
OptionOrSearch: function(key) { return can.misc.Search(can, key)||msg.Option(key) },
Option: function(key, val) {
if (key == undefined) { return msg && msg.option || [] }
if (can.base.isObject(key)) { can.core.Item(key, msg.Option) }
if (val == undefined) { return msg && msg[key] && msg[key][0] || "" }
return msg.option = can.base.AddUniq(msg.option, key), msg[key] = can.core.List(arguments).slice(1), val
},
Append: function(key, val) {
if (key == undefined) { return msg && msg.append || [] }
if (can.base.isObject(key)) { can.core.Item(key, msg.Append) }
if (val == undefined) { return msg && msg[key] && msg[key][0] || "" }
return msg.append = can.base.AddUniq(msg.append, key), msg[key] = can.core.List(arguments).slice(1), val
},
Result: function() { return msg.result && msg.result.join("") || "" },
Length: function() {
var max = "", len = 0; can.core.List(msg.append, function(key, index) {
if (msg[key] && msg[key].length > len) { max = key, len = msg[key].length }
})
return len
},
Table: function(cb) { if (!msg.append || msg.append.length == 0) { return }
var max = "", len = 0; can.core.List(msg.append, function(key, index) {
if (msg[key] && msg[key].length > len) { max = key, len = msg[key].length }
})
return can.core.List(msg[max], function(value, index, array) { var one = {}, res
can.core.List(msg.append, function(key) { one[key] = (msg[key]&&msg[key][index]||"") })
return can.base.isFunc(cb) && (res = cb(one, index, array)) && res != undefined && res || one
})
},
Clear: function(key) { switch (key||ice.MSG_APPEND) {
case ice.MSG_APPEND:
case ice.MSG_OPTION:
can.core.List(msg[key], function(item) { delete(msg[item]) })
default: msg[key] = []
} },
Copy: function(res) { if (!res) { return msg }
res.result && (msg.result = (msg.result||[]).concat(res.result))
res.append && (msg.append = res.append) && res.append.forEach(function(item) {
var i = msg.option && msg.option.indexOf(item); if (i > -1) {
msg.option[i] = "", delete(msg[item])
} }
res[item] && (msg[item] = (msg[item]||[]).concat(res[item])) return false
}) },
res.option && (msg.option = res.option) && res.option.forEach(function(item) { Display: function(file) { msg.Option(ice.MSG_DISPLAY, file) },
res[item] && (msg[item] = res[item]) DisplayStory: function(file) { msg.Option(ice.MSG_DISPLAY, "/plugin/story/"+file) },
}) OptionStatus: function() { return msg.Option(ice.MSG_STATUS) },
res._option && (msg._option = res._option) && res._option.forEach(function(item) { OptionProcess: function() { return msg.Option(ice.MSG_PROCESS) },
res[item] && (msg[item] = res[item]) OptionOrSearch: function(key) { return can.misc.Search(can, key)||msg.Option(key) },
}) Option: function(key, val) {
return msg if (key == undefined) { return msg && msg.option || [] }
}, if (can.base.isObject(key)) { can.core.Item(key, msg.Option) }
Push: function(key, value, detail) { if (val == undefined) { return msg && msg[key] && msg[key][0] || "" }
if (can.base.isObject(key)) { return msg.option = can.base.AddUniq(msg.option, key), msg[key] = can.core.List(arguments).slice(1), val
value = value||can.core.Item(key), can.core.List(value, function(item) { },
detail? msg.Push(mdb.KEY, item).Push(mdb.VALUE, key[item]||""): msg.Push(item, key[item]||"") Append: function(key, val) {
if (key == undefined) { return msg && msg.append || [] }
if (can.base.isObject(key)) { can.core.Item(key, msg.Append) }
if (val == undefined) { return msg && msg[key] && msg[key][0] || "" }
return msg.append = can.base.AddUniq(msg.append, key), msg[key] = can.core.List(arguments).slice(1), val
},
Result: function() { return msg.result && msg.result.join("") || "" },
Length: function() {
var max = "", len = 0; can.core.List(msg.append, function(key, index) {
if (msg[key] && msg[key].length > len) { max = key, len = msg[key].length }
})
return len
},
Table: function(cb) { if (!msg.append || msg.append.length == 0) { return }
var max = "", len = 0; can.core.List(msg.append, function(key, index) {
if (msg[key] && msg[key].length > len) { max = key, len = msg[key].length }
})
return can.core.List(msg[max], function(value, index, array) { var one = {}, res
can.core.List(msg.append, function(key) { one[key] = (msg[key]&&msg[key][index]||"") })
return can.base.isFunc(cb) && (res = cb(one, index, array)) && res != undefined && res || one
})
},
Clear: function(key) { switch (key||ice.MSG_APPEND) {
case ice.MSG_APPEND:
case ice.MSG_OPTION:
can.core.List(msg[key], function(item) { delete(msg[item]) })
default: msg[key] = []
} },
Copy: function(res) { if (!res) { return msg }
res.result && (msg.result = (msg.result||[]).concat(res.result))
res.append && (msg.append = res.append) && res.append.forEach(function(item) {
var i = msg.option && msg.option.indexOf(item); if (i > -1) {
msg.option[i] = "", delete(msg[item])
}
res[item] && (msg[item] = (msg[item]||[]).concat(res[item]))
})
res.option && (msg.option = res.option) && res.option.forEach(function(item) {
res[item] && (msg[item] = res[item])
})
res._option && (msg._option = res._option) && res._option.forEach(function(item) {
res[item] && (msg[item] = res[item])
}) })
return msg return msg
} },
Push: function(key, value, detail) {
if (can.base.isObject(key)) {
value = value||can.core.Item(key), can.core.List(value, function(item) {
detail? msg.Push(mdb.KEY, item).Push(mdb.VALUE, key[item]||""): msg.Push(item, key[item]||"")
})
return msg
}
msg.append = can.base.AddUniq(msg.append, key), msg[key] = msg[key] || [] msg.append = can.base.AddUniq(msg.append, key), msg[key] = msg[key] || []
msg[key].push(can.base.isString(value)||can.base.isFunction(value)? value: JSON.stringify(value)) msg[key].push(can.base.isString(value)||can.base.isFunction(value)? value: JSON.stringify(value))
return msg return msg
}, },
Status: function(obj) { msg.Option(ice.MSG_STATUS, JSON.stringify(can.core.Item(obj, function(key, value) { return {name: key, value: value} }))) }, Status: function(obj) { msg.Option(ice.MSG_STATUS, JSON.stringify(can.core.Item(obj, function(key, value) { return {name: key, value: value} }))) },
StatusTimeCount: function(obj) { msg.append && msg.Status(can.base.Copy({"time": can.base.Time(), "count": msg.Length()+"x"+msg.append.length}, obj)) }, StatusTimeCount: function(obj) { msg.append && msg.Status(can.base.Copy({"time": can.base.Time(), "count": msg.Length()+"x"+msg.append.length}, obj)) },
Echo: function(res) { msg.result = msg.result || [] Echo: function(res) { msg.result = msg.result || []
for (var i = 0; i < arguments.length; i++) { msg.result.push(arguments[i]) } for (var i = 0; i < arguments.length; i++) { msg.result.push(arguments[i]) }
return msg._hand = true, msg return msg._hand = true, msg
}, },
Dump: function(can) { Dump: function(can) {
can.onmotion.clear(can) can.onmotion.clear(can)
can.onappend.table(can, msg) can.onappend.table(can, msg)
can.onappend.board(can, msg) can.onappend.board(can, msg)
}, },
} }
return can.misc.proto(msg, proto) return can.misc.proto(msg, proto)
}, },
POST: function(can, msg, url, form, cb) { // _method _accept _upload _progress POST: function(can, msg, url, form, cb) { // _method _accept _upload _progress
var xhr = new XMLHttpRequest(); msg._xhr = xhr var xhr = new XMLHttpRequest(); msg._xhr = xhr
xhr.open(msg._method||"POST", url), xhr.onreadystatechange = function() { xhr.open(msg._method||"POST", url), xhr.onreadystatechange = function() {

View File

@ -44,7 +44,8 @@ Volcanos(chat.ONIMPORT, {help: "导入数据", list: [], _init: function(can, ms
can.onengine.signal(can, chat.ONACTION_CMD) can.onengine.signal(can, chat.ONACTION_CMD)
can.onappend.plugin(can, can.base.Copy(item, {opts: can.misc.Search(can)}), function(sub, meta, skip) { can.onappend.plugin(can, can.base.Copy(item, {opts: can.misc.Search(can)}), function(sub, meta, skip) {
can.page.style(can, sub._output, html.MAX_WIDTH, can._root._width) sub.ConfHeight(can.ConfHeight()-can.Conf(html.MARGIN_Y))
can.page.style(can, sub._output, html.MAX_WIDTH, can.ConfWidth())
can.user.title(meta.name), skip || next() can.user.title(meta.name), skip || next()
}) })
}, },
@ -90,7 +91,7 @@ Volcanos(chat.ONPLUGIN, {help: "注册插件", list: [],
can.onappend.parse(can, can.onappend._parse(can, cmds[0])) can.onappend.parse(can, can.onappend._parse(can, cmds[0]))
}) })
}, },
}, ["text", "show:button@auto"], function(can, msg, cmds, cb) { can.run({}, cmds, cb, true) }), }, ["text", "show:button@auto"], function(can, msg, cmds, cb) { can._root.Action.run({}, cmds, cb, true) }),
"plugin": shy("插件", {}, ["text", "list", "back"], function(can, msg, cmds) { "plugin": shy("插件", {}, ["text", "list", "back"], function(can, msg, cmds) {
msg.Echo("hello world") msg.Echo("hello world")

View File

@ -147,7 +147,7 @@ Volcanos(chat.ONACTION, {help: "交互数据", list: [], _init: function(can, cb
}, },
onmain: function(can, msg) { onmain: function(can, msg) {
can.run({}, [], function(msg) { can.run({}, [], function(msg) {
if (!can.Conf(aaa.USERNICK, msg.Option(ice.MSG_USERNICK)||msg.Option(ice.MSG_USERNAME))) { if (!can.Conf(aaa.USERNICK, msg.Option(aaa.USERNICK)||msg.Option(ice.MSG_USERNAME))) {
msg.Option(chat.SSO)? can.user.jumps(msg.Option(chat.SSO)): can.user.login(can, function() { msg.Option(chat.SSO)? can.user.jumps(msg.Option(chat.SSO)): can.user.login(can, function() {
can.onengine.signal(can, chat.ONMAIN, msg) can.onengine.signal(can, chat.ONMAIN, msg)
}, msg.Option(aaa.LOGIN), msg.Option("login.dev")) }, msg.Option(aaa.LOGIN), msg.Option("login.dev"))

View File

@ -1,45 +1,47 @@
Volcanos(chat.ONIMPORT, {help: "导入数据", list: [], _init: function(can, msg, list, cb, target) { Volcanos(chat.ONIMPORT, {help: "导入数据", list: [], _init: function(can, msg, cb, target) {
can.require(["/plugin/local/wiki/draw.js", "/plugin/local/wiki/draw/path.js"], function() { can.require(["/plugin/local/wiki/draw.js", "/plugin/local/wiki/draw/path.js"], function() {
var color = [cli.RED, cli.YELLOW, cli.GREEN, cli.CYAN, cli.BLUE, cli.PURPLE]
var color = ["#3300FF", "#2196F3", "#4CAF50", "#CDDC39", "#FFEB3B", "#9C27B0", "#795548", "#607D8B", "#CC33FF"]
var height = msg.Option(html.HEIGHT)||can.ConfHeight() var height = msg.Option(html.HEIGHT)||can.ConfHeight()
can.onmotion.clear(can), can.base.isFunc(cb) && cb(msg) can.onmotion.clear(can), can.base.isFunc(cb) && cb(msg)
can.onmotion.clear(can), can.onimport._show(can, msg) can.onimport._show(can, msg), can.onmotion.hidden(can, can._action), can.onappend._status(can, [].concat(msg.append, ["weight"]))
var r = height/2-20, margin = 20; can.svg.Val(html.WIDTH, 2*(r+margin)), can.svg.Val(html.HEIGHT, 2*(r+margin)) var margin = height/8, r = height/2-margin; can.svg.Val(html.WIDTH, 2*(r+margin)), can.svg.Val(html.HEIGHT, 2*(r+margin))
can._args = can.base.Copy({field: "value"}, can.base.ParseURL(can._display)) can.onimport._draw(can, msg, can.Conf(mdb.FIELD), color, r+margin, r+margin, r, margin, 0)
can.onimport._draw(can, msg, can._args.field, r+margin, r+margin, r, margin, 0)
can.onmotion.clear(can, can.ui.project), can.onappend.table(can, msg, null, can.ui.project) can.page.style(can, can.ui.project, html.MAX_WIDTH, can.ConfWidth()-height)
can.onmotion.hidden(can, can.ui.project, true) can.onmotion.clear(can, can.ui.project), can.onmotion.hidden(can, can.ui.project, true)
var rest = can.ConfWidth()-height can.onappend.table(can, msg, null, can.ui.project), can.page.Select(can, can.ui.project, html.TR, function(tr, index) {
can.page.style(can, can.ui.project, html.MAX_WIDTH, rest)
can.page.Select(can, can.ui.project, html.TR, function(tr, index) {
can.page.Modify(can, tr, {onmouseenter: function(event) { can.page.Modify(can, tr, {onmouseenter: function(event) {
can.onmotion.clear(can, can.svg), can.onimport._draw(can, msg, can._args.field, r+margin, r+margin, r, margin, index-1) can.onimport._draw(can, msg, can.Conf(mdb.FIELD), color, r+margin, r+margin, r, margin, index-1)
}}) }})
}) })
}) })
}, },
_draw: function(can, msg, field, x, y, r, margin, which) { _draw: function(can, msg, field, color, x, y, r, margin, which) { field = field||mdb.VALUE
function pos(x, y, r, angle) { angle -= 90 function pos(x, y, r, angle) { angle -= 90; return [x + r * Math.cos(angle * Math.PI / 180), y + r * Math.sin(angle * Math.PI / 180)] }
return [x + r * Math.cos(angle * Math.PI / 180), y + r * Math.sin(angle * Math.PI / 180)] function pie(x, y, r, begin, span, color, cb) { can.onimport.draw({}, can, {shape: svg.PATH, style: kit.Dict(
} html.STROKE_WIDTH, 1, html.STROKE, color, html.FILL, color, "d", can.base.joins([
function pie(x, y, r, begin, span, color, cb) { can.onimport.draw({}, can, {shape: "path", style: {
"stroke-width": 1, stroke: color, fill: color, d: can.base.joins([
["M", x, y], ["L"].concat(pos(x, y, r, begin)), ["A", r, r, "0", span>180? "1": "0", "1"].concat(pos(x, y, r, begin+span)), ["Z"] ["M", x, y], ["L"].concat(pos(x, y, r, begin)), ["A", r, r, "0", span>180? "1": "0", "1"].concat(pos(x, y, r, begin+span)), ["Z"]
], ice.SP, ice.FS), ], ice.SP, ice.FS),
}, onmouseenter: function(event) { ), onmouseenter: function(event) { can.base.isFunc(cb) && cb(event) } }) }
can.base.isFunc(cb) && cb(event)
} }) }
var total = 0; msg.Table(function(value) { total += parseInt(value[field]) }) if (which == can._last) { return } can._last = which
var color = [cli.RED, cli.YELLOW, cli.GREEN, cli.CYAN, cli.BLUE, cli.PURPLE, cli.WHITE, cli.BLACK] can.onmotion.clear(can, can.svg), can.svg.Value(mdb.COUNT, 0)
var begin = 0; msg["color"] = [], msg["weight"] = [], msg.Table(function(value, index) { var span = parseInt(value[field])/total*360 var total = 0; msg.Table(function(value) { total += can.onimport._parseInt(can, value[field]) })
var p = index==which? pos(x, y, margin, begin+span/2): [x, y]; index == which && can.Status(value) var begin = 0; msg[cli.COLOR] = [], msg["weight"] = [], msg.Table(function(value, index) { var span = can.onimport._parseInt(can, value[field])/total*360
var c = color[index%color.length]; pie(p[0], p[1], r, begin, span, c, function(event) { var p = index==which? pos(x, y, margin, begin+span/2): [x, y], c = color[index%color.length]
if (index == can._last) { return } can._last = index
can.onmotion.clear(can, can.svg), can.svg.Value("count", 0) pie(p[0], p[1], r, begin, span, c, function(event) { can.onimport._draw(can, msg, field, color, x, y, r, margin, index) }), begin += span
can.onimport._draw(can, msg, field, x, y, r, margin, index) msg.Push(cli.COLOR, '<span style="background-color:'+c+'"> </span>')
can.onimport._profile(can, event.target) msg.Push("weight", parseInt(span*100/360)+"%")
}), begin += span, msg.Push("color", '<span style="background-color:'+c+'"> </span>') if (index == which) { can.Status(value), can.Status("weight", parseInt(span*100/360)+"%") }
msg.Push("weight", parseInt(parseInt(value[field])*10000/total)/100+"%")
}) })
}, },
_parseInt: function(can, value) { value = value.toLowerCase()
if (can.base.endWith(value, "mi")) { return parseInt(value)*1000000 }
if (can.base.endWith(value, "gi")) { return parseInt(value)*1000000000 }
return parseInt(value)
}
}) })
Volcanos(chat.ONEXPORT, {help: "导出数据", list: [], _show: function(can) {}})

View File

@ -3,16 +3,13 @@ Volcanos(chat.ONIMPORT, {help: "导入数据", list: [], _init: function(can, ms
if (msg.Length() == 0) { return } if (msg.Length() == 0) { return }
if (msg.Option("branch")) { return can.onappend.table(can, msg) } if (msg.Option("branch")) { return can.onappend.table(can, msg) }
can.onappend._status(can, ["from", "commit", "total", "max", "date", "text", "add", "del"])
can.data = msg.Table(), can.onimport._sum(can) can.data = msg.Table(), can.onimport._sum(can)
can.Action(html.HEIGHT, msg.Option(html.HEIGHT)||ice.AUTO) can.Action(html.HEIGHT, msg.Option(html.HEIGHT)||ice.AUTO)
can.Action("speed", parseInt(msg.Option("speed")||"100")) can.Action(html.SPEED, parseInt(msg.Option(html.SPEED)||"100"))
can.onmotion.hidden(can, can._action) can.page.ClassList.add(can, can._fields, "draw")
can.require(["/plugin/local/wiki/draw.js", "/plugin/local/wiki/draw/path.js"], function() { can.require(["/plugin/local/wiki/draw.js", "/plugin/local/wiki/draw/path.js"], function() {
can.page.ClassList.add(can, can._fields, "draw") can.onimport.layout(can)
can.onimport._show(can, msg), can.onmotion.hidden(can, can.ui.project)
can.onaction[can.Action(ice.VIEW)](event, can)
}) })
}, },
_sum: function(can) { _sum: function(can) {
@ -40,34 +37,41 @@ Volcanos(chat.ONIMPORT, {help: "导入数据", list: [], _init: function(can, ms
}) })
can.Status({"from": begin, "commit": count, "total": add+del, "max": max}) can.Status({"from": begin, "commit": count, "total": add+del, "max": max})
}, },
}, [""]) _layout: function(can) {
Volcanos(chat.ONACTION, {help: "组件菜单", list: ["edit", [ice.VIEW, "趋势图", "柱状图", "数据源"], ["height", "100", "200", "400", "600", "800", "auto"], ["speed", "10", "20", "50", "100"]], var height = can.onexport.height(can)
"edit": function(event, can) { can.onmotion.toggle(can, can._action), can.onmotion.toggle(can, can._status) }, var width = parseInt(can.ConfWidth()), space = 10
"趋势图": function(event, can) { var height = can.Action(html.HEIGHT)
if (height == ice.AUTO) { height = can.ConfHeight() }
height = parseInt(height)
var space = 10, width = parseInt(can.ConfWidth())
var step = parseInt((width-2*space) / can.list.length) var step = parseInt((width-2*space) / can.list.length)
can.onmotion.clear(can, can.svg) can.onmotion.clear(can, can._output)
can.svg.Val(html.HEIGHT, height) can.onimport._show(can, can._msg), can.onmotion.hidden(can, can.ui.project)
can.svg.Val(html.WIDTH, width) can.svg.Val(html.HEIGHT, height), can.svg.Val(html.WIDTH, width)
return {height: height, width: width, space: 10, step: step}
},
layout: function(can) {
can.onaction[can.Action(ice.VIEW)]({}, can)
},
}, [""])
Volcanos(chat.ONACTION, {help: "组件菜单", list: ["edit",
[ice.VIEW, "趋势图", "柱状图", "数据源"],
[html.HEIGHT, "100", "200", "400", "600", "800", ice.AUTO],
[html.SPEED, "10", "20", "50", "100"]
],
"edit": function(event, can) { can.onmotion.toggle(can, can._action), can.onmotion.toggle(can, can._status) },
function scale(y) { return (y - can.min)/(can.max - can.min)*(height-2*space) } "趋势图": function(event, can) { var args = can.onimport._layout(can)
function order(index, x, y) { return {x: space+step*index+x, y: height-space-scale(y)} } function scale(y) { return (y - can.min)/(can.max - can.min)*(args.height-2*args.space) }
function order(index, x, y) { return {x: args.space+args.step*index+x, y: args.height-args.space-scale(y)} }
can.core.Next(can.list, function(line, next, index) { can.core.Next(can.list, function(line, next, index) {
can.onimport.draw({}, can, { can.onimport.draw({}, can, {
shape: svg.LINE, point: [ shape: svg.LINE, point: [
order(index, step/2, line.min), order(index, step/2, line.max), order(index, args.step/2, line.min), order(index, args.step/2, line.max),
], style: kit.Dict(html.STROKE_WIDTH, 1, html.STROKE, line.begin < line.close? chat.WHITE: chat.BLACK), ], style: kit.Dict(html.STROKE_WIDTH, 1, html.STROKE, line.begin < line.close? chat.WHITE: chat.BLACK),
}) })
can.onimport.draw({}, can, { can.onimport.draw({}, can, {
shape: svg.RECT, point: [ shape: svg.RECT, point: [
order(index, step/4, line.close), order(index, step/4*3, line.begin), order(index, args.step/4, line.close), order(index, args.step/4*3, line.begin),
], style: can.base.Copy(kit.Dict(html.STROKE_WIDTH, 1, svg.RX, 0, svg.RY, 0), line.begin < line.close? ], style: can.base.Copy(kit.Dict(html.STROKE_WIDTH, 1, svg.RX, 0, svg.RY, 0), line.begin < line.close?
kit.Dict(html.STROKE, chat.WHITE, html.FILL, chat.WHITE): kit.Dict(html.STROKE, chat.BLACK, html.FILL, chat.BLACK) kit.Dict(html.STROKE, chat.WHITE, html.FILL, chat.WHITE): kit.Dict(html.STROKE, chat.BLACK, html.FILL, chat.BLACK)
), ),
@ -77,60 +81,48 @@ Volcanos(chat.ONACTION, {help: "组件菜单", list: ["edit", [ice.VIEW, "趋势
}) })
can.Status(line, ["date", "text", "add", "del"]) can.Status(line, ["date", "text", "add", "del"])
can.core.Timer(parseInt(can.Action("speed")), next) can.core.Timer(parseInt(can.Action(html.SPEED)), next)
}) })
}, },
"柱状图": function(event, can) { "柱状图": function(event, can) { var args = can.onimport._layout(can)
var max = {}, min = {} var max = {}, min = {}; can.core.List(can._msg.append, function(key, which) {
can.core.List(can._msg.append, function(key, which) {
can.core.List(can.data, function(value, index) { can.core.List(can.data, function(value, index) {
var v = parseInt(value[key])||0; if (index == 0) { var v = parseInt(value[key])||0; if (index == 0) {
max[key] = v, min[key] = v return max[key] = v, min[key] = v
return
} }
if (v > max[key]) { max[key] = v } if (v > max[key]) { max[key] = v }
if (v < min[key]) { min[key] = v } if (v < min[key]) { min[key] = v }
}) })
}) })
var height = parseInt(can.Action(html.HEIGHT)) function scale(key, y) { return (y - min[key])/(max[key] - min[key])*(args.height-2*args.space) }
var space = 10, width = parseInt(can.ConfWidth())
var step = parseInt((width-2*space) / can.list.length)
can.onmotion.clear(can, can.svg) var width = args.step/can._msg.append.length, which = 0
can.svg.Val(html.HEIGHT, height) can.core.List(can._msg.append, function(key, which) { if (max[key] == min[key]) { return }
can.svg.Val(html.WIDTH, width) can.core.Next(can.data, function(line, next, index) { if (parseInt(line[key]) == 0) { return }
can.onimport.draw({}, can, {shape: svg.RECT, point: [
function scale(key, y) { return (y - min[key])/(max[key] - min[key])*(height-2*space) } {x: args.space+args.step*index+width*which+2, y: args.height-args.space-scale(key, parseInt(line[key]))},
function order(index, key, x, y) { return {x: space+step*index+x, y: space+scale(key, y)} } {x: args.space+args.step*index+width*(which+1)+2, y: args.height-args.space},
], style: kit.Dict(html.STROKE_WIDTH, 1, html.STROKE, cli.WHITE, html.FILL, cli.WHITE, svg.RX, 0, svg.RY, 0), _init: function(view) {
var width = (step-4)/can._msg.append.length can.core.ItemCB(can.ondetail, function(key, cb) { view[key] = function(event) { cb(event, can, line) } })
can.core.List(can._msg.append, function(key, which) { }}), can.core.Timer(parseInt(can.Action(html.SPEED)), next)
max[key] != min[key] && can.core.Next(can.data, function(line, next, index) { }), which++
var y = scale(key, parseFloat(line[key]))
y && can.onimport.draw({}, can, {
shape: svg.RECT, point: [
order(index, key, width*which+2, 0), order(index, key, width*which+2+width, y),
], style: kit.Dict(html.STROKE_WIDTH, 1, html.STROKE, cli.WHITE, html.FILL, cli.WHITE, svg.RX, 0, svg.RY, 0),
_init: function(view) {
can.core.ItemCB(can.ondetail, function(key, cb) { view[key] = function(event) { cb(event, can, line) } })
},
})
can.core.Timer(parseInt(can.Action("speed")), next)
})
}) })
}, },
"数据源": function(event, can) { "数据源": function(event, can) {
can.onmotion.clear(can, can.ui.display) can.onmotion.clear(can, can._output)
can.onappend.table(can, can._msg, null, can.ui.display) can.onappend.table(can, can._msg, null, can._output)
can.onmotion.show(can, can.ui.display)
}, },
height: function(event, can) { can.onaction[can.Action(ice.VIEW)](event, can) }, height: function(event, can) { can.onimport.layout(can) },
speed: function(event, can) { can.onaction[can.Action(ice.VIEW)](event, can) }, speed: function(event, can) { can.onimport.layout(can) },
}) })
Volcanos(chat.ONDETAIL, {help: "用户交互", list: [], Volcanos(chat.ONDETAIL, {help: "用户交互", list: [],
onmouseenter: function(event, can, line) { can.Status(line, ["date", "text", "add", "del"]) }, onmouseenter: function(event, can, line) { can.Status(line, ["date", "note", "adds", "dels"]) },
})
Volcanos(chat.ONEXPORT, {help: "导出数据", list: ["from", "commit", "total", "max", "date", "note", "adds", "dels"],
height: function(can) { var height = can.Action(html.HEIGHT)
if (height == ice.AUTO) { height = can.ConfHeight() }
return parseInt(height)
},
}) })
Volcanos(chat.ONEXPORT, {help: "导出数据", list: []})

View File

@ -62,6 +62,7 @@ var cli = {
DAEMON: "daemon", DAEMON: "daemon",
START: "start", STOP: "stop", OPEN: "open", CLOSE: "close", BEGIN: "begin", END: "end", START: "start", STOP: "stop", OPEN: "open", CLOSE: "close", BEGIN: "begin", END: "end",
COLOR: "color",
RED: "red", GREEN: "green", BLUE: "blue", RED: "red", GREEN: "green", BLUE: "blue",
YELLOW: "yellow", CYAN: "cyan", PURPLE: "purple", MAGENTA: "magenta", YELLOW: "yellow", CYAN: "cyan", PURPLE: "purple", MAGENTA: "magenta",
WHITE: "white", BLACK: "black", WHITE: "white", BLACK: "black",
@ -197,11 +198,11 @@ var mall = {
} }
var svg = { var svg = {
PID: "pid", GROUP: "group", PID: "pid",
GROUP: "group",
SHAPE: "shape", TEXT: "text", RECT: "rect", LINE: "line", CIRCLE: "circle", ELLIPSE: "ellipse", SHAPE: "shape", TEXT: "text", RECT: "rect", LINE: "line", CIRCLE: "circle", ELLIPSE: "ellipse",
G: "g", X: "x", Y: "y", R: "r", RX: "rx", RY: "ry", CX: "cx", CY: "cy", X1: "x1", Y1: "y1", X2: "x2", Y2: "y2", G: "g", X: "x", Y: "y", R: "r", RX: "rx", RY: "ry", CX: "cx", CY: "cy", X1: "x1", Y1: "y1", X2: "x2", Y2: "y2",
M: "M", Q: "Q", T: "T", PATH2V: "path2v", PATH2H: "path2h", PATH: "path", PATH2V: "path2v", PATH2H: "path2h",
M: "M", Q: "Q", T: "T",
} }
var html = { var html = {
// FIELDSET // FIELDSET