-
Notifications
You must be signed in to change notification settings - Fork 1
/
OpeningRadarChart.mxml
118 lines (103 loc) · 5.91 KB
/
OpeningRadarChart.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
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import com.google.maps.wrappers.SpriteFactory;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.text.TextField;
import mx.controls.*;
import mx.containers.HBox;
import mx.containers.VBox;
import mx.core.UIComponent;
private var _gridSprite:Sprite = new Sprite();
private var _radarSprite:Sprite = new Sprite();
private var _pointSprite:Sprite = new Sprite();
private var _pieceSprite:Sprite = new Sprite();
private var _percents:Array = new Array();
private var _label:TextField = new TextField();
public function loadData(openingData:Array):void {
var cx:Number = width / 2;
var cy:Number = height / 2;
var r:Number = height / 2 * 0.8;
var theta:Number = - Math.PI / 2 + Math.PI / 24;
_gridSprite.graphics.lineStyle(0.5, 0x000000, 1, true, "normal", null, JointStyle.MITER);
_radarSprite.graphics.lineStyle(2, 0xff0000, 1, true, "normal", null, JointStyle.MITER);
_radarSprite.graphics.beginFill(0xff0000, 0.5);
_pointSprite.graphics.lineStyle(1, 0xff0000, 1, true, "normal");
_pieceSprite.graphics.lineStyle(0.5, 0x000000, 1, true, "normal", null, JointStyle.MITER);
var i:int = 0;
for each (var datum:Object in openingData) {
trace(datum.group);
if (datum.black_wins + datum.black_losses == 0) _percents.push( -50);
else _percents.push(datum.black_wins / (datum.black_wins + datum.black_losses) * 100);
if (datum.white_wins + datum.white_losses == 0) _percents.push( -50);
else _percents.push(datum.white_wins / (datum.white_wins + datum.white_losses) * 100);
}
theta = - Math.PI / 2 - Math.PI / 12;
_radarSprite.graphics.moveTo(cx + (r / 3 + r * 2 / 3 * _percents[_percents.length - 1] / 100) * Math.cos(theta), cy + (r / 3 + r * 2 / 3 * _percents[_percents.length - 1] / 100) * Math.sin(theta));
for (i = 0; i < _percents.length; i++) {
theta += Math.PI / 6;
_gridSprite.graphics.moveTo(cx + r / 3 * Math.cos(theta + Math.PI / 6), cy + r / 3 * Math.sin(theta + Math.PI / 6));
_gridSprite.graphics.lineTo(cx + r / 3 * Math.cos(theta), cy + r / 3 * Math.sin(theta));
if (_percents[i] < 0) _gridSprite.graphics.lineStyle(0.5, 0x000000, 0.2, true);
_gridSprite.graphics.lineTo(cx + r * Math.cos(theta), cy + r * Math.sin(theta));
if (_percents[i] < 0) _gridSprite.graphics.lineStyle(0.5, 0x000000, 1, true);
_gridSprite.graphics.lineTo(cx + r * Math.cos(theta + Math.PI / 6), cy + r * Math.sin(theta + Math.PI / 6));
_gridSprite.graphics.moveTo(cx + r * 2 / 3 * Math.cos(theta + Math.PI / 6), cy + r * 2 / 3 * Math.sin(theta + Math.PI / 6));
_gridSprite.graphics.lineTo(cx + r * 2 / 3 * Math.cos(theta), cy + r * 2 / 3 * Math.sin(theta));
_radarSprite.graphics.lineTo(cx + (r / 3 + r * 2 / 3 * _percents[i] / 100) * Math.cos(theta), cy + (r / 3 + r * 2 / 3 * _percents[i] / 100) * Math.sin(theta));
var pSprite:Sprite = new Sprite();
pSprite.graphics.beginFill(0xff0000, 1);
pSprite.graphics.drawCircle(cx + (r / 3 + r * 2 / 3 * _percents[i] / 100) * Math.cos(theta), cy + (r / 3 + r * 2 / 3 * _percents[i] / 100) * Math.sin(theta), 3);
pSprite.graphics.endFill();
if (_percents[i] >= 0) {
pSprite.addEventListener(MouseEvent.MOUSE_OVER, _handleMouseOver);
pSprite.addEventListener(MouseEvent.MOUSE_OUT, _handleMouseOut);
}
_pointSprite.addChild(pSprite);
// _pointSprite.graphics.beginFill(0xff0000, 1);
// _pointSprite.graphics.drawCircle(cx + (r / 3 + r * 2 / 3 * percents[i] / 100) * Math.cos(theta), cy + (r / 3 + r * 2 / 3 * percents[i] / 100) * Math.sin(theta), 3);
// _pointSprite.graphics.endFill();
if (i % 2 == 0) _pieceSprite.graphics.beginFill(0x000000, 1);
_pieceSprite.graphics.moveTo(cx + 1.1 * r * Math.cos(theta), cy + 1.1 * r * Math.sin(theta));
_pieceSprite.graphics.lineTo(cx + 1.08 * r * Math.cos(theta+0.03), cy + 1.08 * r * Math.sin(theta+0.03));
_pieceSprite.graphics.lineTo(cx + r * Math.cos(theta+0.05), cy + r * Math.sin(theta+0.05));
_pieceSprite.graphics.lineTo(cx + r * Math.cos(theta-0.05), cy + r * Math.sin(theta-0.05));
_pieceSprite.graphics.lineTo(cx + 1.08 * r * Math.cos(theta - 0.03), cy + 1.08 * r * Math.sin(theta - 0.03));
_pieceSprite.graphics.lineTo(cx + 1.1 * r * Math.cos(theta), cy + 1.1 * r * Math.sin(theta));
if (i % 2 == 0) _pieceSprite.graphics.endFill();
}
_radarSprite.graphics.endFill();
radarUI.addChild(_gridSprite);
radarUI.addChild(_pieceSprite);
radarUI.addChild(_radarSprite);
radarUI.addChild(_pointSprite);
_label.autoSize = "left";
_label.defaultTextFormat = new TextFormat("Meiryo UI", 15, 0x00aa00, true);
_label.selectable = false;
_pointSprite.addChild(_label);
}
private function _handleMouseOver(e:MouseEvent):void {
_label.x = e.localX - 18;
_label.y = e.localY - 25;
for (var i:int = 0; i < _pointSprite.numChildren; i++) {
if (_pointSprite.getChildAt(i) == e.target) {
_label.text = String(_percents[i].toFixed(0)) + "%";
break;
}
}
}
private function _handleMouseOut(e:MouseEvent):void {
_label.text = "";
}
]]>
</mx:Script>
<mx:UIComponent id="radarUI" width="100%" height="100%"/>
<mx:Label text="対抗型 居飛車" x="235" y="0" toolTip="Static Rook in Opposition" />
<mx:Label text="矢倉・角換り" x="300" y="100" toolTipShow="true" toolTip="Yagura / Bishop Exchange" />
<mx:Label text="相掛かり・横歩" x="240" y="200" toolTip="Side Pawn Picker / Double Wing Attack" />
<mx:Label text="対抗型 振り飛車" x="85" y="0" toolTip="Ranging Rook in Opposition" />
<mx:Label text="相振り飛車" x="45" y="100" toolTip="Double Ranging Rook" />
<mx:Label text="力戦" x="125" y="200" toolTip="Free-style" />
</mx:Canvas>