Skip to content

Commit

Permalink
Update GradientPalette._create_coefficients to utilize pairwise
Browse files Browse the repository at this point in the history
  • Loading branch information
jrycw committed May 31, 2024
1 parent 8920821 commit fd19eda
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions great_tables/_data_color/palettes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from math import isinf, isnan
from typing import TypedDict

from great_tables._utils import pairwise

from .base import RGBColor, _hex_to_rgb, _html_color


Expand Down Expand Up @@ -155,11 +157,10 @@ def _linspace_to_one(n_steps: int) -> list[float]:
def _create_coefficients(self, cutoffs: list[float], channel: list[int]) -> CoeffSequence:
"""Return coefficients for interpolating between cutoffs on a color channel."""

p_cutoffs = list(zip(cutoffs[:-1], cutoffs[1:]))
p_colors = list(zip(channel[:-1], channel[1:]))

coeffs: list[GradientCoefficients] = []
for (prev_cutoff, crnt_cutoff), (prev_color, crnt_color) in zip(p_cutoffs, p_colors):
for (prev_cutoff, crnt_cutoff), (prev_color, crnt_color) in zip(
pairwise(cutoffs), pairwise(channel)
):
cutoff_diff = crnt_cutoff - prev_cutoff
color_scalar = (crnt_color - prev_color) / cutoff_diff

Expand Down

0 comments on commit fd19eda

Please sign in to comment.