Module graph not found

Posted on
  • Hi,

    I want to display a graph:

    require("graph").drawLine(g, steps, {
            axes : true,
            gridy : gridyValue,
            y : 50, //offset on screen
            x : 5, //offset on screen
        });
    

    When uploading to RAM from IDE, the code works, the graph is displayed.
    When installed as an application from the app loader, I get this error in IDE and the graph is not displayed:

    Uncaught Error: Module graph not found
     at line 26 col 20
        require("graph").drawLine(g, steps, {
                       ^
    in function "drawGraph" called from line 3 col 15
        drawGraph();
                  ^
    in function called from system
    

    Thanks
    Christian

  • Yes, the issue is the app loader isn't handling modules yet.

    If you upload this file: https://www.espruino.com/modules/graph.m­in.js

    to a Storage file called graph then you should be sorted though

  • Confirmed, then it is working.
    Any ETA for the app loader change?

    What to do in the meantime, add the graph module to the app?

  • Any ETA for the app loader change?

    Not yet. I'll probably just combine it with the minification changes by basically pulling in the Web IDE backend.

    I think the most sane solution is to just include it up the top of the source for now:

    Modules.addCached("graph",function(){exp­orts.drawAxes=function(b,c,a){function h(a){return e+m*(a-t)/x}function l(a){return f+g-g*(a-n)/u}var k=a.padx||0,d=a.pady||0,t=-k,w=c.length+­k-1,n=(void 0!==a.miny?a.miny:a.miny=c.reduce(functi­on(a,b){return Math.min(a,b)},c[0]))-d;c=(void 0!==a.maxy?a.maxy:a.maxy=c.reduce(functi­on(a,b){return Math.max(a,b)},c[0]))+d;a.gridy&&(d=a.gr­idy,n=d*Math.floor(n/d),c=d*Math.ceil(c/­d));var e=a.x||0,f=a.y||0,m=a.width||b.getWidth(­)-(e+1),g=a.height||b.getHeight()-(f+1);­a.axes&&(null!==a.ylabel&&
    (e+=6,m-=6),null!==a.xlabel&&(g-=6));a.t­itle&&(f+=6,g-=6);a.axes&&(b.drawLine(e,­f,e,f+g),b.drawLine(e,f+g,e+m,f+g));a.ti­tle&&(b.setFontAlign(0,-1),b.drawString(­a.title,e+m/2,f-6));var x=w-t,u=c-n;u||(u=1);if(a.gridx){b.setFo­ntAlign(0,-1,0);var v=a.gridx;for(d=Math.ceil((t+k)/v)*v;d<=­w-k;d+=v){var r=h(d),p=a.xlabel?a.xlabel(d):d;b.setPix­el(r,f+g-1);var q=b.stringWidth(p)/2;null!==a.xlabel&&r>­q&&b.getWidth()>r+q&&b.drawString(p,r,f+­g+2)}}if(a.gridy)for(b.setFontAlign(0,0,­1),d=n;d<=c;d+=a.gridy)k=l(d),
    p=a.ylabel?a.ylabel(d):d,b.setPixel(e+1,­k),q=b.stringWidth(p)/2,null!==a.ylabel&­&k>q&&b.getHeight()>k+q&&b.drawString(p,­e-5,k+1);b.setFontAlign(-1,-1,0);return{­x:e,y:f,w:m,h:g,getx:h,gety:l}};exports.­drawLine=function(b,c,a){a=a||{};a=expor­ts.drawAxes(b,c,a);var h=!0,l;for(l in c)h?b.moveTo(a.getx(l),a.gety(c[l])):b.l­ineTo(a.getx(l),a.gety(c[l])),h=!1;retur­n a};exports.drawBar=function(b,c,a){a=a||­{};a.padx=1;a=exports.drawAxes(b,c,a);fo­r(var h in c)b.fillRect(a.getx(h-.5)+1,a.gety(c[h])­,a.getx(h+
    .5)-1,a.gety(0));return a}});
    ... your code here
    
  • I think the most sane solution is to just include it up the top of the source for now:

    I will do that, thanks.

  • Hi, I'm using forked version of AppLoader. Is it still the best choice to include module into source as stated above?

  • Actually the App Loader was updated several months ago, so there should be no need for this now. I believe any referenced modules should automatically get pulled in when they are referenced?

  • Because few days ago I forked "BangleApps" repository to dive deeper into Espruino ecosystem. I was not able to use "Vertical watch face" from forked repo until I've not inserted Font8x12 module directly into application.
    Maybe should I fork modules repository too?

  • Odd - it shouldn't be needed. Are there any log messages in the chrome dev console that might help?

    If you're uploading a file named .min.js then no transforms will be performed, so that might be it?

  • Just looked into this and it's now fixed. I'm afraid a recent update to the app loader meant it stopped parsing code for modules in a lot of cases, but it's now sorted.

  • Yes, I can confirm. It work without module manually included. Thank You.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Module graph not found

Posted by Avatar for Purple-Tentacle @Purple-Tentacle

Actions