{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "9324701a-df5f-47c2-83c8-0e5a9849bdd2", "metadata": { "execution": { "iopub.execute_input": "2024-12-17T13:35:25.471261Z", "iopub.status.busy": "2024-12-17T13:35:25.469193Z", "iopub.status.idle": "2024-12-17T13:35:27.401040Z", "shell.execute_reply": "2024-12-17T13:35:27.400307Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%useLatestDescriptors\n", "%use lets-plot" ] }, { "cell_type": "code", "execution_count": 2, "id": "58fe2f92-6711-4096-b4d1-e566a12c81f1", "metadata": { "execution": { "iopub.execute_input": "2024-12-17T13:35:27.404038Z", "iopub.status.busy": "2024-12-17T13:35:27.403829Z", "iopub.status.idle": "2024-12-17T13:35:27.451562Z", "shell.execute_reply": "2024-12-17T13:35:27.451685Z" } }, "outputs": [ { "data": { "text/plain": [ "Lets-Plot Kotlin API v.4.9.3. Frontend: Notebook with dynamically loaded JS. Lets-Plot JS v.4.5.2." ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "LetsPlot.getInfo()" ] }, { "cell_type": "code", "execution_count": 3, "id": "82bffdd3-fca2-46bd-b4cd-b3e27ede27e0", "metadata": { "execution": { "iopub.execute_input": "2024-12-17T13:35:27.453503Z", "iopub.status.busy": "2024-12-17T13:35:27.453286Z", "iopub.status.idle": "2024-12-17T13:35:27.486068Z", "shell.execute_reply": "2024-12-17T13:35:27.485796Z" } }, "outputs": [], "source": [ "import org.jetbrains.letsPlot.intern.Feature" ] }, { "cell_type": "code", "execution_count": 4, "id": "27fb7202-f86c-4ff7-a3be-fbfbb138b9cd", "metadata": { "execution": { "iopub.execute_input": "2024-12-17T13:35:27.488457Z", "iopub.status.busy": "2024-12-17T13:35:27.488242Z", "iopub.status.idle": "2024-12-17T13:35:27.519098Z", "shell.execute_reply": "2024-12-17T13:35:27.518831Z" } }, "outputs": [], "source": [ "val colorMargin = \"#b3cde3\"\n", "val colorKey = \"#decbe4\"\n", "val colorLabel = \"#fddaec\"\n", "val colorPlot = \"#ccebc5\"" ] }, { "cell_type": "code", "execution_count": 5, "id": "3f3dd770-6484-4c25-961f-358f06f864d0", "metadata": { "execution": { "iopub.execute_input": "2024-12-17T13:35:27.521839Z", "iopub.status.busy": "2024-12-17T13:35:27.521030Z", "iopub.status.idle": "2024-12-17T13:35:27.953276Z", "shell.execute_reply": "2024-12-17T13:35:27.953014Z" } }, "outputs": [], "source": [ "data class Bounds(val xmin: Double, val ymin: Double, val xmax: Double, val ymax: Double)\n", "\n", "fun legendElement(b: Bounds): Feature {\n", " return geomRect(xmin = b.xmin, xmax = b.xmax, ymin = b.ymin, ymax = b.ymax,\n", " fill = colorLabel, color = colorLabel, size = 0) +\n", " geomRect(xmin = b.xmin, xmax = b.xmin + 1.5, ymin = b.ymin, ymax = b.ymax,\n", " fill = colorKey, color = colorKey, size = 0) +\n", " geomText(x = b.xmin + 0.1, y = (b.ymin + b.ymax) / 2.0,\n", " label = \"key\", vjust = 0.5, hjust = 0.0, size = 10) +\n", " geomText(x = b.xmin + 1.6, y = (b.ymin + b.ymax) / 2.0,\n", " label = \"label\", vjust = 0.5, hjust = 0.0, size = 10)\n", "}\n", "\n", "fun legend(x: Double, y: Double, w: Double, h: Double): Feature {\n", " val xmin = x\n", " val xmax = x + w\n", " val ymin = y\n", " val ymax = ymin + h\n", "\n", " val margin = 1.0\n", " val space = 1.0\n", " val titleH = 1.5\n", " val elemW = ((w - margin * 2.0) - space) / 2.0\n", " val elemH = ((h - margin * 2.0)) / 2.0 - space - 0.2\n", "\n", " // elements bounds\n", " val innerBounds = Bounds(xmin + margin, ymin + margin,\n", " xmax - margin, ymax - margin)\n", " val elem11 = Bounds(innerBounds.xmin, innerBounds.ymax - titleH - elemH,\n", " innerBounds.xmin + elemW, innerBounds.ymax - titleH)\n", " val elem12 = Bounds(innerBounds.xmin + elemW + space, innerBounds.ymax - titleH - elemH,\n", " innerBounds.xmax, innerBounds.ymax - titleH)\n", " val elem21 = Bounds(elem11.xmin, innerBounds.ymin, elem11.xmax, innerBounds.ymin + elemH)\n", " val elem22 = Bounds(elem12.xmin, innerBounds.ymin, innerBounds.xmax, elem21.ymax)\n", "\n", " // plot elements\n", " val legendBackground = geomRect(xmin = xmin, xmax = xmax,\n", " ymin = ymin, ymax = ymax,\n", " fill = colorMargin, size = 1.5)\n", " val legendElementsBox = geomRect(xmin = innerBounds.xmin, xmax = innerBounds.xmax,\n", " ymin = innerBounds.ymin, ymax = innerBounds.ymax,\n", " fill = \"white\", size = 0)\n", " val title = geomText(label = \"Title\",\n", " x = innerBounds.xmin + 0.1, y = innerBounds.ymax - titleH / 2.0,\n", " vjust = 0.5, hjust = 0, size = 10)\n", " val row1 = legendElement(elem11) + legendElement(elem12)\n", " val row2 = legendElement(elem21) + legendElement(elem22)\n", " \n", " return legendBackground + legendElementsBox + title + row1 + row2\n", "}\n", "\n", "fun annotationLine(x: Double, y: Double, xend: Double? = null, yend: Double? = null,\n", " typeArrow: String? = \"both\", linetype: String = \"solid\"): Feature {\n", " val xend: Double = xend ?: x\n", " val yend: Double = yend ?: y\n", " val withArrow: Map