{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# IPerl display demo\n", "\n", "author: Zaki Mughal\n", "\n", "date: 2015-02-09\n", "\n", "This notebook demonstrates how to use the *rich display system* in IPerl and how it can be extended on the fly.\n", "\n", "All data that is displayed implements a `Displayable` role. This role requires a method called `iperl_data_representations` that returns a HashRef of different representations of the data where the keys are the MIME type of the data (e.g., `text/html`) and values are the strings that contain the bytestream for that MIME type. For example, with PNG, we have" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "scrolled": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[0m[\n", " \u001b[97m[0] \u001b[0m\"\u001b[93mimage/png\u001b[0m\",\n", " \u001b[97m[1] \u001b[0m\"\u001b[93mtext/html\u001b[0m\",\n", " \u001b[97m[2] \u001b[0m\"\u001b[93mtext/plain\u001b[0m\"\n", "]\n" ] }, { "data": { "image/png": "‰PNG\r\n\u001a\n\u0000\u0000\u0000\rIHDR\u0000\u0000\u0000 \u0000\u0000\u0000 \b\u0003\u0000\u0000\u0000D¤ŠÆ\u0000\u0000\u0000\u0004gAMA\u0000\u0001† 1è–_\u0000\u0000\u0000 cHRM\u0000\u0000z&\u0000\u0000€„\u0000\u0000ú\u0000\u0000\u0000€è\u0000\u0000u0\u0000\u0000ê`\u0000\u0000:˜\u0000\u0000\u0017pœºQ<\u0000\u0000\u0002âPLTEö°Þ‰ÿuäÿÅ\rÿkêÿŒ5ÿ­ÿ1ÀŒI—€ÿÖþ&4ÿ±4à2þ\u001cˆÿÿ\u000etQÿ#Å\u0003ÓÈ\u0001lÿÎ-ÿ^¥þ>bOÿw3ÿXþ\u000b”ÿ.c$ÿˆÿÄsÿÌÿ§ƒÿ‰=ÿ»ÿÑæ\u001bÿ––ÿÊÿ;\u001dY‰ÿ½\u0018Çÿ\u001f\\z<ÿûûüäÿ\u000e\u001eÿœÿµHâþA(ÿÿ¨Ü-ÿƒÿž\u001cI\u0013¾`ÿ¨%ÿÑ\u0011ÿ{’ÿKRÿÙ~\u0000™\u001doÿà\u0015ý÷ü\u001d¸àÿµÿÞê|œÄÿðüüdüàâqjÿÁ€ÚÝÝõú`î\u001eÿ¥¦ÿÒÉÿä+ÿ_ö\u0003p´5ÿ\u001fÿèÆÿÍ]ÿƒÿg­+Üþÿ\u0013=dâþ\u000eýëEÿ¾ÿcC=ÿ‹ÈÎíÊÿ\u0014ÂÿKÿ& \u001aÿü‚Îÿ0ŒÒÿ3\u00177ÿ£\u0000cŽÿ½þÿú›àÿÿ\u0019,\u000fÿ°\tÿ\u0010ÿG\u0014Òþ6ÿ\u001dÇ«Îÿï¼ÿáfÿÈÚ×úñ™ÿâûÿúýûüã\u0002YÿL‹ÿ\u0014\u001f›ÿ\u000fÿŸàþýÔÿÐÿqLý\u0017َÉÿÿÀ\u001džÿ€àÿJ\u0013ÿ{AÁÿúûü<ñýö»Þÿpñÿ,~ÿ\u001e!ÿa¢ÿ1³ÿ„\fÿÊ\u0018ÿX\u0014óý\tÿ]eÿ®Gÿþ\n>õÞíÿL¯;\u0001[úý¬@ÿ˜ïþ]ÿ~Tÿ´Êÿôý<‘ÿã\u0016§ÿeÿÈ9\u0003ÆO¥ÿìðþÿ)fý\t·ªûëœÿ²ÿ˝¢ÿ\u000fö4©º÷þÿ…®ã\u0004æ£ÿfÿ–ÿo\u0019âÿXÿ㌖ÿîAÿe=ÿ6&ÿÜ^ÿ\u001bþ?Õ)ÿ gÿÐÿáâúþêçKT!¹ÿÒiÿýÖ¿ÿ‹kÉÿ¯ÿºÿðòKÿ ÿÇ{ýñ|Sÿêÿè\u001eÿÿÿiÿCÿ¨/ÿ\u001b†ÿ5^eüõÿÄÿMuÿ@~ÿrÿs\u000eÿ>ªÿŽ\u001boÿ¢ã£Ý›ÿ?@ÿ¯3ÿ¶'óý\u001aÿ0|ÿÝÿ{ÑÿO%?ÿð|öþÿ{S ÿ9\u0000ÄÿÖOÿU¦ïÿõ¯Áÿÿ\u001a­>ÿÛ/Wÿ€¦ÿ\u0014ÿíÿ’LbÿÚÿ¶zŽäÿçâãì\u0001¤þ\nY+ÿ´¹¸ÃÚÿÒÿïÿœÐºÿ+À\u0013Jª\u0000\u0000\u0002¯IDATxœc8B\u00000\u0010­ÀËÛmÊÞ\\Ü\n4»ºRR®¯÷Â¥ Ž™¹¥#åúõ´*ì\n\\“kjZÜÜî]OÛhœ‹MÁ$£\u001a]Ýun¢ëù6n¼¼\rSUr„„n°È:Ñõ\u001b››\u000b›¶a(`ˆ\b\u000eîé\u0011YwôhsáâÅÑñh\n\\‹å7OÚ¿ßÛ{ÊÑ£—[›BCWÇ£*˜U¬±yÿ~ƒ‹\u0017§œ5¾Üú5T]Ý\u0016EÁ£$çÍW¦vwk^”a\\±\",:ÚÂâðAd\u00059IÎW\n45ãdªV„…UO·8\\Y¹\u0006IÁ–¤\u000f²³¤$ã\u0016.lk›¶zõô•zz‹\u0010\n\fÁ\n$\u0015\\\\öîžöÉÖöÁ\u0003Ácz\u0017Îí‚)øÜnh\b4€CÁÅÊkÚ'–ƒ™™\u000f¸Ž]¸pnÕ.¨‚µí†OM^Ýàȱr-eš8q́\u0003¯_¾¼°jÕ­[» \nN\u0006l\u0000)˜±Àæs6SÆÄE\u0007^¿~YP\u0016tKQQÑ\u000e¬àö\u000bÏۇNÞX»À&ûѶŒ]‹\u0016I¯¼{7(ˆ“31‘s+HÁ‹\u0017׀\nî¬]jSR·okVÖ©e+­OŸ\u0016\u0016>áç×{bß\u0011†’ÎÎkõ'ïܙ¼téÜ>¹¬†/_N-[&$\u0004T\"®â×+¼a)P^ËßÿM‚eˆ#ƒÎ—S‘>B\u000fϜ93ožŠÊûÞÓr\f“S}}µü÷TT<¾tIçæÍFŸþþóQQÇyyß¿W±\u0006º’áMjjmíž=\u0015Ï\u001dvîtrÚ´‰mIx8PÚ=ÿô—<°7ßìØQ[;çùs{¨ü“'bbîù\u0002 ͐€J˜9³hŽ’’½‡\u000777wyùüùï\u0004b·§ç!bÓ²ˆ‡G陪ª‡‡¹ùòr l¬õ[”$gÉcföL\u001b,ϯ\u001c\u001b˞®†–ªëÌÌb´µUïß¿o:a\u0002ûÛ#è€áÈ㘘ٳõ'\u0000e?ªaHƒÓC£cÈǏ\u001f15Ã\u0013-^\u0000\u0000ñ\u0001k4¥³Ã3\u0000\u0000\u0000\u0000IEND®B`‚", "text/html": [ "" ], "text/plain": [ "[PNG image]" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "use v5.16;\n", "use DDP; # Data::Printer\n", "\n", "my $png_display = Devel::IPerl::Display::PNG->new( \"http://www.libpng.org/pub/png/PngSuite/ccwn3p08.png\" );\n", "\n", "say &np( [ keys %{ $png_display->iperl_data_representations } ] );\n", "\n", "$png_display;" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Notice that I just displayed that PNG by just putting the `$png_display` variable at the end? That's because any displayable is automatically displayed if it is at the end of a cell.\n", "\n", "But there's a problem: I don't want to type or remember `Devel::IPerl::Display::PNG` every time I want to load up a PNG.\n", "\n", "Instead, you can just call the helper method `IPerl->png()` and you'll get the same result." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "image/png": "‰PNG\r\n\u001a\n\u0000\u0000\u0000\rIHDR\u0000\u0000\u0000 \u0000\u0000\u0000 \b\u0003\u0000\u0000\u0000D¤ŠÆ\u0000\u0000\u0000\u0004gAMA\u0000\u0001† 1è–_\u0000\u0000\u0000 cHRM\u0000\u0000z&\u0000\u0000€„\u0000\u0000ú\u0000\u0000\u0000€è\u0000\u0000u0\u0000\u0000ê`\u0000\u0000:˜\u0000\u0000\u0017pœºQ<\u0000\u0000\u0002âPLTEö°Þ‰ÿuäÿÅ\rÿkêÿŒ5ÿ­ÿ1ÀŒI—€ÿÖþ&4ÿ±4à2þ\u001cˆÿÿ\u000etQÿ#Å\u0003ÓÈ\u0001lÿÎ-ÿ^¥þ>bOÿw3ÿXþ\u000b”ÿ.c$ÿˆÿÄsÿÌÿ§ƒÿ‰=ÿ»ÿÑæ\u001bÿ––ÿÊÿ;\u001dY‰ÿ½\u0018Çÿ\u001f\\z<ÿûûüäÿ\u000e\u001eÿœÿµHâþA(ÿÿ¨Ü-ÿƒÿž\u001cI\u0013¾`ÿ¨%ÿÑ\u0011ÿ{’ÿKRÿÙ~\u0000™\u001doÿà\u0015ý÷ü\u001d¸àÿµÿÞê|œÄÿðüüdüàâqjÿÁ€ÚÝÝõú`î\u001eÿ¥¦ÿÒÉÿä+ÿ_ö\u0003p´5ÿ\u001fÿèÆÿÍ]ÿƒÿg­+Üþÿ\u0013=dâþ\u000eýëEÿ¾ÿcC=ÿ‹ÈÎíÊÿ\u0014ÂÿKÿ& \u001aÿü‚Îÿ0ŒÒÿ3\u00177ÿ£\u0000cŽÿ½þÿú›àÿÿ\u0019,\u000fÿ°\tÿ\u0010ÿG\u0014Òþ6ÿ\u001dÇ«Îÿï¼ÿáfÿÈÚ×úñ™ÿâûÿúýûüã\u0002YÿL‹ÿ\u0014\u001f›ÿ\u000fÿŸàþýÔÿÐÿqLý\u0017َÉÿÿÀ\u001džÿ€àÿJ\u0013ÿ{AÁÿúûü<ñýö»Þÿpñÿ,~ÿ\u001e!ÿa¢ÿ1³ÿ„\fÿÊ\u0018ÿX\u0014óý\tÿ]eÿ®Gÿþ\n>õÞíÿL¯;\u0001[úý¬@ÿ˜ïþ]ÿ~Tÿ´Êÿôý<‘ÿã\u0016§ÿeÿÈ9\u0003ÆO¥ÿìðþÿ)fý\t·ªûëœÿ²ÿ˝¢ÿ\u000fö4©º÷þÿ…®ã\u0004æ£ÿfÿ–ÿo\u0019âÿXÿ㌖ÿîAÿe=ÿ6&ÿÜ^ÿ\u001bþ?Õ)ÿ gÿÐÿáâúþêçKT!¹ÿÒiÿýÖ¿ÿ‹kÉÿ¯ÿºÿðòKÿ ÿÇ{ýñ|Sÿêÿè\u001eÿÿÿiÿCÿ¨/ÿ\u001b†ÿ5^eüõÿÄÿMuÿ@~ÿrÿs\u000eÿ>ªÿŽ\u001boÿ¢ã£Ý›ÿ?@ÿ¯3ÿ¶'óý\u001aÿ0|ÿÝÿ{ÑÿO%?ÿð|öþÿ{S ÿ9\u0000ÄÿÖOÿU¦ïÿõ¯Áÿÿ\u001a­>ÿÛ/Wÿ€¦ÿ\u0014ÿíÿ’LbÿÚÿ¶zŽäÿçâãì\u0001¤þ\nY+ÿ´¹¸ÃÚÿÒÿïÿœÐºÿ+À\u0013Jª\u0000\u0000\u0002¯IDATxœc8B\u00000\u0010­ÀËÛmÊÞ\\Ü\n4»ºRR®¯÷Â¥ Ž™¹¥#åúõ´*ì\n\\“kjZÜÜî]OÛhœ‹MÁ$£\u001a]Ýun¢ëù6n¼¼\rSUr„„n°È:Ñõ\u001b››\u000b›¶a(`ˆ\b\u000eîé\u0011YwôhsáâÅÑñh\n\\‹å7OÚ¿ßÛ{ÊÑ£—[›BCWÇ£*˜U¬±yÿ~ƒ‹\u0017§œ5¾Üú5T]Ý\u0016EÁ£$çÍW¦vwk^”a\\±\",:ÚÂâðAd\u00059IÎW\n45ãdªV„…UO·8\\Y¹\u0006IÁ–¤\u000f²³¤$ã\u0016.lk›¶zõô•zz‹\u0010\n\fÁ\n$\u0015\\\\öîžöÉÖöÁ\u0003Ácz\u0017Îí‚)øÜnh\b4€CÁÅÊkÚ'–ƒ™™\u000f¸Ž]¸pnÕ.¨‚µí†OM^Ýàȱr-eš8q́\u0003¯_¾¼°jÕ­[» \nN\u0006l\u0000)˜±Àæs6SÆÄE\u0007^¿~YP\u0016tKQQÑ\u000e¬àö\u000bÏۇNÞX»À&ûѶŒ]‹\u0016I¯¼{7(ˆ“31‘s+HÁ‹\u0017׀\nî¬]jSR·okVÖ©e+­OŸ\u0016\u0016>áç×{bß\u0011†’ÎÎkõ'ïܙ¼téÜ>¹¬†/_N-[&$\u0004T\"®â×+¼a)P^ËßÿM‚eˆ#ƒÎ—S‘>B\u000fϜ93ožŠÊûÞÓr\f“S}}µü÷TT<¾tIçæÍFŸþþóQQÇyyß¿W±\u0006º’áMjjmíž=\u0015Ï\u001dvîtrÚ´‰mIx8PÚ=ÿô—<°7ßìØQ[;çùs{¨ü“'bbîù\u0002 ͐€J˜9³hŽ’’½‡\u000777wyùüùï\u0004b·§ç!bÓ²ˆ‡G陪ª‡‡¹ùòr l¬õ[”$gÉcföL\u001b,ϯ\u001c\u001b˞®†–ªëÌÌb´µUïß¿o:a\u0002ûÛ#è€áÈ㘘ٳõ'\u0000e?ªaHƒÓC£cÈǏ\u001f15Ã\u0013-^\u0000\u0000ñ\u0001k4¥³Ã3\u0000\u0000\u0000\u0000IEND®B`‚", "text/html": [ "" ], "text/plain": [ "[PNG image]" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "IPerl->png( \"http://www.libpng.org/pub/png/PngSuite/ccwn3p08.png\" );" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "There are other `Displayable`s too. For example, let's load up an `\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "my $iframe_display = IPerl->iframe( \"http://metacpan.org/recent\", width => \"75%\" );" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "What if we want to display multiple things in one cell? For example, we want to loop over a number of images and display each of them?\n", "\n", "You can do that by calling the `IPerl->display()` on the `Displayable` object." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n" ], "text/html": [ "" ], "text/plain": [ "[SVG image]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "image/svg+xml": [ "\n", "\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " image/svg+xml\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " Epoxy lens/case\n", " Semiconductor die\n", " Wire bond\n", " Cathode\n", " Anode\n", " Reflective cavity\n", " \n", " Anvil\n", " Post\n", " \n", " Leadframe\n", " \n", " \n", " \n", " \n", " \n", " \n", " Flat spot\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n" ], "text/html": [ "" ], "text/plain": [ "[SVG image]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "image/png": "‰PNG\r\n\u001a\n\u0000\u0000\u0000\rIHDR\u0000\u0000\u0000 \u0000\u0000\u0000 \b\u0003\u0000\u0000\u0000D¤ŠÆ\u0000\u0000\u0000\u0004gAMA\u0000\u0001† 1è–_\u0000\u0000\u0000 cHRM\u0000\u0000z&\u0000\u0000€„\u0000\u0000ú\u0000\u0000\u0000€è\u0000\u0000u0\u0000\u0000ê`\u0000\u0000:˜\u0000\u0000\u0017pœºQ<\u0000\u0000\u0002âPLTEö°Þ‰ÿuäÿÅ\rÿkêÿŒ5ÿ­ÿ1ÀŒI—€ÿÖþ&4ÿ±4à2þ\u001cˆÿÿ\u000etQÿ#Å\u0003ÓÈ\u0001lÿÎ-ÿ^¥þ>bOÿw3ÿXþ\u000b”ÿ.c$ÿˆÿÄsÿÌÿ§ƒÿ‰=ÿ»ÿÑæ\u001bÿ––ÿÊÿ;\u001dY‰ÿ½\u0018Çÿ\u001f\\z<ÿûûüäÿ\u000e\u001eÿœÿµHâþA(ÿÿ¨Ü-ÿƒÿž\u001cI\u0013¾`ÿ¨%ÿÑ\u0011ÿ{’ÿKRÿÙ~\u0000™\u001doÿà\u0015ý÷ü\u001d¸àÿµÿÞê|œÄÿðüüdüàâqjÿÁ€ÚÝÝõú`î\u001eÿ¥¦ÿÒÉÿä+ÿ_ö\u0003p´5ÿ\u001fÿèÆÿÍ]ÿƒÿg­+Üþÿ\u0013=dâþ\u000eýëEÿ¾ÿcC=ÿ‹ÈÎíÊÿ\u0014ÂÿKÿ& \u001aÿü‚Îÿ0ŒÒÿ3\u00177ÿ£\u0000cŽÿ½þÿú›àÿÿ\u0019,\u000fÿ°\tÿ\u0010ÿG\u0014Òþ6ÿ\u001dÇ«Îÿï¼ÿáfÿÈÚ×úñ™ÿâûÿúýûüã\u0002YÿL‹ÿ\u0014\u001f›ÿ\u000fÿŸàþýÔÿÐÿqLý\u0017َÉÿÿÀ\u001džÿ€àÿJ\u0013ÿ{AÁÿúûü<ñýö»Þÿpñÿ,~ÿ\u001e!ÿa¢ÿ1³ÿ„\fÿÊ\u0018ÿX\u0014óý\tÿ]eÿ®Gÿþ\n>õÞíÿL¯;\u0001[úý¬@ÿ˜ïþ]ÿ~Tÿ´Êÿôý<‘ÿã\u0016§ÿeÿÈ9\u0003ÆO¥ÿìðþÿ)fý\t·ªûëœÿ²ÿ˝¢ÿ\u000fö4©º÷þÿ…®ã\u0004æ£ÿfÿ–ÿo\u0019âÿXÿ㌖ÿîAÿe=ÿ6&ÿÜ^ÿ\u001bþ?Õ)ÿ gÿÐÿáâúþêçKT!¹ÿÒiÿýÖ¿ÿ‹kÉÿ¯ÿºÿðòKÿ ÿÇ{ýñ|Sÿêÿè\u001eÿÿÿiÿCÿ¨/ÿ\u001b†ÿ5^eüõÿÄÿMuÿ@~ÿrÿs\u000eÿ>ªÿŽ\u001boÿ¢ã£Ý›ÿ?@ÿ¯3ÿ¶'óý\u001aÿ0|ÿÝÿ{ÑÿO%?ÿð|öþÿ{S ÿ9\u0000ÄÿÖOÿU¦ïÿõ¯Áÿÿ\u001a­>ÿÛ/Wÿ€¦ÿ\u0014ÿíÿ’LbÿÚÿ¶zŽäÿçâãì\u0001¤þ\nY+ÿ´¹¸ÃÚÿÒÿïÿœÐºÿ+À\u0013Jª\u0000\u0000\u0002¯IDATxœc8B\u00000\u0010­ÀËÛmÊÞ\\Ü\n4»ºRR®¯÷Â¥ Ž™¹¥#åúõ´*ì\n\\“kjZÜÜî]OÛhœ‹MÁ$£\u001a]Ýun¢ëù6n¼¼\rSUr„„n°È:Ñõ\u001b››\u000b›¶a(`ˆ\b\u000eîé\u0011YwôhsáâÅÑñh\n\\‹å7OÚ¿ßÛ{ÊÑ£—[›BCWÇ£*˜U¬±yÿ~ƒ‹\u0017§œ5¾Üú5T]Ý\u0016EÁ£$çÍW¦vwk^”a\\±\",:ÚÂâðAd\u00059IÎW\n45ãdªV„…UO·8\\Y¹\u0006IÁ–¤\u000f²³¤$ã\u0016.lk›¶zõô•zz‹\u0010\n\fÁ\n$\u0015\\\\öîžöÉÖöÁ\u0003Ácz\u0017Îí‚)øÜnh\b4€CÁÅÊkÚ'–ƒ™™\u000f¸Ž]¸pnÕ.¨‚µí†OM^Ýàȱr-eš8q́\u0003¯_¾¼°jÕ­[» \nN\u0006l\u0000)˜±Àæs6SÆÄE\u0007^¿~YP\u0016tKQQÑ\u000e¬àö\u000bÏۇNÞX»À&ûѶŒ]‹\u0016I¯¼{7(ˆ“31‘s+HÁ‹\u0017׀\nî¬]jSR·okVÖ©e+­OŸ\u0016\u0016>áç×{bß\u0011†’ÎÎkõ'ïܙ¼téÜ>¹¬†/_N-[&$\u0004T\"®â×+¼a)P^ËßÿM‚eˆ#ƒÎ—S‘>B\u000fϜ93ožŠÊûÞÓr\f“S}}µü÷TT<¾tIçæÍFŸþþóQQÇyyß¿W±\u0006º’áMjjmíž=\u0015Ï\u001dvîtrÚ´‰mIx8PÚ=ÿô—<°7ßìØQ[;çùs{¨ü“'bbîù\u0002 ͐€J˜9³hŽ’’½‡\u000777wyùüùï\u0004b·§ç!bÓ²ˆ‡G陪ª‡‡¹ùòr l¬õ[”$gÉcföL\u001b,ϯ\u001c\u001b˞®†–ªëÌÌb´µUïß¿o:a\u0002ûÛ#è€áÈ㘘ٳõ'\u0000e?ªaHƒÓC£cÈǏ\u001f15Ã\u0013-^\u0000\u0000ñ\u0001k4¥³Ã3\u0000\u0000\u0000\u0000IEND®B`‚", "text/html": [ "" ], "text/plain": [ "[PNG image]" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "my @svg = split ' ', q[\n", " https://upload.wikimedia.org/wikipedia/commons/f/fd/Ghostscript_Tiger.svg\n", " https://upload.wikimedia.org/wikipedia/commons/f/f9/LED,_5mm,_green_(en).svg\n", " ];\n", "IPerl->display( IPerl->svg( $_ , width => \"200\" ) ) for @svg;\n", "\n", "$png_display;" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "There is also a way to display arbitrary HTML. Here, we create a simple HTML table that loops over a 2D nested ArrayRef.\n", "\n", "We could send the string directly to the `IPerl->html()` method, but that isn't very [DRY](https://en.wikipedia.org/wiki/Don't_repeat_yourself). Instead, we'll create our own helper!" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "IPerl->helper( my_table => sub {\n", " my ($self, $data) = @_;\n", " return unless ref $data eq 'ARRAY';\n", " \n", " my $html = \"\";\n", " for my $row (@$data) {\n", " $html .= \"\";\n", " for my $cell (@$row) {\n", " my $cell_html = $cell->iperl_data_representations->{\"text/html\"};\n", " $html .= \"\\n\";\n", " }\n", " $html .= \"\";\n", " }\n", " $html .= \"
$cell_html
\";\n", "\n", " IPerl->html( $html );\n", "});\n", "\n", "my $N = 4; my $M = 10;\n", "my $d = [ ([ ( $png_display ) x $M ]) x $N ];\n", "IPerl->my_table( $d );" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "There are other plugins besides the `Displayable`s that work directly on file types (PNG, SVG, HTML, etc.).\n", "\n", "For example, you can load a plugin that adds a role to [`PDL::Graphics::Gnuplot`](http://p3rl.org/PDL::Graphics::Gnuplot) and makes it displayable as an SVG." ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/latex": [ " $\\sin\\theta$ and $\\cos\\theta$ " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "image/svg+xml": [ "\n", "\n", "\n", "Gnuplot\n", "Produced by GNUPLOT 5.2 patchlevel 2 \n", "\n", "\n", "\n", "\n", "\n", "\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t \n", "\t \n", "\t\n", "\t\n", "\t \n", "\t \n", "\t\n", "\n", "\n", "\n", "\n", "\n", "\n", "\t\n", "\n", "\t\t\n", "\t\t-1\n", "\t\n", "\n", "\n", "\n", "\n", "\t\n", "\n", "\t\t\n", "\t\t-0.8\n", "\t\n", "\n", "\n", "\n", "\n", "\t\n", "\n", "\t\t\n", "\t\t-0.6\n", "\t\n", "\n", "\n", "\n", "\n", "\t\n", "\n", "\t\t\n", "\t\t-0.4\n", "\t\n", "\n", "\n", "\n", "\n", "\t\n", "\n", "\t\t\n", "\t\t-0.2\n", "\t\n", "\n", "\n", "\n", "\n", "\t\n", "\n", "\t\t\n", "\t\t 0\n", "\t\n", "\n", "\n", "\n", "\n", "\t\n", "\n", "\t\t\n", "\t\t 0.2\n", "\t\n", "\n", "\n", "\n", "\n", "\t\n", "\n", "\t\t\n", "\t\t 0.4\n", "\t\n", "\n", "\n", "\n", "\n", "\t\n", "\n", "\t\t\n", "\t\t 0.6\n", "\t\n", "\n", "\n", "\n", "\n", "\t\n", "\n", "\t\t\n", "\t\t 0.8\n", "\t\n", "\n", "\n", "\n", "\n", "\t\n", "\n", "\t\t\n", "\t\t 1\n", "\t\n", "\n", "\n", "\n", "\n", "\t\n", "\n", "\t\t\n", "\t\t-4\n", "\t\n", "\n", "\n", "\n", "\n", "\t\n", "\n", "\t\t\n", "\t\t-3\n", "\t\n", "\n", "\n", "\n", "\n", "\t\n", "\n", "\t\t\n", "\t\t-2\n", "\t\n", "\n", "\n", "\n", "\n", "\t\n", "\n", "\t\t\n", "\t\t-1\n", "\t\n", "\n", "\n", "\n", "\n", "\t\n", "\n", "\t\t\n", "\t\t 0\n", "\t\n", "\n", "\n", "\n", "\n", "\t\n", "\n", "\t\t\n", "\t\t 1\n", "\t\n", "\n", "\n", "\n", "\n", "\t\n", "\n", "\t\t\n", "\t\t 2\n", "\t\n", "\n", "\n", "\n", "\n", "\t\n", "\n", "\t\t\n", "\t\t 3\n", "\t\n", "\n", "\n", "\n", "\n", "\t\n", "\n", "\t\t\n", "\t\t 4\n", "\t\n", "\n", "\n", "\n", "\n", "\t\n", "\n", "\n", "\tgnuplot_plot_1\n", "\n", "\n", "\n", "\t\n", "\t\n", "\tgnuplot_plot_2\n", "\n", "\n", "\n", "\t\n", "\t\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n" ], "text/html": [ "" ], "text/plain": [ "[SVG image]" ] }, "metadata": {}, "output_type": "display_data" }, { "ename": "Warning", "evalue": "WARNING - dumping ON - gnuplot commands go to the terminal only.\n at /home/zaki/perl5/perlbrew/perls/perl-5.26.1/lib/site_perl/5.26.1/Devel/IPerl/Plugin/PDLGraphicsGnuplot.pm line 40.\n\n(killed gnuplot)\n at /home/zaki/perl5/perlbrew/perls/perl-5.26.1/lib/site_perl/5.26.1/Devel/IPerl/Plugin/PDLGraphicsGnuplot.pm line 56.\n", "output_type": "error", "traceback": [ "WARNING - dumping ON - gnuplot commands go to the terminal only.\n at /home/zaki/perl5/perlbrew/perls/perl-5.26.1/lib/site_perl/5.26.1/Devel/IPerl/Plugin/PDLGraphicsGnuplot.pm line 40.\n\n(killed gnuplot)\n at /home/zaki/perl5/perlbrew/perls/perl-5.26.1/lib/site_perl/5.26.1/Devel/IPerl/Plugin/PDLGraphicsGnuplot.pm line 56.\n" ] } ], "source": [ "IPerl->load_plugin( \"PDLGraphicsGnuplot\" );\n", "use PDL;\n", "use PDL::Graphics::Gnuplot;\n", "use PDL::Constants qw(PI);\n", "\n", "my $gp = gpwin();\n", "# do some styling\n", "$gp->option( topcmd => <<'GP');\n", "# define axis\n", "# remove border on top and right and set color to gray\n", "set style line 11 lc rgb '#808080' lt 1\n", "set border 3 back ls 11\n", "set tics nomirror\n", "\n", "# define grid\n", "set style line 12 lc rgb '#808080' lt 0 lw 1\n", "set grid back ls 12\n", "GP\n", "\n", "my $theta = zeros(200)->xlinvals(-1*PI, 1*PI);\n", "\n", "$gp->plot( { lw => 2 }, $theta, sin($theta), {}, $theta, cos($theta) );\n", "\n", "IPerl->display( IPerl->tex( q| $\\sin\\theta$ and $\\cos\\theta$ | ) );\n", "\n", "$gp;" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Have fun and let me know what you make with your IPerl notebooks!\n", "\n", "Feel free to add your notebooks to the [IPerl wiki](https://github.com/zmughal/p5-Devel-IPerl/wiki)!" ] } ], "metadata": { "kernelspec": { "display_name": "IPerl 0.009", "language": "perl", "name": "iperl" }, "language": "Perl", "language_info": { "file_extension": ".pl", "mimetype": "text/x-perl", "name": "perl", "version": "5.26.1" } }, "nbformat": 4, "nbformat_minor": 1 }