with a little research a come up with my script in creating a canvas that would look like this. 54d736fd19df9f8ac8a05733938b3e59

it has a multiple link one link per circle.

function binTree(aData, source, baseLink){
                var canvas = document.getElementById(source),
                    c = canvas.getContext("2d");
                c.translate(0.5,0.5);

                c.fillStyle = "#ffffff";
                c.fillRect(0, 0, canvas.width, canvas.height);

                c.strokeStyle = "#000000";
                c.strokeRect(0, 0, canvas.width-1, canvas.height-1);

                c.lineWidth = 1;
                c.font = "12px monospace";

                var canvasWidth = canvas.width;

                var initPosXPower = 1;
                var initPosx = 2;
                var initPosy = 50;
                var TWO_PI =Math.PI * 2;

                var Links = [];
                var hoverLink = "";
                c.textBaseline = "middle";
                c.textAlign="center";

                for (var i = 0; i < aData.length; i++)
                {
                  var posX = canvasWidth / initPosx, inc = 1, tmpInc = 1;

                  for (var j = 0; j < aData[i].length; j++)
                  {
                    var x = posX * inc;
                    c.fillStyle = "#c5cbd1";

                    c.beginPath();
                    c.arc(x, initPosy, 50, 0, TWO_PI * 2, false);
                    c.fill();
                    c.strokeStyle = "blue";
                    c.stroke();

                    c.fillStyle = "red";
                    drawLink(x,initPosy,baseLink + aData[i][j],aData[i][j]);

                    for (var k = 0; k < 2; k++) {
                      c.strokeStyle = "#000000";
                      var tmpPosX = canvasWidth / Math.pow(2, initPosXPower + 1);
                      var tmpX = tmpPosX * tmpInc;

                      c.beginPath();
                      c.moveTo(x, initPosy + 50);
                      c.lineTo(tmpX, initPosy + 100);
                      c.stroke();

                      tmpInc += 2;
                    }

                    inc += 2;
                  }

                  initPosx = Math.pow(2, initPosXPower +=1);
                  initPosy += 150;
                }

                function drawLink(x,y,href,title){
                    var linkWidth = c.measureText(title).width,
                        linkHeight = parseInt(c.font);

                    c.fillText(title, x, y);

                    canvas.addEventListener("mousemove", on_mousemove, false);
                    canvas.addEventListener("click", on_click, false);

                    Links.push(x - (linkWidth/2) + ";" + y + ";" + linkWidth + ";" + linkHeight + ";" + href);
                }

                function on_mousemove (ev) {
                    var x, y;

                    if (ev.layerX || ev.layerX == 0) {
                        x = ev.layerX;
                        y = ev.layerY;
                    }

                    for (var i = Links.length - 1; i >= 0; i--) {
                        var params = [];

                        params = Links[i].split(";");

                        var linkX = parseInt(params[0]),
                            linkY = parseInt(params[1]),
                            linkWidth = parseInt(params[2]),
                            linkHeight = parseInt(params[3]),
                            linkHref = params[4];

                        if (x >= linkX && x <= (linkX + linkWidth) && y + 5 >= linkY && y + 5 <= (linkY + linkHeight)){
                            document.body.style.cursor = "pointer";
                            hoverLink = linkHref;
                            break;
                        }
                        else {
                            document.body.style.cursor = "";
                            hoverLink = "";
                        }
                    }
                }

                function on_click(e) {
                    if (hoverLink){
                        window.location = hoverLink;
                    }
                }
            }

and i can call it like this.

<script>
    window.onload=function()
        {var aData = [['DVEX20131004'],
                      ['EWFS20131004','YHDF20131004'],
                      ['NGET20131004','VFEW20131004','ASFR20131004','FGVF20131004'],
                      ['SAEF20131004','ASDW20131004','UJFH20131004','VACANT','AENF20131004','VACANT','VACANT','VACANT']];

    binTree(aData, 'paper','http://localhost/networking/#111');
    }
</script>

then i try to run it in chrome and it works perfectly, but in IE the link is missing and on firefox the link is just in one circle above pointing to the last url created and not perfectly aligned with the text.

is there any solution to fix it, that would on ff and ie.

I will appreciate for any help will come.

Thank you

Dani AI

Generated

reported that clickable labels drawn into a canvas work in Chrome but are missing or misaligned in Firefox and IE. 's reply to "wait for browser updates" isn't helpful here — the issue is how mouse coordinates and hit rectangles are computed, and that can be fixed reliably today.

The two most common cross‑browser problems for canvas hit testing are (1) using nonstandard event properties like layerX/layerY, which behave inconsistently, and (2) failing to map DOM mouse coordinates into the canvas's drawing buffer when the canvas is styled with CSS or runs on a high‑DPI screen. Add to that creating event listeners inside a per‑link routine and treating the text y‑coordinate as a top rather than a middle; the result is missing or one‑wrong link. A robust approach is to compute mouse position from getBoundingClientRect() and scale it to canvas.width/height, store each link as an object {x,y,w,h,href} and add mouse listeners once after building the list.

Example helpers that fix coordinate mapping and make hit testing consistent across browsers:

function getMousePos(canvas, evt) {
  var r = canvas.getBoundingClientRect();
  return {
    x: (evt.clientX - r.left) * (canvas.width / r.width),
    y: (evt.clientY - r.top)  * (canvas.height / r.height)
  };
}

When textBaseline = "middle" compute the hit rect as top = y - fontPx/2 and height = fontPx. Draw the rects temporarily with strokeRect to verify bounds, attach a single mousemove/click pair after building the links, and use location.assign(url) or location.href = url on click. If supporting very old IE versions, add an attachEvent fallback or a small polyfill for addEventListener. These steps will make per‑circle links work predictably in Chrome, Firefox and IE.

Recommended Answers

All 2 Replies

Member Avatar for Member #949455

then i try to run it in chrome and it works perfectly, but in IE the link is missing and on firefox the link is just in one circle above pointing to the last url created and not perfectly aligned with the text.

You have to wait until the IE and Firefox update their browsers that is suitable for HTML5 / CSS3 code.

Right now, most of those CSS3 will not work on IE & Firefox.

I think firefox support canvas, beacuase on the exmaple i saw in google he created two links.

but when i tried it using loop and it goes wrong.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.