Listing 3. Arrows in All Four Quadrants dojo.addOnLoad(function() { var node = dojo.byId("surface"); var surface = dojox.gfx.createSurface(node, 600, 600) function drawArrow(p) { ///////////////////////////////////////////////////// //Create a group that can be manipulated as a whole ///////////////////////////////////////////////////// var group = surface.createGroup(); var x1 = p.start.x, y1=p.start.y, x2 = p.end.x, y2=p.end.y; var len = Math.sqrt(Math.pow(x2-x1,2) + Math.pow(y2-y1,2)); var _defaultStroke = { color : "black", style : "solid", width : 1 }; /////////////////////////// //Add a line to the group /////////////////////////// group.createLine({ x1 : 0, y1 : 0, x2 : 0+len, y2 : 0 }) .setStroke(p.stroke || _defaultStroke) ; var _arrowHeight = p.arrowHeight || 5; var _arrowWidth = p.arrowWidth || 3; ///////////////////////////////////////////////////// //Add a custom path that is a triangle to the group ///////////////////////////////////////////////////// group.createPath() .moveTo(len-_arrowHeight,0) .lineTo(len-_arrowHeight,-_arrowWidth) .lineTo(len,0) .lineTo(len-_arrowHeight,_arrowWidth) .lineTo(len-_arrowHeight,0) .setStroke(p.stroke || _defaultStroke) .setFill(p.stroke ? p.stroke.color : "black" ) ; var _rot = Math.asin((y2-y1)/len)*180/Math.PI; if (x2 <= x1) {_rot = 180-_rot;} ///////////////////////////////////////////////////////////// //Translate and rotate the entire group as a whole ///////////////////////////////////////////////////////////// group.setTransform([ dojox.gfx.matrix.translate(x1,y1), dojox.gfx.matrix.rotategAt(_rot,0,0) ]); } //diagonals drawArrow({start: {x:300,y:300}, end: {x : 435, y : 435}}); drawArrow({start: {x:300,y:300}, end: {x : 165, y : 165}}); drawArrow({start: {x:300,y:300}, end: {x : 435, y : 165}}); drawArrow({start: {x:300,y:300}, end: {x : 165, y : 435}}); //up, down, left, right drawArrow({start: {x:300,y:300}, end: {x : 300, y : 450}}); drawArrow({start: {x:300,y:300}, end: {x : 300, y : 150}}); drawArrow({start: {x:300,y:300}, end: {x : 150, y : 300}}); drawArrow({start: {x:300,y:300}, end: {x : 450, y : 300}}); });