def expand_palette()

in chartify/_core/colors.py [0:0]


    def expand_palette(self, target_color_count):
        """Linearly expand the color palette up to the target color count."""
        palette_color_count = len(self.colors)
        if target_color_count <= palette_color_count:
            return self
        target_color_count = target_color_count - 1
        extrapolation_count = [target_color_count // (palette_color_count - 1)] * (palette_color_count - 1)
        for i in range(target_color_count % (palette_color_count - 1)):
            extrapolation_count[i] += 1

        extrapolated_palette = []
        for i, count in enumerate(extrapolation_count):
            extrapolated_palette.extend(self.colors[i].linear_gradient(self.colors[i + 1], count + 1)[:-1])
        extrapolated_palette.extend([self.colors[-1]])

        return ColorPalette.from_hex_list(colors=extrapolated_palette, palette_type=self.palette_type, name=self.name)