├── .env ├── .github └── workflows │ └── ci.yml ├── .gitignore ├── Dockerfile ├── LICENSE ├── README.md ├── compose.yml ├── docs └── ObsidianVault │ ├── Concept.md │ ├── Docker.md │ ├── Installation.md │ ├── References.md │ ├── Usage │ ├── ECharts.md │ └── Setup.md │ ├── assets │ ├── javascripts │ │ ├── interactive_graph.js │ │ └── obsidian_tags.js │ └── stylesheets │ │ ├── interactive_graph.css │ │ └── obsidian_tags.css │ └── index.md ├── mkdocs.yml ├── obsidian_interactive_graph ├── __init__.py └── plugin.py ├── requirements.txt └── setup.py /.env: -------------------------------------------------------------------------------- 1 | IP=0.0.0.0 2 | PORT=8000 3 | DEV=ON 4 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: ci 2 | on: [push] 3 | permissions: 4 | contents: write 5 | jobs: 6 | build: 7 | name: Build plugin 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v4 11 | - uses: actions/setup-python@v5 12 | with: 13 | python-version: 3.x 14 | - run: pip install setuptools 15 | - run: python setup.py sdist 16 | - name: Archive plugin 17 | uses: actions/upload-artifact@v4 18 | with: 19 | name: dist 20 | path: dist 21 | 22 | release: 23 | name: Upload release to PyPI 24 | needs: build 25 | runs-on: ubuntu-latest 26 | environment: 27 | name: pypi 28 | url: https://pypi.org/p/mkdocs-obsidian-interactive-graph-plugin 29 | permissions: 30 | id-token: write 31 | steps: 32 | - name: Download Artifact 33 | uses: actions/download-artifact@v4 34 | with: 35 | name: dist 36 | path: dist 37 | - name: List 38 | run: | 39 | ls dist 40 | - name: Publish package distributions to PyPI 41 | if: startsWith(github.ref, 'refs/tags') 42 | uses: pypa/gh-action-pypi-publish@release/v1 43 | with: 44 | skip-existing: true 45 | 46 | deploy: 47 | needs: release 48 | runs-on: ubuntu-latest 49 | steps: 50 | - uses: actions/checkout@v4 51 | - name: Configure Git Credentials 52 | run: | 53 | git config user.name github-actions[bot] 54 | git config user.email 41898282+github-actions[bot]@users.noreply.github.com 55 | - uses: actions/setup-python@v5 56 | with: 57 | python-version: 3.x 58 | - run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV 59 | - uses: actions/cache@v4 60 | with: 61 | key: mkdocs-material-${{ env.cache_id }} 62 | path: .cache 63 | restore-keys: | 64 | mkdocs-material- 65 | - run: pip install mkdocs-material 66 | - run: pip install -r requirements.txt --upgrade 67 | - run: mkdocs gh-deploy --force 68 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .obsidian/ -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM squidfunk/mkdocs-material:latest 2 | 3 | WORKDIR /notes 4 | 5 | COPY ./obsidian_interactive_graph /plugin/obsidian_interactive_graph 6 | 7 | COPY ./setup.py /plugin/setup.py 8 | 9 | COPY ./README.md /plugin/README.md 10 | 11 | COPY ./.git/ /plugin/.git/ 12 | 13 | ARG DEV 14 | 15 | RUN if [[ "$DEV" == "ON" ]]; then pip install /plugin/; fi 16 | 17 | COPY ./requirements.txt /notes/requirements.txt 18 | 19 | RUN pip install --upgrade -r requirements.txt 20 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 daxcore 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Interactive Graph for Material for MkDocs 2 | Plugin for Material for MkDocs to draw an interactive graph like Obsidian. 3 | The graph inside the sidebar is just available for non-mobile website. The modal view via the button next to the light/dark mode switch shall work on all devices. 4 | 5 | Refer [Github Pages](https://daxcore.github.io/mkdocs-obsidian-interactive-graph-plugin/) for a **demonstration** of the interactive graph in Material for MkDocs. 6 | 7 | [](https://github.com/daxcore/mkdocs-obsidian-interactive-graph-plugin/actions/workflows/ci.yml) 8 | [](https://pypi.org/project/mkdocs-obsidian-interactive-graph-plugin/) 9 | [](https://pypi.org/project/mkdocs-obsidian-interactive-graph-plugin/) 10 | [](https://github.com/daxcore/mkdocs-obsidian-interactive-graph-plugin/blob/main/LICENSE) 11 | 12 | # Installation 13 | Available on [PyPI](https://pypi.org/project/mkdocs-obsidian-interactive-graph-plugin/). 14 | Install via `pip install mkdocs-obsidian-interactive-graph-plugin` or add it to your `requirements.txt`. 15 | 16 | # Usage 17 | ## Setup in MkDocs 18 | Activate the plugin in `mkdocs.yml`, but **note** that this plugin has to be located before plugins, that replace wikilinks by markdown links. Currently just wikilinks like `[[Link#Anchor|Custom Text]]` are supported. 19 | ``` 20 | plugins: 21 | - obsidian-interactive-graph 22 | 23 | extra_javascript: 24 | - https://fastly.jsdelivr.net/npm/jquery/dist/jquery.min.js 25 | - https://fastly.jsdelivr.net/npm/echarts/dist/echarts.min.js 26 | - assets/javascripts/interactive_graph.js 27 | 28 | extra_css: 29 | - assets/stylesheets/interactive_graph.css 30 | ``` 31 | 32 | ## Graph Javascript by Apache ECharts 33 | A `interactive_graph.js` example can be downloaded from [here](https://raw.githubusercontent.com/daxcore/mkdocs-obsidian-interactive-graph-plugin/main/docs/ObsidianVault/assets/javascripts/interactive_graph.js) and must be located into the docs directory under `docs/YourSiteName/assets/javascripts/interactive_graph.js`. 34 | 35 | Beginning from version `0.3.0` the default graph inside the sidebar was minimized to edges related to the current page only. The previous behavior can be restored by setting `global` to `true` at line `draw_graph_sidebar(myChart, global=false)` at top of javascript file. 36 | 37 | # Docker 38 | Adapt the `.env` and `mkdocs.yml` files to your needs. `DEV=ON` will rebuild the `mkdocs-obsidian-interactive-graph-plugin` from local files. If `DEV != ON` the upstream packages of PyPI will be used. Build and start the Docker container via `docker compose up --build [-d]`. 39 | 40 | # References 41 | * https://www.mkdocs.org/ 42 | * https://squidfunk.github.io/mkdocs-material/ 43 | * https://github.com/ndy2/mkdocs-obsidian-support-plugin/tree/main 44 | * https://github.com/GooRoo/mkdocs-obsidian-bridge 45 | * https://github.com/blueswen/mkdocs-glightbox 46 | * https://echarts.apache.org 47 | -------------------------------------------------------------------------------- /compose.yml: -------------------------------------------------------------------------------- 1 | services: 2 | mkdocs: 3 | build: 4 | context: . 5 | args: 6 | - DEV=$DEV 7 | network: host 8 | restart: unless-stopped 9 | ports: 10 | - $IP:$PORT:8000 11 | volumes: 12 | - ./mkdocs.yml:/notes/mkdocs.yml:ro 13 | - ./docs/:/notes/docs/:ro 14 | -------------------------------------------------------------------------------- /docs/ObsidianVault/Concept.md: -------------------------------------------------------------------------------- 1 | # Concept 2 | ## JSON file 3 | 4 | The python plugin for Material for #MkDocs creates a `graph.json` file, which will be used by [[ECharts]] javascript. 5 | 6 | You can find the #JSON file for this example site here: [graph.json](../assets/javascripts/graph.json) 7 | -------------------------------------------------------------------------------- /docs/ObsidianVault/Docker.md: -------------------------------------------------------------------------------- 1 | # Docker 2 | ## Development 3 | 4 | Adapt the `.env` and `mkdocs.yml` files to your needs. `DEV=ON` will rebuild the `mkdocs-obsidian-interactive-graph-plugin` from local files. 5 | 6 | ## Productive 7 | 8 | If `DEV != ON` is set in `mkdocs.yml` the upstream packages of #PyPI will be used. 9 | 10 | ## Start 11 | 12 | Build and start the Docker container via `docker compose up --build [-d]`. 13 | -------------------------------------------------------------------------------- /docs/ObsidianVault/Installation.md: -------------------------------------------------------------------------------- 1 | # Installation 2 | 3 | Available on [PyPI](https://pypi.org/project/mkdocs-obsidian-interactive-graph-plugin/){:target="\_blank"}. 4 | Install via `pip install mkdocs-obsidian-interactive-graph-plugin` or add it to your `requirements.txt`. 5 | -------------------------------------------------------------------------------- /docs/ObsidianVault/References.md: -------------------------------------------------------------------------------- 1 | # References 2 | 3 | * [https://www.mkdocs.org/](https://www.mkdocs.org/){:target="\_blank"} 4 | * [https://squidfunk.github.io/mkdocs-material/](https://squidfunk.github.io/mkdocs-material/){:target="\_blank"} 5 | * [https://github.com/ndy2/mkdocs-obsidian-support-plugin/tree/main](https://github.com/ndy2/mkdocs-obsidian-support-plugin/tree/main){:target="\_blank"} 6 | * [https://github.com/GooRoo/mkdocs-obsidian-bridge](https://github.com/GooRoo/mkdocs-obsidian-bridge){:target="\_blank"} 7 | * [https://github.com/blueswen/mkdocs-glightbox](https://github.com/blueswen/mkdocs-glightbox){:target="\_blank"} 8 | * [https://echarts.apache.org](https://echarts.apache.org){:target="\_blank"} 9 | -------------------------------------------------------------------------------- /docs/ObsidianVault/Usage/ECharts.md: -------------------------------------------------------------------------------- 1 | # ECharts 2 | ## Graph Javascript by Apache ECharts 3 | 4 | A `interactive_graph.js` example can be downloaded from [here](https://raw.githubusercontent.com/daxcore/mkdocs-obsidian-interactive-graph-plugin/main/docs/ObsidianVault/assets/javascripts/interactive_graph.js){:target="\_blank"} and must be located into the docs directory under `docs/ObsidianVault/assets/javascripts/interactive_graph.js`. 5 | 6 | ## Live Editor 7 | 8 | There is a web-based live editor for the #EChart javascript file: [Live Editor](https://echarts.apache.org/examples/en/editor.html?c=graph){:target="\_blank"} 9 | -------------------------------------------------------------------------------- /docs/ObsidianVault/Usage/Setup.md: -------------------------------------------------------------------------------- 1 | # Setup 2 | ## Setup in MkDocs 3 | 4 | Activate the plugin in `mkdocs.yml`, but **note** that this plugin has to be located **before** plugins, that replace wikilinks by markdown links. Currently just wikilinks like `[[Link#Anchor|Custom Text]]` are supported. 5 | 6 | ``` 7 | plugins: 8 | - obsidian-interactive-graph 9 | 10 | extra_javascript: 11 | - https://fastly.jsdelivr.net/npm/jquery/dist/jquery.min.js 12 | - https://fastly.jsdelivr.net/npm/echarts/dist/echarts.min.js 13 | - assets/javascripts/interactive_graph.js 14 | 15 | extra_css: 16 | - assets/stylesheets/interactive_graph.css 17 | ``` 18 | -------------------------------------------------------------------------------- /docs/ObsidianVault/assets/javascripts/interactive_graph.js: -------------------------------------------------------------------------------- 1 | // draw graph in sidebar, change global to true if prefered 2 | function draw_graph_sidebar(myChart, global=false) { 3 | draw_graph(myChart, global) 4 | } 5 | 6 | // draw graph in modal view 7 | function draw_graph_modal(myChart, global=true) { 8 | draw_graph(myChart, global) 9 | } 10 | 11 | // add graph button next to light/dark mode switch if activated, but before search 12 | $('.md-search').before('
'); 20 | 21 | // add a div to html in which the graph will be drawn 22 | function add_graph_div(params) { 23 | $('.md-sidebar--secondary').each(function() { 24 | $(this).contents().append(''); 25 | }); 26 | }; 27 | 28 | add_graph_div(); 29 | 30 | function init_graph(params) { 31 | var myChart = echarts.init(document.getElementById('graph'), null, { 32 | renderer: 'canvas', 33 | useDirtyRect: false 34 | }); 35 | return myChart; 36 | }; 37 | 38 | var myChart = init_graph(); 39 | 40 | function draw_graph(myChart, global=true) { 41 | var _option = $.extend(true, {}, option); 42 | if(!global) { 43 | _option.series[0].data = graph_nodes(); 44 | _option.series[0].links = graph_links(); 45 | } 46 | // draw the graph 47 | myChart.setOption(_option); 48 | 49 | // add click event for nodes 50 | myChart.on('click', function (params) { 51 | if(params.dataType == "node") { 52 | window.location = params.value; 53 | } 54 | }); 55 | 56 | // redraw on resize 57 | window.addEventListener('resize', myChart.resize); 58 | }; 59 | 60 | var option; 61 | 62 | function graph_links() { 63 | id = option.series[0].data.find(it => it.value === window.location.pathname).id; 64 | return option.series[0].links.filter(it => it.source === id || it.target === id); 65 | } 66 | 67 | function graph_nodes() { 68 | id = option.series[0].data.find(it => it.value === window.location.pathname).id; 69 | links = option.series[0].links.filter(it => it.source === id || it.target === id); 70 | ids = []; 71 | links.forEach(function (link) { 72 | ids.push(link.source, link.target); 73 | }); 74 | return option.series[0].data.filter(it => [...new Set(ids)].includes(it.id)); 75 | } 76 | 77 | $.getJSON(document.currentScript.src + '/../graph.json', function (graph) { 78 | myChart.hideLoading(); 79 | 80 | // an offset of 5, so the dot/node is not that small 81 | graph.nodes.forEach(function (node) { 82 | node.symbolSize += 5; 83 | }); 84 | 85 | // special feature, if u want to have long note titles, u can use this ' •' 86 | // to cut everything behind in graph view 87 | graph.nodes.forEach(function (node) { 88 | node.name = node.name.split(' •')[0]; 89 | }); 90 | graph.links.forEach(function (link) { 91 | link.source = link.source.split(' •')[0]; 92 | link.target = link.target.split(' •')[0]; 93 | }); 94 | 95 | option = { 96 | tooltip: { 97 | show: false, 98 | }, 99 | legend: [ // categories not supported yet 100 | //{ 101 | // data: graph.categories.map(function (a) { 102 | // return a.name; 103 | // }) 104 | //} 105 | ], 106 | darkMode: "auto", 107 | backgroundColor: $("body").css("background-color"), 108 | series: [ 109 | { 110 | name: 'Interactive Graph', 111 | type: 'graph', 112 | layout: 'force', 113 | data: graph.nodes, 114 | links: graph.links, 115 | categories: [], 116 | zoom: 2, 117 | roam: true, 118 | draggable: false, 119 | label: { 120 | show: true, 121 | position: 'right', 122 | formatter: '{b}' 123 | }, 124 | emphasis: { 125 | focus: 'adjacency', // gray out not related nodes on mouse over 126 | label: { 127 | fontWeight: "bold" 128 | } 129 | }, 130 | labelLayout: { 131 | hideOverlap: false // true could be a good idea for large graphs 132 | }, 133 | scaleLimit: { 134 | min: 0.5, 135 | max: 5 136 | }, 137 | lineStyle: { 138 | color: 'source', 139 | curveness: 0 // 0.3, if not 0, link an backlink will have 2 lines 140 | } 141 | } 142 | ] 143 | }; 144 | // initial draw in sidebar 145 | draw_graph_sidebar(myChart); 146 | }); 147 | 148 | $("#__palette_0").change(function(){ 149 | option.backgroundColor = $("body").css("background-color"); 150 | myChart.setOption(option); 151 | }); 152 | $("#__palette_1").change(function(){ 153 | option.backgroundColor = $("body").css("background-color"); 154 | myChart.setOption(option); 155 | }); 156 | 157 | $('#graph_button').on('click', function (params) { 158 | $("body").css({ overflow: "hidden", position: "fixed" }); 159 | $('#graph').remove(); 160 | $('