Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

point-line-switcher #149

Merged
merged 1 commit into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 72 additions & 1 deletion davis_one/davis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,18 @@ namespace dvs {
R"(
<head>
<script src="./%8" charset="utf-8"></script>
%13
</head>
<body><div style = "display: flex;
align-items:center;height:100%; width:100%;background:#dddfd4;
justify-content: center;"><div style="%11:99%; %12:99%; aspect-ratio: %9/%10;"
id="gd"></div></div>
%14
<script>
%1
%2
%3
%15
var layout = {
title: {
text:'%4'
Expand Down Expand Up @@ -407,7 +410,8 @@ const char kHtmlMultiChartModel[] = R"davis_delimeter(
<head>
<script src="%1" charset="utf-8"></script>
</head>
<body><div style = "display: flex;
<body>
<div style = "display: flex;
align-items:center;height:100%; width:100%;background:#dddfd4;
justify-content: center;"><div style="%9:99%; %10:99%; aspect-ratio: %7/%8;"
id="gd"></div></div>
Expand Down Expand Up @@ -504,6 +508,70 @@ const char kHtmlSimpleDataBlock[]= R"davis_delimeter({
})davis_delimeter";


const char kHtmlComboboxStyleBlock[] = R"davis_delimeter(
<style>
#dropdown {
position: fixed;
top: 10px;
left: 10px;
z-index: 1000;
width: 50px;
height: 30px;
background: no-repeat center;
background-size: contain;
appearance: none;
-webkit-appearance: none;
-moz-appearance: none;
border: 1px solid #ccc;
border-radius: 4px;
padding: 5px;
font-size: 16px;
color:transparent;
}

#dropdown option {
background: white;
color: black;
}
</style>
)davis_delimeter";

const char kHtmlComboboxSelectBlock[] =R"davis_delimeter(
<select id="dropdown" onchange="updateBackground(this)">
<option value="image1" data-image="<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 171.373 11.261'><path d='M0 0h171.373v11.261H0z'/></svg>">line</option>
<option value="image2" data-image="<svg width='100' height='100' xmlns='http://www.w3.org/2000/svg' viewBox='0 0 171.373 50'><g transform='translate(-20.762 -48.999)'><path d='M20.762 68.268h171.373v11.261H20.762z'/><circle cx='107.49' cy='73.999' r='25'/></g></svg>">line + point</option>
<option value="3.svg" data-image="<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 171.373 50'><circle cx='107.49' cy='73.999' r='25' transform='translate(-20.762 -48.999)'/></svg>">point</option>
</select>
)davis_delimeter";


const char kHtmlComboboxUpdateFooBlock[] = R"davis_delimeter(
function updateBackground(select) {

var selectedImage = select.options[select.selectedIndex].getAttribute('data-image');
select.style.backgroundImage = 'url("data:image/svg+xml,' + encodeURIComponent(selectedImage) + '")';
var selectedOption = select.options[select.selectedIndex].text;
switch (selectedOption) {
case 'line':
trace.mode='lines';
break;
case 'line + point':
trace.mode='lines+markers';
break;
case 'point':
trace.mode='markers';
break;
default: console.log('uknown option');
}
Plotly.newPlot('gd', data, layout, config);
}

document.addEventListener('DOMContentLoaded', function() {
var dropdown = document.getElementById('dropdown');
updateBackground(dropdown);
});
)davis_delimeter";

