General refactoring

master
Aadhavan Srinivasan 1 month ago
parent a38657ddf1
commit 7112874a06

@ -117,7 +117,7 @@ const district2lang = { // Should override state colors
"Hapur": languages["urdu"],
"Kutch": languages["sindhi"],
"Godda": languages["santali"],
"Deoghar": languages["santali"],
"Dumka": languages["santali"],
@ -142,6 +142,7 @@ const district2lang = { // Should override state colors
"Bahraich": languages["awadhi"],
}
// Functions for calculating and dealing with language boundaries
function reverseCoordArrays(coords) {
if (!Array.isArray(coords)) {
return coords;
@ -157,14 +158,13 @@ function reverseCoordArrays(coords) {
return coords.map(reverseCoordArrays);
}
function getOuterBoundaryPolygon(features) {
// Check if we have features to process
if (!features || features.length === 0) {
console.warn("No features to process for boundary");
return null;
}
// Handle single feature case
if (features.length === 1) {
return features[0];
@ -176,6 +176,15 @@ function getOuterBoundaryPolygon(features) {
return combined;
}
function district2langFunc(d) {
if (district2lang.hasOwnProperty(d.properties.district)) {
return district2lang[d.properties.district];
} else if (state2lang.hasOwnProperty(d.properties.st_nm)) {
return state2lang[d.properties.st_nm];
} else {
return undefined;
}
}
function stateOrDistrictOrLanguage(d) {
if (typeof d.properties.district !== 'undefined') {
@ -204,24 +213,18 @@ function drawMap(world) {
.attr("d", path)
.attr("class", d => stateOrDistrictOrLanguage(d))
.attr("fill", function(d) {
if (stateOrDistrictOrLanguage(d) === "district") {
if (district2lang.hasOwnProperty(d.properties.district)) {
return district2lang[d.properties.district].color;
} else if (state2lang.hasOwnProperty(d.properties.st_nm)) {
return state2lang[d.properties.st_nm].color;
} else {
return defaultColor;
}
}
if (stateOrDistrictOrLanguage(d) === "district") {
const districtLang = district2langFunc(d)
if (typeof districtLang !== 'undefined') {
return districtLang.color
} else {
return defaultColor;
}
}
})
.each(function(d) {
if (stateOrDistrictOrLanguage(d) === "district") {
let districtLang;
if (district2lang.hasOwnProperty(d.properties.district)) {
districtLang = district2lang[d.properties.district];
} else if (state2lang.hasOwnProperty(d.properties.st_nm)) {
districtLang = state2lang[d.properties.st_nm];
}
const districtLang = district2langFunc(d);
if (typeof districtLang !== 'undefined') {
districtLang.districts.push(d)
}
@ -248,7 +251,7 @@ function drawMap(world) {
if (stateOrDistrictOrLanguage(d) == "language") {
return d.properties.lang_name;
} else {
d3.select(this).remove() // Only add text if the element is a language
d3.select(this).remove() // Only add this attribute if the element is a language
}
});

Loading…
Cancel
Save