burn.ui.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. window.randTipInfo = function(rowDatas)
  2. {
  3. let tipHtml = burnBy == 'storyPoint' ? `<p>${rowDatas[0].name} ${storyPoint} /sp</p>` : `<p>${rowDatas[0].name} ${workHour} /h</p>`;
  4. rowDatas.forEach(rowData =>
  5. {
  6. if(rowData.data == 'null') return;
  7. tipHtml += `<div><span style="background: ${rowData.color}; height: 10px; width: 10px; display: inline-block; margin-right: 10px;"></span>${rowData.seriesName} ${rowData.data}</div>`;
  8. });
  9. return tipHtml;
  10. }
  11. $(document).on('change', '#burnBy', function()
  12. {
  13. $.cookie.set('burnBy', $('input[name=burnBy]').val(), {expires:config.cookieLife, path:config.webRoot});
  14. let interval = typeof($('input[name=interval]').val()) == 'undefined' ? 0 : $('input[name=interval]').val() ;
  15. loadPage($.createLink('execution', 'burn', 'executionID=' + executionID + '&type=' + type + '&interval=' + interval + '&burnBy=' + $('input[name=burnBy]').val()));
  16. });
  17. $(document).off('change', '#interval').on('change', '#interval', function()
  18. {
  19. loadPage($.createLink('execution', 'burn', 'executionID=' + executionID + '&type=' + type + '&interval=' + $('input[name=interval]').val()));
  20. });
  21. /* Save burn as image.*/
  22. window.downloadBurn = function()
  23. {
  24. let $canvas = $('#burnPanel canvas');
  25. $('#burnPanel').append("<div class='hidden' id='cloneCanvas'></div>");
  26. $('#cloneCanvas').append($canvas.clone());
  27. $('#cloneCanvas').append("<img id='cloneImage' />");
  28. $('#cloneCanvas #cloneImage').attr('src', $canvas.get(0).toDataURL("image/png"));
  29. setTimeout(function()
  30. {
  31. /* Add watermark */
  32. var canvas = document.querySelector('#cloneCanvas canvas');
  33. var cans = canvas.getContext('2d');
  34. canvas.height = canvas.height + 25;
  35. canvas.width = canvas.width + 50;
  36. // Set background color to white
  37. cans.fillStyle = '#fff';
  38. cans.fillRect(0, 0, canvas.width, canvas.height);
  39. cans.drawImage($('#cloneCanvas #cloneImage').get(0), 0, 25);
  40. cans.font = "16px Microsoft JhengHei";
  41. cans.fillStyle = "rgba(17, 17, 17, 0.50)";
  42. cans.textAlign = 'left';
  43. cans.textBaseline = 'Middle';
  44. cans.fillText(watermark, 50, canvas.height - 50);
  45. cans.fillText(burnYUnit, 0, 20);
  46. cans.fillText(burnXUnit, canvas.width - 50, canvas.height - 15);
  47. var type = 'png';
  48. var $canvas = $('#cloneCanvas canvas');
  49. var imgSrc = $canvas.get(0).toDataURL("image/png");
  50. var imgData = imgSrc.replace(type,'image/octet-stream');
  51. var filename = executionName + '.' + type;
  52. saveFile(imgData,filename);
  53. $('#burnPanel #cloneCanvas').remove();
  54. }, 500);
  55. }
  56. var saveFile = function(data, filename)
  57. {
  58. var saveLink = document.createElement('a');
  59. saveLink.href = data;
  60. saveLink.download = filename;
  61. var event = document.createEvent('MouseEvents');
  62. event.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
  63. saveLink.dispatchEvent(event);
  64. };