plot.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /**
  2. * @license
  3. * Visual Blocks Editor
  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 Plotting blocks for Blockly.
  22. * @author acbart@vt.edu (Austin Cory Bart)
  23. */
  24. 'use strict';
  25. goog.provide('Blockly.Blocks.plot');
  26. goog.require('Blockly.Blocks');
  27. Blockly.Blocks.plot.HUE = 20;
  28. Blockly.Blocks['plot_show'] = {
  29. init: function() {
  30. this.setHelpUrl('http://www.example.com/');
  31. this.setColour(Blockly.Blocks.plot.HUE);
  32. this.appendDummyInput()
  33. .appendField("show plot canvas");
  34. this.setInputsInline(false);
  35. this.setPreviousStatement(true);
  36. this.setNextStatement(true);
  37. this.setOutput(false);
  38. this.setTooltip('Makes the canvas appear');
  39. }
  40. };
  41. Blockly.Blocks['plot_scatter'] = {
  42. init: function() {
  43. this.setHelpUrl('http://www.example.com/');
  44. this.setColour(Blockly.Blocks.plot.HUE);
  45. this.setPreviousStatement(true);
  46. this.setNextStatement(true);
  47. this.appendValueInput("x_values")
  48. .appendField("plot scatter ")
  49. .setCheck('Array');
  50. this.appendValueInput("y_values")
  51. .appendField("vs. ")
  52. .setCheck('Array');
  53. this.setInputsInline(false);
  54. this.setOutput(false);
  55. this.setTooltip('Plots onto the canvas');
  56. }
  57. };
  58. var OPEN_QUOTE = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAKCAYAAACALL/6AAAA0UlEQVQY023QP0oDURSF8e8MImhlUIiCjWKhrUUK3YCIVkq6bMAF2LkCa8ENWLoNS1sLEQKprMQ/GBDks3kDM+Oc8nfPfTxuANQTYBeYAvdJLL4FnAFfwF2ST9Rz27kp5YH/kwrYp50LdaXHAU4rYNYzWAdeenx7AbgF5sAhcARsAkkyVQ+ACbAKjIGqta4+l78udXxc/LiJG+qvet0pV+q7+tHE+iJzdbGz8FhmOzVcqj/qq7rcKI7Ut1Leq70C1oCrJMMk343HB8ADMEzyVOMff72l48gwfqkAAAAASUVORK5CYII=';
  59. var CLOSED_QUOTE = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAKCAYAAACALL/6AAAAvklEQVQY022PoapCQRRF97lBVDRYhBcEQcP1BwS/QLAqr7xitZn0HzRr8Rts+htmQdCqSbQIwmMZPMIw3lVmZu0zG44UAFSBLdBVBDAFZqFo8eYKtANfBC7AE5h8ZNOHd1FrDnh4VgmDO3ADkujDHPgHfkLZ84bfaLjg/hD6RFLq9z6wBDr+rvuZB1bAEDABY76pA2mGHyWSjvqmIemc4WsCLKOp4nssIj8wD8qS/iSVJK3N7OTeJPV9n72ZbV7iDuSc2BaQBQAAAABJRU5ErkJggg==';
  60. Blockly.Blocks['plot_title'] = {
  61. init: function() {
  62. this.setHelpUrl('http://www.example.com/');
  63. this.setColour(Blockly.Blocks.plot.HUE);
  64. this.appendDummyInput()
  65. .appendField("make plot's title")
  66. .appendField(this.newQuote_(true))
  67. .appendField(new Blockly.FieldTextInput('title'), 'TEXT')
  68. .appendField(this.newQuote_(false));
  69. this.setInputsInline(true);
  70. this.setPreviousStatement(true);
  71. this.setNextStatement(true);
  72. this.setOutput(false);
  73. this.setTooltip('Sets the plot\'s title');
  74. },
  75. newQuote_: function(open) {
  76. if (open == this.RTL) {
  77. var file = OPEN_QUOTE;
  78. } else {
  79. var file = CLOSED_QUOTE;
  80. }
  81. return new Blockly.FieldImage(file, 12, 12, '"');
  82. }
  83. };
  84. Blockly.Blocks['plot_xlabel'] = {
  85. init: function() {
  86. this.setHelpUrl('http://www.example.com/');
  87. this.setColour(Blockly.Blocks.plot.HUE);
  88. this.appendDummyInput()
  89. .appendField("make plot's x-axis label")
  90. .appendField(this.newQuote_(true))
  91. .appendField(new Blockly.FieldTextInput('title'), 'TEXT')
  92. .appendField(this.newQuote_(false));
  93. this.setInputsInline(true);
  94. this.setPreviousStatement(true);
  95. this.setNextStatement(true);
  96. this.setOutput(false);
  97. this.setTooltip('Sets the plot\'s x-axis title (horizontal axis)');
  98. },
  99. newQuote_: function(open) {
  100. if (open == this.RTL) {
  101. var file = OPEN_QUOTE;
  102. } else {
  103. var file = CLOSED_QUOTE;
  104. }
  105. return new Blockly.FieldImage(file, 12, 12, '"');
  106. }
  107. };
  108. Blockly.Blocks['plot_ylabel'] = {
  109. init: function() {
  110. this.setHelpUrl('http://www.example.com/');
  111. this.setColour(Blockly.Blocks.plot.HUE);
  112. this.appendDummyInput()
  113. .appendField("make plot's y-axis label")
  114. .appendField(this.newQuote_(true))
  115. .appendField(new Blockly.FieldTextInput('title'), 'TEXT')
  116. .appendField(this.newQuote_(false));
  117. this.setInputsInline(true);
  118. this.setPreviousStatement(true);
  119. this.setNextStatement(true);
  120. this.setOutput(false);
  121. this.setTooltip('Sets the plot\'s y-axis title (vertical axis)');
  122. },
  123. newQuote_: function(open) {
  124. if (open == this.RTL) {
  125. var file = OPEN_QUOTE;
  126. } else {
  127. var file = CLOSED_QUOTE;
  128. }
  129. return new Blockly.FieldImage(file, 12, 12, '"');
  130. }
  131. };
  132. Blockly.Blocks['plot_line'] = {
  133. init: function() {
  134. this.setHelpUrl('http://www.example.com/');
  135. this.setColour(Blockly.Blocks.plot.HUE);
  136. this.setPreviousStatement(true);
  137. this.setNextStatement(true);
  138. this.appendValueInput("y_values")
  139. .appendField("plot line ")
  140. .setCheck('Array');
  141. this.setInputsInline(false);
  142. this.setOutput(false);
  143. this.setTooltip('Plots onto the canvas');
  144. }
  145. };
  146. Blockly.Blocks['plot_hist'] = {
  147. init: function() {
  148. this.setHelpUrl('http://www.example.com/');
  149. this.setColour(Blockly.Blocks.plot.HUE);
  150. this.setPreviousStatement(true);
  151. this.setNextStatement(true);
  152. this.appendValueInput("values")
  153. .appendField("plot histogram ")
  154. .setCheck('Array');
  155. this.setInputsInline(false);
  156. this.setOutput(false);
  157. this.setTooltip('Plots a histogram onto the canvas');
  158. }
  159. };
  160. Blockly.Blocks['plot_lineXY'] = {
  161. init: function() {
  162. this.setHelpUrl('http://www.example.com/');
  163. this.setColour(Blockly.Blocks.plot.HUE);
  164. this.setPreviousStatement(true);
  165. this.setNextStatement(true);
  166. this.appendValueInput("x_values")
  167. .appendField("plot Xs:")
  168. .setCheck('Array');
  169. this.appendValueInput("y_values")
  170. .appendField("vs. Ys:")
  171. .setCheck('Array');
  172. this.setInputsInline(false);
  173. this.setOutput(false);
  174. this.setTooltip('Plots onto the canvas');
  175. }
  176. };