Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding crossing minimisation and straightness model #136

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions floweaver/diagram_optimisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ def optimise_position_model(model_inputs, scale, wslb = 1):
m += (y[v] >= y[u] + node_weight[u])

### OBJECTIVE FUNCTION: MINIMISE DEVIATION * FLOW WEIGHT
m.objective = minimize( xsum(s[edge]*edge_weight[edge] for edge in s.keys()) )
m.objective = minimize( xsum(s[edge]*edge_weight[edge]**2 for edge in s.keys()) )

# Run the model and optimise!
status = m.optimize()
Expand All @@ -545,7 +545,7 @@ def optimise_node_positions(sankey_data,
height=None,
margins=None,
scale=None,
minimum_gap=20):
minimum_gap=10):
"""Optimise node positions to maximise straightness.

Returns new version of `sankey_data` with `node_positions` set.
Expand All @@ -571,7 +571,7 @@ def optimise_node_positions(sankey_data,

model = straightness_model(sankey_data)
# FIXME this needs to know what scale we want to use?
ys = optimise_position_model(model, scale, wslb=minimum_gap)
ys = optimise_position_model(model, scale, wslb=minimum_gap*scale)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stratus85 why does the minimum gap need to be scaled? I think it probably makes sense to have this defined in terms of pixels (i.e. the actual gap in the final Sankey diagram)?

ys = {k: y + margins['top'] for k, y in ys.items()}

# Work out appropriate diagram height, if not specified explicitly
Expand Down