Skip to content

Commit b27308a

Browse files
committed
fix: 修复 deque 因某些原因会导致报错
1 parent d8755cf commit b27308a

File tree

3 files changed

+194
-14
lines changed

3 files changed

+194
-14
lines changed

assets/js/common.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,9 @@ class Style {
353353
this._current_theme = name || Object.keys(this._themes)[0];
354354
this.render();
355355
}
356+
getThemeValue(key) {
357+
return (this._themes[this._current_theme] || {})[key];
358+
}
356359
setTheme(name, style) {
357360
this._themes[name] = style;
358361
}

assets/js/index.js

Lines changed: 189 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ class FlexElement extends Element {
453453
if (this.$autoheight) {
454454
child.style("height", `${heightHandler(child)}px`)
455455
}
456+
child.origin.getBoundingClientRect()
456457
}
457458
}
458459
_render_calc_child_width(total_child, index, container_width) {
@@ -494,6 +495,73 @@ class FlexElement extends Element {
494495
return this;
495496
}
496497
}
498+
const EchartType = {
499+
DATA: 0,
500+
LABEL: 1
501+
}
502+
class TemplateEchartElement extends Element {
503+
constructor() {
504+
super("div")
505+
this.instance = echarts.init(this.origin)
506+
this.formatter = this._format_number_unit
507+
this.type = EchartType.DATA
508+
this.setOption({
509+
stateAnimation: {
510+
duration: 300,
511+
easing: "cubicOut"
512+
},
513+
tooltip: {
514+
trigger: 'axis',
515+
formatter: (params) => this._e_templates(params)
516+
}
517+
})
518+
}
519+
setFormatter(formatter) {
520+
this.formatter = formatter || this._format_number_unit
521+
return this
522+
}
523+
setOption(option) {
524+
this.instance.setOption(option)
525+
if ('tooltip' in option && 'formatter' in option['tooltip']) return this
526+
this.setOption({
527+
tooltip: {
528+
...option['tooltip'],
529+
formatter: (params) => this._e_templates(params)
530+
}
531+
})
532+
return this
533+
}
534+
setType(type) {
535+
this.type = type
536+
return this
537+
}
538+
clear() {
539+
this.instance.clear()
540+
return this
541+
}
542+
_format_number_unit(n) {
543+
var d = (n + "").split("."), i = d[0], f = d.length >= 2 ? "." + d.slice(1).join(".") : ""
544+
return i.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") + f;
545+
}
546+
resize() {
547+
this.instance.resize()
548+
return this
549+
}
550+
_e_templates(params) {
551+
const value_formatter = this.formatter
552+
const data_label = this.type == EchartType.LABEL
553+
const templates = `<div style="margin: 0px 0 0;line-height:1;"><div style="margin: 0px 0 0;line-height:1;">` + (data_label ? '' : `<span style="display:inline-block;margin-right:4px;border-radius:10px;width:10px;height:10px;background-color:{color};"></span>`) + `<span style="font-size:14px;color:#666;font-weight:400;margin-left:2px">{name}</span><span style="float:right;margin-left:20px;font-size:14px;color:#666;font-weight:900">{value}</span><div style="clear:both"></div></div><div style="clear:both"></div></div>`
554+
var template = ''
555+
for (const data of (Array.isArray(params) ? params : [params])) {
556+
let value = isNaN(data.value) ? 0 : data.value
557+
template += templates.replace("{color}", data.color).replace("{name}", `${data.seriesName}${data_label ? `(${data.data.label})` : ""}`).replace("{value}", value_formatter ? value_formatter(value) : value)
558+
}
559+
return `<div style="margin: 0px 0 0;line-height:1;"><div style="margin: 0px 0 0;line-height:1;">` + (data_label ? `` : `<div style="font-size:14px;color:#666;font-weight:400;line-height:1;">${(Array.isArray(params) ? params[0] : params).name}</div>`) + `<div style="margin: ${data_label ? 0 : 10}px 0 0;line-height:1;">${template}</div><div style="clear:both"></div></div><div style="clear:both"></div></div>`
560+
}
561+
getOption() {
562+
return this.instance.getOption()
563+
}
564+
}
497565

498566
const $configuration = new Configuration();
499567
const $ElementManager = new ElementManager();
@@ -785,6 +853,14 @@ class Tools {
785853
}
786854
return `${bytes.toFixed(2)}${Object.keys(Tools._BYTES)[i]}`
787855
}
856+
static createEchartElement(handler) {
857+
var base = new TemplateEchartElement()
858+
handler({
859+
echart: base.instance,
860+
base
861+
})
862+
return base
863+
}
788864
}
789865
async function load() {
790866
const $dom_body = new Element(document.body);
@@ -851,7 +927,7 @@ async function load() {
851927
}
852928
}
853929
}),
854-
).child(2).minWidth(680).autoHeight(true)
930+
).child(2).minWidth(680)
855931
)
856932
})
857933
$dashboard_locals.info_runtime = ref({}, {
@@ -1004,30 +1080,123 @@ async function load() {
10041080
$dashboard_locals.files_info,
10051081
$dashboard_locals.system_info
10061082
)
1083+
const section = Tools.createFlexElement().child('70%', '30%').minWidth(1280)
10071084
$dashboard_locals.basic_qps = Tools.createPanel(({ pre, panel }) => {
1008-
var task = null;
1085+
var instance = Tools.createEchartElement(({
1086+
echart, base
1087+
}) => {
1088+
base.style("min-height", "180px")
1089+
$dashboard_locals.basic_qps_echart = {
1090+
echart, base
1091+
};
1092+
})
1093+
panel.append(
1094+
createElement("div").classes("title").append(
1095+
createElement("div").append(
1096+
createElement("p").i18n("dashboard.title.qps"),
1097+
// ...
1098+
)
1099+
),
1100+
instance
1101+
)
10091102
var observer = new ResizeObserver(() => {
1010-
clearTimeout(task)
1011-
task = setTimeout(() => {
1012-
pre.style("height", `${calcElementHeight(info_collection)}px`)
1013-
panel.style("height", "100%")
1014-
clearTimeout(task)
1015-
}, 250)
1103+
var width = calcElementWidth(section)
1104+
if (width < 1280) {
1105+
pre.style("height", `auto`)
1106+
return
1107+
}
1108+
pre.style("height", `${calcElementHeight(info_collection)}px`)
1109+
panel.style("height", "100%")
1110+
instance.resize()
10161111
})
10171112
observer.observe(info_collection.origin)
10181113
})
10191114
basic.push(
1020-
Tools.createFlexElement().append(
1115+
section.append(
10211116
info_collection,
10221117
$dashboard_locals.basic_qps
1023-
).child('60%', '40%').minWidth(1280)
1118+
)
10241119
)
10251120
})();
10261121

