-
Notifications
You must be signed in to change notification settings - Fork 1
/
OpeningPieChart.mxml
222 lines (198 loc) · 9.83 KB
/
OpeningPieChart.mxml
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<?xml version="1.0" encoding="utf-8"?>
<mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import flash.display.Sprite;
import mx.controls.*;
import mx.containers.HBox;
import mx.containers.VBox;
import mx.core.UIComponent;
private var _n:int = 0;
private var _nStatic:int = 0;
private var _nRanging:int = 0;
private var _nOpposition:int = 0;
private var _ui:UIComponent = new UIComponent();
private var _pieSprite:Sprite = new Sprite();
private var _percents:Object = new Object();
private static const RIGHT_ANGLE : Number = Math.PI / 2;
public function loadData(openingData:Array):void {
for each (var datum:Object in openingData) {
_n += (datum.black + datum.white);
if (["opposition_ranging", "double_ranging"].indexOf(datum.group) >= 0) _nRanging += (datum.black + datum.white);
if (["yagura_and_bishop", "side_and_wing", "opposition_static"].indexOf(datum.group) >= 0) _nStatic += (datum.black + datum.white);
if (["opposition_ranging", "opposition_static"].indexOf(datum.group) >= 0) _nOpposition += (datum.black + datum.white);
}
if (_n == 0) return;
_ui.width = pieChartCanvas.width;
_ui.height = pieChartCanvas.height;
pieChartCanvas.addChild(_ui);
var thetaOut:Number = - Math.PI / 2;
var thetaIn:Number = thetaOut;
var thetaBorder1:Number = thetaOut;
var thetaBorder2:Number = thetaOut;
var cx:Number = _ui.width / 2;
var cy:Number = _ui.height / 2;
var rOut:Number = _ui.width * 0.45;
var rIn:Number = rOut * 0.4;
_pieSprite.graphics.lineStyle();
_pieSprite.graphics.beginFill(0xcccccc, 1);
_pieSprite.graphics.drawCircle(cx + 2, cy + 2, rOut+1);
_pieSprite.graphics.endFill();
_pieSprite.graphics.moveTo(cx, cy);
for each (datum in openingData) {
listVBox.addChild(_listItem(datum));
if (datum.name == "unknown") thetaBorder1 = thetaOut;
if (datum.black + datum.white > 0) {
_pieSprite.graphics.beginFill(datum.color, 1);
drawPie(_pieSprite.graphics, cx, cy, rOut, thetaOut, thetaOut += 2 * Math.PI * (datum.black + datum.white) / _n, true);
_pieSprite.graphics.lineTo(cx, cy);
_pieSprite.graphics.endFill();
//_pieSprite.graphics.lineStyle(0.5, 0x000000, 1, true, "normal", null, JointStyle.MITER);
if (datum.black > 0) {
_pieSprite.graphics.beginFill(0x000000, 1);
drawPie(_pieSprite.graphics, cx, cy, rIn, thetaIn, thetaIn += 2 * Math.PI * datum.black / _n, true);
_pieSprite.graphics.lineTo(cx, cy);
_pieSprite.graphics.endFill();
}
if (datum.white > 0){
_pieSprite.graphics.beginFill(0xffffff, 1);
drawPie(_pieSprite.graphics, cx, cy, rIn, thetaIn, thetaIn += 2 * Math.PI * datum.white / _n, true);
_pieSprite.graphics.lineTo(cx, cy);
_pieSprite.graphics.endFill();
}
}
if (datum.name == "unknown") thetaBorder2 = thetaIn;
}
_pieSprite.graphics.lineStyle(3, 0x00ee00, 0.7, true);
_pieSprite.graphics.lineTo(cx , cy - rOut * 1.08);
_pieSprite.graphics.moveTo(cx + rOut * 1.08 * Math.cos(thetaBorder1), cy + rOut * 1.08 * Math.sin(thetaBorder1));
_pieSprite.graphics.lineTo(cx, cy);
_pieSprite.graphics.lineTo(cx + rOut * 1.08 * Math.cos(thetaBorder2), cy + rOut * 1.08 * Math.sin(thetaBorder2));
_ui.addChild(_pieSprite);
if (_n < 10) {
typeLabel.text = "Unknown (lack data)"; typeLabel.toolTip = "";
} else if (_nStatic >= 2.0/3.0*_n) {
typeLabel.toolTip = "居飛車党"; typeLabel.text = "Static Rook Player";
if (_nRanging <= 0.05 * _n) {
typeLabel.toolTip = "純粋居飛車党"; typeLabel.text = "Pure Static Rook Player";
}
if (_percents["yagura"] / 100 >= _nStatic / _n * 0.6) {
typeLabel.toolTip = "矢倉マニア"; typeLabel.text = "Yagura Enthusiast";
} else if (_percents["bishop_exchange"] / 100 >= _nStatic / _n * 0.6) {
typeLabel.toolTip = "角換りマニア"; typeLabel.text = "Bishop Exchange Enthusiast";
} else if (_percents["side_pawn"] / 100 >= _nStatic / _n * 0.6) {
typeLabel.toolTip = "横歩取りマニア"; typeLabel.text = "Side Pawn Picker Enthusiast";
}
} else if (_nRanging >= 2.0 / 3.0 * _n) {
typeLabel.toolTip = "振り飛車党"; typeLabel.text = "Ranging Rook Player";
if (_percents["3rd_file_rook"] / 100 >= _nRanging / _n * 2.0 / 3.0 ||
_nRanging/_n - (_percents["3rd_file_rook"] + _percents["double_ranging"])/100 <= 0.25*_percents["3rd_file_rook"]/100) {
typeLabel.toolTip = "三間飛車党"; typeLabel.text = "3rd-file Rook Player";
} else if (_percents["4th_file_rook"] / 100 >= _nRanging / _n * 2.0 / 3.0 ||
_nRanging/_n - (_percents["4th_file_rook"] + _percents["double_ranging"])/100 <= 0.25*_percents["4th_file_rook"]/100) {
typeLabel.toolTip = "四間飛車党"; typeLabel.text = "4th-file Rook Player";
} else if (_percents["central_rook"] / 100 >= _nRanging / _n * 2.0 / 3.0 ||
_nRanging/_n - (_percents["central_rook"] + _percents["double_ranging"])/100 <= 0.25*_percents["central_rook"]/100) {
typeLabel.toolTip = "中飛車党"; typeLabel.text = "Central Rook Player";
}
if (_nStatic <= 0.05 * _n) {
switch (typeLabel.toolTip) {
case "三間飛車党":
typeLabel.toolTip = "三間飛車マニア"; typeLabel.text = "3rd-file Rook Enthusiast"; break;
case "四間飛車党":
typeLabel.toolTip = "四間飛車マニア"; typeLabel.text = "4th-file Rook Enthusiast"; break;
case "中飛車党":
typeLabel.toolTip = "中飛車マニア"; typeLabel.text = "Central Rook Enthusiast"; break;
default:
typeLabel.toolTip = "純粋振り飛車党"; typeLabel.text = "Pure Ranging Rook Player";
}
}
} else if (_nOpposition >= 2.0 / 3.0 * _n && _percents["opposition_static"]/100 >= 0.25* _nOpposition/_n && _percents["oppsition_static"]/100 <= 0.75 *_nOpposition/_n) {
typeLabel.toolTip = "対抗形志向"; typeLabel.text = "Opposition Seeker";
if (_nOpposition >= 0.9 * _n) {
typeLabel.toolTip = "対抗形マニア"; typeLabel.text = "Opposition Enthusiast";
}
} else if (_percents["unknown"] > 1.0 / 2.0 * 100) {
typeLabel.toolTip = "力戦派"; typeLabel.text = "Free-style Player";
} else if (_percents["double_ranging"] >= 7 && _percents["3rd_file_rook"] >= 7 && _percents["central_rook"] >= 7 &&
_percents["yagura"] >= 7 && _percents["bishop_exchange"] >= 7 && _percents["side_pawn"] >= 7) {
typeLabel.toolTip = "真正オールラウンダー"; typeLabel.text = "Genuine All-rounder";
} else if (_percents["opposition_static"] / 100 >= 0.8 * _nStatic / _n) {
typeLabel.toolTip = "対抗形志向"; typeLabel.text = "Opposition Seeker";
} else if (_nRanging <= 0.05 * _n) {
typeLabel.toolTip = "純粋居飛車党"; typeLabel.text = "Pure Static Rook Player";
} else if (_nStatic <= 0.05 * _n) {
typeLabel.toolTip = "純粋振り飛車党"; typeLabel.text = "Pure Ranging Rook Player";
} else {
typeLabel.toolTip = "オールラウンダー"; typeLabel.text = "All-rounder";
}
}
private function _listItem(datum:Object):HBox {
var hbox:HBox = new HBox();
hbox.setStyle('horizontalGap', 0);
hbox.setStyle('paddingBottom', 0);
var label:Label = new Label();
label.setStyle('leading', 1);
label.text = "■";
label.setStyle('color', datum.color);
hbox.addChild(label);
label = new Label();
label.setStyle('leading', 1);
label.width = 90;
label.text = InfoFetcher.openingNameJp(datum.name);
label.toolTip = InfoFetcher.openingNameEn(datum.name);
hbox.addChild(label);
label = new Label();
label.setStyle('leading', 1);
label.width = 60;
label.setStyle('textAlign', 'right');
_percents[datum.name] = (datum.black + datum.white) / _n * 100;
label.text = _percents[datum.name].toFixed(1) + " %";
hbox.addChild(label);
return hbox;
}
public static function drawPie(g : Graphics, x : Number, y : Number, r : Number, t1 : Number, t2 : Number, lineTo : Boolean = false) : void {
var div : int = Math.max(1, Math.floor(Math.abs(t1 - t2) / 0.4) );
var lx : Number;
var ly : Number;
var lt : Number;
for (var i : int = 0; i <= div; i++) {
var ct : Number = t1 + (t2 - t1) * i / div;
var cx : Number = Math.cos(ct) * r + x;
var cy : Number = Math.sin(ct) * r + y;
if (i == 0) {
if (lineTo) {
g.lineTo(cx, cy);
} else {
g.moveTo(cx, cy);
}
} else {
var cp : Point = getControlPoint(lx, ly, lt + RIGHT_ANGLE, cx, cy, ct + RIGHT_ANGLE);
g.curveTo(cp.x, cp.y, cx, cy);
}
lx = cx;
ly = cy;
lt = ct;
}
}
public static function getControlPoint(
x1 : Number, y1 : Number, t1 : Number,
x2 : Number, y2 : Number, t2 : Number
) : Point {
var x12 : Number = x2 - x1;
var y12 : Number = y2 - y1;
var l12 : Number = Math.sqrt(x12 * x12 + y12 * y12);
var t12 : Number = Math.atan2(y12, x12);
var l13 : Number = l12 * Math.sin(t2 - t12) / Math.sin(t2 - t1);
var x3 : Number = x1 + l13 * Math.cos(t1);
var y3 : Number = y1 + l13 * Math.sin(t1);
return new Point(x3, y3);
}
]]>
</mx:Script>
<mx:VBox horizontalAlign="center" width="210" height="220" verticalScrollPolicy="off" horizontalScrollPolicy="off" verticalGap="0">
<mx:Label id="typeLabel" paddingTop="-3" paddingBottom="-2" fontWeight="bold" fontSize="14" fontFamily="Meiryo UI" textDecoration="underline" />
<mx:Canvas id="pieChartCanvas" width="200" height="200" verticalScrollPolicy="off" horizontalScrollPolicy="off"/>
</mx:VBox>
<mx:VBox id="listVBox" width="180" height="220" borderStyle="solid" verticalScrollPolicy="off" horizontalScrollPolicy="off" verticalGap="0" />
</mx:HBox>