You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

JDataBuilder.java 3.4 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. MIT License
  3. Copyright (c) 2018-2019 Gang ZHANG
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in all
  11. copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  18. SOFTWARE.
  19. */
  20. package depends.format.json;
  21. import java.util.ArrayList;
  22. import java.util.Collection;
  23. import java.util.HashMap;
  24. import java.util.List;
  25. import java.util.Map;
  26. import depends.format.FileAttributes;
  27. import depends.matrix.core.DependencyDetail;
  28. import depends.matrix.core.DependencyMatrix;
  29. import depends.matrix.core.DependencyPair;
  30. import depends.matrix.core.DependencyValue;
  31. public class JDataBuilder {
  32. public JDepObject build(DependencyMatrix dependencyMatrix, FileAttributes attribute) {
  33. ArrayList<String> files = dependencyMatrix.getNodes();
  34. Collection<DependencyPair> dependencyPairs = dependencyMatrix.getDependencyPairs();
  35. ArrayList<JCellObject> cellObjects = buildCellObjects(dependencyPairs); // transform finalRes into cellObjects
  36. JDepObject depObject = new JDepObject();
  37. depObject.setVariables(files);
  38. depObject.setName(attribute.getAttributeName());
  39. depObject.setSchemaVersion(attribute.getSchemaVersion());
  40. depObject.setCells(cellObjects);
  41. return depObject;
  42. }
  43. private ArrayList<JCellObject> buildCellObjects(Collection<DependencyPair> dependencyPairs) {
  44. ArrayList<JCellObject> cellObjects = new ArrayList<JCellObject>();
  45. for (DependencyPair dependencyPair : dependencyPairs) {
  46. Map<String, Float> valueObject = buildValueObject(dependencyPair.getDependencies());
  47. List<DetailItem> details = buildDetails(dependencyPair.getDependencies());
  48. JCellObject cellObject = new JCellObject();
  49. cellObject.setSrc(dependencyPair.getFrom());
  50. cellObject.setDest(dependencyPair.getTo());
  51. cellObject.setValues(valueObject);
  52. cellObject.setDetails(details);
  53. cellObjects.add(cellObject);
  54. }
  55. return cellObjects;
  56. }
  57. private List<DetailItem> buildDetails(Collection<DependencyValue> dependencies) {
  58. List<DetailItem> r = new ArrayList<>();
  59. for (DependencyValue dependency : dependencies) {
  60. for (DependencyDetail detail:dependency.getDetails()) {
  61. r.add(new DetailItem(detail.getSrc(),detail.getDest(),dependency.getType()));
  62. }
  63. }
  64. if (r.size()==0) return null;
  65. return r;
  66. }
  67. private Map<String, Float> buildValueObject(Collection<DependencyValue> dependencies) {
  68. Map<String, Float> valueObject = new HashMap<String, Float>();
  69. for (DependencyValue dependency : dependencies) {
  70. valueObject.put(dependency.getType(), (float) dependency.getWeight());
  71. }
  72. return valueObject;
  73. }
  74. }

基于Vue的大屏可视化设计器,前后端一体化解决方案,几十种炫酷图表,支持多种数据来源接入,适用于大屏、低代码、BI场景,使用简单,代码完全开源。

Contributors (2)