// *INDENT-ON*

} // namespace dvs end
Expand Down Expand Up @@ -1143,6 +1211,9 @@ bool showLineChartInBrowser(const vector<double>& xValues, const vector<double>&
}
args[ARG_ASPECT_WIDTH_OR_HEIGHT] = paramWH;
args[ARG_ASPECT_WIDTH_OR_HEIGHT_FOR_AUTOSCALE] = paramWHsecond;
args[ARG_POINT_LINE_SWITCHER_STYLE] = kHtmlComboboxStyleBlock;
args[ARG_POINT_LINE_SWITCHER_SELECT] = kHtmlComboboxSelectBlock;
args[ARG_POINT_LINE_SWITCHER_UPDATE_FOO] = kHtmlComboboxUpdateFooBlock;
make_string(kHtmlModel, args, page);
string pageName;
mayBeCreateJsWorkingFolder();
Expand Down
10 changes: 9 additions & 1 deletion davis_one/davis.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ enum ARGS_INDEX {
ARG_ASPECT_RATIO_HEIGHT, //%10
ARG_ASPECT_WIDTH_OR_HEIGHT, //%11 "width" if ARG_ASPECT_RATIO_WIDTH > ARG_ASPECT_RATIO_HEIGHT and "height" if not
ARG_ASPECT_WIDTH_OR_HEIGHT_FOR_AUTOSCALE, //%12 if value of it is equal to ARG_ASPECT_WIDTH_OR_HEIGHT it's mean no autoscale.
ARG_POINT_LINE_SWITCHER_STYLE, //%13
ARG_POINT_LINE_SWITCHER_SELECT, //%14
ARG_POINT_LINE_SWITCHER_UPDATE_FOO, //%15
// ADD NEW ENUM BEFORE THIS COMMENT
ARGS_SIZE
};
Expand Down Expand Up @@ -158,7 +161,9 @@ enum ARGS_DATE_TIME_PAGE_INDEX {
ARG_DATE_TIME_ASPECT_RATIO_HEIGHT, //%4
ARG_DATE_TIME_ASPECT_WIDTH_OR_HEIGHT, //%5 "width" if ARG_ASPECT_RATIO_WIDTH > ARG_ASPECT_RATIO_HEIGHT and "height" if not
ARG_DATE_TIME_ASPECT_WIDTH_OR_HEIGHT_FOR_AUTOSCALE, //%6 if value of it is equal to ARG_ASPECT_WIDTH_OR_HEIGHT it's mean no autoscale.

ARG_DATE_TIME_POINT_LINE_SWITCHER_STYLE, //%7
ARG_DATE_TIME_POINT_LINE_SWITCHER_SELECT, //%8
ARG_DATE_TIME_POINT_LINE_SWITCHER_UPDATE_FOO, //%9
// ADD NEW ENUM BEFORE THIS COMMENT
ARGS_DATE_TIME_PAGE_SIZE
};
Expand Down Expand Up @@ -229,6 +234,9 @@ extern const char kHtmlMultiChartModel[];
extern const char kHtmlCloudOfPoints[];

extern const char kHtmlSimpleDataBlock[];
extern const char kHtmlComboboxStyleBlock[];
extern const char kHtmlComboboxSelectBlock[];
extern const char kHtmlComboboxUpdateFooBlock[];


} // namespace dvs end
Expand Down
70 changes: 69 additions & 1 deletion plotly_maker/html_parts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@ namespace dvs {
R"(
<head>
<script src="./%8" charset="utf-8"></script>
%13
</head>
<body><div style = "display: flex;
align-items:center;height:100%; width:100%;background:#dddfd4;
justify-content: center;"><div style="%11:99%; %12:99%; aspect-ratio: %9/%10;"
id="gd"></div></div>
%14
<script>
%1
%2
%3
%15
var layout = {
title: {
text:'%4'
Expand Down Expand Up @@ -375,7 +378,8 @@ const char kHtmlMultiChartModel[] = R"davis_delimeter(
<head>
<script src="%1" charset="utf-8"></script>
</head>
<body><div style = "display: flex;
<body>
<div style = "display: flex;
align-items:center;height:100%; width:100%;background:#dddfd4;
justify-content: center;"><div style="%9:99%; %10:99%; aspect-ratio: %7/%8;"
id="gd"></div></div>
Expand Down Expand Up @@ -472,6 +476,70 @@ const char kHtmlSimpleDataBlock[]= R"davis_delimeter({
})davis_delimeter";


const char kHtmlComboboxStyleBlock[] = R"davis_delimeter(
<style>
#dropdown {
position: fixed;
top: 10px;
left: 10px;
z-index: 1000;
width: 50px;
height: 30px;
background: no-repeat center;
background-size: contain;
appearance: none;
-webkit-appearance: none;
-moz-appearance: none;
border: 1px solid #ccc;
border-radius: 4px;
padding: 5px;
font-size: 16px;
color:transparent;
}

#dropdown option {
background: white;
color: black;
}
</style>
)davis_delimeter";

const char kHtmlComboboxSelectBlock[] =R"davis_delimeter(
<select id="dropdown" onchange="updateBackground(this)">
<option value="image1" data-image="<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 171.373 11.261'><path d='M0 0h171.373v11.261H0z'/></svg>">line</option>
<option value="image2" data-image="<svg width='100' height='100' xmlns='http://www.w3.org/2000/svg' viewBox='0 0 171.373 50'><g transform='translate(-20.762 -48.999)'><path d='M20.762 68.268h171.373v11.261H20.762z'/><circle cx='107.49' cy='73.999' r='25'/></g></svg>">line + point</option>
<option value="3.svg" data-image="<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 171.373 50'><circle cx='107.49' cy='73.999' r='25' transform='translate(-20.762 -48.999)'/></svg>">point</option>
</select>
)davis_delimeter";


