Skip to content

Commit

Permalink
Code Refacting;Fix Canvas bug;
Browse files Browse the repository at this point in the history
  • Loading branch information
birdeggb2777 committed Apr 29, 2024
1 parent 1fb0e43 commit bfa18ef
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 17 deletions.
4 changes: 2 additions & 2 deletions bluelight/scripts/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ function displayRuler2(viewportNum = viewportNumber) {
function setTransform(viewportnum = viewportNumber) {
var element = GetViewport(viewportnum);
var scale = element.scale ? element.scale : 1;
GetViewportMark(viewportnum).style.transform = "translate(" + "calc(-50% + " + Fpx(element.translate.x) + ")" + "," + "calc(-50% + " + Fpx(element.translate.y) + ")" + ")scale(" + scale + ") rotate(" + element.rotate + "deg)";
element.canvas.style.transform = "translate(" + "calc(-50% + " + Fpx(element.translate.x) + ")" + "," + "calc(-50% + " + Fpx(element.translate.y) + ")" + ")scale(" + scale + ") rotate(" + element.rotate + "deg)";
GetViewportMark(viewportnum).style.transform = `translate(calc(-50% + ${Fpx(element.translate.x)}) , calc(-50% + ${Fpx(element.translate.y)})) scale( ${scale} ) rotate( ${element.rotate}deg)`;
element.canvas.style.transform = `translate(calc(-50% + ${Fpx(element.translate.x)}) , calc(-50% + ${Fpx(element.translate.y)})) scale( ${scale} ) rotate( ${element.rotate}deg)`;
//element.canvas.style.transform=" translate(-50%,-50%)"
element.canvas.style.position = "absolute";
GetViewportMark(viewportnum).style.position = "absolute";
Expand Down
2 changes: 1 addition & 1 deletion bluelight/scripts/eventmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ onloadFunction.push2Last(function () {
for (var elem of getClass("MyDicomDiv")) {
elem.addEventListener("drop", (event) => {
event.preventDefault();
if (!openLeftImgClick) return;
if (!openLeftImgClick || !dragged) return;
viewportNumber = parseInt(event.currentTarget.viewportNum);
PictureOnclick(dragged.QRLevel);
dragged = null;
Expand Down
8 changes: 4 additions & 4 deletions bluelight/scripts/gui.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class LeftLayout {
ImgDiv.onclick = function () {
PictureOnclick(this.QRLevel);
};

ImgDiv.ondrag = function () {
event.preventDefault();
dragged = this;
Expand Down Expand Up @@ -443,18 +443,18 @@ function SetTable(row0, col0) {
try {
var WandH = getViewportFixSize(window.innerWidth, window.innerHeight, row, col);
for (var i = 0; i < Viewport_Total; i++)
GetViewport(i).div.style = "position:relative;float: left;left:100px;overflow:hidden;border:" + bordersize + "px #D3D9FF groove;margin:0px";
GetViewport(i).div.style = `position:relative;float:left;left:100px;overflow:hidden;border:${bordersize}px #D3D9FF groove;margin:0px`;
for (var r = 0; r < row; r++) {
for (var c = 0; c < col; c++) {
GetViewport(r * col + c).div.style.width = "calc(" + parseInt(100 / col) + "% - " + (parseInt(100 / col) + (bordersize * 2)) + "px)";
GetViewport(r * col + c).div.style.width = `calc(${parseInt(100 / col)}% - ${(parseInt(100 / col) + (bordersize * 2))}px)`;
GetViewport(r * col + c).div.style.height = (WandH[1] - (bordersize * 2)) + "px";
}
}
} catch (ex) { }
//重置各個Viewport的長寬大小(不顯示時)
for (var i = row * col; i < Viewport_Total; i++) {
try {
GetViewport(i).div.style = "position:relative;float: right;;width:0px;" + "height:" + 0 + "px;overflow:hidden;border:" + 0 + "px #D3D9FF groove;margin:0px";
GetViewport(i).div.style = "position:relative;float: right;width:0px;" + "height:" + 0 + "px;overflow:hidden;border:" + 0 + "px #D3D9FF groove;margin:0px";
} catch (ex) { }
}

Expand Down
2 changes: 1 addition & 1 deletion bluelight/scripts/label.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function displayWindowLevel(viewportNum = viewportNumber) {
getByid("textWW").value = "originWindowWidth";
getByid("textWW").value = "" + parseInt(GetViewport(viewportNum).windowWidth);
getByid("textWC").value = "" + parseInt(GetViewport(viewportNum).windowCenter);
getClass("labelWC")[viewportNum].innerText = " WC: " + parseInt(GetViewport(viewportNum).windowCenter) + " WW: " + parseInt(GetViewport(viewportNum).windowWidth);
getClass("labelWC")[viewportNum].innerText = ` WC: ${parseInt(GetViewport(viewportNum).windowCenter)} WW: ${parseInt(GetViewport(viewportNum).windowWidth)}`;
}

function DisplaySeriesCount(viewportNum = viewportNumber) {
Expand Down
5 changes: 5 additions & 0 deletions bluelight/scripts/onload.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,11 @@ function getJsonByInstanceRequest(SeriesResponse, InstanceRequest, instance) {
"&seriesUID=" + DicomResponse[i]["0020000E"].Value[0] +
"&objectUID=" + DicomResponse[i]["00080018"].Value[0] +
"&contentType=" + "application/dicom";
/*
var url = `${ConfigLog.WADO.https}://${ConfigLog.WADO.hostname}:${ConfigLog.WADO.PORT}/${ConfigLog.WADO.service}?requestType=WADO&` +
`studyUID=${DicomResponse[i]["0020000D"].Value[0]}&seriesUID=${DicomResponse[i]["0020000E"].Value[0]}` +
`&objectUID=${DicomResponse[i]["00080018"].Value[0]}&contentType=application/dicom`;
*/
} else if (ConfigLog.WADO.WADOType == "RS") {
var url = ConfigLog.WADO.https + "://" + ConfigLog.WADO.hostname + ":" + ConfigLog.WADO.PORT + "/" + ConfigLog.WADO.service +
"/studies/" + DicomResponse[i]["0020000D"].Value[0] +
Expand Down
10 changes: 5 additions & 5 deletions bluelight/scripts/plugin/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function displayDicomTagsList(viewportNum = viewportNumber) {

function displayAIM(viewportNum = viewportNumber) {
if (openTable == false) return;

var break1 = false;
dropTable(viewportNum);
GetViewport(viewportNum).div.style.overflowY = "hidden";
Expand Down Expand Up @@ -151,11 +151,11 @@ function dropTable(num) {
}
}

function createDicomTagsList2Viewport(viewport){
function createDicomTagsList2Viewport(viewport) {
function getTag(tag) {
var group = tag.substring(1, 5);
var element = tag.substring(5, 9);
var tagIndex = ("(" + group + "," + element + ")").toUpperCase();
var tagIndex = (`(${group},${element})`).toUpperCase();
var attr = TAG_DICT[tagIndex];
return attr;
}
Expand All @@ -172,7 +172,7 @@ function createDicomTagsList2Viewport(viewport){

for (el in viewport.content.image.data.elements) {
try {
var tag = ("(" + el.substring(1, 5) + "," + el.substring(5, 9) + ")").toUpperCase();
var tag = (`(${el.substring(1, 5)},${el.substring(5, 9)})`).toUpperCase();
var el1 = getTag(el);
el1.tag = "" + el;
var content = dicomParser.explicitElementToString(viewport.content.image.data, el1);
Expand Down Expand Up @@ -209,6 +209,6 @@ function createDicomTagsList2Viewport(viewport){
viewport[el1.name] = viewport.content.image[name];
}
}
} catch (ex) {}
} catch (ex) { }
}
}
8 changes: 4 additions & 4 deletions bluelight/scripts/viewport.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,13 +436,13 @@ function refleshCanvas(viewport) {
const diff = (1 / (max - min)) * 255;
const data = imgData.data;
if (image.color == true) {
for (var i = data.length; i >= 0; i -= 4) {
for (var i = data.length - 4; i >= 0; i -= 4) {
data[i + 0] = pixelData[i] * diff;
data[i + 1] = pixelData[i + 1] * diff;
data[i + 2] = pixelData[i + 2] * diff;
}
} else {
for (var i = data.length, j = data.length / 4; i >= 0; i -= 4, j--) {
for (var i = data.length - 4, j = data.length / 4 - 1; i >= 0; i -= 4, j--) {
data[i + 0] = data[i + 1] = data[i + 2] = pixelData[j] * diff;
}
}
Expand Down Expand Up @@ -476,13 +476,13 @@ function refleshCanvas(viewport) {
const addition = (- low + intercept) / (high - low) * 255;
const data = imgData.data;
if (image.color == true) {
for (var i = data.length; i >= 0; i -= 4) {
for (var i = data.length - 4; i >= 0; i -= 4) {
data[i + 0] = pixelData[i] * multiplication + addition;
data[i + 1] = pixelData[i + 1] * multiplication + addition;
data[i + 2] = pixelData[i + 2] * multiplication + addition;
}
} else {
for (var i = data.length, j = data.length / 4; i >= 0; i -= 4, j--) {
for (var i = data.length - 4, j = data.length / 4 - 1; i >= 0; i -= 4, j--) {
data[i + 0] = data[i + 1] = data[i + 2] = pixelData[j] * multiplication + addition;
}
}
Expand Down

0 comments on commit bfa18ef

Please sign in to comment.