Skip to content

Commit

Permalink
Add org chart generation
Browse files Browse the repository at this point in the history
Using the staff.yaml file and the graphs from
https://developers.google.com/chart/interactive/docs/gallery/orgchart
add a small CLI wrapper to generate a pretty org chart.

This provides a different, and more familliar, view of the staff parts
of the dataset.
  • Loading branch information
deanwilson committed Aug 7, 2019
1 parent b7f4e69 commit fc241e7
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 0 deletions.
64 changes: 64 additions & 0 deletions bin/build-org-chart
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env python3

import argparse

from jinja2 import Environment, FileSystemLoader
from pathlib import PurePath
from yaml import load, SafeLoader


def _inflate_yaml(file_name):
yaml = None

with open(file_name, 'r') as yaml_file:
yaml = yaml_file.read()

inflated_yaml = load(yaml, Loader=SafeLoader)
return inflated_yaml


def load_staff(staff_file):
staff = _inflate_yaml(staff_file)

return staff


def main(args):
staff = load_staff(PurePath(args.data, args.staff))
people = []


for name in staff:
person = staff[name]

if 'manages' in person:
reports = person['manages']

for report in reports:
people.append([report, name, ''])

jinja = Environment(loader=FileSystemLoader('templates'),
trim_blocks=True)

template = jinja.get_template('org-chart.html.j2')
rendered_file = template.render(people=people)

with open(args.output, 'w') as rendered_chart:
rendered_chart.write(rendered_file)


if __name__ == '__main__':

parser = argparse.ArgumentParser(description='Build the organisation chart')

parser.add_argument('--data', type=str, default='data',
help='A directory containing your yaml data files')
parser.add_argument('--output', type=str, default='output/org-chart.html',
help='The file to write the HTML organisation chart to')
parser.add_argument('--staff', type=str, default='staff.yaml',
help='A valid yaml file containing your staff information')

args = parser.parse_args()


main(args)
Binary file added images/rendered-org-chart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions output/org-chart.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<html>
<head>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {packages:["orgchart"]});
google.charts.setOnLoadCallback(drawChart);

function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Name');
data.addColumn('string', 'Manager');
data.addColumn('string', 'ToolTip');

// For each orgchart box, provide the name, manager, and tooltip to show.
data.addRows(
[['Scott Summers', 'Susan Storm', ''], ['Phillip Coulson', 'Susan Storm', ''], ['James Howlett', 'Scott Summers', ''], ['James Proudstar', 'Scott Summers', ''], ['Tabitha Smith', 'Scott Summers', ''], ['Samuel Guthrie', 'Scott Summers', ''], ['Wade Wilson', 'Scott Summers', ''], ['Warren Worthington', 'Scott Summers', ''], ['Jean Grey-Summers', 'Scott Summers', ''], ['Emma Frost', 'Scott Summers', ''], ['Bobbi Morse', 'Phillip Coulson', ''], ['Elena Rodriguez', 'Phillip Coulson', ''], ['Jemma Simmons', 'Phillip Coulson', ''], ['Lance Hunter', 'Phillip Coulson', ''], ['Leo Fitz', 'Phillip Coulson', ''], ['Melinda May', 'Phillip Coulson', ''], ['Piper', 'Melinda May', ''], ['Deke Shaw', 'Jemma Simmons', ''], ['Gaveedra Seven', 'James Howlett', ''], ['Celeste Cuckoo', 'Emma Frost', ''], ['Phoebe Cuckoo', 'Emma Frost', '']]
);

// Create the chart.
var chart = new google.visualization.OrgChart(document.getElementById('chart_div'));
// Draw the chart, setting the allowHtml option to true for the tooltips.
chart.draw(data, {allowHtml:true});
}
</script>
</head>
<body>
<div id="chart_div"></div>
</body>
</html>
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Jinja2==2.10.1
py2neo==4.3.0
pyyaml
29 changes: 29 additions & 0 deletions templates/org-chart.html.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<html>
<head>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {packages:["orgchart"]});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Name');
data.addColumn('string', 'Manager');
data.addColumn('string', 'ToolTip');
// For each orgchart box, provide the name, manager, and tooltip to show.
data.addRows(
{{ people }}
);
// Create the chart.
var chart = new google.visualization.OrgChart(document.getElementById('chart_div'));
// Draw the chart, setting the allowHtml option to true for the tooltips.
chart.draw(data, {allowHtml:true});
}
</script>
</head>
<body>
<div id="chart_div"></div>
</body>
</html>

0 comments on commit fc241e7

Please sign in to comment.