|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": 1, |
| 6 | + "id": "cc4e651b", |
| 7 | + "metadata": {}, |
| 8 | + "outputs": [], |
| 9 | + "source": [ |
| 10 | + "import copy\n", |
| 11 | + "import xml.etree.ElementTree as xml\n", |
| 12 | + "\n", |
| 13 | + "import graphcat.notebook" |
| 14 | + ] |
| 15 | + }, |
| 16 | + { |
| 17 | + "cell_type": "code", |
| 18 | + "execution_count": 2, |
| 19 | + "id": "f0261a32", |
| 20 | + "metadata": {}, |
| 21 | + "outputs": [], |
| 22 | + "source": [ |
| 23 | + "def append_element(graph, name, inputs):\n", |
| 24 | + " parent = copy.copy(inputs.getone(\"parent\"))\n", |
| 25 | + " child = inputs.getone(\"child\")\n", |
| 26 | + " parent.append(child)\n", |
| 27 | + " return parent\n", |
| 28 | + "\n", |
| 29 | + "\n", |
| 30 | + "def create_element(tag, attrib={}, **extra):\n", |
| 31 | + " def implementation(graph, name, inputs):\n", |
| 32 | + " return xml.Element(tag, attrib=attrib, **extra)\n", |
| 33 | + " return implementation" |
| 34 | + ] |
| 35 | + }, |
| 36 | + { |
| 37 | + "cell_type": "code", |
| 38 | + "execution_count": 3, |
| 39 | + "id": "aec611fb", |
| 40 | + "metadata": {}, |
| 41 | + "outputs": [], |
| 42 | + "source": [ |
| 43 | + "graph = graphcat.StaticGraph()\n", |
| 44 | + "graph.add_task(\"canvas\", create_element(\"canvas\"))\n", |
| 45 | + "graph.add_task(\"axes1\", create_element(\"cartesian\"))\n", |
| 46 | + "graph.add_task(\"append1\", append_element)\n", |
| 47 | + "graph.add_links(\"canvas\", (\"append1\", \"parent\"))\n", |
| 48 | + "graph.add_links(\"axes1\", (\"append1\", \"child\"))\n", |
| 49 | + "graph.add_task(\"axes2\", create_element(\"radial\"))\n", |
| 50 | + "graph.add_task(\"append2\", append_element)\n", |
| 51 | + "graph.add_links(\"append1\", (\"append2\", \"parent\"))\n", |
| 52 | + "graph.add_links(\"axes2\", (\"append2\", \"child\"))" |
| 53 | + ] |
| 54 | + }, |
| 55 | + { |
| 56 | + "cell_type": "code", |
| 57 | + "execution_count": 4, |
| 58 | + "id": "829dff2f", |
| 59 | + "metadata": {}, |
| 60 | + "outputs": [ |
| 61 | + { |
| 62 | + "data": { |
| 63 | + "image/svg+xml": [ |
| 64 | + "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"258pt\" height=\"72pt\" viewBox=\"0.00 0.00 258.00 72.00\">\n", |
| 65 | + "<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 68)\">\n", |
| 66 | + "<polygon fill=\"white\" stroke=\"transparent\" points=\"-4,4 -4,-68 254,-68 254,4 -4,4\"/>\n", |
| 67 | + "<!-- canvas -->\n", |
| 68 | + "<g id=\"node1\" class=\"node\">\n", |
| 69 | + "<title>canvas</title>\n", |
| 70 | + "<polygon fill=\"white\" stroke=\"#494744\" points=\"38,-64 0,-64 0,-49 38,-49 38,-64\"/>\n", |
| 71 | + "<text text-anchor=\"middle\" x=\"19\" y=\"-54.6\" font-family=\"Helvetica,sans-Serif\" font-size=\"8.00\" fill=\"#494744\">canvas</text>\n", |
| 72 | + "</g>\n", |
| 73 | + "<!-- append1 -->\n", |
| 74 | + "<g id=\"node2\" class=\"node\">\n", |
| 75 | + "<title>append1</title>\n", |
| 76 | + "<polygon fill=\"white\" stroke=\"#494744\" points=\"144,-48 100,-48 100,-33 144,-33 144,-48\"/>\n", |
| 77 | + "<text text-anchor=\"middle\" x=\"122\" y=\"-38.6\" font-family=\"Helvetica,sans-Serif\" font-size=\"8.00\" fill=\"#494744\">append1</text>\n", |
| 78 | + "</g>\n", |
| 79 | + "<!-- canvas->append1 -->\n", |
| 80 | + "<g id=\"edge1\" class=\"edge\">\n", |
| 81 | + "<title>canvas->append1</title>\n", |
| 82 | + "<path fill=\"none\" stroke=\"#494744\" d=\"M38.06,-53.64C52.44,-51.36 72.9,-48.12 89.9,-45.43\"/>\n", |
| 83 | + "<polygon fill=\"#494744\" stroke=\"#494744\" points=\"90.63,-48.86 99.96,-43.83 89.53,-41.94 90.63,-48.86\"/>\n", |
| 84 | + "<text text-anchor=\"middle\" x=\"69\" y=\"-53.1\" font-family=\"Helvetica,sans-Serif\" font-size=\"8.00\"> parent </text>\n", |
| 85 | + "</g>\n", |
| 86 | + "<!-- append2 -->\n", |
| 87 | + "<g id=\"node4\" class=\"node\">\n", |
| 88 | + "<title>append2</title>\n", |
| 89 | + "<polygon fill=\"white\" stroke=\"#494744\" points=\"250,-31 206,-31 206,-16 250,-16 250,-31\"/>\n", |
| 90 | + "<text text-anchor=\"middle\" x=\"228\" y=\"-21.6\" font-family=\"Helvetica,sans-Serif\" font-size=\"8.00\" fill=\"#494744\">append2</text>\n", |
| 91 | + "</g>\n", |
| 92 | + "<!-- append1->append2 -->\n", |
| 93 | + "<g id=\"edge3\" class=\"edge\">\n", |
| 94 | + "<title>append1->append2</title>\n", |
| 95 | + "<path fill=\"none\" stroke=\"#494744\" d=\"M144.05,-37.06C158.99,-34.62 179.29,-31.3 196.07,-28.56\"/>\n", |
| 96 | + "<polygon fill=\"#494744\" stroke=\"#494744\" points=\"196.68,-32 205.99,-26.94 195.55,-25.09 196.68,-32\"/>\n", |
| 97 | + "<text text-anchor=\"middle\" x=\"175\" y=\"-37.1\" font-family=\"Helvetica,sans-Serif\" font-size=\"8.00\"> parent </text>\n", |
| 98 | + "</g>\n", |
| 99 | + "<!-- axes1 -->\n", |
| 100 | + "<g id=\"node3\" class=\"node\">\n", |
| 101 | + "<title>axes1</title>\n", |
| 102 | + "<polygon fill=\"white\" stroke=\"#494744\" points=\"36,-31 2,-31 2,-16 36,-16 36,-31\"/>\n", |
| 103 | + "<text text-anchor=\"middle\" x=\"19\" y=\"-21.6\" font-family=\"Helvetica,sans-Serif\" font-size=\"8.00\" fill=\"#494744\">axes1</text>\n", |
| 104 | + "</g>\n", |
| 105 | + "<!-- axes1->append1 -->\n", |
| 106 | + "<g id=\"edge2\" class=\"edge\">\n", |
| 107 | + "<title>axes1->append1</title>\n", |
| 108 | + "<path fill=\"none\" stroke=\"#494744\" d=\"M36.06,-25.79C49.23,-27.71 68.35,-30.6 85,-33.5 86.49,-33.76 88.01,-34.03 89.55,-34.31\"/>\n", |
| 109 | + "<polygon fill=\"#494744\" stroke=\"#494744\" points=\"89.23,-37.81 99.71,-36.22 90.52,-30.93 89.23,-37.81\"/>\n", |
| 110 | + "<text text-anchor=\"middle\" x=\"69\" y=\"-36.1\" font-family=\"Helvetica,sans-Serif\" font-size=\"8.00\"> child </text>\n", |
| 111 | + "</g>\n", |
| 112 | + "<!-- axes2 -->\n", |
| 113 | + "<g id=\"node5\" class=\"node\">\n", |
| 114 | + "<title>axes2</title>\n", |
| 115 | + "<polygon fill=\"white\" stroke=\"#494744\" points=\"139,-15 105,-15 105,0 139,0 139,-15\"/>\n", |
| 116 | + "<text text-anchor=\"middle\" x=\"122\" y=\"-5.6\" font-family=\"Helvetica,sans-Serif\" font-size=\"8.00\" fill=\"#494744\">axes2</text>\n", |
| 117 | + "</g>\n", |
| 118 | + "<!-- axes2->append2 -->\n", |
| 119 | + "<g id=\"edge4\" class=\"edge\">\n", |
| 120 | + "<title>axes2->append2</title>\n", |
| 121 | + "<path fill=\"none\" stroke=\"#494744\" d=\"M139.12,-6.04C153.02,-5.18 173.54,-4.88 191,-8.5 194.99,-9.33 199.09,-10.6 203.03,-12.05\"/>\n", |
| 122 | + "<polygon fill=\"#494744\" stroke=\"#494744\" points=\"201.77,-15.31 212.34,-15.91 204.44,-8.85 201.77,-15.31\"/>\n", |
| 123 | + "<text text-anchor=\"middle\" x=\"175\" y=\"-11.1\" font-family=\"Helvetica,sans-Serif\" font-size=\"8.00\"> child </text>\n", |
| 124 | + "</g>\n", |
| 125 | + "</g>\n", |
| 126 | + "</svg>" |
| 127 | + ], |
| 128 | + "text/plain": [ |
| 129 | + "<IPython.core.display.SVG object>" |
| 130 | + ] |
| 131 | + }, |
| 132 | + "metadata": {}, |
| 133 | + "output_type": "display_data" |
| 134 | + } |
| 135 | + ], |
| 136 | + "source": [ |
| 137 | + "graphcat.notebook.display(graph)" |
| 138 | + ] |
| 139 | + }, |
| 140 | + { |
| 141 | + "cell_type": "code", |
| 142 | + "execution_count": 5, |
| 143 | + "id": "85047669", |
| 144 | + "metadata": {}, |
| 145 | + "outputs": [ |
| 146 | + { |
| 147 | + "name": "stdout", |
| 148 | + "output_type": "stream", |
| 149 | + "text": [ |
| 150 | + "<canvas><cartesian /><radial /></canvas>\n" |
| 151 | + ] |
| 152 | + } |
| 153 | + ], |
| 154 | + "source": [ |
| 155 | + "xml.dump(graph.output(\"append2\"))" |
| 156 | + ] |
| 157 | + }, |
| 158 | + { |
| 159 | + "cell_type": "code", |
| 160 | + "execution_count": 6, |
| 161 | + "id": "1c168856", |
| 162 | + "metadata": {}, |
| 163 | + "outputs": [ |
| 164 | + { |
| 165 | + "data": { |
| 166 | + "text/plain": [ |
| 167 | + "<Element 'canvas' at 0x7fbdb8771a40>" |
| 168 | + ] |
| 169 | + }, |
| 170 | + "execution_count": 6, |
| 171 | + "metadata": {}, |
| 172 | + "output_type": "execute_result" |
| 173 | + } |
| 174 | + ], |
| 175 | + "source": [ |
| 176 | + "graph.output(\"canvas\")" |
| 177 | + ] |
| 178 | + }, |
| 179 | + { |
| 180 | + "cell_type": "code", |
| 181 | + "execution_count": 7, |
| 182 | + "id": "43b70ff2", |
| 183 | + "metadata": {}, |
| 184 | + "outputs": [ |
| 185 | + { |
| 186 | + "data": { |
| 187 | + "text/plain": [ |
| 188 | + "<Element 'canvas' at 0x7fbdb8771a90>" |
| 189 | + ] |
| 190 | + }, |
| 191 | + "execution_count": 7, |
| 192 | + "metadata": {}, |
| 193 | + "output_type": "execute_result" |
| 194 | + } |
| 195 | + ], |
| 196 | + "source": [ |
| 197 | + "graph.output(\"append1\")" |
| 198 | + ] |
| 199 | + }, |
| 200 | + { |
| 201 | + "cell_type": "code", |
| 202 | + "execution_count": 8, |
| 203 | + "id": "ac3fb8fc", |
| 204 | + "metadata": {}, |
| 205 | + "outputs": [ |
| 206 | + { |
| 207 | + "data": { |
| 208 | + "text/plain": [ |
| 209 | + "<Element 'canvas' at 0x7fbdb87719a0>" |
| 210 | + ] |
| 211 | + }, |
| 212 | + "execution_count": 8, |
| 213 | + "metadata": {}, |
| 214 | + "output_type": "execute_result" |
| 215 | + } |
| 216 | + ], |
| 217 | + "source": [ |
| 218 | + "graph.output(\"append2\")" |
| 219 | + ] |
| 220 | + }, |
| 221 | + { |
| 222 | + "cell_type": "code", |
| 223 | + "execution_count": 9, |
| 224 | + "id": "19bfccf5", |
| 225 | + "metadata": {}, |
| 226 | + "outputs": [ |
| 227 | + { |
| 228 | + "data": { |
| 229 | + "text/plain": [ |
| 230 | + "<Element 'cartesian' at 0x7fbdb8771b30>" |
| 231 | + ] |
| 232 | + }, |
| 233 | + "execution_count": 9, |
| 234 | + "metadata": {}, |
| 235 | + "output_type": "execute_result" |
| 236 | + } |
| 237 | + ], |
| 238 | + "source": [ |
| 239 | + "graph.output(\"axes1\")" |
| 240 | + ] |
| 241 | + }, |
| 242 | + { |
| 243 | + "cell_type": "code", |
| 244 | + "execution_count": 10, |
| 245 | + "id": "53b6eaad", |
| 246 | + "metadata": {}, |
| 247 | + "outputs": [ |
| 248 | + { |
| 249 | + "data": { |
| 250 | + "text/plain": [ |
| 251 | + "<Element 'cartesian' at 0x7fbdb8771b30>" |
| 252 | + ] |
| 253 | + }, |
| 254 | + "execution_count": 10, |
| 255 | + "metadata": {}, |
| 256 | + "output_type": "execute_result" |
| 257 | + } |
| 258 | + ], |
| 259 | + "source": [ |
| 260 | + "graph.output(\"append1\")[0]" |
| 261 | + ] |
| 262 | + }, |
| 263 | + { |
| 264 | + "cell_type": "code", |
| 265 | + "execution_count": 11, |
| 266 | + "id": "de4c208e", |
| 267 | + "metadata": {}, |
| 268 | + "outputs": [ |
| 269 | + { |
| 270 | + "data": { |
| 271 | + "text/plain": [ |
| 272 | + "<Element 'cartesian' at 0x7fbdb8771b30>" |
| 273 | + ] |
| 274 | + }, |
| 275 | + "execution_count": 11, |
| 276 | + "metadata": {}, |
| 277 | + "output_type": "execute_result" |
| 278 | + } |
| 279 | + ], |
| 280 | + "source": [ |
| 281 | + "graph.output(\"append2\")[0]" |
| 282 | + ] |
| 283 | + }, |
| 284 | + { |
| 285 | + "cell_type": "code", |
| 286 | + "execution_count": 12, |
| 287 | + "id": "58b101aa", |
| 288 | + "metadata": {}, |
| 289 | + "outputs": [ |
| 290 | + { |
| 291 | + "data": { |
| 292 | + "text/plain": [ |
| 293 | + "<Element 'radial' at 0x7fbdb8771b80>" |
| 294 | + ] |
| 295 | + }, |
| 296 | + "execution_count": 12, |
| 297 | + "metadata": {}, |
| 298 | + "output_type": "execute_result" |
| 299 | + } |
| 300 | + ], |
| 301 | + "source": [ |
| 302 | + "graph.output(\"axes2\")" |
| 303 | + ] |
| 304 | + }, |
| 305 | + { |
| 306 | + "cell_type": "code", |
| 307 | + "execution_count": 13, |
| 308 | + "id": "84afef9d", |
| 309 | + "metadata": {}, |
| 310 | + "outputs": [ |
| 311 | + { |
| 312 | + "data": { |
| 313 | + "text/plain": [ |
| 314 | + "<Element 'radial' at 0x7fbdb8771b80>" |
| 315 | + ] |
| 316 | + }, |
| 317 | + "execution_count": 13, |
| 318 | + "metadata": {}, |
| 319 | + "output_type": "execute_result" |
| 320 | + } |
| 321 | + ], |
| 322 | + "source": [ |
| 323 | + "graph.output(\"append2\")[1]" |
| 324 | + ] |
| 325 | + } |
| 326 | + ], |
| 327 | + "metadata": { |
| 328 | + "kernelspec": { |
| 329 | + "display_name": "Python 3 (ipykernel)", |
| 330 | + "language": "python", |
| 331 | + "name": "python3" |
| 332 | + }, |
| 333 | + "language_info": { |
| 334 | + "codemirror_mode": { |
| 335 | + "name": "ipython", |
| 336 | + "version": 3 |
| 337 | + }, |
| 338 | + "file_extension": ".py", |
| 339 | + "mimetype": "text/x-python", |
| 340 | + "name": "python", |
| 341 | + "nbconvert_exporter": "python", |
| 342 | + "pygments_lexer": "ipython3", |
| 343 | + "version": "3.8.10" |
| 344 | + } |
| 345 | + }, |
| 346 | + "nbformat": 4, |
| 347 | + "nbformat_minor": 5 |
| 348 | +} |
0 commit comments