Repository navigation
fix(navlayers): interpolate gradient colors between stops - #250
Open
bacescuandrei wants to merge 1 commit into
Open
bacescuandrei wants to merge 1 commit into
bacescuandrei wants to merge 1 commit into
Conversation
Gradient.compute_color() looked scores up in a precomputed curve whose length depended on how evenly the score range divided between the color stops. With four or more colors and a range such as 0-11, scores near the maximum raised IndexError, which aborts Excel and SVG export of the layer. Each segment of the curve also repeated its end color, so intermediate scores took the next stop color early (with stops red, yellow, green over 0-4, a score of 1 was yellow), and a single-color gradient raised ZeroDivisionError. Interpolate linearly in RGB between evenly spaced stops instead, as the ATT&CK Navigator does, and drop the precomputed curve.
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Gradient.compute_color()looks scores up in a precomputed curve. The curve's length depends on how evenlymaxValue - minValuedivides between the color stops. This causes three problems:IndexError. This abortsToExcel.to_xlsx()andToSvg.to_svg()for the whole layer.ZeroDivisionError.This change interpolates linearly in RGB between evenly spaced stops, approximately as the ATT&CK Navigator does. Navigator uses tinygradient's RGB interpolation, quantised to 100 steps, so small differences remain on steep gradients. It also removes the precomputed
curveattribute and_compute_curve. Neither is documented or used elsewhere in the package.Validation:
tests/test_gradient.pywith 13 cases: 9 of them fail on main and all pass with the change.uv run pytest: 310 passed, 4 skipped.ruff checkandruff format --check: clean.#ff0000, #00ff00, #0000ff, #ffffffover 0–11 and T1003 scored 10. On main, bothto_xlsxandto_svgraiseIndexError; with the change, both succeed.