plain_data_source.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * DevExtreme (viz/tree_map/plain_data_source.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 proto = require("./tree_map.base").prototype;
  11. proto._optionChangesMap.idField = proto._optionChangesMap.parentField = "NODES_CREATE";
  12. proto._processDataSourceItems = function(items) {
  13. var i;
  14. var struct = {};
  15. var currentItem;
  16. var idField = this._getOption("idField", true);
  17. var parentField = this._getOption("parentField", true);
  18. var parentId;
  19. var rootNodes = [];
  20. var tmpItems;
  21. var item;
  22. if (!idField || !parentField || 0 === items.length) {
  23. return {
  24. items: items,
  25. isPlain: true
  26. }
  27. }
  28. for (i = 0; i < items.length; i++) {
  29. currentItem = items[i];
  30. parentId = currentItem[parentField];
  31. if (parentId) {
  32. struct[parentId] = struct[parentId] || {
  33. items: []
  34. };
  35. tmpItems = struct[parentId].items
  36. } else {
  37. tmpItems = rootNodes
  38. }
  39. tmpItems.push(currentItem)
  40. }
  41. treeFiller({
  42. struct: struct,
  43. idField: idField
  44. }, rootNodes);
  45. for (item in struct) {
  46. struct[item] && rootNodes.push(struct[item])
  47. }
  48. return {
  49. items: rootNodes,
  50. isPlain: true
  51. }
  52. };
  53. function treeFiller(context, items) {
  54. var currentItem;
  55. var i;
  56. var struct = context.struct;
  57. var id;
  58. for (i = 0; i < items.length; i++) {
  59. currentItem = items[i];
  60. id = currentItem[context.idField];
  61. if (struct[id]) {
  62. currentItem.items = struct[id].items;
  63. struct[id] = null;
  64. treeFiller(context, currentItem.items)
  65. }
  66. }
  67. }