/samples/unit-tests/exporting/sourcewidth/demo.js

https://github.com/aadrian/highcharts.com · JavaScript · 120 lines · 107 code · 10 blank · 3 comment · 2 complexity · e5d952b2754bf313b7ded536d82b84eb MD5 · raw file

  1. QUnit.skip('Exported chart sourceWidth and sourceHeight', function (assert) {
  2. var chart = Highcharts.chart('container', {
  3. title: {
  4. text: 'Highcharts sourceWidth and sourceHeight demo'
  5. },
  6. subtitle: {
  7. text:
  8. 'The on-screen chart is 600x400.<br/>The exported chart is 800x400<br/>(sourceWidth and sourceHeight multiplied by scale)',
  9. floating: true,
  10. align: 'left',
  11. x: 60,
  12. y: 50
  13. },
  14. xAxis: {
  15. categories: [
  16. 'Jan',
  17. 'Feb',
  18. 'Mar',
  19. 'Apr',
  20. 'May',
  21. 'Jun',
  22. 'Jul',
  23. 'Aug',
  24. 'Sep',
  25. 'Oct',
  26. 'Nov',
  27. 'Dec'
  28. ]
  29. },
  30. series: [
  31. {
  32. data: [
  33. 29.9,
  34. 71.5,
  35. 106.4,
  36. 129.2,
  37. 144.0,
  38. 176.0,
  39. 135.6,
  40. 148.5,
  41. 216.4,
  42. 194.1,
  43. 95.6,
  44. 54.4
  45. ]
  46. }
  47. ],
  48. exporting: {
  49. sourceWidth: 400,
  50. sourceHeight: 200,
  51. // scale: 2 (default)
  52. chartOptions: {
  53. subtitle: null
  54. }
  55. }
  56. }),
  57. done = assert.async();
  58. var originalPost = Highcharts.HttpUtilities.post;
  59. Highcharts.HttpUtilities.post = function (url, data) {
  60. function serialize(obj) {
  61. var str = [];
  62. for (var p in obj) {
  63. if (Object.hasOwnProperty.call(obj, p)) {
  64. str.push(
  65. encodeURIComponent(p) + '=' + encodeURIComponent(obj[p])
  66. );
  67. }
  68. }
  69. return str.join('&');
  70. }
  71. data.async = true;
  72. $.ajax({
  73. type: 'POST',
  74. data: serialize(data),
  75. url: url,
  76. success: function (result) {
  77. var img = new Image();
  78. img.src = url + result;
  79. img.onload = function () {
  80. // Since the default scale is 2 and the sourceWidth is 400, we
  81. // expect the exported width to be 800px.
  82. assert.strictEqual(
  83. this.width,
  84. 800,
  85. 'Generated image width is 800px'
  86. );
  87. assert.strictEqual(
  88. this.height,
  89. 400,
  90. 'Generated image height is 400px'
  91. );
  92. document.body.appendChild(img);
  93. Highcharts.HttpUtilities.post = originalPost;
  94. done();
  95. };
  96. },
  97. error: function () {
  98. Highcharts.HttpUtilities.post = originalPost;
  99. console.log(
  100. assert.test.testName,
  101. 'Export server XHR error or timeout'
  102. );
  103. assert.expect(0);
  104. done();
  105. },
  106. timeout: 1000
  107. });
  108. };
  109. chart.exportChart();
  110. });