MarkMindCkm / obsidian-markmind

A mind map, outline for obsidian,It support mobile and desktop
770 stars 35 forks source link

[FR] wish working with dataview plugin. #679

Open ccchan234 opened 1 year ago

ccchan234 commented 1 year ago

as you may know, dataview is the powerful plugin of obsidian, to dig info from markdown texts.

test: using the 2 files below

  1. what i expect: the file1.md's dataview should show the hereditary inside the .json

  2. result: it only sees the hereditary outside .json. the mindmap, the .json is omitted.

this breaks obsidian ideology...

thanks

file1.md:

table hereditary
from #dv-test

file2.md:

mindmap-plugin: rich

tags: dv-test


hereditary::autosomal-recessive

mindmap-plugin: basic

json: {"theme":"","mindData":[[{"id":"3c7689f1-ae41-a570","text":"mindmap-plugin: basic","isExpand":true,"useHandMode":false,"isRoot":true,"useScale":true,"x":3940,"y":3800,"main":true,"layout":{"layoutName":"mindmap2","direct":"mindmap"},"stroke":""},{"id":"75cd1f0d-f89e-dd49","text":"hello","stroke":"#c6a5e5","x":4282,"y":3810,"layout":null,"isExpand":true,"pid":"3c7689f1-ae41-a570"},{"id":"54716d2d-153a-901c","text":"hereditary::x-linked","stroke":"#c6a5e5","x":4372,"y":3818,"layout":null,"isExpand":true,"pid":"75cd1f0d-f89e-dd49"}]],"induceData":[],"wireFrameData":[],"relateLinkData":[],"calloutData":[]}

ccchan234 commented 1 year ago

outside: hereditary::autosomal-recessive inside json: hereditary::X-lined

i expect it list out both, i.e. see both.

may be i should cross post to dataview... will do so later, thx

ccchan234 commented 1 year ago

ps: my solution: rich mode copy paste into basic mode. basic mode could be processed by dataview. that's it, i like basic mode more. but however only rich mode could "import" .xmind files

ccchan234 commented 1 year ago

gpt suggest we ... make a copy of the json data into the yaml... then dataview can deal /w the data in the yaml.

me: i got a md file like this, contains a json block. dataview didn't touch the json. what can i do? ---

mindmap-plugin: rich


mindmap-plugin: basic

{"theme":"","mindData":[[{"id":"f2cbb51d-be9e-5909","text":"111","isExpand":true,"isRoot":true,"useScale":true,"useHandMode":false,"x":3940,"y":3800,"main":true,"layout":{"layoutName":"mindmap2","direct":"mindmap"},"stroke":""},{"id":"41457844-5c49-418d","text":"123","stroke":"#6ed3ea","x":4058,"y":3779,"layout":null,"isExpand":true,"pid":"f2cbb51d-be9e-5909"},{"id":"86601dce-6d29-312c","text":"345","stroke":"#acdb48","x":4058,"y":3840,"layout":null,"isExpand":true,"pid":"f2cbb51d-be9e-5909"},{"id":"8f1d1c02-0b0c-7add","text":"567","stroke":"#f0c2f9","x":3847,"y":3810,"layout":null,"isExpand":true,"pid":"f2cbb51d-be9e-5909"},{"id":"d04f15c6-3780-b17b","text":"aaa","stroke":"#6ed3ea","x":4141,"y":3787,"layout":null,"isExpand":true,"pid":"41457844-5c49-418d"},{"id":"217fb5ad-67a2-02a6","text":"bbb","stroke":"#acdb48","x":4141,"y":3848,"layout":null,"isExpand":true,"pid":"86601dce-6d29-312c"},{"id":"c39db16d-9173-af79","text":"ccc","stroke":"#f0c2f9","x":3785,"y":3818,"layout":null,"isExpand":true,"pid":"8f1d1c02-0b0c-7add"}]],"induceData":[],"wireFrameData":[],"relateLinkData":[],"calloutData":[]}
ccchan234 commented 1 year ago

