General refactoring
This commit is contained in:
37
index.js
37
index.js
@@ -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,7 +158,6 @@ function reverseCoordArrays(coords) {
|
||||
return coords.map(reverseCoordArrays);
|
||||
}
|
||||
|
||||
|
||||
function getOuterBoundaryPolygon(features) {
|
||||
// Check if we have features to process
|
||||
if (!features || features.length === 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
|
||||
}
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user