Skip to content

Commit

Permalink
Merge branch 'master' of github.com:sandialabs/InterSpec
Browse files Browse the repository at this point in the history
  • Loading branch information
wcjohns committed Jan 7, 2024
2 parents c77c829 + 209979a commit 7c0ddfe
Show file tree
Hide file tree
Showing 7 changed files with 174 additions and 17 deletions.
5 changes: 5 additions & 0 deletions InterSpec/D3TimeChart.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ class D3TimeChart : public Wt::WContainerWidget
void setNeutronsHidden( const bool hide );
bool neutronsHidden() const;

void setGammaLogY( const bool logy );
bool gammaLogY() const;


void setXAxisRangeSamples( const int min_sample_num, const int max_sample_num );

/** Returns the current user-entered gamma energy range that should be summed to create this gross count chart. */
Expand Down Expand Up @@ -253,6 +257,7 @@ class D3TimeChart : public Wt::WContainerWidget
bool m_showHorizontalLines;
bool m_dontRebin;
bool m_hideNeutrons;
bool m_gammaLogY;

std::shared_ptr<const SpecUtils::SpecFile> m_spec;
std::vector<std::string> m_detectors_to_display;
Expand Down
1 change: 1 addition & 0 deletions InterSpec/ExportSpecFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ class ExportSpecFileTool : public Wt::WContainerWidget
void handleFormatChange();
void handleForePlusBackChanged();
void handleFilterDetectorCbChanged();
void handleDetectorsToFilterChanged();

void handleSumToSingleRecordChanged();
void handleSumTypeToSingleRecordChanged();
Expand Down
2 changes: 1 addition & 1 deletion InterSpec_resources/D3TimeChart.css
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@
}


