Skip to content

Add user-defined color schemes with color picker UI#6

Merged
martin-raden merged 9 commits into
mainfrom
copilot/color-chooser-implementation
Jul 2, 2026
Merged

Add user-defined color schemes with color picker UI#6
martin-raden merged 9 commits into
mainfrom
copilot/color-chooser-implementation

Conversation

Copilot AI commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Users had no way to customize the colors used in visualizations — all colors (strand coloring, highlighting, background highlighting, subsequence highlighting) were hardcoded throughout the library.

vaRRI.js — Configurable color API

Added a module-level COLORS object with default values, plus setColors() / getColors() in the public API:

// Override one or more colours before rendering
vaRRI.setColors({
  sequence1: '#0077bb',
  sequence2: '#ee7733',
  intermolecularHighlight: '#009988',
  backgroundHighlight: '#cc3311',
  subsequenceHighlight: '#aa3377',
});

// Inspect current settings
const current = vaRRI.getColors();

All five color keys (sequence1, sequence2, intermolecularHighlight, backgroundHighlight, subsequenceHighlight) have existing defaults preserved, so existing usage is unaffected. Updated functions: sequenceColoring, colorLabelRed, highlightingRegion, highlightingBasepairs, backgroundhighlightingBasepairs, backgroundhighlightingRegion, highlightSubsequence.

index.html — Color picker legend

  • Replaced static color swatches in the legend with <input type="color"> elements styled to match the existing swatch shapes (circular / rectangular).
  • Each picker initializes to the library default.
  • On change, applyColors() reads all pickers → calls vaRRI.setColors() → re-renders. Uses onchange (not oninput) to avoid continuous re-renders while dragging.
  • runVisualization() also calls applyColors() on every run to keep picker state and library state in sync.

Tests

Added 9 tests covering getColors/setColors: default values, copy isolation, partial and multi-key overrides, effect on sequenceColoring, and state restoration after reset.

Copilot AI linked an issue Jul 2, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Enable user defined color schemes in varri.js library Add user-defined color schemes with color picker UI Jul 2, 2026
Copilot AI requested a review from martin-raden July 2, 2026 08:32
@martin-raden

Copy link
Copy Markdown
Member

@copilot

  • replace in the legend "G-U basepair (dashed)" with "base pair" and replace the associated dashed line with a colored bar (similar to "Background highlight") in the base pair color (currently red as default)
  • make the new colored bar a color chooser for base pair color
  • add the option to chose a base pair color to the JS lib and connect it with the introduced color choser for base pair color

Copilot AI commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

@copilot

  • replace in the legend "G-U basepair (dashed)" with "base pair" and replace the associated dashed line with a colored bar (similar to "Background highlight") in the base pair color (curr...

Done in commit Add basepair color: COLORS.basepair key, color picker in legend, tests.

  • Added basepair key to the COLORS object in vaRRI.js (default 'red').
  • visualiseBasepairStrength now sets stroke to COLORS.basepair on all basepair links (G-U dashed styling is preserved on top of the color).
  • Replaced the static dashed-line legend entry ("G-U basepair (dashed)") with a rectangular <input type="color"> picker (id color-basepair, default #ff0000) labeled "Base pair", styled the same way as the "Background highlight" swatch.
  • applyColors() now passes the picker value as the basepair color to vaRRI.setColors().
  • Tests updated: new key present in getColors result, default is 'red', and setColors({basepair: …}) works correctly (102/102 pass).

@martin-raden

Copy link
Copy Markdown
Member

@copilot BUG: the base pair color in the visualization is not changed when using the base pair color chooser

Copilot AI commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

@copilot BUG: the base pair color in the visualization is not changed when using the base pair color chooser

Fixed in the latest commit. The root cause was CSS specificity: the Fornac stylesheet has line.fornac-link[link_type="basepair"] { stroke: red; }, which always overrides SVG presentation attributes set via setAttribute('stroke', ...). Changed visualiseBasepairStrength to use link.style.stroke = COLORS.basepair (inline style) instead, which has higher priority in the CSS cascade and correctly reflects the chosen color.

Comment thread src/vaRRI.js Outdated
*
* @param {number} targetIndex
*/
function colorLabelRed(targetIndex) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot rename function and all occurrences to highlightLabel

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done — colorLabelRed renamed to highlightLabel at all occurrences in the latest commit.

Comment thread src/vaRRI.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to highlightRegion and update all usages

Comment thread src/vaRRI.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to highlightBasepairs and update all usages

Comment thread src/vaRRI.js Outdated
*
* @param {Object} v Validated parameter dictionary.
*/
function visualiseBasepairStrength(v) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to styleBasepairs and update all occurrences

Comment thread index.html Outdated
<div class="legend-grid">
<div class="legend-item">
<div class="swatch" style="background:lightblue;"></div>
<input type="color" id="color-seq1" class="legend-color" value="#add8e6"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

read and set all default color values of all color choosers from the varri.js COLORS object

Copilot AI requested a review from martin-raden July 2, 2026 11:49
@martin-raden

Copy link
Copy Markdown
Member

@copilot implement all requested changes from the review

Copilot AI commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

@copilot implement all requested changes from the review

All four review requests are addressed in the latest commit:

  • highlightingRegionhighlightRegion (all call sites + exports updated)
  • highlightingBasepairshighlightBasepairs (all call sites + exports updated)
  • visualiseBasepairStrengthstyleBasepairs (all call sites + exports updated)
  • Color pickers now read initial values from vaRRI.getColors() via initColorPickers() (canvas-based CSS→hex conversion), removing the hardcoded hex values from the HTML

Comment thread src/vaRRI.js Outdated
// G-U basepair strength
if (v.guBasepairs) {
visualiseBasepairStrength(v);
styleBasepairs(v);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot move the surrounding if-statement into "styleBasepairs" and check within the function how GU base pairs should be styled (if v.guBasepairs is true, use dashed style, otherwise normal solid style)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in commit Refactor styleBasepairs: move guBasepairs check inside function. The surrounding if (v.guBasepairs) guard has been moved inside styleBasepairs. The function is now called unconditionally and handles both cases internally: when v.guBasepairs is true, G-U pairs get dashed styling while all others get solid; when false, all basepairs use solid styling. The basepair color is always applied regardless.

Copilot AI requested a review from martin-raden July 2, 2026 12:01
@martin-raden
martin-raden marked this pull request as ready for review July 2, 2026 12:23
@martin-raden
martin-raden merged commit 747dcbd into main Jul 2, 2026
1 check passed
@martin-raden
martin-raden deleted the copilot/color-chooser-implementation branch July 2, 2026 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

color chooser

2 participants