Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

window.renderChart() does not work with admonition #22

Closed
wychwitch opened this issue Oct 14, 2021 · 12 comments
Closed

window.renderChart() does not work with admonition #22

wychwitch opened this issue Oct 14, 2021 · 12 comments

Comments

@wychwitch
Copy link

Hello! I absolutely love this plugin and I intend to use it a lot more. However, I've run into a strange error. Using window.renderchart within dataviewjs that is also wrapped in a admonition block will throw the following error:

Evaluation Error: SyntaxError: missing ) after argument list
    at DataviewInlineApi.eval {...}

Using it without the block it works fine, but I make heavy use of admonition blocks for organizational purposes.

Is there something I'm doing wrong? I can post the full script that I'm using and the full error if needed, just let me know!

@phibr0
Copy link
Owner

phibr0 commented Oct 14, 2021

It would definetly be helpful if you post the full code you are using

@wychwitch
Copy link
Author

Sorry about that! You're right, not sure why I didn't supply it in the first place.

Here it is together with the encompassing admonition block
````ad-note
title: Blood Pressure Graph Sept-Oct
icon: tint
color: 220, 20, 60
collapse: closed

```dataviewjs

var dateStart = "2021-09-01";

var dateEnd = "2021-10-31";

var dnotes = dv.pages("#daily-log").where(p => 
            dv.date(p.file.name) >= 
            dv.date(dateStart) && 
            dv.date(p.file.name) <= 
            dv.date(dateEnd));

        var tdata = [];
        var bdata = [];
        var allLabels = [];
        
        for (let i = 0; i < dnotes.length; i++) {
            
            if (dnotes[i].avgbp){
                allLabels.push(dnotes[i].file.name) 
                var strNum = dnotes[i].avgbp.split("/")[0]
                var num = parseInt(strNum)
                
                tdata.push(num);
                
                var strrNum = dnotes[i].avgbp.split("/")[1]
                var numm = parseInt(strrNum)
                    bdata.push(numm);
                    //console.log(parseInt(dnotes[i].avgbp.trimLeft("/"));
                    //console.log(parseInt(dnotes[i].avgbp.trimRight("/"))
                }
            
        }
        allLabels.reverse()
        tdata.reverse()
        bdata.reverse()

        const chartData = {
            type: 'bar',
            data: {
                labels: allLabels,
                width: "10%",
                datasets: [{
                    label: 'Top',
                    data: tdata     ,
                    backgroundColor: ['rgba(217, 121, 137)'
                    ],
                }, 
                {
                    label: 'Bottom',
                    data: bdata, 
                    backgroundColor: 'rgba(121, 156, 212)'}]
            }
        }

        //console.log(allLabels)
        const average = (array) => array.reduce((a, b) => a + b) / array.length;

        if (!String.prototype.format) {
        String.prototype.format = function() {
            var args = arguments;
            return this.replace(/{(\d+)}/g, function(match, number) { 
            return typeof args[number] != 'undefined'
                ? args[number]
                : match
            ;
            });
        };
        }
        var avgBP = 'Average Blood Pressure: {0}/{1}'.format(
            Math.round(
                (average(tdata) + Number.EPSILON) * 100) / 100,
            Math.round(
                (average(bdata) + Number.EPSILON) * 100) / 100);


window.renderChart(chartData, this.container);

dv.header(2, avgBP)

```
````
Here is the full error stack, I can't make heads or tails of it sadly

Evaluation Error: SyntaxError: missing ) after argument list
    at DataviewInlineApi.eval (eval at <anonymous> (app://obsidian.md/app.js:1:1215379), <anonymous>:12641:21)
    at evalInContext (eval at <anonymous> (app://obsidian.md/app.js:1:1215379), <anonymous>:12642:7)
    at eval (eval at <anonymous> (app://obsidian.md/app.js:1:1215379), <anonymous>:12653:36)
    at Generator.next (<anonymous>)
    at eval (eval at <anonymous> (app://obsidian.md/app.js:1:1215379), <anonymous>:26:71)
    at new Promise (<anonymous>)
    at __awaiter (eval at <anonymous> (app://obsidian.md/app.js:1:1215379), <anonymous>:22:12)
    at asyncEvalInContext (eval at <anonymous> (app://obsidian.md/app.js:1:1215379), <anonymous>:12648:12)
    at DataviewJSRenderer.eval (eval at <anonymous> (app://obsidian.md/app.js:1:1215379), <anonymous>:13175:23)
    at Generator.next (<anonymous>)

@phibr0
Copy link
Owner

phibr0 commented Oct 14, 2021

Okay, do other dataview blocks work fine inside admonitions?

@phibr0
Copy link
Owner

phibr0 commented Oct 14, 2021

I cannot find any error in your code, it might actually be an issue with admonitions

@wychwitch
Copy link
Author

Okay, do other dataview blocks work fine inside admonitions?

Yes they do actually! I just ran a quick test with wrapping dv.header(2, "test") in an admonition block.

I cannot find any error in your code, it might actually be an issue with admonitions

Interesting! I'll open an issue on its page then and update if I make any more progress. Thank you!

@phibr0
Copy link
Owner

phibr0 commented Oct 31, 2021

Does it work now?

@wychwitch
Copy link
Author

Does it work now?

Sorry today has been a lot and i only just saw this! No, it's still not working (I just made sure to update and made sure admonition works with other dataviewjs blocks, and it does)

phibr0 added a commit that referenced this issue Nov 2, 2021
CodeMirror Options WSYSWIG breaks because the MarkdownPostprocessorContext is not passed
@phibr0
Copy link
Owner

phibr0 commented Nov 2, 2021

Please check with the new Update

@wychwitch
Copy link
Author

wychwitch commented Nov 2, 2021

Just ran the 'check for updates' command in obsidian, installed all updates and checked, and no it's still causing the same error. Again the code still works outside of the admonition block just not at all inside.

If there's anything else you'd like me to test let me know!

@phibr0
Copy link
Owner

phibr0 commented Dec 16, 2021

image
It is now working for me. Does the error still occur on your End?

@phibr0
Copy link
Owner

phibr0 commented Dec 16, 2021

Ah, no I forgot this Issue has to do with the dataview api..

@wychwitch
Copy link
Author

Ah, no I forgot this Issue has to do with the dataview api..

SORRY I NEVER SAW THIS REPLY My github notifs were flooded with a project I accidentally subscribed to

YES it works!!!!!!!!!!! I have no idea what changed but its totally working!! thank you!

Obsidian Plugins automation moved this from in progress to done Jan 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: done
Development

No branches or pull requests

2 participants