Skip to content

Commit 112696c

Browse files
committed
Make JS/CSS resource directory a required argument for the functions that use that.
Not totally done however, the `SpecFile::write(...)` function still defaults to the compiled directory. There is probably a better mecahanism to be done here (maybe an ugly static variable that can be set?)
1 parent c18dc21 commit 112696c

File tree

4 files changed

+52
-10
lines changed

4 files changed

+52
-10
lines changed

SpecUtils/D3SpectrumExport.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,23 @@ namespace D3SpectrumExport
7373
//Legacy function for the moment... makes an entire HTML page for the provided Measurement
7474
bool write_d3_html( std::ostream &ostr,
7575
const std::vector< std::pair<const SpecUtils::Measurement *,D3SpectrumOptions> > &measurements,
76-
const D3SpectrumChartOptions &options );
77-
76+
const D3SpectrumChartOptions &options
77+
#if( !SpecUtils_D3_SUPPORT_FILE_STATIC )
78+
/// @param base_dir The location of where the JS and CSS files are stored. You may be able to use D3_SCRIPT_RUNTIME_DIR defined in D3SpectrumExportResources.h
79+
, const std::string &base_dir
80+
#endif
81+
);
82+
7883
/** Writes the HTML page header (</head> is the last thing written), including
7984
all JSS and CSS necassary for SpectrumChartD3.
8085
*/
86+
#if( SpecUtils_D3_SUPPORT_FILE_STATIC )
8187
bool write_html_page_header( std::ostream &ostr, const std::string &page_title );
82-
88+
#else
89+
/// @param base_dir The location of where the JS and CSS files are stored. You may be able to use D3_SCRIPT_RUNTIME_DIR defined in D3SpectrumExportResources.h
90+
bool write_html_page_header( std::ostream &ostr, const std::string &page_title, const std::string &base_dir );
91+
#endif
92+
8393

8494
/** Write the javascript for a SpectrumChartD3 that should be displayed in a
8595
<div> with id specified by div_name.

SpecUtils/SpecFile.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2287,7 +2287,12 @@ class SpecFile
22872287
bool write_d3_html( std::ostream &output,
22882288
const D3SpectrumExport::D3SpectrumChartOptions &options,
22892289
std::set<int> sample_nums,
2290-
std::vector<std::string> det_names ) const;
2290+
std::vector<std::string> det_names
2291+
#if( !SpecUtils_D3_SUPPORT_FILE_STATIC )
2292+
/// @param base_dir The location of where the JS and CSS files are stored. You may be able to use D3_SCRIPT_RUNTIME_DIR defined in D3SpectrumExportResources.h
2293+
, const std::string &base_dir
2294+
#endif
2295+
) const;
22912296
#endif
22922297

22932298
#if( SpecUtils_INJA_TEMPLATES )

src/D3SpectrumExport.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,11 @@ D3SpectrumChartOptions::D3SpectrumChartOptions()
395395
}
396396

397397

398+
#if( SpecUtils_D3_SUPPORT_FILE_STATIC )
398399
bool write_html_page_header( std::ostream &ostr, const std::string &title )
400+
#else
401+
bool write_html_page_header( std::ostream &ostr, const std::string &title, const std::string &basdir )
402+
#endif
399403
{
400404
const char *endline = "\r\n";
401405

@@ -423,7 +427,6 @@ D3SpectrumChartOptions::D3SpectrumChartOptions()
423427
//could also:
424428
//ostr << "include(\"" << D3_MIN_JS_FILENAME << "\");" << endline;
425429
using SpecUtils::append_path;
426-
const std::string basdir = D3_SCRIPT_RUNTIME_DIR;
427430

428431
ostr << "<script>" << file_to_string( append_path(basdir, D3_MIN_JS_FILENAME) ) << "</script>" << endline;
429432

@@ -682,12 +685,20 @@ D3SpectrumChartOptions::D3SpectrumChartOptions()
682685

683686
bool write_d3_html( std::ostream &ostr,
684687
const std::vector< std::pair<const SpecUtils::Measurement *,D3SpectrumOptions> > &measurements,
685-
const D3SpectrumChartOptions &options )
688+
const D3SpectrumChartOptions &options
689+
#if( !SpecUtils_D3_SUPPORT_FILE_STATIC )
690+
, const std::string &base_dir
691+
#endif
692+
)
686693
{
687694
const char *endline = "\r\n";
688-
695+
696+
#if( SpecUtils_D3_SUPPORT_FILE_STATIC )
689697
write_html_page_header( ostr, options.m_title );
690-
698+
#else
699+
write_html_page_header( ostr, options.m_title, base_dir );
700+
#endif
701+
691702
const string div_id = "chart1";
692703

693704
ostr << "<body><div id=\"" << div_id << "\" class=\"chart\" oncontextmenu=\"return false;\"></div>" << endline; // Adding the main chart div

src/SpecFile.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@
6969

7070
#if( SpecUtils_ENABLE_D3_CHART )
7171
#include "SpecUtils/D3SpectrumExport.h"
72+
#if( !SpecUtils_D3_SUPPORT_FILE_STATIC )
73+
#include "D3SpectrumExportResources.h"
74+
#endif
7275
#endif
7376

7477
#if( SpecUtils_ENABLE_URI_SPECTRA )
@@ -7109,7 +7112,11 @@ std::string SpecFile::generate_psuedo_uuid() const
71097112
bool SpecFile::write_d3_html( ostream &ostr,
71107113
const D3SpectrumExport::D3SpectrumChartOptions &options,
71117114
std::set<int> sample_nums,
7112-
std::vector<std::string> det_names ) const
7115+
std::vector<std::string> det_names
7116+
#if( !SpecUtils_D3_SUPPORT_FILE_STATIC )
7117+
, const std::string &base_dir
7118+
#endif
7119+
) const
71137120
{
71147121
try
71157122
{
@@ -7130,8 +7137,12 @@ bool SpecFile::write_d3_html( ostream &ostr,
71307137
vector< pair<const Measurement *,D3SpectrumExport::D3SpectrumOptions> > measurements;
71317138
D3SpectrumExport::D3SpectrumOptions spec_options;
71327139
measurements.push_back( pair<const Measurement *,::D3SpectrumExport::D3SpectrumOptions>(summed.get(),spec_options) );
7133-
7140+
7141+
#if( SpecUtils_D3_SUPPORT_FILE_STATIC )
71347142
return D3SpectrumExport::write_d3_html( ostr, measurements, options );
7143+
#else
7144+
return D3SpectrumExport::write_d3_html( ostr, measurements, options, base_dir );
7145+
#endif
71357146
}catch( std::exception & )
71367147
{
71377148
return false;
@@ -8951,7 +8962,12 @@ void SpecFile::write( std::ostream &strm,
89518962
case SaveSpectrumAsType::HtmlD3:
89528963
{
89538964
D3SpectrumExport::D3SpectrumChartOptions options;
8965+
#if( SpecUtils_D3_SUPPORT_FILE_STATIC )
89548966
success = info.write_d3_html( strm, options, samples, info.detector_names_ );
8967+
#else
8968+
// TODO: we should probably fix defaulting to `D3_SCRIPT_RUNTIME_DIR` to specify the JS/CSS source dir
8969+
success = info.write_d3_html( strm, options, samples, info.detector_names_, D3_SCRIPT_RUNTIME_DIR );
8970+
#endif
89558971
break;
89568972
}
89578973
#endif

0 commit comments

Comments
 (0)