.D3TimeDontRebin, .D3TimeHideNeutrons {
.D3TimeDontRebin, .D3TimeHideNeutrons, .D3TimeGammaLogY {
margin-top: 5px;
}

Expand Down
68 changes: 59 additions & 9 deletions InterSpec_resources/D3TimeChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ D3TimeChart = function (elem, options) {
|| (this.options.yAxisGammaNeutronRelMaxSf < 0.04)
|| (this.options.yAxisGammaNeutronRelMaxSf > 25) )
this.options.yAxisGammaNeutronRelMaxSf = 1;
if (typeof this.options.gammaLogY !== "boolean") this.options.gammaLogY = false;

/* The dontRebin option makes it so when there are more time samples than pixels, instead of
averaging multiple time samples together, instead the min and max counts from that interval are
Expand Down Expand Up @@ -1634,10 +1635,17 @@ D3TimeChart.prototype.updateChart = function( scales, compressionIndex, options
var yAxisLeft = d3.svg
.axis()
.scale(yScaleGamma)
.ticks(3)
.orient("left")
.tickFormat(d3.format(".1g"));
.orient("left");

// Adjust which/how-many labels is shown
if( this.options.gammaLogY ) {
//yScaleGamma.nice(); //rounds down to next power of 10, and up to next power - its not bad; if we use this then we should remove scaling the domain by a factor of two in `this.getScales(...)`, for log display
yAxisLeft.tickFormat( yScaleGamma.tickFormat(1) );
}else{
yAxisLeft.ticks(3)
.tickFormat(d3.format(".1g"));
}

// update or create axis
this.axisLeftG
.attr("transform", "translate(" + this.margin.left + ",0)")
Expand Down Expand Up @@ -2334,6 +2342,7 @@ D3TimeChart.prototype.getDomainsFromRaw = function (rawData) {
return d[1];
});

var yMinGamma = Number.MAX_SAFE_INTEGER;
var yMaxGamma = Number.MIN_SAFE_INTEGER;
var yMaxNeutron = Number.MIN_SAFE_INTEGER;

Expand All @@ -2360,6 +2369,7 @@ D3TimeChart.prototype.getDomainsFromRaw = function (rawData) {

var cps = dontRebin ? rawData.gammaCounts[i].maxCps[j] : (rawData.gammaCounts[i].counts[j] / dt);
yMaxGamma = Math.max(yMaxGamma, cps );
yMinGamma = Math.min(yMinGamma, cps );
}
}

Expand All @@ -2378,10 +2388,18 @@ D3TimeChart.prototype.getDomainsFromRaw = function (rawData) {
}
}

// This function gives a gamma y-range of zero to yMaxGamma, since this seems right for when you
// are viewing the whole time-chart (if you zoom-in, then the y-axis is no longer forced to zero,
// but to the actual minimum of data showing), but if we are using a log-y axis, we actually
// want to know what the data minimum value is - so we'll do kinda a hack and add an extra
// variable to the returned domains, `yGammaMin`, that we can use for this; this is the only
// place this variable is assigned.

return {
x: [xMin, xMax],
yGamma: [0, yMaxGamma],
yNeutron: [0, yMaxNeutron],
yGammaMin: yMinGamma
};
};

Expand Down Expand Up @@ -2453,12 +2471,34 @@ D3TimeChart.prototype.getScales = function (domains) {
.domain(domains.x)
.range([this.margin.left, this.state.width - this.margin.right])
: undefined;
var yScaleGamma = domains.yGamma
? d3.scale
.linear()
.domain([domains.yGamma[0],yGammaMult*domains.yGamma[1]])
.range([this.state.height - this.margin.bottom, this.margin.top])
: undefined;

var yScaleGamma = undefined;
if( domains.yGamma )
{
if( this.options.gammaLogY )
{
// If we are fully zoomed-out, the `this.getDomainsFromRaw()` function puts the gamma
// y-minimum to zero (which we dont want), but it also defines another variable,
// `yGammaMin`, that `this.getYDomainsInRange()` doesnt define, so we'l use it if available.
let lowery = domains.yGamma[0];
let uppery = domains.yGamma[1];
if (typeof domains.yGammaMin !== 'undefined') {
lowery = domains.yGammaMin;
}

yScaleGamma = d3.scale
.log()
.domain([Math.max(0.5, 0.5*lowery),2*yGammaMult*uppery])
.range([this.state.height - this.margin.bottom, this.margin.top]);
}else
{
yScaleGamma = d3.scale
.linear()
.domain([domains.yGamma[0],yGammaMult*domains.yGamma[1]])
.range([this.state.height - this.margin.bottom, this.margin.top]);
}
}//if( domains.yGamma )

var yScaleNeutron = domains.yNeutron
? d3.scale
.linear()
Expand Down Expand Up @@ -4001,6 +4041,16 @@ D3TimeChart.prototype.setNeutronsHidden = function (hide) {
};


D3TimeChart.prototype.setGammaLogY = function (logy) {
logy = !!logy; // make sure its a boolean
if( this.options.gammaLogY === logy ) //dont waste time if we dont need to
return;

this.options.gammaLogY = logy;
if( this.state.data.raw )
this.setData( this.state.data.raw );
};



/** Sets the displayed sample numbers.
Expand Down
62 changes: 62 additions & 0 deletions src/D3TimeChart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class D3TimeChartFilters : public WContainerWidget
WPushButton *m_clearEnergyFilterBtn;
WCheckBox *m_dontRebin;
WCheckBox *m_hideNeutrons;
WCheckBox *m_gammaLogY;
NativeFloatSpinBox *m_gammaNeutRelEmphasis;
float m_gammaNeutRelEmphasisValue; // Tracking for undo/redo support
WCheckBox* m_normalizeCb;
Expand All @@ -130,6 +131,7 @@ class D3TimeChartFilters : public WContainerWidget
m_clearEnergyFilterBtn( nullptr ),
m_dontRebin( nullptr ),
m_hideNeutrons( nullptr ),
m_gammaLogY( nullptr ),
m_gammaNeutRelEmphasis( nullptr ),
m_gammaNeutRelEmphasisValue( 1.0f ),
m_normalizeCb(nullptr),
Expand Down Expand Up @@ -358,6 +360,13 @@ class D3TimeChartFilters : public WContainerWidget
m_hideNeutrons->unChecked().connect( this, &D3TimeChartFilters::hideNeutronsChanged );


m_gammaLogY = new WCheckBox( "Log Y Scale", optContents );
m_gammaLogY->addStyleClass( "D3TimeGammaLogY" );
m_gammaLogY->setToolTip( "Make the y-axis log, for the gammas" );
m_gammaLogY->checked().connect( this, &D3TimeChartFilters::gammaLogYChanged );
m_gammaLogY->unChecked().connect( this, &D3TimeChartFilters::gammaLogYChanged );


WContainerWidget *sfDiv = new WContainerWidget(optContents);
sfDiv->addStyleClass( "D3TimeYAxisRelScale" );

Expand Down Expand Up @@ -862,6 +871,34 @@ class D3TimeChartFilters : public WContainerWidget
}//void hideNeutronsChanged()


void gammaLogYChanged()
{
const bool logy = m_gammaLogY->isChecked();
m_parentChart->setGammaLogY( logy );

// Take care of undo/redo
UndoRedoManager *undoRedo = UndoRedoManager::instance();
if( undoRedo && !undoRedo->isInUndoOrRedo() )
{
auto toggleLogYCB = wApp->bind( boost::bind( &WCheckBox::setChecked, m_gammaLogY, !logy ) );
auto unToggleLogYCB = wApp->bind( boost::bind( &WCheckBox::setChecked, m_gammaLogY, logy ) );
auto callLogYChanged = wApp->bind( boost::bind( &D3TimeChartFilters::gammaLogYChanged, this ) );

auto undo = [toggleLogYCB, callLogYChanged](){
toggleLogYCB();
callLogYChanged();
};

auto redo = [unToggleLogYCB, callLogYChanged](){
unToggleLogYCB();
callLogYChanged();
};

undoRedo->addUndoRedoStep( undo, redo, "Toggle y-axis on time chart log/lin" );
}//if( undoRedo && !undoRedo->isInUndoOrRedo() )
}//void gammaLogYChanged()


void handleGammaNeutRelEmphasisChanged()
{
float value = 1.0f;
Expand Down Expand Up @@ -934,6 +971,11 @@ class D3TimeChartFilters : public WContainerWidget
m_gammaNeutRelEmphasis->setHidden( !visible );
// Should we also reset m_gammaNeutRelEmphasis to 1.0 if we are hiding the option?
}

void setGammaLogY( const bool logy )
{
m_gammaLogY->setChecked( logy );
}
};//class D3TimeChartFilters


Expand All @@ -948,6 +990,7 @@ D3TimeChart::D3TimeChart( Wt::WContainerWidget *parent )
m_showHorizontalLines( false ),
m_dontRebin( false ),
m_hideNeutrons( false ),
m_gammaLogY( false ),
m_spec( nullptr ),
m_detectors_to_display(),
m_highlights(),
Expand Down Expand Up @@ -1031,6 +1074,7 @@ void D3TimeChart::defineJavaScript()
options += ", gridy: " + jsbool(m_showHorizontalLines);
options += ", chartLineWidth: 1.0"; //ToDo: Let this be specified in C++
options += ", dontRebin: " + jsbool(m_dontRebin);
options += ", gammaLogY: " + jsbool(m_gammaLogY);
options += "}";

setJavaScriptMember( "chart", "new D3TimeChart(" + m_chart->jsRef() + "," + options + ");");
Expand Down Expand Up @@ -2348,6 +2392,24 @@ bool D3TimeChart::neutronsHidden() const
return m_hideNeutrons;
}


void D3TimeChart::setGammaLogY( const bool logy )
{
m_gammaLogY = logy;
if( m_options )
m_options->setGammaLogY( logy );

if( isRendered() )
doJavaScript( m_jsgraph + ".setGammaLogY(" + jsbool(logy) + ");" );
}//void setGammaLogY( const bool logy )


bool D3TimeChart::gammaLogY() const
{
return m_gammaLogY;
}//bool gammaLogY() const


void D3TimeChart::setXAxisRangeSamples( const int min_sample_num, const int max_sample_num )
{
doJavaScript( m_jsgraph + ".setXAxisZoomSamples("
Expand Down
Loading

0 comments on commit 7c0ddfe

Please sign in to comment.