waibu-db 1.1.16 → 1.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bajoTemplate/partial/crud/~echarts-window.html +1 -1
- package/lib/crud/helper/add-ons-handler.js +3 -2
- package/lib/prep-crud.js +1 -1
- package/package.json +1 -1
- package/plugin/method/stat/aggregate.js +1 -0
- package/plugin/method/stat/histogram.js +1 -0
- package/waibuBootstrap/theme/component/factory/echarts-bar.js +59 -0
- package/waibuBootstrap/theme/component/factory/echarts-pie.js +39 -0
- package/waibuBootstrap/theme/component/factory/echarts.js +41 -41
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
<c:card-title t:content="<%= attr.name %>" />
|
|
4
4
|
</c:card-header>
|
|
5
5
|
<c:card-body>
|
|
6
|
-
<c:wdb-echarts style="height: 150px;"
|
|
6
|
+
<c:wdb-echarts style="height: 150px;" setting="<%= attr.setting %>">
|
|
7
7
|
</c:wdb-echarts>
|
|
8
8
|
</c:card-body>
|
|
9
9
|
</c:card>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
async function addOnsHandler ({ req, reply, data, schema }) {
|
|
2
|
+
const { escape } = this.app.waibu
|
|
2
3
|
const { base64JsonEncode } = this.app.waibuMpa
|
|
3
4
|
const { statAggregate } = this.app.waibuDb
|
|
4
5
|
const { get, map, pick, pullAt } = this.lib._
|
|
@@ -17,7 +18,7 @@ async function addOnsHandler ({ req, reply, data, schema }) {
|
|
|
17
18
|
for (const d of resp.data) {
|
|
18
19
|
const key = o.dbOpts.fields[0]
|
|
19
20
|
data.push({
|
|
20
|
-
name: d[key],
|
|
21
|
+
name: escape(d[key]),
|
|
21
22
|
value: d[key + 'Count']
|
|
22
23
|
})
|
|
23
24
|
}
|
|
@@ -37,7 +38,7 @@ async function addOnsHandler ({ req, reply, data, schema }) {
|
|
|
37
38
|
if (dropped.length > 0) pullAt(opts, dropped)
|
|
38
39
|
return map(opts, o => {
|
|
39
40
|
return {
|
|
40
|
-
data: {
|
|
41
|
+
data: { setting: o.chartOpts, name: o.name },
|
|
41
42
|
resource: 'waibuDb.partial:/crud/~echarts-window.html'
|
|
42
43
|
}
|
|
43
44
|
})
|
package/lib/prep-crud.js
CHANGED
|
@@ -2,7 +2,7 @@ function prepCrud ({ model, body, id, req, reply, options = {}, args }) {
|
|
|
2
2
|
const { parseFilter } = this.app.waibu
|
|
3
3
|
const { pascalCase } = this.app.bajo
|
|
4
4
|
const { cloneDeep, has } = this.lib._
|
|
5
|
-
const cfgWeb = this.app.waibu.
|
|
5
|
+
const cfgWeb = this.app.waibu.getConfig()
|
|
6
6
|
const opts = cloneDeep(options)
|
|
7
7
|
const params = this.getParams(req, ...args)
|
|
8
8
|
for (const k of ['count', 'fields']) {
|
package/package.json
CHANGED
|
@@ -7,6 +7,7 @@ async function aggregate ({ model, req, reply, options = {} }) {
|
|
|
7
7
|
for (const item of ['group', 'aggregate']) {
|
|
8
8
|
opts[item] = options[item] ?? req.params[item] ?? req.query[item]
|
|
9
9
|
}
|
|
10
|
+
opts.aggregate = opts.aggregate ?? 'count'
|
|
10
11
|
return await statAggregate(name, parseFilter(req), opts)
|
|
11
12
|
}
|
|
12
13
|
|
|
@@ -7,6 +7,7 @@ async function histogram ({ model, req, reply, options = {} }) {
|
|
|
7
7
|
for (const item of ['type', 'group', 'aggregate']) {
|
|
8
8
|
opts[item] = options[item] ?? req.params[item] ?? req.query[item]
|
|
9
9
|
}
|
|
10
|
+
opts.aggregate = opts.aggregate ?? 'count'
|
|
10
11
|
return await statHistogram(name, parseFilter(req), opts)
|
|
11
12
|
}
|
|
12
13
|
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import echartsBase from './echarts.js'
|
|
2
|
+
|
|
3
|
+
async function echartsBar () {
|
|
4
|
+
const WdbEcharts = await echartsBase.call(this)
|
|
5
|
+
|
|
6
|
+
return class WdbEchartsBar extends WdbEcharts {
|
|
7
|
+
build = async () => {
|
|
8
|
+
const { jsonStringify } = this.plugin.app.waibuMpa
|
|
9
|
+
const { merge } = this.plugin.lib._
|
|
10
|
+
merge(this.setting, {
|
|
11
|
+
tooltip: {
|
|
12
|
+
trigger: 'axis',
|
|
13
|
+
axisPointer: {
|
|
14
|
+
type: 'shadow'
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
grid: {
|
|
18
|
+
containLabel: true,
|
|
19
|
+
top: 8,
|
|
20
|
+
bottom: 0,
|
|
21
|
+
left: 0,
|
|
22
|
+
right: 0
|
|
23
|
+
},
|
|
24
|
+
xAxis: {
|
|
25
|
+
type: 'category',
|
|
26
|
+
data: [],
|
|
27
|
+
axisTick: {
|
|
28
|
+
alignWithLabel: true
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
yAxis: {
|
|
32
|
+
type: 'value'
|
|
33
|
+
},
|
|
34
|
+
series: [{
|
|
35
|
+
data: [],
|
|
36
|
+
type: 'bar'
|
|
37
|
+
}]
|
|
38
|
+
})
|
|
39
|
+
const onLoad = []
|
|
40
|
+
if (this.params.attr.remote) {
|
|
41
|
+
const remote = this._parseBase64Attr(this.params.attr.remote)
|
|
42
|
+
onLoad.push(`
|
|
43
|
+
this.chart.showLoading('default', { text: '' })
|
|
44
|
+
const remote = ${jsonStringify(remote, true)}
|
|
45
|
+
const agg = remote.filter.aggregate ?? 'count'
|
|
46
|
+
const recs = await wmpa.fetchApi(remote.url, { fetching: false }, remote.filter)
|
|
47
|
+
this.chart.hideLoading()
|
|
48
|
+
this.option = {
|
|
49
|
+
xAxis: { data: _.map(recs, remote.key.name) },
|
|
50
|
+
series: [{ type: 'bar', data: _.map(recs, remote.key.value ?? agg ) }]
|
|
51
|
+
}
|
|
52
|
+
`)
|
|
53
|
+
}
|
|
54
|
+
this._build({ onLoad })
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export default echartsBar
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import echartsBase from './echarts.js'
|
|
2
|
+
|
|
3
|
+
async function echartsPie () {
|
|
4
|
+
const WdbEcharts = await echartsBase.call(this)
|
|
5
|
+
|
|
6
|
+
return class WdbEchartsPie extends WdbEcharts {
|
|
7
|
+
build = async () => {
|
|
8
|
+
const { jsonStringify } = this.plugin.app.waibuMpa
|
|
9
|
+
const { merge } = this.plugin.lib._
|
|
10
|
+
merge(this.setting, {
|
|
11
|
+
tooltip: {
|
|
12
|
+
trigger: 'item'
|
|
13
|
+
},
|
|
14
|
+
series: [{
|
|
15
|
+
type: 'pie',
|
|
16
|
+
data: []
|
|
17
|
+
}]
|
|
18
|
+
})
|
|
19
|
+
const onLoad = []
|
|
20
|
+
if (this.params.attr.remote) {
|
|
21
|
+
const remote = this._parseBase64Attr(this.params.attr.remote)
|
|
22
|
+
onLoad.push(`
|
|
23
|
+
this.chart.showLoading('default', { text: '' })
|
|
24
|
+
const remote = ${jsonStringify(remote, true)}
|
|
25
|
+
const agg = remote.filter.aggregate ?? 'count'
|
|
26
|
+
const keyName = remote.key.name ?? remote.filter.group
|
|
27
|
+
const keyValue = remote.key.value ?? keyName + _.upperFirst(agg)
|
|
28
|
+
const recs = await wmpa.fetchApi(remote.url, { fetching: false }, remote.filter)
|
|
29
|
+
const data = recs.map(r => ({ name: r[keyName], value: r[keyValue] }))
|
|
30
|
+
this.chart.hideLoading()
|
|
31
|
+
this.option = { series: [{ type: 'pie', data }]}
|
|
32
|
+
`)
|
|
33
|
+
}
|
|
34
|
+
this._build({ onLoad })
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export default echartsPie
|
|
@@ -10,7 +10,8 @@ async function echarts () {
|
|
|
10
10
|
|
|
11
11
|
constructor (options) {
|
|
12
12
|
super(options)
|
|
13
|
-
|
|
13
|
+
const { generateId } = this.plugin.app.bajo
|
|
14
|
+
this.defSetting = {
|
|
14
15
|
grid: {
|
|
15
16
|
top: 8,
|
|
16
17
|
bottom: 20,
|
|
@@ -19,49 +20,48 @@ async function echarts () {
|
|
|
19
20
|
}
|
|
20
21
|
}
|
|
21
22
|
this.params.tag = 'div'
|
|
23
|
+
this.params.attr.id = this.params.attr.id ?? generateId('alpha')
|
|
24
|
+
this.params.attr['x-data'] = `chart${this.params.attr.id}`
|
|
25
|
+
this.params.attr['@resize.window.debounce.500ms'] = 'resize()'
|
|
26
|
+
this.params.attr['@load.window'] = 'await windowLoad()'
|
|
22
27
|
}
|
|
23
28
|
|
|
24
|
-
|
|
25
|
-
const {
|
|
26
|
-
const {
|
|
27
|
-
|
|
28
|
-
this.
|
|
29
|
-
this.
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
},
|
|
48
|
-
get chart () {
|
|
49
|
-
return chart
|
|
50
|
-
},
|
|
51
|
-
resize: {
|
|
52
|
-
['@resize.window.debounce.500ms']() {
|
|
53
|
-
if (chart) {
|
|
54
|
-
chart.resize()
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
option: ${jsonStringify(option, true)}
|
|
29
|
+
_build = ({ setting = {}, onLoad = [] } = {}) => {
|
|
30
|
+
const { jsonStringify } = this.plugin.app.waibuMpa
|
|
31
|
+
const { merge, isArray } = this.plugin.app.bajo.lib._
|
|
32
|
+
if (!isArray(onLoad)) onLoad = [onLoad]
|
|
33
|
+
const option = merge({}, this.defSetting, this.setting, setting)
|
|
34
|
+
this.component.addScriptBlock('alpineInit', `
|
|
35
|
+
Alpine.data('chart${this.params.attr.id}', () => {
|
|
36
|
+
let chart
|
|
37
|
+
return {
|
|
38
|
+
init () {
|
|
39
|
+
const el = document.getElementById('${this.params.attr.id}')
|
|
40
|
+
chart = echarts.init(el, null, { renderer: 'canvas' })
|
|
41
|
+
chart.setOption(this.option)
|
|
42
|
+
this.$watch('option', val => {
|
|
43
|
+
chart.setOption(val)
|
|
44
|
+
})
|
|
45
|
+
},
|
|
46
|
+
get chart () {
|
|
47
|
+
return chart
|
|
48
|
+
},
|
|
49
|
+
resize () {
|
|
50
|
+
if (chart) {
|
|
51
|
+
chart.resize()
|
|
59
52
|
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
53
|
+
},
|
|
54
|
+
async windowLoad () {
|
|
55
|
+
${onLoad.join('\n')}
|
|
56
|
+
},
|
|
57
|
+
option: ${jsonStringify(option, true)}
|
|
58
|
+
}
|
|
59
|
+
})
|
|
60
|
+
`)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
build = async () => {
|
|
64
|
+
this._build()
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
}
|