コード例 #1
0
 def parse_specs(self, state):
     """Parse colorbar specifications from application state"""
     if isinstance(state, dict):
         state = forest.state.State.from_dict(state)
     if forest.data.FEATURE_FLAGS["multiple_colorbars"]:
         specs = []
         for _, settings in sorted(state.layers.index.items()):
             if "colorbar" in settings:
                 spec = parse_color_spec(settings["colorbar"])
                 specs.append(spec)
     else:
         specs = [parse_color_spec(state.colorbar.to_dict())]
     return specs
コード例 #2
0
    def render(self, state):
        """Query state for color_mapper settings"""
        layers = state.get("layers", {}).get("index", {})
        specs = []
        for _, settings in sorted(layers.items()):
            if "colorbar" in settings:
                spec = parse_color_spec(settings["colorbar"])
                specs.append(spec)

        # Balance number of color_mappers
        missing = len(specs) - len(self.color_mappers)
        if missing > 0:
            for _ in range(missing):
                figure, color_mapper = self.make_colorbar()
                self.color_mappers.append(color_mapper)
                self.figures.append(figure)

        # Add/reuse figures and color_mappers
        for i, spec in enumerate(specs):
            spec.apply(self.color_mappers[i])

        # Update layout
        self.layout.children = self.figures[:len(specs)]
コード例 #3
0
 def render(self, state):
     if "colorbar" in state:
         spec = colors.parse_color_spec(state["colorbar"])
         spec.apply(self.color_mapper)
コード例 #4
0
def test_parse_color_spec(given, expect):
    assert colors.parse_color_spec(given) == expect