{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "ExecuteTime": {
     "start_time": "2023-04-06T09:22:43.059031Z",
     "end_time": "2023-04-06T09:22:43.082815Z"
    }
   },
   "outputs": [],
   "source": [
    "import sys\n",
    "from datetime import datetime\n",
    "sys.path.append('../../src')\n",
    "from pjplan import Task, DefaultScheduler, WBS, MermaidGantt"
   ]
  },
  {
   "cell_type": "markdown",
   "source": [
    "### Sample project"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "outputs": [
    {
     "data": {
      "text/plain": "\u001B[92mID   NAME       RESOURCE   ESTIMATE   SPENT   START             END               PREDECESSORS \u001B[0m\n\u001B[94m     Task 1     Tester     40         0       06.04.2023 00:00  13.04.2023 00:00  []           \u001B[0m\n\u001B[94m     Task 2     Tester     20         0       13.04.2023 00:00  17.04.2023 12:00  [1]          \u001B[0m\n\u001B[94m     Task 3     -          150        0       17.04.2023 12:00  12.05.2023 06:00  []           \u001B[0m\n\u001B[96m        Task 4  -          100        0       17.04.2023 12:00  04.05.2023 00:00  [2]          \u001B[0m\n\u001B[96m        Task 5  -          50         0       04.05.2023 00:00  12.05.2023 06:00  [2]          \u001B[0m\n\u001B[94m     Task 6     -          32         0       12.05.2023 06:00  18.05.2023 06:00  []           \u001B[0m\n\u001B[96m        Task 7  -          16         0       12.05.2023 06:00  16.05.2023 06:00  [5]          \u001B[0m\n\u001B[96m        Task 8  -          16         0       16.05.2023 06:00  18.05.2023 06:00  [7]          \u001B[0m"
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "with WBS() as prj:\n",
    "    prj // Task(1, 'Task 1', estimate=40, resource='Tester')\n",
    "    prj // Task(2, 'Task 2', predecessors=[prj[1]], estimate=20, resource='Tester')\n",
    "    with prj // Task(3, 'Task 3') as t:\n",
    "        t // Task(4, 'Task 4', predecessors=[prj[2]], estimate=100)\n",
    "        t // Task(5, 'Task 5', predecessors=[prj[2]], estimate=50)\n",
    "    with prj // Task(6, 'Task 6') as t:\n",
    "        t // Task(7, 'Task 7', predecessors=[prj[5]], estimate=16)\n",
    "        t // Task(8, 'Task 8', predecessors=[prj[7]], estimate=16)\n",
    "\n",
    "plan, usage = DefaultScheduler(datetime.now()).calc(prj)\n",
    "plan"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2023-04-06T09:22:43.067852Z",
     "end_time": "2023-04-06T09:22:43.114069Z"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "### Simple Gantt"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "ExecuteTime": {
     "start_time": "2023-04-06T09:22:43.082815Z",
     "end_time": "2023-04-06T09:22:43.114069Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "<pjplan.viz.mermaid.gantt.MermaidGantt at 0x15874ea3730>",
      "text/html": "<iframe srcdoc=\"&lt;html&gt;\n&lt;meta charset=&quot;UTF-8&quot;&gt;\n&lt;body&gt;\n&lt;style&gt;\n\n&lt;/style&gt;\n\n&lt;div class=&quot;mermaid&quot;&gt;\ngantt\n  dateFormat DD.MM.YYYY\n    Task 1: active, id_1, 06.04.2023, 13.04.2023\n    Task 2:  id_2, 13.04.2023, 17.04.2023\n    Task 3:  id_3, 17.04.2023, 12.05.2023\n    Task 4:  id_4, 17.04.2023, 04.05.2023\n    Task 5:  id_5, 04.05.2023, 12.05.2023\n    Task 6:  id_6, 12.05.2023, 18.05.2023\n    Task 7:  id_7, 12.05.2023, 16.05.2023\n    Task 8:  id_8, 16.05.2023, 18.05.2023\n\n&lt;/div&gt;\n\n&lt;script src=&quot;https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js&quot;&gt;&lt;/script&gt;\n&lt;script&gt;\n    mermaid.ganttConfig = {\n        mirrorActor: true\n    }\n    mermaid.initialize({\n        startOnLoad: true\n    });\n&lt;/script&gt;\n&lt;/body&gt;\n&lt;/html&gt;\" width=\"100%\" height=\"320\" style=\"border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe>"
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "MermaidGantt(plan, height=320)"
   ]
  },
  {
   "cell_type": "markdown",
   "source": [
    "### Sections and weekends"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "outputs": [
    {
     "data": {
      "text/plain": "<pjplan.viz.mermaid.gantt.MermaidGantt at 0x15875ff6050>",
      "text/html": "<iframe srcdoc=\"&lt;html&gt;\n&lt;meta charset=&quot;UTF-8&quot;&gt;\n&lt;body&gt;\n&lt;style&gt;\n\n&lt;/style&gt;\n\n&lt;div class=&quot;mermaid&quot;&gt;\ngantt\n  dateFormat DD.MM.YYYY\n  excludes weekends\n  section Tester\n    Task 1: active, id_1, 06.04.2023, 13.04.2023\n    Task 2:  id_2, 13.04.2023, 17.04.2023\n  section -\n    Task 3:  id_3, 17.04.2023, 12.05.2023\n    Task 4:  id_4, 17.04.2023, 04.05.2023\n    Task 5:  id_5, 04.05.2023, 12.05.2023\n    Task 6:  id_6, 12.05.2023, 18.05.2023\n    Task 7:  id_7, 12.05.2023, 16.05.2023\n    Task 8:  id_8, 16.05.2023, 18.05.2023\n\n&lt;/div&gt;\n\n&lt;script src=&quot;https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js&quot;&gt;&lt;/script&gt;\n&lt;script&gt;\n    mermaid.ganttConfig = {\n        mirrorActor: true\n    }\n    mermaid.initialize({\n        startOnLoad: true\n    });\n&lt;/script&gt;\n&lt;/body&gt;\n&lt;/html&gt;\" width=\"100%\" height=\"320\" style=\"border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe>"
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "plan_copy = plan.clone()\n",
    "plan_copy.tasks(resource='Tester').gantt_section='Tester'\n",
    "\n",
    "MermaidGantt(plan_copy, height=320, weekends=True)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2023-04-06T09:22:43.098441Z",
     "end_time": "2023-04-06T09:22:43.114069Z"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "### Custom bar styles"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "outputs": [
    {
     "data": {
      "text/plain": "<pjplan.viz.mermaid.gantt.MermaidGantt at 0x15874d66e60>",
      "text/html": "<iframe srcdoc=\"&lt;html&gt;\n&lt;meta charset=&quot;UTF-8&quot;&gt;\n&lt;body&gt;\n&lt;style&gt;\n#id_1, #id_2, #id_3, #id_4, #id_5, #id_6, #id_7, #id_8{fill:white!important;stroke:#23964d!important;}\n#id_1-text, #id_2-text, #id_3-text, #id_4-text, #id_5-text, #id_6-text, #id_7-text, #id_8-text{fill:black!important;}\n\n&lt;/style&gt;\n\n&lt;div class=&quot;mermaid&quot;&gt;\ngantt\n  dateFormat DD.MM.YYYY\n    Task 1: active, id_1, 06.04.2023, 13.04.2023\n    Task 2:  id_2, 13.04.2023, 17.04.2023\n    Task 3:  id_3, 17.04.2023, 12.05.2023\n    Task 4:  id_4, 17.04.2023, 04.05.2023\n    Task 5:  id_5, 04.05.2023, 12.05.2023\n    Task 6:  id_6, 12.05.2023, 18.05.2023\n    Task 7:  id_7, 12.05.2023, 16.05.2023\n    Task 8:  id_8, 16.05.2023, 18.05.2023\n\n&lt;/div&gt;\n\n&lt;script src=&quot;https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js&quot;&gt;&lt;/script&gt;\n&lt;script&gt;\n    mermaid.ganttConfig = {\n        mirrorActor: true\n    }\n    mermaid.initialize({\n        startOnLoad: true\n    });\n&lt;/script&gt;\n&lt;/body&gt;\n&lt;/html&gt;\" width=\"100%\" height=\"320\" style=\"border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe>"
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "plan_copy = plan.clone()\n",
    "plan_copy.tasks(parent_id_ne_=0).gantt_bar_style={'fill': 'white', 'stroke': '#23964d'}\n",
    "plan_copy.tasks(parent_id_ne_=0).gantt_text_style={'fill': 'black'}\n",
    "\n",
    "MermaidGantt(plan_copy, height=320)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2023-04-06T09:22:43.114069Z",
     "end_time": "2023-04-06T09:22:43.129691Z"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "### Tick intervals"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "outputs": [
    {
     "data": {
      "text/plain": "<pjplan.viz.mermaid.gantt.MermaidGantt at 0x15875fe6b60>",
      "text/html": "<iframe srcdoc=\"&lt;html&gt;\n&lt;meta charset=&quot;UTF-8&quot;&gt;\n&lt;body&gt;\n&lt;style&gt;\n\n&lt;/style&gt;\n\n&lt;div class=&quot;mermaid&quot;&gt;\ngantt\n  dateFormat DD.MM.YYYY\n  tickInterval 1day\n    Task 1: active, id_1, 06.04.2023, 13.04.2023\n    Task 2:  id_2, 13.04.2023, 17.04.2023\n    Task 3:  id_3, 17.04.2023, 12.05.2023\n    Task 4:  id_4, 17.04.2023, 04.05.2023\n    Task 5:  id_5, 04.05.2023, 12.05.2023\n    Task 6:  id_6, 12.05.2023, 18.05.2023\n    Task 7:  id_7, 12.05.2023, 16.05.2023\n    Task 8:  id_8, 16.05.2023, 18.05.2023\n\n&lt;/div&gt;\n\n&lt;script src=&quot;https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js&quot;&gt;&lt;/script&gt;\n&lt;script&gt;\n    mermaid.ganttConfig = {\n        mirrorActor: true\n    }\n    mermaid.initialize({\n        startOnLoad: true\n    });\n&lt;/script&gt;\n&lt;/body&gt;\n&lt;/html&gt;\" width=\"100%\" height=\"300\" style=\"border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe>"
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "plan_copy = plan.clone()\n",
    "MermaidGantt(plan_copy, tick_interval='1day')"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2023-04-06T09:22:43.129691Z",
     "end_time": "2023-04-06T09:22:43.162600Z"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
