Generate PlantUML diagrams based on JOII-classes
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
vendor
demostuff.js
index.html
readme.md

readme.md

JOII Diagram Generator

This is a plugin for JOII: https://github.com/haroldiedema/joii

This plugin allows you to generate class diagrams for JOII-based classes. At this moment, it only supports PlantUML. More types may be added by (pull-) request if you wish to see more diagram types implemented.

Example diagram: Example Diagram

Requirements

This plugin requires JOII 2.2. Starting from this version, it's possible to create plugins that register themselves inside the JOII-namespace.

Basic usage

var diagram = new JoiiDiagram([
    SomeNamespace.MyClass1, 
    SomeNamespace.MyClass2
], {
    "Application": SomeNamespace
})

var src = diagram.getPlantUML();
// Use the value of 'src' on http://www.plantuml.com/plantuml/ to see the result in action.

The JoiiDiagram class accepts 2 parameters: A list of classes and a key/value pair of namespaces. Because there is no way to find out the name of a class in a graceful way, you specify a namespace which will be scanned for objects that are exactly the same as the ones you provided in the class list. If the plugin is unable to associate a name with your class, the name "Anonymous" will be used, suffixed with an index number.

Be aware though that this can have some strange behaviour when using namespaces, since the plugin can't associate your class to something it already processed when scanning object inheritance or interface implementations. I hope to fix this in a future release.

Adding relations

You can add relations by using the addRelation method. This method accepts 5 parameters of which 3 are optional:

  • class_a FQN of class_a. eg.: My.Namespace.FooClass
  • class_b FQN of class_b. eg.: My.Namespace.BarClass
  • relation_type optional. see PlantUML arrow types, leave blank for default arrow
  • count_a optional. How many of class_a fit in class_b ?
  • count_b optional. How many of class_b fit in class_a ?

In the image above, the relation between UserProvider and the AuthenticationManager is one of these extra relations. The same goes for the relation between the User and UserProvider. The rest is done automatically.

var diagram = new JoiiDiagram([
    SomeNamespace.MyClass1, 
    SomeNamespace.MyClass2
], {
    "Application": SomeNamespace
});

// Add custom relations.
diagram.addRelation('SomeClass', 'SomeNamespace.MyClass1')
       .addRelation('SomeNamespace.MyClass1', 'SomeNamespace.MyClass2', '-|>', '*', '1');

// Grab the source.
var src = diagram.getPlantUML();

Hint: All methods are chainable.

Public API

When a Public API is defined within a class, the diagram will show the methods defined in the Public API as "public" while keeping the remaining properties shown as "private" as they are not accessible from the outside world. This behavior does not apply for parent classes, as public API's are only applicable for calls made from outside the class scope.

For a usage example of the way Public API works, please check out http://joii.zone/documentation/classes (bottom of the page).

Please note...

This is the initial version of this plugin. More functionality will be added in the near future. However, the way this plugin works right now will remain as-is. Feel free to start using it, stay tuned for shiny additions.