Commit deb35db7116495979a4775bcffa54a9ff9f1dad2

Authored by Erdogan Furkan
2 parents facc7b91 c6ee3ae0
Exists in FER_CR42

Merge branch 'FER_7618' into FER_CR42

Showing 1 changed file with 69 additions and 0 deletions   Show diff stats
js/app/views/PlotTabResultUI.js
... ... @@ -231,6 +231,68 @@ Ext.define('amdaUI.PlotTabResultUI', {
231 231 return parseFloat(val).toPrecision(5);
232 232 },
233 233  
  234 + stringToRgbArray : function (str) {
  235 + var rgbArray = Ext.Array.map(str.split("|"), function(val) {
  236 + var rgb = val.replace(/\[|\]/g, "").split(",");
  237 + return [parseInt(rgb[0]), parseInt(rgb[1]), parseInt(rgb[2])];
  238 + });
  239 + rgbArray.pop();
  240 + return rgbArray;
  241 + },
  242 +
  243 + getZAxisValue: function(image, x,y, size, axis, bgColor ){
  244 +
  245 + var me = this;
  246 + if(bgColor==="[-1,-1,-1]")
  247 + bgColor="[255,255,255]"; // More readable for IHM part
  248 +
  249 + // Get the color under the cursor
  250 + var imgEl = image.getEl();
  251 + var canvas = document.createElement('canvas');
  252 + var context = canvas.getContext('2d');
  253 + canvas.width = size.width;
  254 + canvas.height = size.height;
  255 + context.drawImage(imgEl.dom, 0, 0, canvas.width, canvas.height);
  256 + var imageData = context.getImageData(x, y, 1, 1);
  257 + var r = imageData.data[0];
  258 + var g = imageData.data[1];
  259 + var b = imageData.data[2];
  260 + var cursorColor = "["+r+","+g+","+b+"]";
  261 +
  262 + // Now we'll transform the color information to values
  263 +
  264 + if(cursorColor !== bgColor){
  265 + var colorListArray = me.stringToRgbArray(axis.colorsList);
  266 +
  267 + // Creating the value scale
  268 + var interval = (axis.max - axis.min) / ( colorListArray.length- 1);
  269 + valuesListArray = new Array(colorListArray.length+1);
  270 +
  271 + for(var i=0;i< colorListArray.length+1; i++)
  272 + valuesListArray[i] = axis.min + i * interval;
  273 +
  274 + // Computation of the closest r,g,b values to the cursorColor
  275 + lowestChi = new Array(2);
  276 + for(var i=0;i< colorListArray.length; i++){
  277 + var chi = Math.sqrt(Math.pow(colorListArray[i][0]-r, 2) +
  278 + Math.pow(colorListArray[i][1]-g, 2) +
  279 + Math.pow(colorListArray[i][2]-b, 2) );
  280 +
  281 + if (i == 0)
  282 + lowestChi = [i,chi];
  283 + else if (chi < lowestChi[1])
  284 + lowestChi = [i,chi];
  285 + }
  286 +
  287 + // Returning values
  288 +
  289 + if(axis.logarithmic)
  290 + return "[1e"+valuesListArray[lowestChi[0]].toFixed(3)+",1e"+valuesListArray[lowestChi[0]+1].toFixed(4)+"]";
  291 + return "["+valuesListArray[lowestChi[0]].toFixed(4)+","+valuesListArray[lowestChi[0]+1].toFixed(4)+"]";
  292 + }
  293 + return "";
  294 + },
  295 +
234 296 createPlotImage: function (resultFolder, plotFile) {
235 297 var me = this;
236 298 var size = this.getImageSize();
... ... @@ -284,8 +346,10 @@ Ext.define(&#39;amdaUI.PlotTabResultUI&#39;, {
284 346  
285 347 var xText = '';
286 348 var yLeftText = '';
  349 + var colorText = '';
287 350 var yRightText = '';
288 351 var intervalText = '';
  352 + var image=this;
289 353 Ext.each(panel.plotArea.axes, function (axis) {
290 354 switch (axis.id) {
291 355 case 'timeAxis':
... ... @@ -300,6 +364,9 @@ Ext.define(&#39;amdaUI.PlotTabResultUI&#39;, {
300 364 case 'y-right':
301 365 yRightText = me.getAxisValue(axis, panel.plotArea.y + panel.plotArea.height, panel.plotArea.y, sourceYPos);
302 366 break;
  367 + case 'colorAxis':
  368 + colorText = me.getZAxisValue(image, x,y, size,axis,panel.plotArea.plotAreaBackgroundColor );
  369 + break;
303 370 case 'xaxis_id':
304 371 xText = me.getAxisValue(axis, panel.plotArea.x, panel.plotArea.x + panel.plotArea.width, sourceXPos);
305 372 break;
... ... @@ -318,6 +385,8 @@ Ext.define(&#39;amdaUI.PlotTabResultUI&#39;, {
318 385 text += (', Y Right : ' + yRightText);
319 386 if (intervalText != '')
320 387 text += (', ' + intervalText);
  388 + if (colorText != '')
  389 + text += (', Z : '+ colorText);
321 390 }
322 391 else
323 392 me.panelImage.resetCursor();
... ...