gpt: You can extract information from the JSON block in the markdown file using the Dataview inline query, but you'll need to first convert the JSON block into a YAML frontmatter format. JSON is not natively supported within the frontmatter, but you can convert it to YAML, which is supported.

Here's the converted YAML frontmatter from the given JSON:

---
mindmap-plugin: rich
mindData:
  - - id: f2cbb51d-be9e-5909
      text: "111"
      isExpand: true
      isRoot: true
      useScale: true
      useHandMode: false
      x: 3940
      y: 3800
      main: true
      layout:
        layoutName: mindmap2
        direct: mindmap
      stroke: ""
    - id: 41457844-5c49-418d
      text: "123"
      stroke: "#6ed3ea"
      x: 4058
      y: 3779
      layout: null
      isExpand: true
      pid: f2cbb51d-be9e-5909
    - id: 86601dce-6d29-312c
      text: "345"
      stroke: "#acdb48"
      x: 4058
      y: 3840
      layout: null
      isExpand: true
      pid: f2cbb51d-be9e-5909
    - id: 8f1d1c02-0b0c-7add
      text: "567"
      stroke: "#f0c2f9"
      x: 3847
      y: 3810
      layout: null
      isExpand: true
      pid: f2cbb51d-be9e-5909
    - id: d04f15c6-3780-b17b
      text: "aaa"
      stroke: "#6ed3ea"
      x: 4141
      y: 3787
      layout: null
      isExpand: true
      pid: 41457844-5c49-418d
    - id: 217fb5ad-67a2-02a6
      text: "bbb"
      stroke: "#acdb48"
      x: 4141
      y: 3848
      layout: null
      isExpand: true
      pid: 86601dce-6d29-312c
    - id: c39db16d-9173-af79
      text: "ccc"
      stroke: "#f0c2f9"
      x: 3785
      y: 3818
      layout: null
      isExpand: true
      pid: 8f1d1c02-0b0c-7add
induceData: []
wireFrameData: []
relateLinkData: []
calloutData: []
---

Now you can use Dataview inline queries to extract information from the YAML frontmatter. For example, if you want to list all the text properties from the mindData array, you can use the following inline query:

= this.mindData.map(item => item.text).join(', ')

This will output: 111, 123, 345, 567, aaa, bbb, ccc.

Remember to place the inline query in the same file where you have the YAML frontmatter.

ccchan234 commented 1 year ago

me: can the dataview query be put in another markdown file? gpt: Yes, you can use Dataview queries in other markdown files to query data from the file containing the YAML frontmatter. However, you will need to use a file-based query instead of this to reference the target file.

Assuming the file with the YAML frontmatter is named example.md, you can use the following query in another markdown file to list the text properties from the mindData array:

```dataviewjs
const targetFile = dv.pages('"example.md"')[0];
const mindData = dv.page(targetFile).mindData;
const textArray = mindData.flatMap(item => item.text);
dv.list(textArray);


This will output: `111, 123, 345, 567, aaa, bbb, ccc`.

Adjust the query accordingly if the filename is different or if you're using a specific folder structure. Remember to use double quotes (`""`) around the filename in the `dv.pages()` function.
ccchan234 commented 1 year ago

me: can i use tag instead?

gpt: Yes, you can use tags to query files with specific tags. Let's assume you have added a tag #mindmap to the example.md file containing the YAML frontmatter. You can then use the following Dataview query in another markdown file to list the text properties from the mindData array for all files with the #mindmap tag:

```dataviewjs
const taggedFiles = dv.pages("#mindmap");
taggedFiles.forEach(file => {
  const mindData = dv.page(file).mindData;
  const textArray = mindData.flatMap(item => item.text);
  dv.list(textArray);
});


This query will list the `text` properties for all files with the `#mindmap` tag. If you have multiple files with the same tag, the output will display the results for each file separately.
ccchan234 commented 1 year ago

complexed.