-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
b7f4e69
commit fc241e7
Showing
5 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
Jinja2==2.10.1 | ||
py2neo==4.3.0 | ||
pyyaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |