{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Example of creating an SVG diagram \n",
    "The ProgramAnaiysis Module creates a SVG diagram with links to demonstrate a function. The left hand side has boxes that represent the input and have links to the input in text form. The central box represents the action or function being done and has a link to the code of the function. The right most boxes represent the output and has a link to the text version of the output. The output can have a transformation function for viewing"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "from pyMez.Code.DataHandlers.Translations import S2PV1_to_XmlDataTable\n",
    "from pyMez.Code.Analysis.ProgramAnalysis import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# to display this diagram it is good to have a html form first\n",
    "new_svg=create_svg_black_box_diagram(inputs={\"s2p\":S2PV1(os.path.join(TESTS_DIRECTORY,\"thru.s2p\"))},\n",
    "                                             outputs=[\"S2P_as_xml\"],function=S2PV1_to_XmlDataTable,\n",
    "                                     output_transformation_function=lambda x: x.to_HTML(os.path.join(TESTS_DIRECTORY,\n",
    "                                                                                                     '../XSL/S2P_DB_STYLE.xsl')),\n",
    "                                     output_mime_type=\"text/html\",box_text_ratio=15)\n",
    "\n",
    "new_html=HTMLBase()\n",
    "new_html.add_head()\n",
    "new_html.add_body()\n",
    "new_html.append_to_body({\"tag\":\"br\"})\n",
    "new_html.append_to_body(new_svg)\n",
    "new_html.append_to_head({\"tag\":\"style\",\"text\":\"rect:hover {stroke-width:8;stroke:blue;}\"})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# from IPython.display import SVG,HTML\n",
    "# HTML(str(new_html))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "file://c:/users/sandersa/appdata/local/temp/1/tmptr1sln.html\n"
     ]
    }
   ],
   "source": [
    "# this shows the html file in your browser\n",
    "new_html.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "file://c:/users/sandersa/appdata/local/temp/1/tmpgfov0j.html\n"
     ]
    }
   ],
   "source": [
    "# this works for any function\n",
    "black_box=create_svg_black_box_diagram(inputs={\"list_of_strings\":[\"This is one string\",\"This is number two\"]},\n",
    "                                       function=string_list_collapse,outputs=[\"Collapsed String\"])\n",
    "new_html.append_to_body(black_box)\n",
    "new_html.show()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
