_base.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. if(!dojo._hasResource["dojox.geo.charting._base"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.geo.charting._base"] = true;
  8. dojo.provide("dojox.geo.charting._base");
  9. dojo.require("dojo.NodeList-traverse");
  10. dojo.require("dojox.gfx.matrix");
  11. dojo.require("dijit.Tooltip");
  12. (function(){
  13. var dgc = dojox.geo.charting;
  14. dgc.showTooltip = function(/*String*/innerHTML, /*dojox.gfx.shape*/ gfxObject, /*String[]?*/ position){
  15. var arroundNode = dgc._normalizeArround(gfxObject);
  16. return dijit.showTooltip(innerHTML, arroundNode, position);
  17. };
  18. dgc.hideTooltip = function( /*dojox.gfx.shape*/gfxObject){
  19. return dijit.hideTooltip(gfxObject);
  20. };
  21. dgc._normalizeArround = function(gfxObject){
  22. var bbox = dgc._getRealBBox(gfxObject);
  23. //var bbox = gfxObject.getBoundingBox();
  24. //get the real screen coords for gfx object
  25. var realMatrix = gfxObject._getRealMatrix() || {xx:1,xy:0,yx:0,yy:1,dx:0,dy:0};
  26. var point = dojox.gfx.matrix.multiplyPoint(realMatrix, bbox.x, bbox.y);
  27. var gfxDomContainer = dojo.coords(dgc._getGfxContainer(gfxObject));
  28. gfxObject.x = dojo.coords(gfxDomContainer,true).x + point.x,
  29. gfxObject.y = dojo.coords(gfxDomContainer,true).y + point.y,
  30. gfxObject.width = bbox.width * realMatrix.xx,
  31. gfxObject.height = bbox.height * realMatrix.yy
  32. return gfxObject;
  33. };
  34. dgc._getGfxContainer = function(gfxObject){
  35. return (new dojo.NodeList(gfxObject.rawNode)).parents("div")[0];
  36. };
  37. dgc._getRealBBox = function(gfxObject){
  38. var bboxObject = gfxObject.getBoundingBox();
  39. if(!bboxObject){//the gfx object is group
  40. var shapes = gfxObject.children;
  41. var bboxObject = dojo.clone(dgc._getRealBBox(shapes[0]));
  42. dojo.forEach(shapes, function(item){
  43. var nextBBox = dgc._getRealBBox(item);
  44. bboxObject.x = Math.min(bboxObject.x, nextBBox.x);
  45. bboxObject.y = Math.min(bboxObject.y, nextBBox.y);
  46. bboxObject.endX = Math.max(bboxObject.x + bboxObject.width, nextBBox.x + nextBBox.width);
  47. bboxObject.endY = Math.max(bboxObject.y + bboxObject.height, nextBBox.y + nextBBox.height);
  48. });
  49. bboxObject.width = bboxObject.endX - bboxObject.x;
  50. bboxObject.height = bboxObject.endY - bboxObject.y;
  51. }
  52. return bboxObject;
  53. };
  54. })();
  55. }