Skip to content

Commit a557bec

Browse files
committed
Update D3SpectrumDisplayDiv to better match how the underlying JS and CSS handle color setting.
Made setting the spectrum colors according to the color theme a application wide function (since it used global CSS variables anyway), and changed the color setting functions to be overrides of the color theme. Movedhandling the global CSS rules to InterSpecApp, since we will probably also use it for other elements in the future.
1 parent 814963d commit a557bec

File tree

9 files changed

+369
-193
lines changed

9 files changed

+369
-193
lines changed

InterSpec/D3SpectrumDisplayDiv.h

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -160,29 +160,32 @@ class D3SpectrumDisplayDiv : public Wt::WContainerWidget
160160
void scheduleUpdateSecondData();
161161

162162

163-
/** Schedules the foreground peaks to be re-loaded to the client during the
164-
next call to #render (which Wt takes care of calling); this function is called by the PeakModel.
165-
*/
166-
void scheduleForegroundPeakRedraw();
167-
168-
/** Schedules peak redraw for the given spectrum.
169-
170-
TODO: As of 20250802, only foreground spectrum has any effect.
163+
/** Schedules the peaks to be re-loaded to the client, for the specified spectrum, during the
164+
next call to #render (which Wt takes care of calling).
171165
*/
172166
void schedulePeakRedraw( const SpecUtils::SpectrumType spectrum_type );
173167

174-
/** Applies the current color theme.
175-
if nullptr, then sets to default colors.
168+
/** Applies the color theme globally to all D3SpectrumDisplayDiv instances in the current app.
169+
Should be called once when the color theme changes, typically from InterSpec::applyColorTheme().
170+
If nullptr, then sets to default colors.
171+
172+
Uses InterSpecApp::setGlobalD3SpectrumCssRule() to track the global CSS rules per app instance.
176173
*/
177-
void applyColorTheme( std::shared_ptr<const ColorTheme> theme );
178-
179-
void setForegroundSpectrumColor( const Wt::WColor &color );
180-
void setBackgroundSpectrumColor( const Wt::WColor &color );
181-
void setSecondarySpectrumColor( const Wt::WColor &color );
182-
void setTextColor( const Wt::WColor &color );
183-
void setAxisLineColor( const Wt::WColor &color );
184-
void setChartMarginColor( const Wt::WColor &color );
185-
void setChartBackgroundColor( const Wt::WColor &color );
174+
static void applyColorTheme( std::shared_ptr<const ColorTheme> theme );
175+
176+
/** Updates the default peak color for this specific instance based on the color theme.
177+
This is needed because peak color is passed in JSON, not via CSS variables.
178+
Also updates peak label size/rotation and log Y-axis min from theme.
179+
*/
180+
void updateDefaultPeakColorForColorTheme( std::shared_ptr<const ColorTheme> theme );
181+
182+
void overrideForegroundSpectrumColor( const Wt::WColor &color );
183+
void overrideBackgroundSpectrumColor( const Wt::WColor &color );
184+
void overrideSecondarySpectrumColor( const Wt::WColor &color );
185+
void overrideTextColor( const Wt::WColor &color );
186+
void overrideAxisLineColor( const Wt::WColor &color );
187+
void overrideChartMarginColor( const Wt::WColor &color );
188+
void overrideChartBackgroundColor( const Wt::WColor &color );
186189
void setDefaultPeakColor( const Wt::WColor &color );
187190

188191
/** Sets the charts font size.
@@ -467,12 +470,6 @@ class D3SpectrumDisplayDiv : public Wt::WContainerWidget
467470
/** Sets the highlight regions to client - currently unimplemented. */
468471
void setHighlightRegionsToClient();
469472

470-
void setForegroundPeaksToClient();
471-
472-
void setSecondaryPeaksToClient();
473-
474-
void setBackgroundPeaksToClient();
475-
476473
void setReferenceLinesToClient();
477474

478475
protected:
@@ -500,7 +497,6 @@ class D3SpectrumDisplayDiv : public Wt::WContainerWidget
500497

