128

I have been searching for some material that describes how to generate simple class diagrams with doxygen, but couldn't find one. Can anybody help?

I need to create diagrams as shown below from a set of C++ files. alt text

If there are better tools to achieve this easier, please let me know.

softwarematter
  • 28,015
  • 64
  • 169
  • 263
  • did you achieve diagrams like this including info about attribute and method types? – IzZy Aug 28 '20 at 14:44

6 Answers6

81

Hmm, this seems to be a bit of an old question, but since I've been messing about with Doxygen configuration last few days, while my head's still full of current info let's have a stab at it -

I think the previous answers almost have it:

The missing option is to add COLLABORATION_GRAPH = YES in the Doxyfile. I assume you can do the equivalent thing somewhere in the doxywizard GUI (I don't use doxywizard).

So, as a more complete example, typical "Doxyfile" options related to UML output that I tend to use are:

EXTRACT_ALL          = YES
CLASS_DIAGRAMS      = YES
HIDE_UNDOC_RELATIONS = NO
HAVE_DOT             = YES
CLASS_GRAPH          = YES
COLLABORATION_GRAPH  = YES
UML_LOOK             = YES
UML_LIMIT_NUM_FIELDS = 50
TEMPLATE_RELATIONS   = YES
DOT_GRAPH_MAX_NODES  = 100
MAX_DOT_GRAPH_DEPTH  = 0
DOT_TRANSPARENT      = YES

These settings will generate both "inheritance" (CLASS_GRAPH=YES) and "collaboration" (COLLABORATION_GRAPH=YES) diagrams.

Depending on your target for "deployment" of the doxygen output, setting DOT_IMAGE_FORMAT = svg may also be of use. With svg output the diagrams are "scalable" instead of the fixed resolution of bitmap formats such as .png. Apparently, if viewing the output in browsers other than IE, there is also INTERACTIVE_SVG = YES which will allow "interactive zooming and panning" of the generated svg diagrams. I did try this some time ago, and the svg output was very visually attractive, but at the time, browser support for svg was still a bit inconsistent, so hopefully that situation may have improved lately.

As other comments have mentioned, some of these settings (DOT_GRAPH_MAX_NODES in particular) do have potential performance impacts, so YMMV.

I tend to hate "RTFM" style answers, so apologies for this sentence, but in this case the Doxygen documentation really is your friend, so check out the Doxygen docs on the above mentioned settings- last time I looked you can find the details at http://www.doxygen.nl/manual/config.html.

albert
  • 8,285
  • 3
  • 19
  • 32
user6092647
  • 1,031
  • 9
  • 8
  • Good answer. In your answer you wrote "CLASS _DIAGRAMS" instead if "CLASS_GRAPH". – DavidS Jul 13 '16 at 12:38
  • Hmm, actually, now you bring it up, I see I have both CLASS_DIAGRAMS = YES and CLASS_GRAPH= YES. After checking the docs for Doxygen 1.8.9.1 I found that actually CLASS_GRAPH = YES will override CLASS_DIAGRAMS = YES so the two options interact, with CLASS_GRAPH = YES taking precedence. So, actually, for the purposes of the original question what I have will work, nevertheless good catch ! – user6092647 Jul 14 '16 at 02:07
  • 1
    you can also change the OUTPUT_DIRECTORY and allow RECURSIVE search –  Aug 09 '17 at 12:38
  • 1
    You may also need to change the `RECURSIVE` filed to YES – prehistoricpenguin Jul 15 '20 at 11:12
  • This helped. But in addition, one more change might be needed: Use a full path for DOT_PATH (e.g. C:\program files\Graphwiz2.20\bin). I got this from http://doxygen.10944.n7.nabble.com/I-can-t-generate-class-graph-with-dot-td3461.html – venk Feb 27 '21 at 08:55
  • Depending on needs, all useful comments ! These are individual preferences not mentioned in the original question so they are all things I was referring to when I said "Doxygen documentation really is your friend", but doesn't hurt to point them out here I guess (IMHO). – user6092647 Mar 17 '21 at 07:44
  • I googled and watched some videos. I found that the class diagram generated by Doxygen could not be modified, they are jpgs and alike. – John Apr 20 '22 at 01:38
  • CLASS_DIAGRAM is gone now – mLstudent33 Mar 08 '23 at 14:59
60

Doxygen creates inheritance diagrams but I dont think it will create an entire class hierachy. It does allow you to use the GraphViz tool. If you use the Doxygen GUI frontend tool you will find the relevant options in Step2: -> Wizard tab -> Diagrams. The DOT relation options are under the Expert Tab.

Besi
  • 22,579
  • 24
  • 131
  • 223
DPD
  • 1,734
  • 2
  • 19
  • 26
  • 6
    You will be able to navigate the whole hierarchy, the limits are on what is displayed on a diagram. There are a couple of parameters that limit the scope of the graph. DOT_GRAPH_NODES limits the number of entries on a single page and MAX_DOT_GRAPH_DEPTH restricts how deep it goes. Setting these to large values makes it very time consuming for a large project. – DanS Jan 21 '11 at 08:36
  • Thanks. It worked for me. I have also overridden few options in Expert->Dot – tsenapathy Apr 07 '20 at 19:51
50

Quote from this post (it's written by the author of doxygen himself) :

run doxygen -g and change the following options of the generated Doxyfile:

    EXTRACT_ALL            = YES
    HAVE_DOT               = YES
    UML_LOOK               = YES

run doxygen again
Community
  • 1
  • 1
wsdookadr
  • 2,584
  • 1
  • 21
  • 44
  • 16
    This won't generate a full class diagram (e.g., the many-to-one relationship between class A and class B); only an inheritance diagram, i.e., showing superclass/subclass relationships. – stepthom Feb 27 '15 at 17:05
7

Enterprise Architect will build a UML diagram from imported source code.

zooropa
  • 3,929
  • 8
  • 39
  • 61
  • Upvoted for also answering the question "If there are better tools to achieve this easier, please let me know." – kaveish Aug 12 '16 at 08:50
6

The 2 highest upvoted answers are correct. As of today, the only thing I needed to change (from default settings) was to enable generation using dot instead of the built-in generator.

Some important notes:

  • Doxygen will not generate an actual full diagram of all classes in the project. It will generate a separate image for each hierarchy. If you have multiple, unrelated class hierarchies you will get multiple images.
  • All these diagrams can be found in html/inherits.html or (from the website navigation) classes => class hierarchy => "Go to the textual class hierarchy".
  • This is a C++ question, so let's talk about templates. Especially if you inherit from T.
    • Each template instantiation will be correctly considered a different type by Doxygen. Types which inherit from different instantations will have different parent classes on the diagram.
    • If a class template foo inherits from T and the T template type parameter has a default, such default will be assumed. If there is a type bar which inherits from foo<U> where U is different than the default, bar will have a foo<U> parent. foo<> and bar<U> will not have a common parent.
    • If there are multiple class templates which inherit from at least one of their template parameters, Doxygen will assume a common parent for these class templates as long as the template type parameters have exactly the same names in the code. This incentivizes for consistency in naming.
    • CRTP and reverse CRTP just work.
    • Recursive template inheritance trees are not expanded. Any variant instantiation will be displayed to inherit from variant<Ts...>.
    • Class templates with no instantiations are being drawn. They will have a <...> string in their name representing type and non-type parameters which did not have defaults.
    • Class template full and partial specializations are also being drawn. Doxygen generates correct graphs if specializations inherit from different types.
Xeverous
  • 973
  • 1
  • 12
  • 25
  • My question is how to create actual full diagram of all classes in the project? @Xeverous –  Jan 26 '22 at 08:06
  • I don't think it's possible. Like I wrote, you get 1 image per hierarchy. – Xeverous Jan 27 '22 at 09:43
  • Do you mean it is not possible with Doxygen or do you mean it is not possible with any kind of software? –  Jan 27 '22 at 11:48
  • The former. It's possible that if you find how to tweak Doxygen and dot you could generate very different images. IIRC Doxygen isn't strictly fixed input-output software and dot can generate almost any type of graph. – Xeverous Jan 28 '22 at 13:33
5

I think you will need to edit the doxys file and set GENERATE_UML (something like that) to true. And you need to have dot/graphviz installed.

fzhou
  • 417
  • 1
  • 4
  • 11