tiling.pyramid.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**
  2. * DevExtreme (viz/funnel/tiling.pyramid.js)
  3. * Version: 19.1.16
  4. * Build date: Tue Oct 18 2022
  5. *
  6. * Copyright (c) 2012 - 2022 Developer Express Inc. ALL RIGHTS RESERVED
  7. * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
  8. */
  9. "use strict";
  10. var CENTER = .5;
  11. var LEFTCORNER = 0;
  12. var RIGHTCORNER = 1;
  13. module.exports = {
  14. getFigures: function(data, neckWidth, neckHeight) {
  15. var height = 0;
  16. var y = 0;
  17. var x = 0;
  18. var offsetX = 0;
  19. var halfNeckWidth = neckWidth / 2;
  20. var offsetFromCorner = CENTER - halfNeckWidth;
  21. var funnelHeight = 1 - neckHeight;
  22. var neckLeftCorner = CENTER - halfNeckWidth;
  23. var neckRightCorner = CENTER + halfNeckWidth;
  24. return data.map(function(value) {
  25. x = offsetX;
  26. y = height;
  27. height += value;
  28. offsetX = offsetFromCorner * height / funnelHeight;
  29. if (y <= funnelHeight && height <= funnelHeight) {
  30. return [x, y, RIGHTCORNER - x, y, RIGHTCORNER - offsetX, height, LEFTCORNER + offsetX, height]
  31. } else {
  32. if (y <= funnelHeight && height > funnelHeight) {
  33. return [x, y, RIGHTCORNER - x, y, neckRightCorner, funnelHeight, neckRightCorner, height, neckLeftCorner, height, neckLeftCorner, funnelHeight]
  34. } else {
  35. return [neckLeftCorner, y, neckRightCorner, y, neckRightCorner, height, neckLeftCorner, height]
  36. }
  37. }
  38. })
  39. },
  40. normalizeValues: function(items) {
  41. var sum = items.reduce(function(sum, item) {
  42. return sum + item.value
  43. }, 0);
  44. return items.map(function(item) {
  45. return item.value / sum
  46. })
  47. }
  48. };