-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
121 lines (106 loc) · 2.5 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
var tempArrNum = shuffle.card.number.slice(0);
var nameList = [];
// 生成名字数组
for(var k=0;k<shuffle.card.number.length;k++){
var list = 'array' + shuffle.card.number[k];
nameList.push(list);
}
for(var l=0;l< nameList.length;l++){
nameList[l] = [];
}
// 执行随机
for (var i = shuffle.times - 1; i >= 0; i--) {
startTest();
};
function startTest(){
var res = shuffle.testFun(tempArrNum);
// 统计各个位置出现的次数
for(var j = 0;j < shuffle.card.number.length;j++){
for (var i = 0; i < res.length; i++) {
if(res[i] == shuffle.card.number[j]){
if(nameList[j][i] == undefined){
nameList[j][i] = 1;
} else {
nameList[j][i]+= 1;
}
break;
}
}
}
}
var myChart = echarts.init(document.getElementById('myChart'));
var option = {
title: {
text: '洗牌算法',
subtext: '次数'
},
tooltip: {
trigger: 'axis'
},
legend: {
data: ['0','1','2','3','5','6','7','8','9','10','11','12']
},
toolbox: {
show: true,
feature: {
dataZoom: {
yAxisIndex: 'none'
},
dataView: {readOnly: false},
magicType: {type: ['line', 'bar']},
restore: {},
saveAsImage: {}
}
},
xAxis: {
type: 'category',
boundaryGap: false,
data: shuffle.card.number
},
yAxis: {
type: 'value',
axisLabel: {
formatter: '{value} 次'
}
},
series: [
]
};
var seriesObj = {
name: '1',
type:'line',
data: '',
markPoint: {
data: [
{type: 'max', name: '最大值'},
{type: 'min', name: '最小值'}
]
}
}
// 深度克隆
function deepClone (obj) {
if(typeof obj !== "object" && typeof obj !== 'function') {
return obj; //原始类型直接返回
}
var o = isArray(obj) ? [] : {};
for(i in obj) {
if(obj.hasOwnProperty(i)){
o[i] = typeof obj[i] === "object" ? deepClone(obj[i]) : obj[i];
}
}
return o;
}
function isArray (arr) {
return Object.prototype.toString.call(arr) === '[object Array]';
}
for (var m = 0; m < nameList.length; m++) {
var cloneSeriesObj = deepClone(seriesObj);
cloneSeriesObj.name = m;
cloneSeriesObj.data = nameList[m];
option.series.push(cloneSeriesObj);
};
// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);
function indexFun(arr,str){
return arr.indexOf(str) + 1;
}