pack.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /**
  2. * @file
  3. * @brief support for connected components
  4. * @ingroup public_apis
  5. *
  6. * **libpack** supports the use of connected components
  7. * in the context of laying out graphs using other graphviz libraries.
  8. * One set of functions can be used to take a single graph and break it
  9. * apart into connected components.
  10. * A complementary set of functions takes a collection of graphs
  11. * (not necessarily components of a single graph) which have been laid
  12. * out separately, and packs them together.
  13. *
  14. * As this library is meant to be used with `libcommon`, it relies on the
  15. * @ref Agraphinfo_t, @ref Agnodeinfo_t and @ref Agedgeinfo_t used in
  16. * that library.
  17. *
  18. * [man 3 libpack](https://graphviz.org/pdf/pack.3.pdf)
  19. *
  20. */
  21. /*************************************************************************
  22. * Copyright (c) 2011 AT&T Intellectual Property
  23. * All rights reserved. This program and the accompanying materials
  24. * are made available under the terms of the Eclipse Public License v1.0
  25. * which accompanies this distribution, and is available at
  26. * https://www.eclipse.org/legal/epl-v10.html
  27. *
  28. * Contributors: Details at https://graphviz.org
  29. *************************************************************************/
  30. #pragma once
  31. #include <stdbool.h>
  32. #include <stddef.h>
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. #include "types.h"
  37. /* Type indicating granularity and method
  38. * l_undef - unspecified
  39. * l_node - polyomino using nodes and edges
  40. * l_clust - polyomino using nodes and edges and top-level clusters
  41. * (assumes ND_clust(n) unused by application)
  42. * l_graph - polyomino using computer graph bounding box
  43. * l_array - array based on graph bounding boxes
  44. * l_aspect - tiling based on graph bounding boxes preserving aspect ratio
  45. * l_hull - polyomino using convex hull (unimplemented)
  46. * l_tile - tiling using graph bounding box (unimplemented)
  47. * l_bisect - alternate bisection using graph bounding box (unimplemented)
  48. */
  49. typedef enum { l_undef, l_clust, l_node, l_graph, l_array, l_aspect } pack_mode;
  50. #define PK_COL_MAJOR (1 << 0)
  51. #define PK_USER_VALS (1 << 1)
  52. #define PK_LEFT_ALIGN (1 << 2)
  53. #define PK_RIGHT_ALIGN (1 << 3)
  54. #define PK_TOP_ALIGN (1 << 4)
  55. #define PK_BOT_ALIGN (1 << 5)
  56. #define PK_INPUT_ORDER (1 << 6)
  57. typedef unsigned int packval_t;
  58. typedef struct {
  59. float aspect; /* desired aspect ratio */
  60. int sz; /* row/column size size */
  61. unsigned int margin; /* margin left around objects, in points */
  62. bool doSplines; ///< use splines in constructing graph shape
  63. pack_mode mode; /* granularity and method */
  64. bool *fixed; /* fixed[i] == true implies g[i] should not be moved */
  65. packval_t* vals; /* for arrays, sort numbers */
  66. int flags;
  67. } pack_info;
  68. #ifdef GVDLL
  69. #ifdef GVC_EXPORTS
  70. #define PACK_API __declspec(dllexport)
  71. #else
  72. #define PACK_API __declspec(dllimport)
  73. #endif
  74. #endif
  75. #ifndef PACK_API
  76. #define PACK_API /* nothing */
  77. #endif
  78. PACK_API pointf *putRects(size_t ng, boxf *bbs, pack_info *pinfo);
  79. PACK_API int packRects(size_t ng, boxf* bbs, pack_info* pinfo);
  80. PACK_API pointf *putGraphs(size_t, Agraph_t **, Agraph_t *, pack_info *);
  81. PACK_API int packGraphs(size_t, Agraph_t **, Agraph_t *, pack_info *);
  82. PACK_API int packSubgraphs(size_t, Agraph_t **, Agraph_t *, pack_info *);
  83. PACK_API int pack_graph(size_t ng, Agraph_t **gs, Agraph_t *root, bool *fixed);
  84. PACK_API int shiftGraphs(size_t, Agraph_t **, pointf *, Agraph_t *, bool);
  85. PACK_API pack_mode getPackMode(Agraph_t * g, pack_mode dflt);
  86. PACK_API int getPack(Agraph_t *, int not_def, int dflt);
  87. PACK_API pack_mode getPackInfo(Agraph_t * g, pack_mode dflt, int dfltMargin, pack_info*);
  88. PACK_API pack_mode getPackModeInfo(Agraph_t * g, pack_mode dflt, pack_info*);
  89. PACK_API pack_mode parsePackModeInfo(const char* p, pack_mode dflt,
  90. pack_info* pinfo);
  91. PACK_API int isConnected(Agraph_t *);
  92. PACK_API Agraph_t **ccomps(Agraph_t *, size_t *, char *);
  93. PACK_API Agraph_t **cccomps(Agraph_t *, size_t *, char *);
  94. PACK_API Agraph_t **pccomps(Agraph_t *, size_t *, char *, bool *);
  95. PACK_API Agraph_t *mapClust(Agraph_t *);
  96. #undef PACK_API
  97. #ifdef __cplusplus
  98. }
  99. #endif