Skip to content

Commit

Permalink
Handle out-of-order graduated renderer ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 5, 2024
1 parent cf38121 commit e9bbb5e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
7 changes: 6 additions & 1 deletion felt/core/fsl_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,12 @@ def graduated_renderer_to_fsl(
converted_symbols = []
range_breaks = []
legend_text = {}
for idx, _range in enumerate(renderer.ranges()):

# we have to sort ranges in ascending order for FSL compatiblity
ranges = renderer.ranges()
ranges.sort(key=lambda r: r.lowerValue())

for idx, _range in enumerate(ranges):
converted_symbol = FslConverter.symbol_to_fsl(_range.symbol(),
context,
layer_opacity)
Expand Down
32 changes: 32 additions & 0 deletions felt/test/test_fsl_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -1951,6 +1951,38 @@ def test_graduated_renderer(self):
'type': 'numeric'}
)

# with out of order ranges
ranges = [
QgsRendererRange(3, 4, line_symbol3.clone(), 'third range'),
QgsRendererRange(1, 2, line_symbol.clone(), 'first range'),
QgsRendererRange(2, 3, line_symbol2.clone(), 'second range'),
]

renderer = QgsGraduatedSymbolRenderer('my_field',
ranges)
self.assertEqual(
FslConverter.vector_renderer_to_fsl(renderer, conversion_context),
{'config': {'numericAttribute': 'my_field',
'steps': [1.0, 2.0, 3.0, 4.0]},
'legend': {'displayName': {'0': 'first range',
'1': 'second range',
'2': 'third range'}},
'style': [{'color': ['rgb(255, 0, 0)', 'rgb(255, 0, 255)',
'rgb(0, 255, 255)'],
'lineCap': 'square',
'lineJoin': 'bevel',
'isClickable': False,
'isHoverable': False,
'size': [1, 23, 26]},
{'color': 'rgb(255, 255, 0)',
'lineCap': 'square',
'lineJoin': 'bevel',
'isClickable': False,
'isHoverable': False,
'size': 19}],
'type': 'numeric'}
)

def test_heatmap_renderer(self):
"""
Test converting heatmap renderers
Expand Down

0 comments on commit e9bbb5e

Please sign in to comment.