Richardsl / heatmap-calendar-obsidian

An Obsidian plugin for displaying data in a calendar similar to the github activity calendar
Apache License 2.0
623 stars 103 forks source link

Edit intensity mapping logic #53

Open shadowlift opened 1 year ago

shadowlift commented 1 year ago

My YAML keys have two values;

---
workout: 30 minutes, 4
study: 1 hour 45 minutes, 8
...
---

for example, to signify my "rating" for an activity along with its duration.

I would like to map my intensity values according to the product of these values in the key, i.e., for this example, the number 0.5 x 4 = 2 for the workout key, and the number 1.75 x 8 = 14 for the 'study' key.

I know this is probably quite a simple operation but I don't know any Dataview and struggled with this. Any advice?

johnsbuck commented 1 year ago

under intensity, you could do the following:

intensity: ((page) => {
    (page.study ?? 0) * (page.workout ?? 0)
})()

I will admit I only did minor testing, so feel free to tell me how effective it is for your project 😄

EDIT: Example


dv.span("**Exercise & Study Score**")

const hue1 = 13 //red
const hue2 = 132 //green

const calendarData = { 
    colors: {
        red2green: [
            `hsl(${hue1}, 100%, 37%)`,     // 1 - darkest red
            `hsl(${hue1}, 100%, 50%)`,     // 2 - 
            `hsl(${hue1}, 100%, 60%)`,     // 3 - 
            `hsl(${hue1}, 100%, 77%)`,     // 4 - lightest red
            `hsl(0, 0%, 80%)`,             // 5 - neutral gray
            `hsl(${hue2*0.7}, 70%, 72%)`,  // 6 - lightest green
            `hsl(${hue2*0.85}, 43%, 56%)`, // 7 - 
            `hsl(${hue2}, 49%, 36%)`,      // 8 - 
            `hsl(${hue2}, 59%, 24%)`,      // 9 - darkest green
        ],
    },
    entries: []
}

for(let page of dv.pages('"daily notes"').where(p=>p.workout)){ 

    calendarData.entries.push({
        date: page.file.name, 
        intensity: (page.study ?? 0) * page.workout,
        content: await dv.span(`[](${page.file.name})`), //for hover preview
    })

}

renderHeatmapCalendar(this.container, calendarData)

You can also edit the where function, but I am not sure all the functions of dataviewjs.