jsplotlib_test.html 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <html>
  2. <head>
  3. <style>
  4. body {
  5. font: 10px sans-serif;
  6. }
  7. </style>
  8. </head>
  9. <body>
  10. <script src="libs/d3.min.js"></script>
  11. <script type="text/javascript" src="libs/math.0.19.0.min.js"></script>
  12. <script src="libs/jquery.js"></script>
  13. <script type="text/javascript" src="skulpt/dist/skulpt.min.js"></script>
  14. <script type="text/javascript" src="skulpt/dist/skulpt-stdlib.js"></script>
  15. <script type="text/javascript">
  16. function outf(text)
  17. {
  18. var output = document.getElementById("html-output");
  19. text = text.replace(/</g, '&lt;');
  20. output.innerHTML = output.innerHTML + text;
  21. }
  22. function builtinRead(x) {
  23. if (Sk.builtinFiles === undefined || Sk.builtinFiles["files"][x] === undefined)
  24. throw "File not found: '" + x + "'";
  25. return Sk.builtinFiles["files"][x];
  26. }
  27. function runit() {
  28. runProgram($("#python-output").text());
  29. }
  30. function runProgram(prog)
  31. {
  32. var output = document.getElementById("html-output");
  33. output.innerHTML = '';
  34. Sk.configure({output:outf, read: builtinRead});
  35. Sk.canvas = "mycanvas";
  36. try {
  37. module = Sk.importMainWithBody("<stdin>", false, prog);
  38. //var obj = module.tp$getattr('a');
  39. //var runMethod = obj.tp$getattr('run');
  40. //var ret = Sk.misceval.callsim(runMethod, 10);
  41. } catch (e) {
  42. $("#error-output").text(e);
  43. }
  44. }
  45. $(document).ready(function() {
  46. runit();
  47. });
  48. </script>
  49. <pre id="python-output">
  50. import matplotlib.pyplot as pp
  51. import numpy as np
  52. pp.plot([0,1,20, 30, 40, 50])
  53. pp.show()</pre>
  54. <button onclick="runit()" type="button">Run</button>
  55. <pre id="html-output"></pre>
  56. <pre id="error-output"></pre>
  57. <svg id="mycanvas" height="400" width="400" style="border:1px solid #000000;">
  58. </svg>
  59. </body>
  60. </html>