AtcoderDevotionGraph

Overlay your devoiting graph on your rating graph

As of 2020-11-24. See the latest version.

  1. // ==UserScript==
  2. // @name AtcoderDevotionGraph
  3. // @namespace http://atcoder.jp/
  4. // @version 0.3.0β
  5. // @description Overlay your devoiting graph on your rating graph
  6. // @author kemkemG0
  7. // @include *://atcoder.jp/users*
  8. // @exclude *://atcoder.jp/users/*?graph=rank
  9. // @exclude *://atcoder.jp/users/*/history*
  10. // @grant none
  11. // @require https://code.jquery.com/jquery-1.8.0.min.js
  12. //@run-at document-end
  13.  
  14. // ==/UserScript==
  15.  
  16. "use strict";
  17.  
  18. (async () => {
  19.  
  20. //##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##
  21.  
  22. let scriptsArray = $('script');//<script>タグのものを配列に突っ込む
  23. scriptsArray[14].remove(); // 対象のタグを消す記述 x[14]がグラフを読み込むjs
  24.  
  25. //なんでこれ必要?? -->>一度読み込んだscriptタグはDOMから消しても効果は残るからそれを消すため
  26. let copyPage = $("html").clone().html(); // 対象のタグが消えたページをコピー
  27. $("html").remove(); // ページをまるごと削除
  28. document.write(copyPage); // コピーしてあったページ内容をペースト
  29.  
  30. const element = document.getElementsByClassName('btn-text-group')[document.getElementsByClassName('btn-text-group').length - 1];
  31. const insertButton = Object.assign(document.createElement('button'), {
  32. className: '',
  33. id: 'shoujinButtonID',
  34. style: '\
  35. margin-left:50px;\
  36. appearance: none;\
  37. border: 0;\
  38. border-radius: 5px;\
  39. background: #20b2aa;\
  40. color: #fff;\
  41. padding: 8px 16px;\
  42. font-size: 16px;\
  43. '
  44. }
  45. );
  46. insertButton.textContent = "精進グラフの表示を切り替える"
  47. element.appendChild(insertButton)
  48. console.log(element)
  49.  
  50.  
  51. //##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##
  52.  
  53. // const
  54. const MARGIN_VAL_X = 86400 * 30;
  55. const MARGIN_VAL_Y_LOW = 100;//
  56. const MARGIN_VAL_Y_HIGH = 300;//自分の最高レート+表示する領域
  57. const OFFSET_X = 50;//グラフの位置?
  58. const OFFSET_Y = 5;
  59. const DEFAULT_WIDTH = 640;
  60. let canvas_status = document.getElementById("ratingStatus");
  61. // <canvas id="ratingStatus" width="1280" height="160"
  62. // style="max-width: 640px; max-height: 80px; height: 100%; width: 100%;"></canvas>
  63. const STATUS_WIDTH = canvas_status.width - OFFSET_X - 10;
  64. const STATUS_HEIGHT = canvas_status.height - OFFSET_Y - 5;
  65. let canvas_graph = document.getElementById("ratingGraph");
  66. // <canvas id="ratingGraph"
  67. // width="1280" height="720"
  68. // style="max-width: 640px; max-height: 360px; height: 100%; width: 100%;"></canvas>
  69. const PANEL_WIDTH = canvas_graph.width - OFFSET_X - 10;
  70. const PANEL_HEIGHT = canvas_graph.height - OFFSET_Y - 30;
  71. //HIGHEST:932 とかの吹き出しのサイズ
  72. const HIGHEST_WIDTH = 80;
  73. const HIGHEST_HEIGHT = 20;
  74. const LABEL_FONT = "12px Lato";
  75. const START_YEAR = 2010;
  76. const MONTH_NAMES = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
  77. const YEAR_SEC = 86400 * 365;
  78. const STEP_SIZE = 400;//グラフのy軸のステップ数
  79. const COLORS = [
  80. [0, "#808080", 0.15],
  81. [400, "#804000", 0.15],
  82. [800, "#008000", 0.15],
  83. [1200, "#00C0C0", 0.2],
  84. [1600, "#0000FF", 0.1],
  85. [2000, "#C0C000", 0.25],
  86. [2400, "#FF8000", 0.2],
  87. [2800, "#FF0000", 0.1]
  88. ];
  89.  
  90. //??????????????????
  91. const STAR_MIN = 3200;
  92. const PARTICLE_MIN = 3;
  93. const PARTICLE_MAX = 20;
  94. const LIFE_MAX = 30;
  95. const EPS = 1e-9;
  96.  
  97. let cj = createjs;
  98. let stage_graph, stage_status;
  99.  
  100. // graph
  101. let panel_shape, border_shape;
  102. let chart_container, line_shape, vertex_shapes, highest_shape;
  103. let n, x_min, x_max, y_min, y_max;
  104.  
  105. //devoting graph
  106. let devoting_panel_shape, devoting_border_shape;
  107. let devoting_chart_container, devoting_line_shape, devoting_vertex_shapes, devoting_highest_shape;
  108. let devoting_n, devoting_x_min, devoting_x_max, devoting_y_min, devoting_y_max;
  109. let devoting_rating_history = []
  110.  
  111. // status
  112. let border_status_shape;
  113. let rating_text, place_text, diff_text, date_text, contest_name_text;
  114. let particles;
  115. let standings_url;
  116. const username = document.getElementsByClassName("username")[0].textContent;
  117. let allJson;
  118. try {
  119. const res = await fetch("https://kenkoooo.com/atcoder/atcoder-api/results?user=" + username);
  120. allJson = await res.json()
  121. } catch (reaseon) { console.log('try失敗') }
  122.  
  123.  
  124.  
  125. console.log(111)
  126. {
  127. let isExist={};
  128. for (let i = 0; i < allJson.length; i++) {
  129. if (allJson[i].result == 'AC' && allJson[i].point <= 3000 && isExist[allJson[i].problem_id]==undefined) {
  130. devoting_rating_history.push({ ...allJson[i] });
  131. isExist[allJson[i].problem_id]=0;
  132. }
  133. }
  134. }
  135. function compare(a, b) { return a.epoch_second - b.epoch_second; }//比較関数
  136. devoting_rating_history.sort(compare);//時間順にソート
  137.  
  138. for (let i = 0; i < devoting_rating_history.length - 1; i++) {//合計の累積和的な
  139. devoting_rating_history[i + 1].point += devoting_rating_history[i].point;
  140. devoting_rating_history[i].point /= 100;
  141. }
  142. devoting_rating_history[devoting_rating_history.length - 1].point /= 100;
  143. //今までの累積和/100 が高さ
  144.  
  145. console.log(222)
  146. console.log("before init()")
  147. console.log("This should be excuted after init()")
  148.  
  149. let shoujinButtonID = document.getElementById('shoujinButtonID');
  150. shoujinButtonID.addEventListener('click', function () {
  151. devoting_chart_container.visible = !devoting_chart_container.visible;
  152. stage_graph.update();
  153. });
  154.  
  155.  
  156. console.log(devoting_rating_history.length);
  157. //クリエイトjsとやらをつかっている
  158. console.log(333)
  159.  
  160.  
  161. //いい感じにキャンバスの大きさを設定してマウスオーバーもONにする
  162. function initStage(stage, canvas) {
  163. let width = canvas.getAttribute('width');// <canvas width="">を取得
  164. let height = canvas.getAttribute('height');
  165.  
  166.  
  167. //最悪、なくても画質悪くなったが動いた よくわからん
  168. if (window.devicePixelRatio) {//ピクセル比 によって解像度を変える 本来は2のときに1にしたらぼやけた
  169. //縦横の設定
  170. canvas.setAttribute('width', Math.round(width * window.devicePixelRatio));//Math.round()は四捨五入
  171. canvas.setAttribute('height', Math.round(height * window.devicePixelRatio));
  172. stage.scaleX = stage.scaleY = window.devicePixelRatio;
  173. }
  174. //最大のキャンパスサイズ=もとのキャンバスサイズにする
  175. canvas.style.maxWidth = width + "px";
  176. canvas.style.maxHeight = height + "px";
  177. canvas.style.width = canvas.style.height = "100%";
  178. stage.enableMouseOver();
  179. }
  180.  
  181. //parent===stageに図形を追加し、その図形をreturnで参照渡し
  182. function newShape(parent) {
  183. let s = new cj.Shape();
  184. parent.addChild(s);
  185. return s;
  186. }
  187. //上のテキストバージョン
  188. function newText(parent, x, y, font) {
  189. let t = new cj.Text("", font, "#000");
  190. t.x = x;
  191. t.y = y;
  192. t.textAlign = "center";
  193. t.textBaseline = "middle";
  194. parent.addChild(t);
  195. return t;
  196. }
  197.  
  198.  
  199.  
  200. //多分一番の大元
  201. function init() {
  202.  
  203. // window.alert('33333');
  204.  
  205. //rating_history はHTML内で取得してある
  206. //rating_history=[{"EndTime":時間(単位不明),"NewRating":11,"OldRating":0,"Place":5200,"ContestName":"コンテスト名","StandingsUrl":"/contests/m-solutions2020/standings?watching=kemkemG0"}];
  207. n = rating_history.length;
  208. devoting_n = devoting_rating_history.length;
  209. if (n == 0) return;
  210.  
  211. //console.log("initの中")
  212.  
  213. //土台のステージ これに図形とかを追加していくイメージ
  214. stage_graph = new cj.Stage("ratingGraph");// Stage("canvasのID");
  215. stage_status = new cj.Stage("ratingStatus");
  216. initStage(stage_graph, canvas_graph);
  217. initStage(stage_status, canvas_status);
  218.  
  219. //グラフのサイズ決定
  220. x_min = 100000000000;
  221. x_max = 0;
  222. y_min = 10000;
  223. y_max = 0;
  224. for (let i = 0; i < n; i++) {
  225. x_min = Math.min(x_min, rating_history[i].EndTime);
  226. x_max = Math.max(x_max, rating_history[i].EndTime);
  227. y_min = Math.min(y_min, rating_history[i].NewRating);
  228. y_max = Math.max(y_max, rating_history[i].NewRating);
  229. }
  230. x_min -= MARGIN_VAL_X;//最初にコンテストに参加した日ー1ヶ月
  231. x_max += MARGIN_VAL_X;//最後にコンテストに参加した日+1ヶ月
  232. y_min = Math.min(1500, Math.max(0, y_min - MARGIN_VAL_Y_LOW));//いい感じに高さも設定
  233. y_max += MARGIN_VAL_Y_HIGH;
  234.  
  235. //精進グラフのサイズ決定
  236. devoting_x_min = 100000000000;
  237. devoting_x_max = 0;
  238. devoting_y_min = 10000;
  239. devoting_y_max = 0;
  240. for (let i = 0; i < devoting_rating_history.length; i++) {
  241. devoting_x_min = Math.min(devoting_x_min, devoting_rating_history[i].epoch_second);
  242. devoting_x_max = Math.max(devoting_x_max, devoting_rating_history[i].epoch_second);
  243. devoting_y_min = Math.min(devoting_y_min, devoting_rating_history[i].point);
  244. devoting_y_max = Math.max(devoting_y_max, devoting_rating_history[i].point);
  245. }
  246. devoting_x_min -= MARGIN_VAL_X;//最初にコンテストに参加した日ー1ヶ月
  247. devoting_x_max += MARGIN_VAL_X;//最後にコンテストに参加した日+1ヶ月
  248. devoting_y_min = Math.min(1500, Math.max(0, devoting_y_min - MARGIN_VAL_Y_LOW));//いい感じに高さも設定
  249. devoting_y_max += MARGIN_VAL_Y_HIGH;
  250.  
  251. //形を決める
  252. y_min = Math.min(y_min, devoting_y_min);
  253. y_max = Math.max(y_max, devoting_y_max);
  254. x_min = Math.min(x_min, devoting_x_min);
  255. x_max = Math.max(x_max, devoting_x_max);
  256.  
  257. console.log("I'm in inside of init 111")
  258.  
  259. initBackground();//背景の描画
  260. initChart();//プロットと直線の描画
  261.  
  262. console.log("I'm in inside of init 222")
  263.  
  264. initDevotingChart()
  265.  
  266.  
  267.  
  268. stage_graph.update();
  269. console.log("I'm in inside of init 333")
  270.  
  271. initStatus();//グラフの上のコンテスト情報とかの描画
  272. stage_status.update();
  273.  
  274.  
  275.  
  276. //window.alert('44444'); アラート→描画の順番なのはなぜなのか
  277.  
  278.  
  279. //マウスオーバー時のほわほわの管理
  280. cj.Ticker.setFPS(60);
  281. cj.Ticker.addEventListener("tick", handleTick);
  282. function handleTick(event) {
  283. updateParticles();
  284. stage_status.update();
  285. }
  286. }
  287.  
  288. function getPer(x, l, r) {
  289. return (x - l) / (r - l);
  290. }
  291.  
  292. function getColor(x) {
  293. for (let i = COLORS.length - 1; i >= 0; i--) {
  294. if (x >= COLORS[i][0]) return COLORS[i];
  295. }
  296. return [-1, "#000000", 0.1];
  297. }
  298.  
  299. function initBackground() {
  300.  
  301. panel_shape = newShape(stage_graph);//stage_graphに図形を追加、また panel_shapeはstage_graphの内部とつながってる(オブジェクトは参照渡し)
  302. panel_shape.x = OFFSET_X;
  303. panel_shape.y = OFFSET_Y;
  304. panel_shape.alpha = 0.3;
  305.  
  306. border_shape = newShape(stage_graph);
  307. border_shape.x = OFFSET_X;
  308. border_shape.y = OFFSET_Y;
  309.  
  310. // testtest = newShape(stage_graph);
  311. // testtest.graphics.beginFill("DarkRed"); // 赤色で描画するように設定
  312. // testtest.graphics.drawCircle(0, 0, 10); //半径 100px の円を描画
  313. // testtest.x = OFFSET_X; //OFFSET_XとOFFSET_Yにしたらグラフの中の四角形の左端になった
  314. // testtest.y = OFFSET_Y;
  315.  
  316. //左の軸のレートの設定
  317. function newLabelY(s, y) {
  318. let t = new cj.Text(s, LABEL_FONT, "#000");
  319. t.x = OFFSET_X - 10;//理解
  320. t.y = OFFSET_Y + y;
  321. t.textAlign = "right";
  322. t.textBaseline = "middle";
  323. stage_graph.addChild(t);
  324. }
  325. //上と同様にX軸のラベルの設定
  326. function newLabelX(s, x, y) {
  327. let t = new cj.Text(s, LABEL_FONT, "#000");
  328. t.x = OFFSET_X + x;
  329. t.y = OFFSET_Y + PANEL_HEIGHT + 2 + y;
  330. t.textAlign = "center";
  331. t.textBaseline = "top";
  332. stage_graph.addChild(t);
  333. }
  334.  
  335. //https://createjs.com/docs/easeljs/classes/Graphics.html Graphics Classのドキュメント
  336. let y1 = 0;
  337.  
  338.  
  339.  
  340. // グラフの中の正方形のパネルを色を設定
  341. for (let i = COLORS.length - 1; i >= 0; i--) {
  342. let y2 = PANEL_HEIGHT - PANEL_HEIGHT * getPer(COLORS[i][0], y_min, y_max);
  343. if (y2 > 0 && y1 < PANEL_HEIGHT) {
  344. y1 = Math.max(y1, 0); //rect ( x, y, w , h )
  345. panel_shape.graphics.beginFill(COLORS[i][1]).rect(0, y1, PANEL_WIDTH, Math.min(y2, PANEL_HEIGHT) - y1);
  346. }
  347. y1 = y2;
  348. }
  349. console.log('after FOR')
  350.  
  351. //Y軸ラベルの設定
  352. for (let i = 0; i <= y_max; i += STEP_SIZE) {
  353. if (i >= y_min) {
  354. let y = PANEL_HEIGHT - PANEL_HEIGHT * getPer(i, y_min, y_max);
  355. newLabelY(String(i), y);
  356. border_shape.graphics.beginStroke("#FFF").setStrokeStyle(0.5);
  357. if (i == 2000) border_shape.graphics.beginStroke("#000");
  358. border_shape.graphics.moveTo(0, y).lineTo(PANEL_WIDTH, y);
  359. }
  360. }
  361. border_shape.graphics.beginStroke("#FFF").setStrokeStyle(0.5);
  362.  
  363. let month_step = 6;
  364. for (let i = 3; i >= 1; i--) {
  365. if (x_max - x_min <= YEAR_SEC * i + MARGIN_VAL_X * 2) month_step = i;//初めてすぐの人は短めに
  366. }
  367.  
  368. //X軸ラベルの設定
  369. let first_flag = true;
  370. for (let i = START_YEAR; i < 3000; i++) {
  371. let break_flag = false;
  372. for (let j = 0; j < 12; j += month_step) {
  373. let month = ('00' + (j + 1)).slice(-2);
  374. let unix = Date.parse(String(i) + "-" + month + "-01T00:00:00") / 1000;
  375. if (x_min < unix && unix < x_max) {
  376. let x = PANEL_WIDTH * getPer(unix, x_min, x_max);
  377. if (j == 0 || first_flag) {
  378. newLabelX(MONTH_NAMES[j], x, 0);
  379. newLabelX(String(i), x, 13);
  380. first_flag = false;
  381. } else {
  382. newLabelX(MONTH_NAMES[j], x, 0);
  383. }
  384. border_shape.graphics.mt(x, 0).lt(x, PANEL_HEIGHT)
  385. }
  386. if (unix > x_max) { break_flag = true; break; }
  387. }
  388. if (break_flag) break;
  389. }
  390. border_shape.graphics.s("#888").ss(1.5).rr(0, 0, PANEL_WIDTH, PANEL_HEIGHT, 2);
  391. }
  392.  
  393.  
  394. function initChart() {
  395. chart_container = new cj.Container();//コンテナでまとめると、同時に動かせたりして良い
  396. stage_graph.addChild(chart_container);
  397. chart_container.shadow = new cj.Shadow("rgba(0,0,0,0.3)", 1, 2, 3);//チャートの下に影
  398.  
  399. line_shape = newShape(chart_container);
  400. highest_shape = newShape(chart_container);
  401. vertex_shapes = new Array();
  402.  
  403. //マウスおいたら丸が大きくなるやつ
  404. function mouseoverVertex(e) {
  405. vertex_shapes[e.target.i].scaleX = vertex_shapes[e.target.i].scaleY = 1.2;
  406. stage_graph.update();
  407. setStatus(rating_history[e.target.i], true);
  408. };
  409. function mouseoutVertex(e) {
  410. vertex_shapes[e.target.i].scaleX = vertex_shapes[e.target.i].scaleY = 1;
  411. stage_graph.update();
  412. };
  413.  
  414. let highest_i = 0;
  415. for (let i = 0; i < n; i++) {
  416. if (rating_history[highest_i].NewRating < rating_history[i].NewRating) {
  417. highest_i = i;
  418. }
  419. }
  420. //historyの数だけ配列にpushしてイベントリスナーも設定
  421. for (let i = 0; i < n; i++) {
  422. vertex_shapes.push(newShape(chart_container));
  423. vertex_shapes[i].graphics.beginStroke("#FFF");
  424. if (i == highest_i) vertex_shapes[i].graphics.s("#000");//Highestなら外枠を黒に
  425. vertex_shapes[i].graphics.setStrokeStyle(0.5).beginFill(getColor(rating_history[i].NewRating)[1]).dc(0, 0, 3.5);
  426.  
  427. vertex_shapes[i].x = OFFSET_X + PANEL_WIDTH * getPer(rating_history[i].EndTime, x_min, x_max);
  428. vertex_shapes[i].y = OFFSET_Y + (PANEL_HEIGHT - PANEL_HEIGHT * getPer(rating_history[i].NewRating, y_min, y_max));
  429.  
  430. vertex_shapes[i].i = i;//なにこれ??
  431.  
  432. let hitArea = new cj.Shape();
  433. hitArea.graphics.f("#000").dc(1.5, 1.5, 6);
  434. vertex_shapes[i].hitArea = hitArea;
  435. vertex_shapes[i].addEventListener("mouseover", mouseoverVertex);
  436. vertex_shapes[i].addEventListener("mouseout", mouseoutVertex);
  437. }
  438.  
  439. {//highest 関連
  440. let dx = 80;
  441. if ((x_min + x_max) / 2 < rating_history[highest_i].EndTime) dx = -80;
  442. let x = vertex_shapes[highest_i].x + dx;
  443. let y = vertex_shapes[highest_i].y - 16;
  444. highest_shape.graphics.s("#FFF").mt(vertex_shapes[highest_i].x, vertex_shapes[highest_i].y).lt(x, y);
  445. highest_shape.graphics.s("#888").f("#FFF").rr(x - HIGHEST_WIDTH / 2, y - HIGHEST_HEIGHT / 2, HIGHEST_WIDTH, HIGHEST_HEIGHT, 2);
  446. highest_shape.i = highest_i;
  447. let highest_text = newText(stage_graph, x, y, "12px Lato");
  448. highest_text.text = "Highest: " + rating_history[highest_i].NewRating;
  449. highest_shape.addEventListener("mouseover", mouseoverVertex);
  450. highest_shape.addEventListener("mouseout", mouseoutVertex);
  451. }
  452.  
  453.  
  454. for (let j = 0; j < 2; j++) {
  455. if (j == 0) line_shape.graphics.s("#AAA").ss(2);
  456. else line_shape.graphics.s("#FFF").ss(0.5);//線の種類を変えてる? よくわからん
  457.  
  458. line_shape.graphics.mt(vertex_shapes[0].x, vertex_shapes[0].y);
  459. for (let i = 0; i < n; i++) {
  460. line_shape.graphics.lt(vertex_shapes[i].x, vertex_shapes[i].y);
  461. }
  462. }
  463. }
  464.  
  465.  
  466. function initDevotingChart() {
  467. devoting_chart_container = new cj.Container();//コンテナでまとめると、同時に動かせたりして良い
  468. stage_graph.addChild(devoting_chart_container);//これは devoting_じゃない
  469. devoting_chart_container.shadow = new cj.Shadow("rgba(0,0,0,0.3)", 1, 2, 3);//チャートの下に影
  470.  
  471. devoting_line_shape = newShape(devoting_chart_container);
  472. devoting_highest_shape = newShape(devoting_chart_container);
  473. devoting_vertex_shapes = new Array();
  474.  
  475. // //マウスおいたら丸が大きくなるやつ
  476. // function devoting_mouseoverVertex(e) {
  477. // devoting_vertex_shapes[e.target.i].scaleX = devoting_vertex_shapes[e.target.i].scaleY = 2;
  478. // stage_graph.update();
  479. // };
  480. // function devoting_mouseoutVertex(e) {
  481. // devoting_vertex_shapes[e.target.i].scaleX = devoting_vertex_shapes[e.target.i].scaleY = 1;
  482. // stage_graph.update();
  483. // };
  484.  
  485.  
  486. //historyの数だけ配列にpushしてイベントリスナーも設定
  487. for (let i = 0; i < devoting_n; i++) {
  488. devoting_vertex_shapes.push(newShape(devoting_chart_container));
  489. devoting_vertex_shapes[i].graphics.beginStroke("#FFF");
  490. if (i == devoting_n - 1) {
  491. devoting_vertex_shapes[i].graphics.s("#000");
  492. devoting_vertex_shapes[i].graphics.setStrokeStyle(1).beginFill(getColor(devoting_rating_history[i].point)[1]).dc(0, 0, 2.5);
  493. }
  494. else {
  495. devoting_vertex_shapes[i].graphics.setStrokeStyle(0.5).beginFill(getColor(devoting_rating_history[i].point)[1]).dc(0, 0, 2);
  496. }
  497. devoting_vertex_shapes[i].x = OFFSET_X + PANEL_WIDTH * getPer(devoting_rating_history[i].epoch_second, x_min, x_max);//devotingじゃないほうに合わせる?
  498. devoting_vertex_shapes[i].y = OFFSET_Y + (PANEL_HEIGHT - PANEL_HEIGHT * getPer(devoting_rating_history[i].point, y_min, y_max));
  499. devoting_vertex_shapes[i].i = i;
  500. let hitArea = new cj.Shape();
  501. hitArea.graphics.f("#000").dc(1.5, 1.5, 6);
  502. devoting_vertex_shapes[i].hitArea = hitArea;
  503. // devoting_vertex_shapes[i].addEventListener("mouseover", devoting_mouseoverVertex);
  504. // devoting_vertex_shapes[i].addEventListener("mouseout", devoting_mouseoutVertex);
  505. }
  506.  
  507. //チャートの線関連
  508. for (let index = 0; index < 2; index++) {
  509. if (index == 0) devoting_line_shape.graphics.s("#AAA").ss(2);
  510. else devoting_line_shape.graphics.s("#FFF").ss(0.5);
  511. devoting_line_shape.graphics.mt(devoting_vertex_shapes[0].x, devoting_vertex_shapes[0].y);
  512. for (let i = 0; i < devoting_rating_history.length; i++) {
  513. devoting_line_shape.graphics.lt(devoting_vertex_shapes[i].x, devoting_vertex_shapes[i].y);
  514. }
  515. }
  516.  
  517.  
  518. }
  519.  
  520. function initStatus() {
  521. border_status_shape = newShape(stage_status);
  522. rating_text = newText(stage_status, OFFSET_X + 75, OFFSET_Y + STATUS_HEIGHT / 2, "48px 'Squada One'");
  523. place_text = newText(stage_status, OFFSET_X + 160, OFFSET_Y + STATUS_HEIGHT / 2.7, "16px Lato");
  524. diff_text = newText(stage_status, OFFSET_X + 160, OFFSET_Y + STATUS_HEIGHT / 1.5, "11px Lato");
  525. diff_text.color = '#888';
  526. date_text = newText(stage_status, OFFSET_X + 200, OFFSET_Y + STATUS_HEIGHT / 4, "14px Lato");
  527. contest_name_text = newText(stage_status, OFFSET_X + 200, OFFSET_Y + STATUS_HEIGHT / 1.6, "20px Lato");
  528. date_text.textAlign = contest_name_text.textAlign = "left";
  529. contest_name_text.maxWidth = STATUS_WIDTH - 200 - 10;
  530. {
  531. let hitArea = new cj.Shape(); hitArea.graphics.f("#000").r(0, -12, contest_name_text.maxWidth, 24);
  532. contest_name_text.hitArea = hitArea;
  533. contest_name_text.cursor = "pointer";
  534. contest_name_text.addEventListener("click", function () {
  535. location.href = standings_url;
  536. });
  537. }
  538. particles = new Array();
  539. for (let i = 0; i < PARTICLE_MAX; i++) {
  540. particles.push(newText(stage_status, 0, 0, "64px Lato"));
  541. particles[i].visible = false;
  542. }
  543. setStatus(rating_history[rating_history.length - 1], false);
  544. }
  545.  
  546. function getRatingPer(x) {
  547. let pre = COLORS[COLORS.length - 1][0] + STEP_SIZE;
  548. for (let i = COLORS.length - 1; i >= 0; i--) {
  549. if (x >= COLORS[i][0]) return (x - COLORS[i][0]) / (pre - COLORS[i][0]);
  550. pre = COLORS[i][0];
  551. }
  552. return 0;
  553. }
  554.  
  555. //@#//@#//@#//@#//@#//@#//@#// 関係ない //@#//@#//@#//@#//@#//@#//@#//@#//@#//@#
  556. function getOrdinal(x) {
  557. let s = ["th", "st", "nd", "rd"], v = x % 100;
  558. return x + (s[(v - 20) % 10] || s[v] || s[0]);
  559. }
  560. function getDiff(x) {
  561. let sign = x == 0 ? 'ツア' : (x < 0 ? '-' : '+');
  562. return sign + Math.abs(x);
  563. }
  564. function setStatus(data, particle_flag) {
  565. let date = new Date(data.EndTime * 1000);
  566. let rating = data.NewRating, old_rating = data.OldRating;
  567. let place = data.Place;
  568. let contest_name = data.ContestName;
  569. let tmp = getColor(rating); let color = tmp[1], alpha = tmp[2];
  570. border_status_shape.graphics.c().s(color).ss(1).rr(OFFSET_X, OFFSET_Y, STATUS_WIDTH, STATUS_HEIGHT, 2);
  571. rating_text.text = rating;
  572. rating_text.color = color;
  573. place_text.text = getOrdinal(place);
  574. diff_text.text = getDiff(rating - old_rating);
  575. date_text.text = date.toLocaleDateString();
  576. contest_name_text.text = contest_name;
  577. if (particle_flag) {
  578. let particle_num = parseInt(Math.pow(getRatingPer(rating), 2) * (PARTICLE_MAX - PARTICLE_MIN) + PARTICLE_MIN);
  579. setParticles(particle_num, color, alpha, rating);
  580. }
  581. standings_url = data.StandingsUrl;
  582. }
  583. //Particle は マウスオーバー時のくるくるのやつw
  584. function setParticle(particle, x, y, color, alpha, star_flag) {
  585. particle.x = x;
  586. particle.y = y;
  587. let ang = Math.random() * Math.PI * 2;
  588. let speed = Math.random() * 4 + 4;
  589. particle.vx = Math.cos(ang) * speed;
  590. particle.vy = Math.sin(ang) * speed;
  591. particle.rot_speed = Math.random() * 20 + 10;
  592. particle.life = LIFE_MAX;
  593. particle.visible = true;
  594. particle.color = color;
  595. if (star_flag) {
  596. particle.text = "★";
  597. } else {
  598. particle.text = "@";
  599. }
  600. particle.alpha = alpha;
  601. }
  602. function setParticles(num, color, alpha, rating) {
  603. for (let i = 0; i < PARTICLE_MAX; i++) {
  604. if (i < num) {
  605. setParticle(particles[i], rating_text.x, rating_text.y, color, alpha, rating >= STAR_MIN);
  606. } else {
  607. particles[i].life = 0;
  608. particles[i].visible = false;
  609. }
  610. }
  611. }
  612. function updateParticle(particle) {
  613. if (particle.life <= 0) {
  614. particle.visible = false;
  615. return;
  616. }
  617. particle.x += particle.vx;
  618. particle.vx *= 0.9;
  619. particle.y += particle.vy;
  620. particle.vy *= 0.9;
  621. particle.life--;
  622. particle.scaleX = particle.scaleY = particle.life / LIFE_MAX;
  623. particle.rotation += particle.rot_speed;
  624. }
  625.  
  626. function updateParticles() {
  627. for (let i = 0; i < PARTICLE_MAX; i++) {
  628. if (particles[i].life > 0) {
  629. updateParticle(particles[i]);
  630. }
  631. }
  632. }
  633. //@#//@#//@#//@#//@#//@#//@#// 関係ない //@#//@#//@#//@#//@#//@#//@#//@#//@#//@#
  634.  
  635.  
  636.  
  637.  
  638. init();
  639.  
  640.  
  641. })()