This questions should be very easy, I haven't been able to find out! even seeing other posts about keeping aspect ratio, because they're all talking about maintaining an aspect ratio relative to width.
For example, if I want it to have a full Width canvas and keep an aspect ratio of 16:9 I would use this code:
var can = document.getElementById('canvas');
can.width = window.innerWidth;
can.height = can.width * (9 / 16);
Based on your code, the relative width can be calculated as follows
var can = document.getElementById('canvas'); can.height = window.innerHeight; can.width = can.height * (16/9);