From 715bb150067d35eb21a8c5c7bb59cda94cc12536 Mon Sep 17 00:00:00 2001 From: Chandrika Singh Jadon Date: Thu, 13 Feb 2025 02:09:20 +0530 Subject: [PATCH 1/6] Enhancements to XML import: Color parsing, polyline handling, independent annotations, and bounding boxes --- apps/port/import.html | 1 + apps/port/xml2geo.js | 54 +++++++++++++++++++++++++++++++------------ 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/apps/port/import.html b/apps/port/import.html index ecf6114da..8d1eff9a3 100644 --- a/apps/port/import.html +++ b/apps/port/import.html @@ -43,3 +43,4 @@

File Contents

+ diff --git a/apps/port/xml2geo.js b/apps/port/xml2geo.js index 4722df21e..4b8b47fb2 100644 --- a/apps/port/xml2geo.js +++ b/apps/port/xml2geo.js @@ -28,14 +28,16 @@ function xml2geo() { let input = document.getElementById('xml_in').value; xmlDoc = parser.parseFromString(input, 'text/xml'); let regions = xmlDoc.getElementsByTagName('Region'); + for (let i of regions) { - console.log('Looking at Region ID', i.getAttribute('Id')); + let regionId = i.getAttribute('Id'); + let regionType = i.getAttribute('Type') || 'Polygon'; // Default to Polygon if Type is missing + console.log('Processing Region ID:', regionId, 'as', regionType); + let vertices = i.getElementsByTagName('Vertex'); let coordinates = []; - let minX = 99e99; - let maxX = 0; - let minY = 99e99; - let maxY = 0; + let minX = 99e99, maxX = 0, minY = 99e99, maxY = 0; + for (let j of vertices) { let x = parseFloat(j.getAttribute('X')); let y = parseFloat(j.getAttribute('Y')); @@ -45,18 +47,38 @@ function xml2geo() { maxY = Math.max(maxY, y); coordinates.push([x, y]); } - coordinates.push(coordinates[0]); + + // **Detect Polygon vs. Polyline** + if (regionType === 'Polygon') { + coordinates.push(coordinates[0]); // Close the polygon by repeating the first point + } + let boundRect = [[minX, minY], [minX, maxY], [maxX, maxY], [maxX, minY], [minX, minY]]; - let feature = {}; - feature['type'] = 'Feature'; - feature['geometry'] = {}; - feature['geometry']['type'] = 'Polygon'; - feature['geometry']['coordinates'] = [coordinates]; - feature['bound'] = {}; - feature['bound']['type'] = 'Polygon'; - feature['bound']['coordinates'] = [boundRect]; + + // **Detect Color** + let colorValue = i.getAttribute('LineColor'); + let hexColor = colorValue ? `#${parseInt(colorValue).toString(16).padStart(6, '0')}` : '#000000'; + + let feature = { + 'type': 'Feature', + 'geometry': { + 'type': regionType === 'Polyline' ? 'LineString' : 'Polygon', + 'coordinates': [coordinates], + }, + 'properties': { + 'regionId': regionId, + 'lineColor': hexColor, + 'group': i.parentNode.getAttribute('Name') || 'Ungrouped', + }, + 'bound': { + 'type': 'BoundingBox', + 'coordinates': [[minX, minY], [maxX, maxY]], + } + }; + features.push(feature); } + let output = Object.assign({}, template); output['geometries']['features'] = features; output['provenance']['image']['slide'] = document.getElementById('slide_id').value; @@ -64,5 +86,7 @@ function xml2geo() { output['properties']['annotations']['name'] = document.getElementById('annot_name').value; output['provenance']['analysis']['name'] = document.getElementById('annot_name').value; output['provenance']['analysis']['execution_id'] = document.getElementById('annot_name').value; - document.getElementById('output').innerHTML = JSON.stringify(output); + + document.getElementById('output').textContent = JSON.stringify(output); + } From 7b909adfa6ef3f332178143d4cdf2130a45192a2 Mon Sep 17 00:00:00 2001 From: Chandrika Date: Thu, 13 Feb 2025 02:30:52 +0530 Subject: [PATCH 2/6] import.html --- apps/port/import.html | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/port/import.html b/apps/port/import.html index 8d1eff9a3..ecf6114da 100644 --- a/apps/port/import.html +++ b/apps/port/import.html @@ -43,4 +43,3 @@

File Contents

- From 56f1978211a336be3b7052830777a703bd3d38fe Mon Sep 17 00:00:00 2001 From: Chandrika Date: Thu, 13 Feb 2025 02:37:10 +0530 Subject: [PATCH 3/6] xml2geo.js From b20a41eda7ee23f7b1c8ec6e4f3a384a5fba5de6 Mon Sep 17 00:00:00 2001 From: Chandrika Date: Thu, 13 Feb 2025 18:49:32 +0530 Subject: [PATCH 4/6] xml2geo.js --- apps/port/xml2geo.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/apps/port/xml2geo.js b/apps/port/xml2geo.js index 4b8b47fb2..e865fa19a 100644 --- a/apps/port/xml2geo.js +++ b/apps/port/xml2geo.js @@ -36,7 +36,7 @@ function xml2geo() { let vertices = i.getElementsByTagName('Vertex'); let coordinates = []; - let minX = 99e99, maxX = 0, minY = 99e99, maxY = 0; + let minX = 99e99; let maxX = 0; let minY = 99e99; let maxY = 0; for (let j of vertices) { let x = parseFloat(j.getAttribute('X')); @@ -73,7 +73,7 @@ function xml2geo() { 'bound': { 'type': 'BoundingBox', 'coordinates': [[minX, minY], [maxX, maxY]], - } + }, }; features.push(feature); @@ -88,5 +88,4 @@ function xml2geo() { output['provenance']['analysis']['execution_id'] = document.getElementById('annot_name').value; document.getElementById('output').textContent = JSON.stringify(output); - } From 2cb1fb277f76ca0439a9057fd7bee94ad009ae98 Mon Sep 17 00:00:00 2001 From: Chandrika Date: Thu, 13 Feb 2025 19:06:32 +0530 Subject: [PATCH 5/6] Update axe-a11y-check.yml so that ChromeDriver version matches Chrome --- .github/workflows/axe-a11y-check.yml | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/.github/workflows/axe-a11y-check.yml b/.github/workflows/axe-a11y-check.yml index 7c6058049..748014b2e 100644 --- a/.github/workflows/axe-a11y-check.yml +++ b/.github/workflows/axe-a11y-check.yml @@ -20,14 +20,30 @@ jobs: uses: actions/setup-node@v1 with: node-version: ${{ matrix.node-version }} + + # Install Dependencies - run: npm install - run: npm install -g http-server + + # Install Google Chrome + - name: Install Google Chrome + run: | + sudo apt update + sudo apt install -y google-chrome-stable + + # Install the matching ChromeDriver version + - name: Install specific version of ChromeDriver + run: | + CHROME_VERSION=$(google-chrome --version | grep -oP '[0-9]+\.[0-9]+\.[0-9]+') + npm install -g chromedriver@$CHROME_VERSION + + # Start local server - run: npm run build --if-present - run: http-server -s & - - name: Install specific version of ChromeDriver - run: npm install -g chromedriver@125 + + # Run Axe tests with ChromeDriver - name: Run axe run: | npm install -g @axe-core/cli - sleep 90 + sleep 90 # Allow server to start axe http://127.0.0.1:8080 --chromedriver-path $(npm root -g)/chromedriver/bin/chromedriver --exit From be0f02a5a6214a52065e5e8690d4e6f4da087101 Mon Sep 17 00:00:00 2001 From: Chandrika Date: Thu, 13 Feb 2025 19:09:05 +0530 Subject: [PATCH 6/6] axe-a11y-check.yml --- .github/workflows/axe-a11y-check.yml | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/.github/workflows/axe-a11y-check.yml b/.github/workflows/axe-a11y-check.yml index 748014b2e..7c6058049 100644 --- a/.github/workflows/axe-a11y-check.yml +++ b/.github/workflows/axe-a11y-check.yml @@ -20,30 +20,14 @@ jobs: uses: actions/setup-node@v1 with: node-version: ${{ matrix.node-version }} - - # Install Dependencies - run: npm install - run: npm install -g http-server - - # Install Google Chrome - - name: Install Google Chrome - run: | - sudo apt update - sudo apt install -y google-chrome-stable - - # Install the matching ChromeDriver version - - name: Install specific version of ChromeDriver - run: | - CHROME_VERSION=$(google-chrome --version | grep -oP '[0-9]+\.[0-9]+\.[0-9]+') - npm install -g chromedriver@$CHROME_VERSION - - # Start local server - run: npm run build --if-present - run: http-server -s & - - # Run Axe tests with ChromeDriver + - name: Install specific version of ChromeDriver + run: npm install -g chromedriver@125 - name: Run axe run: | npm install -g @axe-core/cli - sleep 90 # Allow server to start + sleep 90 axe http://127.0.0.1:8080 --chromedriver-path $(npm root -g)/chromedriver/bin/chromedriver --exit