Simple Linux Panel
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mdserver-web/plugins/simdht/js/simdht.js

264 lines
6.8 KiB

6 years ago
function dhtPostMin(method, args, callback){
6 years ago
var req_data = {};
6 years ago
req_data['name'] = 'simdht';
6 years ago
req_data['func'] = method;
if (typeof(args) != 'undefined' && args!=''){
req_data['args'] = JSON.stringify(args);
}
$.post('/plugins/run', req_data, function(data) {
if (!data.status){
layer.msg(data.msg,{icon:0,time:2000,shade: [0.3, '#000']});
return;
}
if(typeof(callback) == 'function'){
callback(data);
}
},'json');
}
6 years ago
function dhtPost(method, args, callback){
var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 });
dhtPostMin(method,args,function(data){
layer.close(loadT);
if(typeof(callback) == 'function'){
callback(data);
}
});
}
function dhtTrend(){
6 years ago
var obj = $('#dht_trend');
if (obj.length>0){
console.log('已经加载图表...');
return;
}
6 years ago
var trend = '<div id="dht_trend" style="width:100%;height:330px;"></div>';
$('.soft-man-con').html(trend);
dhtTrendRender();
}
function dhtTrendData(callback){
6 years ago
dhtPostMin('get_trend_data',{interval:1},function(data){
6 years ago
if(typeof(callback) == 'function'){
callback(data);
}
});
}
function dhtTrendRender() {
var myChartNetwork = echarts.init(document.getElementById('dht_trend'));
var xData = [];
6 years ago
var oneData = [];
var twoData = [];
var threeData = [];
6 years ago
function getTime() {
var now = new Date();
var hour = now.getHours();
var minute = now.getMinutes();
var second = now.getSeconds();
if (minute < 10) {
minute = "0" + minute;
}
if (second < 10) {
second = "0" + second;
}
var nowdate = hour + ":" + minute + ":" + second;
return nowdate;
}
function ts(m) { return m < 10 ? '0' + m : m }
function format(sjc) {
var time = new Date(sjc);
var h = time.getHours();
var mm = time.getMinutes();
var s = time.getSeconds();
return ts(h) + ':' + ts(mm) + ':' + ts(s);
}
function addData(data) {
6 years ago
// console.log(data);
var rdata = $.parseJSON(data.data);
6 years ago
xData.push(getTime());
6 years ago
oneData.push(rdata[0]);
twoData.push(rdata[1]);
threeData.push(rdata[2]);
xData.shift();
oneData.shift();
twoData.shift();
threeData.shift();
6 years ago
}
for (var i = 8; i >= 0; i--) {
var time = (new Date()).getTime();
6 years ago
xData.push(format(time - (i * 5 * 1000)));
oneData.push(0);
twoData.push(0);
threeData.push(0);
6 years ago
}
// 指定图表的配置项和数据
var option = {
title: {
6 years ago
text: '种子收录趋势',
6 years ago
left: 'center',
textStyle: {
6 years ago
color: '#888888',fontStyle: 'normal',
fontFamily: '宋体',fontSize: 16,
6 years ago
}
},
tooltip: {
trigger: 'axis'
},
legend: {
6 years ago
data: ['1s', '5s', '10s'],
6 years ago
bottom: '2%'
},
xAxis: {
type: 'category',
boundaryGap: false,
data: xData,
axisLine: {
lineStyle: {
color: "#666"
}
}
},
yAxis: {
6 years ago
name: '单位个数',
6 years ago
splitLine: {
lineStyle: {
color: "#eee"
}
},
axisLine: {
lineStyle: {
color: "#666"
}
}
},
series: [{
6 years ago
name: '1s',
6 years ago
type: 'line',
6 years ago
data: oneData,
smooth: true,
showSymbol: false,
symbol: 'circle',
symbolSize: 6,
areaStyle: {
normal: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1,
[{offset: 0,color: 'rgba(205, 51, 51,0.5)'},
{offset: 1,color: 'rgba(205, 51, 51,0.8)'}], false)
}
},
itemStyle: {
normal: {color: '#cd3333'}
},
lineStyle: {
normal: {width: 1}
}
}, {
6 years ago
name: '5s',
6 years ago
type: 'line',
data: twoData,
6 years ago
smooth: true,
showSymbol: false,
symbol: 'circle',
symbolSize: 6,
areaStyle: {
normal: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
offset: 0,
6 years ago
color: 'rgba(30, 144, 255,0.5)'
6 years ago
}, {
offset: 1,
6 years ago
color: 'rgba(30, 144, 255,0.8)'
6 years ago
}], false)
}
},
itemStyle: {
6 years ago
normal: {color: '#52a9ff'}
6 years ago
},
lineStyle: {
normal: {
width: 1
}
}
6 years ago
},{
6 years ago
name: '10s',
6 years ago
type: 'line',
6 years ago
data: threeData,
6 years ago
smooth: true,
showSymbol: false,
symbol: 'circle',
symbolSize: 6,
areaStyle: {
normal: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
offset: 0,
color: 'rgba(30, 144, 255,0.5)'
}, {
offset: 1,
color: 'rgba(30, 144, 255,0.8)'
}], false)
}
},
itemStyle: {
6 years ago
normal: {color: '#C6E2FF'}
6 years ago
},
lineStyle: {
normal: {
width: 1
}
}
}]
};
6 years ago
// 使用刚指定的配置项和数据显示图表。
myChartNetwork.setOption(option);
window.addEventListener("resize", function() {
myChartNetwork.resize();
});
function render(){
6 years ago
dhtTrendData(function(data){
addData(data);
});
myChartNetwork.setOption({
xAxis: {data: xData},
series: [
6 years ago
{name: '1s',data: oneData},
{name: '5s',data: twoData},
{name: '10s',data: threeData}
6 years ago
]
});
6 years ago
}
render();
6 years ago
renderTick = setInterval(function() {
6 years ago
render();
6 years ago
}, 2500);
6 years ago
checkTick = setInterval(function() {
var obj = $('#dht_trend');
if (obj.length>0){
return;
} else {
console.log('取消定时请求...');
clearInterval(renderTick);
clearInterval(checkTick);
}
}, 300);
6 years ago
}