Skip to content

Commit d7581da

Browse files
committed
Fix widget JSON when measure is not "value"
Previous change 14aa45b was incomplete, but it happened to work when there was still a measure called "value" defined (which is what happens by default).
1 parent 1b2c66a commit d7581da

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

floweaver/sankey_data.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ class SankeyLink(object):
177177
target = attr.ib(validator=attr.validators.optional(attr.validators.instance_of(str)))
178178
type = attr.ib(default=None, validator=_validate_opt_str)
179179
time = attr.ib(default=None, validator=_validate_opt_str)
180+
link_width = attr.ib(default=0.0, converter=float)
180181
data = attr.ib(default=lambda: {"value": 0.0})
181182
title = attr.ib(default=None, validator=_validate_opt_str)
182183
color = attr.ib(default=None, validator=_validate_opt_str)
@@ -191,7 +192,7 @@ def to_json(self, format=None):
191192
"target": self.target,
192193
"type": self.type,
193194
"time": self.time,
194-
"value": self.data["value"],
195+
"value": self.link_width,
195196
"title": self.title,
196197
"color": self.color,
197198
"opacity": self.opacity,
@@ -204,6 +205,7 @@ def to_json(self, format=None):
204205
"type": self.type,
205206
"title": self.title,
206207
"time": self.time,
208+
"link_width": self.link_width,
207209
"data": self.data,
208210
"style": {"color": self.color, "opacity": self.opacity,},
209211
}

floweaver/weave.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def make_link(get_value, get_color, v, w, m, t, data):
115115
)
116116
return attr.evolve(
117117
link,
118-
# value=get_value(link, data['measures']),
118+
link_width=get_value(link, data['measures']),
119119
color=get_color(link, data["measures"]),
120120
)
121121

test/test_sankey_data.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,16 @@ def test_sankey_data_link_default_values():
5757

5858

5959
def test_sankey_data_link_json():
60-
link = SankeyLink('a', 'b', type='c', time='d', data={'value': 2}, title='link',
61-
opacity=0.9, color='blue')
60+
link = SankeyLink('a', 'b', type='c', time='d', data={'value': 2},
61+
link_width=3, title='link', opacity=0.9, color='blue')
6262

6363
# draft JSON Sankey serialisation format
6464
assert link.to_json() == {
6565
'source': 'a',
6666
'target': 'b',
6767
'type': 'c',
6868
'time': 'd',
69+
'link_width': 3,
6970
'data': {
7071
'value': 2,
7172
},
@@ -82,7 +83,7 @@ def test_sankey_data_link_json():
8283
'target': 'b',
8384
'type': 'c',
8485
'time': 'd',
85-
'value': 2,
86+
'value': 3,
8687
'data': {
8788
'value': 2,
8889
},

test/test_weave.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ def test_weave_results():
6060

6161
def link(src, tgt, original_flows, value, link_type='*', color='#FBB4AE'):
6262
return SankeyLink(source=src, target=tgt, type=link_type, time='*',
63-
data={'value': value}, title=link_type, color=color,
63+
link_width=value, data={'value': value},
64+
title=link_type, color=color,
6465
original_flows=original_flows)
6566

6667
assert set(n.id for n in result.nodes) == {'a^*', 'b^*', 'via^m', 'via^n', 'c^c1', 'c^c2'}

0 commit comments

Comments
 (0)