vis.js is a dynamic, browser-based visualization library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

173 lines
3.6 KiB

10 years ago
  1. <html>
  2. <head>
  3. <title>Graph3d documentation</title>
  4. <link rel='stylesheet' href='default.css' type='text/css'>
  5. <link href="prettify/prettify.css" type="text/css" rel="stylesheet" />
  6. <script type="text/javascript" src="prettify/prettify.js"></script>
  7. </head>
  8. <body onload="prettyPrint();">
  9. <pre class="prettyprint lang-php">
  10. &lt;?php
  11. /*
  12. This datasource returns a response in the form of a google query response
  13. USAGE
  14. All parameters are optional
  15. datasource.php?xmin=0&xmax=314&xstepnum=25&ymin=0&ymax=314&ystepnum=25
  16. DOCUMENTATION
  17. http://code.google.com/apis/visualization/documentation/dev/implementing_data_source.html
  18. EXAMPLE OF A RESPONSE FILE
  19. Note that the reqId in the response must correspond with the reqId from the
  20. request.
  21. ________________________________________________________________________________
  22. google.visualization.Query.setResponse({
  23. version:'0.6',
  24. reqId:'0',
  25. status:'ok',
  26. table:{
  27. cols:[
  28. {id:'x',
  29. label:'x',
  30. type:'number'},
  31. {id:'y',
  32. label:'y',
  33. type:'number'},
  34. {id:'value',
  35. label:'value',
  36. type:'number'}
  37. ],
  38. rows:[
  39. {c:[{v:0}, {v:0}, {v:10.0}]},
  40. {c:[{v:1}, {v:0}, {v:12.0}]},
  41. {c:[{v:2}, {v:0}, {v:13.0}]},
  42. {c:[{v:0}, {v:1}, {v:11.0}]},
  43. {c:[{v:1}, {v:1}, {v:14.0}]},
  44. {c:[{v:2}, {v:1}, {v:11.0}]}
  45. ]
  46. }
  47. });
  48. ________________________________________________________________________________
  49. */
  50. /**
  51. * A custom function
  52. */
  53. function custom($x, $y) {
  54. $d = sqrt(pow($x/100, 2) + pow($y/100, 2));
  55. return 50 * exp(-5 * $d / 10) * sin($d*5)
  56. }
  57. // retrieve parameters
  58. $default_stepnum = 25;
  59. $xmin = isset($_REQUEST['xmin']) ? (float)$_REQUEST['xmin'] : -100;
  60. $xmax = isset($_REQUEST['xmax']) ? (float)$_REQUEST['xmax'] : 100;
  61. $xstepnum = isset($_REQUEST['xstepnum']) ? (int)$_REQUEST['xstepnum'] : $default_stepnum;
  62. $ymin = isset($_REQUEST['ymin']) ? (float)$_REQUEST['ymin'] : -100;
  63. $ymax = isset($_REQUEST['ymax']) ? (float)$_REQUEST['ymax'] : 100;
  64. $ystepnum = isset($_REQUEST['ystepnum']) ? (int)$_REQUEST['ystepnum'] : $default_stepnum;
  65. // in the reply we must fill in the request id that came with the request
  66. $reqId = getReqId();
  67. // check for a maximum number of datapoints (for safety)
  68. if ($xstepnum * $ystepnum &gt; 10000) {
  69. echo "google.visualization.Query.setResponse({
  70. version:'0.6',
  71. reqId:'$reqId',
  72. status:'error',
  73. errors:[{reason:'not_supported', message:'Maximum number of datapoints exceeded'}]
  74. });";
  75. exit;
  76. }
  77. // output the header part of the response
  78. echo "google.visualization.Query.setResponse({
  79. version:'0.6',
  80. reqId:'$reqId',
  81. status:'ok',
  82. table:{
  83. cols:[
  84. {id:'x',
  85. label:'x',
  86. type:'number'},
  87. {id:'y',
  88. label:'y',
  89. type:'number'},
  90. {id:'value',
  91. label:'',
  92. type:'number'}
  93. ],
  94. rows:[";
  95. // output the actual values
  96. $first = true;
  97. $xstep = ($xmax - $xmin) / $xstepnum;
  98. $ystep = ($ymax - $ymin) / $ystepnum;
  99. for ($x = $xmin; $x &lt; $xmax; $x+=$xstep) {
  100. for ($y = $ymin; $y &lt; $ymax; $y+=$ystep) {
  101. $value = custom($x,$y);
  102. if (!$first) {
  103. echo ",\n";
  104. }
  105. else {
  106. echo "\n";
  107. }
  108. echo " {c:[{v:$x}, {v:$y}, {v:$value}]}";
  109. $first = false;
  110. }
  111. }
  112. // output the end part of the response
  113. echo "
  114. ]
  115. }
  116. });
  117. ";
  118. /**
  119. * Retrieve the request id from the get/post data
  120. * @return {number} $reqId The request id, or 0 if not found
  121. */
  122. function getReqId() {
  123. $reqId = 0;
  124. foreach ($_REQUEST as $req) {
  125. if (substr($req, 0,6) == "reqId:") {
  126. $reqId = substr($req, 6);
  127. }
  128. }
  129. return $reqId;
  130. }
  131. ?&gt;
  132. </pre>
  133. </body>
  134. </html>