10271122
// share
10281123
(() => {
1029-
$dashboard_locals.qps = createElement("div").classes("qps-container").append
1030-
});
1124+
var option = {
1125+
tooltip: {
1126+
trigger: 'axis',
1127+
},
1128+
stateAnimation: {
1129+
duration: 300,
1130+
easing: "cubicOut"
1131+
},
1132+
xAxis: {
1133+
type: "category",
1134+
show: false,
1135+
},
1136+
yAxis: {
1137+
show: false,
1138+
type: "value",
1139+
},
1140+
grid: {
1141+
top: 10,
1142+
bottom: 10,
1143+
right: 0,
1144+
left: 0,
1145+
show: !1,
1146+
z: 0,
1147+
containLabel: !1,
1148+
backgroundColor: "rgba(0,0,0,0)",
1149+
borderWidth: 1,
1150+
borderColor: "#ccc"
1151+
},
1152+
series: [
1153+
{
1154+
type: "bar",
1155+
barGap: "0",
1156+
barMinHeight: 4,
1157+
itemStyle: {
1158+
borderRadius: [2, 2, 0, 0]
1159+
},
1160+
z: 2,
1161+
backgroundStyle: {
1162+
color: "rgba(180, 180, 180, 0.2)",
1163+
borderColor: null,
1164+
borderWidth: 0,
1165+
borderType: "solid",
1166+
borderRadius: 0,
1167+
shadowBlur: 0,
1168+
shadowColor: null,
1169+
shadowOffsetX: 0,
1170+
shadowOffsetY: 0
1171+
},
1172+
select: {
1173+
itemStyle: {
1174+
borderColor: "#212121"
1175+
}
1176+
},
1177+
}
1178+
]
1179+
}
1180+
const instances = [
1181+
$dashboard_locals.basic_qps_echart
1182+
]
1183+
for (let qps of instances) {
1184+
qps.echart.setOption(option)
1185+
}
1186+
$dashboard_locals.qps_task = Tools.runTask(setInterval, async () => {
1187+
var resp = await $channel.send("qps")
1188+
var option = {
1189+
color: $style.getThemeValue("main-color"),
1190+
xAxis: {
1191+
data: Object.keys(resp)
1192+
},
1193+
series: [{ name: 'QPS', data: Object.values(resp) }]
1194+
}
1195+
for (let instance of instances) {
1196+
instance.echart.setOption(option)
1197+
}
1198+
}, 5000)
1199+
})();
10311200

10321201
const reset_display = () => {
10331202
$dashboard_locals.info_runtime.value = Tools.formatTime(0)
@@ -1044,6 +1213,7 @@ async function load() {
10441213
while ($dashboard_locals.container.firstChild != null) {
10451214
$dashboard_locals.container.removeChild($dashboard_locals.container.firstChild)
10461215
}
1216+
clearEcharts()
10471217
clearDashboardTask()
10481218
reset_display()
10491219
if (event.detail.index == 0) {
@@ -1118,10 +1288,17 @@ async function load() {
11181288
)
11191289
})
11201290

1291+
const clearEcharts = (all = false) => {
1292+
const $dashboard_locals = $menu_variables;
1293+
if ($dashboard_locals) return;
1294+
$dashboard_locals.basic_qps_echart.echart.clear()
1295+
}
1296+
11211297
const clearDashboardTask = (all = false) => {
11221298
const $dashboard_locals = $menu_variables;
11231299
if ($dashboard_locals) return;
11241300
clearInterval($dashboard_locals.basic_task_file_info)
1301+
clearInterval($dashboard_locals.basic_task_system_info)
11251302
if (!all) return;
11261303
clearInterval($dashboard_locals.info_runtime_task)
11271304
}

core/dashboard.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def all_qps(self):
109109
CounterQPS(
110110
item._,
111111
item.value.qps
112-
) for item in self._data
112+
) for item in self._data.copy()
113113
]
114114

115115
@property
@@ -120,7 +120,7 @@ def all_system_info(self):
120120
item.value.cpu_usage,
121121
item.value.memory_usage,
122122
item.value.connection
123-
) for item in self._data
123+
) for item in self._data.copy()
124124
]
125125

126126
@dataclass

0 commit comments

Comments
 (0)