vran-dev / obsidian-contribution-graph

generate interactive gitxxx style contribution graph for obsidian, use it to track your goals, habits, or anything else you want to track.
Apache License 2.0
244 stars 5 forks source link

frontmatter list type #93

Open Lucifer-Clegg opened 3 months ago

Lucifer-Clegg commented 3 months ago

Hi, how do I have to change the DVJS code if I have a multi value field modifiedin frontmatter (properties) and I want to display the changes of this file?

so the values are like this:

modified:
  - 2024-01-10T15:33:49
  - 2024-03-26T09:21:35
  - 2024-06-11T18:44:23
  - 2024-06-12T16:15:24
  - 2024-06-13T19:09:05

and when I set: .groupBy(p => p.modified.toFormat('yyyy-MM-dd')) I get : Evaluation Error: TypeError: p.modified.toFormat is not a function

vran-dev commented 3 months ago

sample

const data = dv.pages('#project')
    .filter(p => p.modified)
// core, we should flatmap modified values, because  modified property is list
    .flatMap(p => {
        return p.modified.map(t => {
            return {
                  time: t,
                  page: p
              }
        })
    })
    .groupBy(p =>  p.time.toFormat('yyyy-MM-dd'))
    .map(entry =>{
        return {
            date: entry.key,
            value: entry.rows.length
        }
    })

const calendarData = {
    data: data,
    days: 365
}

renderContributionGraph(this.container, calendarData)
Lucifer-Clegg commented 3 months ago

thank you for your reply, unfortunately I get an error: Evaluation Error: TypeError: p.modified.map is not a function

vran-dev commented 3 months ago

thank you for your reply, unfortunately I get an error: Evaluation Error: TypeError: p.modified.map is not a function

maybe some modified property's value is not list?

try to fixed

const data = dv
    .pages("")
    .filter((p) => p.modified)
    // core, we should flatmap modified values, because  modified property is list
    .flatMap((p) => {
        if (!Array.isArray(p.modified)) {
            return [{
                time: p.modified,
                page: p
            }]
        }
        return p.modified.map((t) => {
            return {
                time: t,
                page: p,
            };
        });
    })
    .groupBy((p) => p.time.toFormat("yyyy-MM-dd"))
    .map((entry) => {
        return {
            date: entry.key,
            value: entry.rows.length,
        };
    });

const calendarData = {
    data: data,
    days: 365,
};

renderContributionGraph(this.container, calendarData);
Lucifer-Clegg commented 3 months ago

thank you very much, but I set only one file in

const data = dv.pages("[[test_file]]")

these are the entries of the file in modified :

---
PrState: 4
modified:
  - 2024-07-06T15:38:34
  - 2024-07-07T15:38:34
  - 2024-07-07T16:48:34
  - 2024-07-08T17:20:34
  - 2024-07-08T20:38:34
  - 2024-07-09T21:52:34
  - 2024-07-10T14:02:18
  - 2024-07-10T14:02:18
  - 2024-07-10T15:56:32
  - 2024-07-11T13:34:26
  - 2024-07-12T13:56:49
  layoutDone: 1
  ---

but with this if (!Array.isArray...

it works.