plot.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /**
  2. * @license
  3. * Visual Blocks Language
  4. *
  5. * Copyright 2012 Google Inc.
  6. * https://developers.google.com/blockly/
  7. *
  8. * Licensed under the Apache License, Version 2.0 (the "License");
  9. * you may not use this file except in compliance with the License.
  10. * You may obtain a copy of the License at
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS,
  16. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. * See the License for the specific language governing permissions and
  18. * limitations under the License.
  19. */
  20. /**
  21. * @fileoverview Generating Pseudo for plot blocks.
  22. * @author acbart@vt.edu (Austin Cory Bart)
  23. */
  24. 'use strict';
  25. goog.provide('Blockly.Pseudo.plot');
  26. goog.require('Blockly.Pseudo');
  27. Blockly.Pseudo['plot_title'] = function(block) {
  28. Blockly.Pseudo.definitions_['import_matplotlib'] = 'Import the PyPlot package from the MatPlotLib module (which let\'s you do plotting).';
  29. var parameter_plot_title = Blockly.Pseudo.quote_(block.getFieldValue('TEXT'))
  30. var code = 'Set the title of the current plot to '+parameter_plot_title+'.\n';
  31. return code;
  32. };
  33. Blockly.Pseudo['plot_line'] = function(block) {
  34. Blockly.Pseudo.definitions_['import_matplotlib'] = 'Import the PyPlot package from the MatPlotLib module (which let\'s you do plotting).';
  35. var code = 'Plot the list ';
  36. var argument1 = Blockly.Pseudo.valueToCode(block, 'y_values',
  37. Blockly.Pseudo.ORDER_NONE) || '___';
  38. code += argument1 +' onto the current canvas as a line.\n';
  39. return code;
  40. };
  41. Blockly.Pseudo['plot_lineXY'] = function(block) {
  42. Blockly.Pseudo.definitions_['import_matplotlib'] = 'Import the PyPlot package from the MatPlotLib module (which let\'s you do plotting).';
  43. var code = 'Plot the list ';
  44. var argument0 = Blockly.Pseudo.valueToCode(block, 'x_values',
  45. Blockly.Pseudo.ORDER_NONE) || '___';
  46. var argument1 = Blockly.Pseudo.valueToCode(block, 'y_values',
  47. Blockly.Pseudo.ORDER_NONE) || '___';
  48. code += argument0 + ','+ argument1 + ' onto the current canvas as an XY Plot\n';
  49. return code;
  50. };
  51. Blockly.Pseudo['plot_scatter'] = function(block) {
  52. Blockly.Pseudo.definitions_['import_matplotlib'] = 'Import the PyPlot package from the MatPlotLib module (which let\'s you do plotting).';
  53. var code = 'plt.scatter(';
  54. var argument0 = Blockly.Pseudo.valueToCode(block, 'x_values',
  55. Blockly.Pseudo.ORDER_NONE) || '___';
  56. var argument1 = Blockly.Pseudo.valueToCode(block, 'y_values',
  57. Blockly.Pseudo.ORDER_NONE) || '___';
  58. code += argument0 + ','+ argument1 + ')\n';
  59. return code;
  60. };
  61. Blockly.Pseudo['plot_show'] = function(block) {
  62. Blockly.Pseudo.definitions_['import_matplotlib'] = 'Import the PyPlot package from the MatPlotLib module (which let\'s you do plotting).';
  63. var code = 'Make the plot appear.\n';
  64. return code;
  65. };