{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "developed-feeling",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"a0sKFv\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"library\">\n",
       "       if(!window.letsPlotCallQueue) {\n",
       "           window.letsPlotCallQueue = [];\n",
       "       }; \n",
       "       window.letsPlotCall = function(f) {\n",
       "           window.letsPlotCallQueue.push(f);\n",
       "       };\n",
       "       (function() {\n",
       "           var script = document.createElement(\"script\");\n",
       "           script.type = \"text/javascript\";\n",
       "           script.src = \"https://cdn.jsdelivr.net/gh/JetBrains/lets-plot@v4.0.0/js-package/distr/lets-plot.min.js\";\n",
       "           script.onload = function() {\n",
       "               window.letsPlotCall = function(f) {f();};\n",
       "               window.letsPlotCallQueue.forEach(function(f) {f();});\n",
       "               window.letsPlotCallQueue = [];\n",
       "               \n",
       "               \n",
       "           };\n",
       "           script.onerror = function(event) {\n",
       "               window.letsPlotCall = function(f) {};\n",
       "               window.letsPlotCallQueue = [];\n",
       "               var div = document.createElement(\"div\");\n",
       "               div.style.color = 'darkred';\n",
       "               div.textContent = 'Error loading Lets-Plot JS';\n",
       "               document.getElementById(\"a0sKFv\").appendChild(div);\n",
       "           };\n",
       "           var e = document.getElementById(\"a0sKFv\");\n",
       "           e.appendChild(script);\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "%useLatestDescriptors\n",
    "%use lets-plot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "composite-liver",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Lets-Plot Kotlin API v.4.4.2. Frontend: Notebook with dynamically loaded JS. Lets-Plot JS v.4.0.0."
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "LetsPlot.getInfo()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "global-lease",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"8qM7W2\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\"\n",
       "},\n",
       "\"data\":{\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"boxplot\",\n",
       "\"whisker_width\":0.2,\n",
       "\"position\":\"dodge\",\n",
       "\"geom\":\"boxplot\",\n",
       "\"data\":{\n",
       "\"..middle..\":[0.010174247519462422,0.10628211826095219,0.25926468816943765],\n",
       "\"..upper..\":[0.6604008232592867,0.6471885375454148,0.6529540308937354],\n",
       "\"..ymax..\":[1.8600533054767678,2.429780509168998,2.162580230059769],\n",
       "\"x\":[\"c\",\"a\",\"b\"],\n",
       "\"..lower..\":[-0.5818406215975382,-0.6302272555314844,-0.4277335200197391],\n",
       "\"..ymin..\":[-2.20104878328904,-1.494802096457127,-1.5234992785571666]\n",
       "}\n",
       "},{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"boxplot_outlier\",\n",
       "\"show_legend\":false,\n",
       "\"position\":\"dodge\",\n",
       "\"geom\":\"point\",\n",
       "\"data\":{\n",
       "\"..middle..\":[0.010174247519462422,0.10628211826095219,0.25926468816943765],\n",
       "\"..upper..\":[0.6604008232592867,0.6471885375454148,0.6529540308937354],\n",
       "\"..ymax..\":[1.8600533054767678,2.429780509168998,2.162580230059769],\n",
       "\"x\":[\"c\",\"a\",\"b\"],\n",
       "\"..lower..\":[-0.5818406215975382,-0.6302272555314844,-0.4277335200197391],\n",
       "\"y\":[NaN,NaN,2.439598419520245],\n",
       "\"..ymin..\":[-2.20104878328904,-1.494802096457127,-1.5234992785571666]\n",
       "}\n",
       "}]\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"8qM7W2\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();    \n",
       "   </script>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "val n = 100\n",
    "val rand = java.util.Random(37)\n",
    "val data = mapOf<String, Any>(\n",
    "    \"x\" to List(n) { listOf(\"a\", \"b\", \"c\").random() },\n",
    "    \"y\" to List(n) { rand.nextGaussian() }\n",
    ")\n",
    "\n",
    "letsPlot(data) { x = \"x\"; y = \"y\" }  + geomBoxplot(whiskerWidth = 0.2)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Kotlin",
   "language": "kotlin",
   "name": "kotlin"
  },
  "language_info": {
   "codemirror_mode": "text/x-kotlin",
   "file_extension": ".kt",
   "mimetype": "text/x-kotlin",
   "name": "kotlin",
   "nbconvert_exporter": "",
   "pygments_lexer": "kotlin",
   "version": "1.8.20"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}