forked from baidut/PatchVQ
-
Notifications
You must be signed in to change notification settings - Fork 1
/
heatmap.htm
239 lines (228 loc) · 15.7 KB
/
heatmap.htm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
<script type="text/javascript" src="js/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="js/include_once.js"></script>
<script src="js/plotly-latest.min.js"></script>
<style>
#image-with-heatmap{
margin-left: auto;
margin-right: auto;
left: 0px;
top: 0px;
position: relative;
background-color:transparent !important;
text-decoration:none solid rgb(0, 0, 0) !important;
}
#heatmap{
align-content:normal;align-items:normal;align-self:auto;alignment-baseline:auto;animation-delay:0s;animation-direction:normal;animation-duration:0s;animation-fill-mode:none;animation-iteration-count:1;animation-name:none;animation-play-state:running;animation-timing-function:ease;appearance:none;backdrop-filter:none;backface-visibility:visible;background-attachment:scroll;background-blend-mode:normal;background-clip:border-box;background-color:rgba(0, 0, 0, 0);background-image:none;background-origin:padding-box;background-position:0% 0%;background-repeat:repeat;background-size:auto;baseline-shift:0px;block-size:809px;border-block-end-color:rgb(0, 0, 0);border-block-end-style:none;border-block-end-width:0px;border-block-start-color:rgb(0, 0, 0);border-block-start-style:none;border-block-start-width:0px;border-bottom-color:rgb(0, 0, 0);border-bottom-left-radius:0px;border-bottom-right-radius:0px;border-bottom-style:none;border-bottom-width:0px;border-collapse:separate;border-image-outset:0;border-image-repeat:stretch;border-image-slice:100%;border-image-source:none;border-image-width:1;border-inline-end-color:rgb(0, 0, 0);border-inline-end-style:none;border-inline-end-width:0px;border-inline-start-color:rgb(0, 0, 0);border-inline-start-style:none;border-inline-start-width:0px;border-left-color:rgb(0, 0, 0);border-left-style:none;border-left-width:0px;border-right-color:rgb(0, 0, 0);border-right-style:none;border-right-width:0px;border-top-color:rgb(0, 0, 0);border-top-left-radius:0px;border-top-right-radius:0px;border-top-style:none;border-top-width:0px;bottom:0px;box-shadow:none;box-sizing:content-box;break-after:auto;break-before:auto;break-inside:auto;buffered-rendering:auto;caption-side:top;caret-color:rgb(0, 0, 0);clear:none;clip:auto;clip-path:none;clip-rule:nonzero;color:rgb(0, 0, 0);color-interpolation:srgb;color-interpolation-filters:linearrgb;color-rendering:auto;column-count:auto;column-gap:normal;column-rule-color:rgb(0, 0, 0);column-rule-style:none;column-rule-width:0px;column-span:none;column-width:auto;content:normal;cursor:auto;cx:0px;cy:0px;d:none;direction:ltr;display:block;dominant-baseline:auto;empty-cells:show;fill:rgb(0, 0, 0);fill-opacity:1;fill-rule:nonzero;filter:none;flex-basis:auto;flex-direction:row;flex-grow:0;flex-shrink:1;flex-wrap:nowrap;float:none;flood-color:rgb(0, 0, 0);flood-opacity:1;font-family:"Times New Roman";font-kerning:auto;font-optical-sizing:auto;font-size:16px;font-stretch:100%;font-style:normal;font-variant:normal;font-variant-caps:normal;font-variant-east-asian:normal;font-variant-ligatures:normal;font-variant-numeric:normal;font-weight:400;grid-auto-columns:auto;grid-auto-flow:row;grid-auto-rows:auto;grid-column-end:auto;grid-column-start:auto;grid-row-end:auto;grid-row-start:auto;grid-template-areas:none;grid-template-columns:none;grid-template-rows:none;height:809px;hyphens:manual;image-orientation:from-image;image-rendering:auto;inline-size:1176px;isolation:auto;justify-content:normal;justify-items:normal;justify-self:auto;left:0px;letter-spacing:normal;lighting-color:rgb(255, 255, 255);line-break:auto;line-height:normal;list-style-image:none;list-style-position:outside;list-style-type:disc;margin-block-end:0px;margin-block-start:0px;margin-bottom:0px;margin-inline-end:0px;margin-inline-start:0px;margin-left:0px;margin-right:0px;margin-top:0px;marker-end:none;marker-mid:none;marker-start:none;mask-type:luminance;max-block-size:none;max-height:none;max-inline-size:none;max-width:none;min-block-size:0px;min-height:0px;min-inline-size:0px;min-width:0px;mix-blend-mode:normal;object-fit:fill;object-position:50% 50%;offset-distance:0px;offset-path:none;offset-rotate:auto 0deg;opacity:1;order:0;orphans:2;outline-color:rgb(0, 0, 0);outline-offset:0px;outline-style:none;outline-width:0px;overflow-anchor:auto;overflow-wrap:normal;overflow-x:visible;overflow-y:visible;overscroll-behavior-block:auto;overscroll-behavior-inline:auto;padding-block-end:0px;padding-block-start:0px;padding-bottom:0px;padding-inline-end:0px;padding-inline-start:0px;padding-left:0px;padding-right:0px;padding-top:0px;paint-order:normal;perspective:none;perspective-origin:588px 404.5px;pointer-events:auto;position:relative;r:0px;resize:none;right:0px;row-gap:normal;ruby-position:over;rx:auto;ry:auto;scroll-behavior:auto;scroll-margin-block-end:0px;scroll-margin-block-start:0px;scroll-margin-inline-end:0px;scroll-margin-inline-start:0px;scroll-padding-block-end:auto;scroll-padding-block-start:auto;scroll-padding-inline-end:auto;scroll-padding-inline-start:auto;shape-image-threshold:0;shape-margin:0px;shape-outside:none;shape-rendering:auto;speak:normal;stop-color:rgb(0, 0, 0);stop-opacity:1;stroke:none;stroke-dasharray:none;stroke-dashoffset:0px;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-width:1px;tab-size:8;table-layout:auto;text-align:start;text-align-last:auto;text-anchor:start;text-decoration:none solid rgb(0, 0, 0);text-decoration-color:rgb(0, 0, 0);text-decoration-line:none;text-decoration-skip-ink:auto;text-decoration-style:solid;text-indent:0px;text-overflow:clip;text-rendering:auto;text-shadow:none;text-size-adjust:auto;text-transform:none;text-underline-position:auto;top:0px;touch-action:auto;transform:none;transform-origin:588px 404.5px;transform-style:flat;transition-delay:0s;transition-duration:0s;transition-property:all;transition-timing-function:ease;unicode-bidi:normal;user-select:auto;vector-effect:none;vertical-align:baseline;visibility:visible;white-space:normal;widows:2;width:1176px;will-change:auto;word-break:normal;word-spacing:0px;writing-mode:horizontal-tb;x:0px;y:0px;z-index:auto;zoom:1;-webkit-app-region:none;-webkit-border-horizontal-spacing:0px;-webkit-border-image:none;-webkit-border-vertical-spacing:0px;-webkit-box-align:stretch;-webkit-box-decoration-break:slice;-webkit-box-direction:normal;-webkit-box-flex:0;-webkit-box-ordinal-group:1;-webkit-box-orient:horizontal;-webkit-box-pack:start;-webkit-box-reflect:none;-webkit-font-smoothing:auto;-webkit-highlight:none;-webkit-hyphenate-character:auto;-webkit-line-break:auto;-webkit-line-clamp:none;-webkit-locale:auto;-webkit-mask-box-image:none;-webkit-mask-box-image-outset:0;-webkit-mask-box-image-repeat:stretch;-webkit-mask-box-image-slice:0 fill;-webkit-mask-box-image-source:none;-webkit-mask-box-image-width:auto;-webkit-mask-clip:border-box;-webkit-mask-composite:source-over;-webkit-mask-image:none;-webkit-mask-origin:border-box;-webkit-mask-position:0% 0%;-webkit-mask-repeat:repeat;-webkit-mask-size:auto;-webkit-print-color-adjust:economy;-webkit-rtl-ordering:logical;-webkit-tap-highlight-color:rgba(0, 0, 0, 0.18);-webkit-text-combine:none;-webkit-text-decorations-in-effect:none;-webkit-text-emphasis-color:rgb(0, 0, 0);-webkit-text-emphasis-position:over right;-webkit-text-emphasis-style:none;-webkit-text-fill-color:rgb(0, 0, 0);-webkit-text-orientation:vertical-right;-webkit-text-security:none;-webkit-text-stroke-color:rgb(0, 0, 0);-webkit-text-stroke-width:0px;-webkit-user-drag:auto;-webkit-user-modify:read-only;-webkit-writing-mode:horizontal-tb;
}
#heatmap1{
left: 0px;
top: 0px;
position: absolute;
/*position: relative; this will make the heatmap non-interactive*/
/*z-index: -1;*/
z-index: 998;
mix-blend-mode: screen !important;
/* overlay; */
}
#imtest {
position: absolute;
left: 0px;
top: 25px;
z-index: 997;
opacity: 0.2;
}
/* this is important */
#heatmap-ctrl{
z-index: 999;
}
</style>
<div class="doublecolumn">
<div id='image-with-heatmap' >
<div id="heatmap"></div>
<img id='imtest' src='demo/Picture1.jpg' style="width:100%;outline: 3px solid black" />
</div>
<br/>
<div class="btn-group" id='heatmap-ctrl' role="group" aria-label="Basic example">
<button type="button" class="btn btn-sm btn-secondary" id='btn_im_only'
data-toggle="tooltip" title="Show image only" >
Image</button>
<button type="button" class="btn btn-sm btn-secondary active" id='btn_im_map'
data-toggle="tooltip" title="Show both image and heatmap" >
Both</button>
<button type="button" class="btn btn-sm btn-secondary" id='btn_map_only'
data-toggle="tooltip" title="Show heatmap only" >
Heatmap</button>
</div>
<br/>
<br/>
<div id="textbox">
<p style="float: left;padding-left: 50px">Poor quaility</p>
<p style="float: right;padding-right: 50px">High quality</p>
<div style="clear: both;"></div>
</div>
<!-- credit:
http://juliagraphics.github.io/Colors.jl/stable/colormaps/
https://www.browserling.com/tools/reverse-lines -->
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="70%" height="4mm" viewBox="0 0 32 1" preserveAspectRatio="none" shape-rendering="crispEdges" stroke="none" style="width: 70%; height: 11.1667px;">
<rect width="32" height="1" x=" 0" y="0" fill="#082C59"></rect>
<rect width="31" height="1" x=" 1" y="0" fill="#143F77"></rect>
<rect width="30" height="1" x=" 2" y="0" fill="#1F5392"></rect>
<rect width="29" height="1" x=" 3" y="0" fill="#2B65A9"></rect>
<rect width="28" height="1" x=" 4" y="0" fill="#3777BC"></rect>
<rect width="27" height="1" x=" 5" y="0" fill="#4588CC"></rect>
<rect width="26" height="1" x=" 6" y="0" fill="#5598D8"></rect>
<rect width="25" height="1" x=" 7" y="0" fill="#65A7E1"></rect>
<rect width="24" height="1" x=" 8" y="0" fill="#76B4E8"></rect>
<rect width="23" height="1" x=" 9" y="0" fill="#87C0ED"></rect>
<rect width="22" height="1" x="10" y="0" fill="#98CBF1"></rect>
<rect width="21" height="1" x="11" y="0" fill="#A9D5F4"></rect>
<rect width="20" height="1" x="12" y="0" fill="#B9DEF7"></rect>
<rect width="19" height="1" x="13" y="0" fill="#C8E6F9"></rect>
<rect width="18" height="1" x="14" y="0" fill="#D7EEFB"></rect>
<rect width="17" height="1" x="15" y="0" fill="#E5F4FD"></rect>
<rect width="16" height="1" x="16" y="0" fill="#FFECE7"></rect>
<rect width="15" height="1" x="17" y="0" fill="#FFE2DA"></rect>
<rect width="14" height="1" x="18" y="0" fill="#FFD6CC"></rect>
<rect width="13" height="1" x="19" y="0" fill="#FFCABD"></rect>
<rect width="12" height="1" x="20" y="0" fill="#FFBCAD"></rect>
<rect width="11" height="1" x="21" y="0" fill="#FFAE9D"></rect>
<rect width="10" height="1" x="22" y="0" fill="#FF9E8C"></rect>
<rect width=" 9" height="1" x="23" y="0" fill="#FF8D7B"></rect>
<rect width=" 8" height="1" x="24" y="0" fill="#FB7B6A"></rect>
<rect width=" 7" height="1" x="25" y="0" fill="#F16858"></rect>
<rect width=" 6" height="1" x="26" y="0" fill="#E35546"></rect>
<rect width=" 5" height="1" x="27" y="0" fill="#D14136"></rect>
<rect width=" 4" height="1" x="28" y="0" fill="#BB2E26"></rect>
<rect width=" 3" height="1" x="29" y="0" fill="#A11C18"></rect>
<rect width=" 2" height="1" x="30" y="0" fill="#820C0A"></rect>
<rect width=" 1" height="1" x="31" y="0" fill="#610102"></rect>
</svg>
<div class="progress" style="display: inline-block; height: 20px; width: 70%" >
<div id='score' class="progress-bar" role="progressbar" aria-valuemin="0" aria-valuemax="100"></div>
</div>
</div>
<script>
function dumpCSSText(element){
var s = '';
var o = getComputedStyle(element);
for(var i = 0; i < o.length; i++){
s+=o[i] + ':' + o.getPropertyValue(o[i])+';';
}
return s;
}
function dbg() {
dumpCSSText($('#image-with-heatmap'))
}
function get_image_resolution(selector) {
// https://stackoverflow.com/questions/318630/get-the-real-width-and-height-of-an-image-with-javascript-in-safari-chrome
var img = $(selector)[0]; // Get my img elem
return {
width:img.width, height:img.height,
clientWidth:img.clientWidth, clientHeight:img.clientHeight,
naturalWidth:img.naturalWidth, naturalHeight:img.naturalHeight,
// realWidth:pic_real_width, realHeight:pic_real_height,
height2:(img.naturalHeight) * img.clientWidth/img.naturalWidth}
}
function show_obj() {
var top_margin = 25;
if (window.obj == undefined) return;
// https://stackoverflow.com/questions/318630/get-the-real-width-and-height-of-an-image-with-javascript-in-safari-chrome
// imtest
// var img = $('#imtest')[0]; //$('#imtest')[0]; // Get my img elem
// width = img.clientWidth// display size
// height = top_margin + (img.clientHeight) // (img.naturalHeight) * width/img.naturalWidth;
// width = 1000; //img.width
// height = top_margin + 500; //img.height
// width = 600; //img.width
// height = top_margin + 400;
// $("<img/>") // Make in memory copy of image to avoid css issues
// .attr("src", $(img).attr("src"))
// .load(function() {
// width = this.width; // Note: $(this).width() will not
// height = this.height; // work for in memory images.
// });
// console.log(width)
// console.log(height)
document.querySelector('#imtest').src = document.querySelector('#imraw').src;
// $('#imtest').fadeTo(1000, 0.2);
// $('#heatmap').fadeTo(1000, 0);
sz = get_image_resolution('#imraw'); //('#imtest');
height = sz.clientHeight+TOP_MARGIN;
// height = sz.naturalHeight+TOP_MARGIN
width = sz.clientWidth;
// width = sz.naturalWidth
$('#image-with-heatmap').height(height);
$('#image-with-heatmap').width(width);
// mat = obj.normalized_local_scores.
// for(var i = 0; i < mat.length; i++) {
// for(var j = 0; j < mat[i].length; j++) {
// mat[i][j] = Math.pow(mat[i][j]/100, 2)*100;
// }
// }
// https://stackoverflow.com/questions/30610523/reverse-array-in-javascript-without-mutating-original-array
var data = [
{
z: window.obj.normalized_local_scores.slice().reverse(),
type: 'heatmap',
// opacity: 0.8,
showscale: false
}
];
if(!do_stretch()){
data[0]['zmin'] = 0; //40
data[0]['zmax'] = 100;
}
var layout = {
// https://stackoverflow.com/questions/29968152/python-setting-background-color-to-transparent-in-plotly-plots
paper_bgcolor: 'rgba(0,0,0,0)',
plot_bgcolor: 'rgba(0,0,0,0)',
height: height,
width: width,
autosize: false, //true,
// hovermode: false, // important
margin: {
l: 0,
r: 0,
b: 0,
t: top_margin, // tooltip bar
pad: 0
},
xaxis: {
fixedrange: true, // disable zoom https://plotly.com/javascript/disable-zoom/
showgrid: false,
zeroline: false,
showline: false,
ticks: '',
showticklabels: false
},
yaxis: {
fixedrange: true, // disable zoom
showgrid: false,
zeroline: false,
showline: false,
ticks: '',
showticklabels: false
},
};
Plotly.newPlot('heatmap', data, layout);
}
$(document).ready(function(){
// bootstrap button group active
// https://jsfiddle.net/Behseini/NsQ2a/
$(".btn-group > .btn").hover(function(){
$(".btn-group > .btn").removeClass("active");
$(this).addClass("active");
});
show_obj();
var trigger_mode = isMobile.any()? 'click':'hover';
on_update_qmap(show_obj);
// https://stackoverflow.com/questions/3326078/jquery-call-function-from-a-string
$('#btn_im_only')[trigger_mode](function(){ $('#imtest').css('opacity', '1'); $('#heatmap').css('opacity', '0'); }); // $('#imtest').fadeTo(1, 1);
$('#btn_im_map')[trigger_mode](function(){ $('#heatmap').css('opacity', '0.8'); $('#imtest').css('opacity', '0.2') }); // $('#imtest').fadeTo(1000, 0.2);
$('#btn_map_only')[trigger_mode](function(){ $('#heatmap').css('opacity', '1'); $('#imtest').css('opacity', '0') });
$('#btn_im_map').trigger( trigger_mode ); // trigger once to show the fused map
if(window.obj != undefined) {
$('.demo_pics')[0].click();
}
})
</script>