Skip to content

Commit

Permalink
Merge pull request #339 from Carifio24/ifig-named-colormaps
Browse files Browse the repository at this point in the history
Update interactive figure export to account for named colormaps
  • Loading branch information
pkgw authored Oct 24, 2022
2 parents 7f98ad2 + 67396a1 commit 8cf07c2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
13 changes: 11 additions & 2 deletions pywwt/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1371,11 +1371,20 @@ def _serialize_state(self):
state["settings"][wwt_name] = value

if self._uniform_color():
state["settings"]["_colorMap"] = 0
state["settings"]["colorMap"] = 0
state["settings"]["colorMapColumn"] = -1
elif self.cmap.name.lower() in VALID_COLORMAPS:
state["settings"]["colorMap"] = 3
state["settings"]["colorMapperName"] = self.cmap.name
state["settings"]["dynamicColor"] = True
state["settings"]["normalizeColorMap"] = True
state["settings"]["normalizeColorMapMin"] = self.cmap_vmin
state["settings"]["normalizeColorMapMax"] = self.cmap_vmax
state["settings"]["colorMapColumn"] = self.cmap_att
else:
state["settings"]["_colorMap"] = 3
state["settings"]["colorMap"] = 3
state["settings"]["colorMapColumn"] = CMAP_COLUMN_NAME
state["settings"]["dynamicColor"] = False

if self._uniform_size():
state["settings"]["sizeColumn"] = -1
Expand Down
13 changes: 9 additions & 4 deletions pywwt/tests/test_serialization.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

from ..core import BaseWWTWidget
from ..layers import SIZE_COLUMN_NAME, CMAP_COLUMN_NAME
from ..layers import SIZE_COLUMN_NAME

import numpy as np
import os
Expand Down Expand Up @@ -456,7 +456,7 @@ def test_table_setting_serialization():
'markerScale': 'world',
'showFarSide': True,
'sizeColumn': -1,
'_colorMap': 0,
'colorMap': 0,
'colorMapColumn': -1,
'xAxisColumn': '',
'yAxisColumn': '',
Expand All @@ -472,9 +472,14 @@ def test_table_setting_serialization():

expected_settings['sizeColumn'] = SIZE_COLUMN_NAME
expected_settings['pointScaleType'] = 0
expected_settings['colorMapColumn'] = CMAP_COLUMN_NAME
expected_settings['_colorMap'] = 3
expected_settings['colorMapColumn'] = layer.cmap_att
expected_settings['colorMap'] = 3
expected_settings['altUnit'] = 'megaParsecs'
expected_settings['dynamicColor'] = True
expected_settings['colorMapperName'] = 'viridis'
expected_settings["normalizeColorMap"] = True
expected_settings["normalizeColorMapMin"] = layer.cmap_vmin
expected_settings["normalizeColorMapMax"] = layer.cmap_vmax

assert widget.quick_serialize()['layers'][0]['settings'] == expected_settings

Expand Down

0 comments on commit 8cf07c2

Please sign in to comment.