501498
UpdateDynamicRefLines = 0x80,
502499

503-
// TODO: Currently background and secondary peaks not loaded to client, so these flags have no effect.
504500
UpdateBackgroundPeaks = 0x0100,
505501
UpdateSecondaryPeaks = 0x0200,
506502
//ToDo: maybe add a few other things to this mechanism.
@@ -694,13 +690,17 @@ class D3SpectrumDisplayDiv : public Wt::WContainerWidget
694690
*/
695691
int m_comptonPeakAngle;
696692

697-
Wt::WColor m_foregroundLineColor;
698-
Wt::WColor m_backgroundLineColor;
699-
Wt::WColor m_secondaryLineColor;
700-
Wt::WColor m_textColor;
701-
Wt::WColor m_axisColor;
702-
Wt::WColor m_chartMarginColor;
703-
Wt::WColor m_chartBackgroundColor;
693+
// Member variables for instance-specific color overrides
694+
// When default (isDefault() == true), the global CSS variable from the theme is used
695+
Wt::WColor m_foregroundLineColorOverride;
696+
Wt::WColor m_backgroundLineColorOverride;
697+
Wt::WColor m_secondaryLineColorOverride;
698+
Wt::WColor m_textColorOverride;
699+
Wt::WColor m_axisColorOverride;
700+
Wt::WColor m_chartMarginColorOverride;
701+
Wt::WColor m_chartBackgroundColorOverride;
702+
703+
// Default peak color - used directly in JSON, not via CSS
704704
Wt::WColor m_defaultPeakColor;
705705

706706
std::string m_peakLabelFontSize;

InterSpec/InterSpecApp.h

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#include "InterSpec_config.h"
2727

28+
#include <map>
2829
#include <set>
2930
#include <mutex>
3031
#include <chrono>
@@ -43,6 +44,7 @@ namespace Wt
4344
class WText;
4445
class WGridLayout;
4546
class WPushButton;
47+
class WCssTextRule;
4648
}//namespace Wt
4749

4850
class PopupDivMenuItem;
@@ -238,7 +240,27 @@ class InterSpec_API InterSpecApp : public Wt::WApplication
238240
the list of the capture group.
239241
*/
240242
static const std::set<std::string> &languagesAvailable();
241-
243+
244+
/** Sets or replaces a global CSS rule for this app instance.
245+
Used by various components to manage global theme colors and styles.
246+
247+
@param rulename Unique name for the CSS rule
248+
@param selector CSS selector (e.g., ":root")
249+
@param declarations CSS declarations (e.g., "--d3spec-fore-line-color: rgb(0,0,0);")
250+
251+
If a rule with the same name already exists, it will be removed before adding the new one.
252+
*/
253+
void setGlobalCssRule( const std::string &rulename,
254+
const std::string &selector,
255+
const std::string &declarations );
256+
257+
/** Removes a global CSS rule for this app instance.
258+
259+
@param rulename Name of the CSS rule to remove
260+
@returns true if the rule was found and removed, false if it didn't exist
261+
*/
262+
bool removeGlobalCssRule( const std::string &rulename );
263+
242264
protected:
243265

244266
//notify(): over-riding WApplication::notify in order to catch any exceptions
@@ -369,7 +391,12 @@ class InterSpec_API InterSpecApp : public Wt::WApplication
369391
/** CSS px values for areas on iPhoneX's like the notch or bottom bar. */
370392
float m_safeAreas[4];
371393
#endif
372-
394+
395+
/** Map of global D3 spectrum CSS rules for this app instance.
396+
Used to manage global theme colors that apply to all D3SpectrumDisplayDiv instances.
397+
*/
398+
std::map<std::string, Wt::WCssTextRule*> m_globalD3SpectrumCssRules;
399+
373400
friend class InterSpec;
374401
#if( INCLUDE_ANALYSIS_TEST_SUITE )
375402
friend class SpectrumViewerTester;

0 commit comments

Comments
 (0)