obsidian-contribution-graph icon indicating copy to clipboard operation
obsidian-contribution-graph copied to clipboard

frontmatter list type

Open Lucifer-Clegg opened this issue 1 year ago • 4 comments

Hi, how do I have to change the DVJS code if I have a multi value field modified in 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

Lucifer-Clegg avatar Jul 10 '24 08:07 Lucifer-Clegg

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)

vran-dev avatar Jul 12 '24 10:07 vran-dev

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

Lucifer-Clegg avatar Jul 12 '24 10:07 Lucifer-Clegg

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);

vran-dev avatar Jul 12 '24 11:07 vran-dev

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.

Lucifer-Clegg avatar Jul 12 '24 12:07 Lucifer-Clegg