1
0
mirror of https://shylinux.com/x/ContextOS synced 2025-04-25 16:58:06 +08:00

add ticket.canvas.js

This commit is contained in:
shaoying 2019-07-09 09:20:16 +08:00
parent 07061b3622
commit 10cf54168f
3 changed files with 72 additions and 6 deletions

View File

@ -4,5 +4,5 @@ var version = struct {
host string
self int
}{
"2019-07-08 16:56:13", "ZYB-20190522USI", 122,
"2019-07-08 23:23:11", "com.mac", 57,
}

View File

@ -1253,7 +1253,7 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
}},
"git": &ctx.Command{Name: "git sum", Help: "版本控制", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
if len(arg) > 0 && arg[0] == "sum" {
if out, e := exec.Command("git", "log", "--shortstat", "--pretty=commit: %ad", "--date=format:%Y-%m-%d").CombinedOutput(); m.Assert(e) {
if out, e := exec.Command("git", "log", "--reverse", "--shortstat", "--pretty=commit: %ad", "--date=format:%Y-%m-%d").CombinedOutput(); m.Assert(e) {
for _, v := range strings.Split(string(out), "commit: ") {
if l := strings.Split(v, "\n"); len(l) > 2 {
fs := strings.Split(strings.TrimSpace(l[2]), ", ")
@ -1395,6 +1395,10 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
m.Cmdy("nfs.dir", "src", "filename", "line", "size", "dir_deep", "dir_type", "file", "dir_sort", "line", "int_r")
return
}
if arg[0] == "git" {
m.Cmdy("nfs.git", "sum")
return
}
m.Append("text", m.Time())
m.Append("style", map[int]string{

View File

@ -854,7 +854,7 @@ function Canvas(plugin, output, width, height, space, msg) {
var list = []
msg[key].forEach(function(value, index) {
var v = parseInt(value)
!isNaN(v) && (list.push(v), v > (max[key]||0) && (max[key] = v))
!isNaN(v) && (list.push((value.indexOf("-") == -1)? v: value), v > (max[key]||0) && (max[key] = v))
})
list.length == nrow && (keys.push(key), data[key] = list, nline++)
})
@ -1072,6 +1072,64 @@ function Canvas(plugin, output, width, height, space, msg) {
return p
},
},
ticket: {
draw: function() {
what.drawAxies().drawXLabel(step)
canvas.beginPath()
var sum = 0, total = 0
for (var i = 0; i < nrow; i++) {
sum += data[keys[1]][i]
sum > total && (total = sum)
sum -= data[keys[2]][i]
}
if (!data["sum"]) {
var sum = 0, max = 0, min = 0, end = 0
keys = keys.concat(["sum", "max", "min", "end"])
data["sum"] = []
data["max"] = []
data["min"] = []
data["end"] = []
for (var i = 0; i < nrow; i++) {
max = sum + data[keys[1]][i]
min = sum - data[keys[2]][i]
end = sum + data[keys[1]][i] - data[keys[2]][i]
data["sum"].push(sum)
data["max"].push(max)
data["min"].push(min)
data["end"].push(end)
sum = end
}
}
for (var i = 0; i < nrow; i++) {
if (data["sum"][i] < data["end"][i]) {
canvas.moveTo(step*i, data["min"][i]/total*height)
canvas.lineTo(step*i, data["sum"][i]/total*height)
canvas.moveTo(step*i, data["max"][i]/total*height)
canvas.lineTo(step*i, data["end"][i]/total*height)
} else {
canvas.moveTo(step*i, data["min"][i]/total*height)
canvas.lineTo(step*i, data["end"][i]/total*height)
canvas.moveTo(step*i, data["max"][i]/total*height)
canvas.lineTo(step*i, data["sum"][i]/total*height)
}
}
canvas.strokeStyle = conf.data.style
canvas.lineWidth = conf.data.width
canvas.stroke()
},
show: function(p) {
index = parseInt(p.x/step)
canvas.moveTo(p.x, -space)
canvas.lineTo(p.x, height)
canvas.moveTo(-space, p.y)
canvas.lineTo(width, p.y)
return p
},
},
stick: {
draw: function() {
what.drawAxies().drawXLabel(step)
@ -1212,9 +1270,12 @@ function Canvas(plugin, output, width, height, space, msg) {
p.x += conf.plabel.offset
p.y -= conf.plabel.offset
if (width - p.x < 200) {
p.x -= 200
}
canvas.fillText("index: "+index, p.x, -p.y+conf.plabel.height)
msg.append.forEach(function(key, i, n) {
msg[key][index] && canvas.fillText(key+": "+msg[key][index], p.x, -p.y+(i+2)*conf.plabel.height)
keys.forEach(function(key, i) {
data[key][index] && canvas.fillText(key+": "+data[key][index], p.x, -p.y+(i+2)*conf.plabel.height)
})
canvas.restore()
return what
@ -1379,6 +1440,7 @@ function Canvas(plugin, output, width, height, space, msg) {
},
trans: {
"折线图": ["type", "trend"],
"股价图": ["type", "ticket"],
"柱状图": ["type", "stick"],
"饼状图": ["type", "weight"],
@ -1459,7 +1521,7 @@ function Canvas(plugin, output, width, height, space, msg) {
}
var action = kit.AppendAction(kit.AppendChild(output, [{view: ["action"]}]).last, [
["折线图", "柱状图", "饼状图"],
["折线图", "股价图", "柱状图", "饼状图"],
["移动", "旋转", "缩放"],
["文本", "直线", "折线", "矩形", "圆形", "椭圆"],
["辅助点", "辅助线"],