/src/elycharts_manager_balloon.js

https://github.com/voidlabs/ElyCharts · JavaScript · 77 lines · 51 code · 12 blank · 14 comment · 30 complexity · b6706e7774cdb8b7363dc236b0779f5a MD5 · raw file

  1. /**********************************************************************
  2. * ELYCHARTS
  3. * A Javascript library to generate interactive charts with vectorial graphics.
  4. *
  5. * Copyright (c) 2010-2014 Void Labs s.n.c. (http://void.it)
  6. * Licensed under the MIT (http://creativecommons.org/licenses/MIT/) license.
  7. **********************************************************************/
  8. (function($) {
  9. var common = $.elycharts.common;
  10. /***********************************************************************
  11. * FEATURE: BALLOON
  12. **********************************************************************/
  13. $.elycharts.balloonmanager = {
  14. afterShow : function(env, pieces) {
  15. // TODO transizioni
  16. if (env.opt.features.balloons.active && env.opt.balloons && env.opt.type == 'funnel') {
  17. var conf = env.opt.features.balloons;
  18. var lastSerie = false, lastIndex = false;
  19. for (var i = 0; i < pieces.length; i++) {
  20. if (pieces[i].section == 'Series' && pieces[i].subSection == 'Plot') {
  21. for (var index = 0; index < pieces[i].paths.length; index ++)
  22. if (env.opt.balloons[pieces[i].serie] && env.opt.balloons[pieces[i].serie][index]) {
  23. lastSerie = pieces[i].serie;
  24. lastIndex = index;
  25. this.drawBalloon(env, lastSerie, index, pieces[i].paths[index].rect);
  26. }
  27. } else if (lastSerie && pieces[i].section == 'Sector' && pieces[i].serie == 'bottom' && !pieces[i].subSection && lastIndex < env.opt.balloons[lastSerie].length - 1) {
  28. this.drawBalloon(env, lastSerie, env.opt.balloons[lastSerie].length - 1, pieces[i].rect);
  29. }
  30. }
  31. }
  32. },
  33. drawBalloon : function(env, serie, index, rect) {
  34. var conf = env.opt.features.balloons;
  35. var balloon = env.opt.balloons[serie][index];
  36. //var offset = $(env.container).offset();
  37. var style = {
  38. position : 'absolute', 'z-index' : 25,
  39. //top : offset.top + rect[1] , left: offset.left + conf.left,
  40. margin : rect[1] + "px 0 0 " + conf.left + "px",
  41. height : (conf.height ? conf.height : rect[3] - rect[1]) - conf.padding[0] * 2 ,
  42. width : conf.width ? conf.width : rect[0],
  43. padding : conf.padding[0] + 'px ' + conf.padding[1] + 'px'
  44. };
  45. if (typeof balloon == 'string')
  46. $("<div></div>").css(style).css(conf.style).html(balloon).prependTo(env.container);
  47. else
  48. $(balloon).css(style).css(conf.style).prependTo(env.container);
  49. // Disegna la linea
  50. if (conf.line) {
  51. var path = [];
  52. for (var j = 0; j < conf.line.length; j++) {
  53. if (j == 0)
  54. path.push([ 'M', rect[0] - conf.line[j][0], rect[1] + conf.line[j][1]]);
  55. else if (j == conf.line.length - 1)
  56. path.push([ 'L', conf.left + (conf.width ? conf.width : rect[0]) - conf.line[j][0], rect[1] + conf.line[j][1] ]);
  57. else
  58. path.push([ 'L', rect[0] - conf.line[j][0], rect[1] + conf.line[j][1]]);
  59. }
  60. common.showPath(env, path).attr(conf.lineProps);
  61. }
  62. }
  63. }
  64. $.elycharts.featuresmanager.register($.elycharts.balloonmanager, 30);
  65. })(jQuery);