bubble-port-with-tabs.html 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <html>
  2. <head>
  3. <style>
  4. .chartWithMarkerOverlay {
  5. position: relative;
  6. width: 700px;
  7. }
  8. .overlay-text {
  9. width: 200px;
  10. height: 200px;
  11. position: absolute;
  12. top: 30px; /* chartArea top */
  13. left: 200px; /* chartArea left */
  14. }
  15. .overlay-marker {
  16. width: 50px;
  17. height: 50px;
  18. position: absolute;
  19. top: 375px; /* chartArea top */
  20. left: 350px; /* chartArea left */
  21. color: #000066;
  22. font: 15px arial;
  23. }
  24. </style>
  25. <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
  26. <script type="text/javascript" src="https://www.google.com/jsapi"></script>
  27. <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
  28. <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
  29. <script type="text/javascript">
  30. google.load("visualization", "1.1", {packages:['corechart']});
  31. google.setOnLoadCallback(drawChart);
  32. function drawChart() {
  33. ////////////////////////////////////////////////////////////////////////////////
  34. // guage functions
  35. var data = google.visualization.arrayToDataTable(
  36. {{{bubble_data}}}
  37. );
  38. var options = { title: 'Portfolio Risk Distribution',
  39. hAxis: {title: 'Strike Price'}, vAxis: {title: ' Unreal P/L'},
  40. // to display labels, remove the color: 'none option
  41. bubble: {textStyle: {fontSize: 11, color: 'none'}}, colorAxis: {colors: ['red', 'blue']},
  42. sizeAxis: {minValue: 2, maxSize: 40}
  43. //backgroundColor: '#E4E4E4'
  44. };
  45. var chart = new google.visualization.BubbleChart(document.getElementById('chart_div'));
  46. chart.draw(data, options);
  47. google.visualization.events.addListener(chart, 'ready', placeIndexMarker);
  48. var button = document.getElementById('b1');
  49. button.onclick = function() {
  50. refreshPortItems();
  51. refreshAcctItems();
  52. }
  53. setInterval(function() {
  54. placeIndexMarker();
  55. }, 2000);
  56. function refreshPortItems() {
  57. $.ajax({
  58. type: 'Post',
  59. url: '/ws_bubble_data',
  60. success: function (s_portitems) {
  61. $('#pt_status').text(s_portitems);
  62. //alert(jdata.delta_all);
  63. lst = eval(s_portitems);
  64. //alert(lst[0]);
  65. data = google.visualization.arrayToDataTable(eval(s_portitems));
  66. chart.draw(data, options);
  67. drawChart();
  68. }
  69. });
  70. }
  71. function refreshAcctItems() {
  72. $.ajax({
  73. type: 'Post',
  74. url: '/ws_acct_data',
  75. success: function (s_accttitems) {
  76. $('#pt_status').text(s_accttitems);
  77. //alert(jdata.delta_all);
  78. lst = eval(s_portitems);
  79. //alert(lst[0]);
  80. dataB = google.visualization.arrayToDataTable(eval(s_accttitems));
  81. chart.draw(dataB, options);
  82. drawChart();
  83. }
  84. });
  85. }
  86. function placeIndexMarker(){
  87. $.ajax({
  88. type: 'Post',
  89. url: '/ws_market_data?r_ckey={{{FUT_CONTRACT}}}&fid=4',
  90. success: function (data) {
  91. var spot = data
  92. $('#spot').text(spot);
  93. var cli = chart.getChartLayoutInterface();
  94. document.querySelector('.overlay-marker').style.top = Math.floor(cli.getYLocation(0) - 25) + "px";
  95. document.querySelector('.overlay-marker').style.left = Math.floor(cli.getXLocation(spot) - 25) + "px";
  96. }
  97. });
  98. var dataB = google.visualization.arrayToDataTable(
  99. {{{barAcct}}}
  100. );
  101. var view = new google.visualization.DataView(dataB);
  102. view.setColumns([0, 1,
  103. { calc: "stringify",
  104. sourceColumn: 1,
  105. type: "string",
  106. role: "annotation" }, 2]);
  107. var options = {
  108. chart: {
  109. title: 'Account Summary {{{account_no}}}',
  110. subtitle: 'Last updated {{{last_updated}}}'
  111. },
  112. bars: 'horizontal',bar: {groupWidth: "55%"},
  113. legend: { position: "none" },
  114. };
  115. var material = new google.visualization.BarChart(document.getElementById('barchart_div'));
  116. material.draw(view, options);
  117. }
  118. //https://groups.google.com/forum/#!msg/google-chart-api/yYxkv4eorhA/P-MHQOLA19MJ
  119. /* testing
  120. function placeMarker() {
  121. var cli = chart.getChartLayoutInterface();
  122. document.querySelector('.overlay-marker').style.top = Math.floor(cli.getYLocation(0) - 25) + "px";
  123. var spot = Math.round(Math.max(25000 * Math.random(), 15000))
  124. $('#pt_status').text(spot);
  125. $('#spot').text(spot);
  126. document.querySelector('.overlay-marker').style.left = Math.floor(cli.getXLocation(spot)) + "px";
  127. };
  128. var cli = chart.getChartLayoutInterface();
  129. var l= cli.getChartAreaBoundingBox().left;
  130. var t=cli.getChartAreaBoundingBox().top;
  131. var h=cli.getChartAreaBoundingBox().height;
  132. var w= cli.getChartAreaBoundingBox().width;
  133. var hx = cli.getYLocation(50000);
  134. var cx = cli.getYLocation(0);
  135. $('#pt_status').text(l + ':' + t + ':' + h + ':' + w + ':' + hx + ':' + cx);
  136. function chartMouseOver(e) {
  137. var cli = chart.getChartLayoutInterface();
  138. var xx = Math.floor(cli.getXLocation(e['row'])) + 'px';
  139. var yy = Math.floor(cli.getYLocation(data.getValue(e['row'], 1))) + 'px';
  140. $('#pt_status').text(e['row'] + ':' + xx + + ':' + yy + ':' + data.getValue(e['row'], 1));
  141. $('#pt2_status').text(e['row'] + ':' + cli.getHAxisValue(e['row']));
  142. }
  143. */
  144. } // end drawChart
  145. </script>
  146. <script>
  147. $(function() {
  148. $( "#tabs" ).tabs();
  149. });
  150. </script>
  151. </head>
  152. <body>
  153. <div id="tabs">
  154. <ul>
  155. <li><a href="#tabs-1">Dashboard</a></li>
  156. <li><a href="#tabs-2">Position Distribution</a></li>
  157. <li><a href="#tabs-3">Risk Distribution</a></li>
  158. </ul>
  159. <div id="tabs-1">
  160. <div id='pt2_status'></div>
  161. <button type='button' id='b1'>Update</button>
  162. <div id="chart_div" style="width: 900px; height: 800px;"></div>
  163. <div class="overlay-marker">
  164. <img src="/public/green_marker.png" height="50"><div id='spot'></div>
  165. </div>
  166. </div>
  167. <div id="tabs-2">
  168. <div id="barchart_div" style="width:800px; height: 600px;"></div>
  169. </div>
  170. <div id="tabs-3">
  171. <div id='temp'></div>
  172. <div id='pt_status'></div>
  173. </div>
  174. </div>
  175. </body>
  176. </html>
  177. </body>
  178. </html>