const char kHtmlComboboxUpdateFooBlock[] = R"davis_delimeter(
function updateBackground(select) {

var selectedImage = select.options[select.selectedIndex].getAttribute('data-image');
select.style.backgroundImage = 'url("data:image/svg+xml,' + encodeURIComponent(selectedImage) + '")';
var selectedOption = select.options[select.selectedIndex].text;
switch (selectedOption) {
case 'line':
trace.mode='lines';
break;
case 'line + point':
trace.mode='lines+markers';
break;
case 'point':
trace.mode='markers';
break;
default: console.log('uknown option');
}
Plotly.newPlot('gd', data, layout, config);
}

document.addEventListener('DOMContentLoaded', function() {
var dropdown = document.getElementById('dropdown');
updateBackground(dropdown);
});
)davis_delimeter";

// *INDENT-ON*
//#STOP_GRAB_TO_DVS_NAMESPACE
} // namespace dvs
10 changes: 9 additions & 1 deletion plotly_maker/html_parts.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ enum ARGS_INDEX {
ARG_ASPECT_RATIO_HEIGHT, //%10
ARG_ASPECT_WIDTH_OR_HEIGHT, //%11 "width" if ARG_ASPECT_RATIO_WIDTH > ARG_ASPECT_RATIO_HEIGHT and "height" if not
ARG_ASPECT_WIDTH_OR_HEIGHT_FOR_AUTOSCALE, //%12 if value of it is equal to ARG_ASPECT_WIDTH_OR_HEIGHT it's mean no autoscale.
ARG_POINT_LINE_SWITCHER_STYLE, //%13
ARG_POINT_LINE_SWITCHER_SELECT, //%14
ARG_POINT_LINE_SWITCHER_UPDATE_FOO, //%15
// ADD NEW ENUM BEFORE THIS COMMENT
ARGS_SIZE
};
Expand Down Expand Up @@ -43,7 +46,9 @@ enum ARGS_DATE_TIME_PAGE_INDEX {
ARG_DATE_TIME_ASPECT_RATIO_HEIGHT, //%4
ARG_DATE_TIME_ASPECT_WIDTH_OR_HEIGHT, //%5 "width" if ARG_ASPECT_RATIO_WIDTH > ARG_ASPECT_RATIO_HEIGHT and "height" if not
ARG_DATE_TIME_ASPECT_WIDTH_OR_HEIGHT_FOR_AUTOSCALE, //%6 if value of it is equal to ARG_ASPECT_WIDTH_OR_HEIGHT it's mean no autoscale.

ARG_DATE_TIME_POINT_LINE_SWITCHER_STYLE, //%7
ARG_DATE_TIME_POINT_LINE_SWITCHER_SELECT, //%8
ARG_DATE_TIME_POINT_LINE_SWITCHER_UPDATE_FOO, //%9
// ADD NEW ENUM BEFORE THIS COMMENT
ARGS_DATE_TIME_PAGE_SIZE
};
Expand Down Expand Up @@ -114,6 +119,9 @@ extern const char kHtmlMultiChartModel[];
extern const char kHtmlCloudOfPoints[];

extern const char kHtmlSimpleDataBlock[];
extern const char kHtmlComboboxStyleBlock[];
extern const char kHtmlComboboxSelectBlock[];
extern const char kHtmlComboboxUpdateFooBlock[];

//#STOP_GRAB_TO_DVS_NAMESPACE
}
Expand Down
3 changes: 3 additions & 0 deletions plotly_maker/plotly_maker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,9 @@ bool showLineChartInBrowser(const vector<double>& xValues, const vector<double>&
}
args[ARG_ASPECT_WIDTH_OR_HEIGHT] = paramWH;
args[ARG_ASPECT_WIDTH_OR_HEIGHT_FOR_AUTOSCALE] = paramWHsecond;
args[ARG_POINT_LINE_SWITCHER_STYLE] = kHtmlComboboxStyleBlock;
args[ARG_POINT_LINE_SWITCHER_SELECT] = kHtmlComboboxSelectBlock;
args[ARG_POINT_LINE_SWITCHER_UPDATE_FOO] = kHtmlComboboxUpdateFooBlock;
make_string(kHtmlModel, args, page);
string pageName;
mayBeCreateJsWorkingFolder();
Expand Down
Loading