Use language code instead of language name; removed 'unavail' language; don't add text for districts
This commit is contained in:
41
index.js
41
index.js
@@ -25,7 +25,7 @@ const santaliColor = "#96bf60" // Santhali
|
|||||||
const sindhiColor = "#e89931" // Sindhi
|
const sindhiColor = "#e89931" // Sindhi
|
||||||
const awadhiColor = "#847fb5" // Awadhi
|
const awadhiColor = "#847fb5" // Awadhi
|
||||||
|
|
||||||
const unavailLangColor = "#555555"
|
const defaultColor = "#555555"
|
||||||
|
|
||||||
const languages = {
|
const languages = {
|
||||||
tamil: {name: "Tamil", color: tamilColor, code: "ta", districts: []},
|
tamil: {name: "Tamil", color: tamilColor, code: "ta", districts: []},
|
||||||
@@ -52,7 +52,6 @@ const languages = {
|
|||||||
santali: {name: "Santali", color: santaliColor, code: "sat", districts: []},
|
santali: {name: "Santali", color: santaliColor, code: "sat", districts: []},
|
||||||
sindhi: {name: "Sindhi", color: sindhiColor, code: "sd", districts: []},
|
sindhi: {name: "Sindhi", color: sindhiColor, code: "sd", districts: []},
|
||||||
awadhi: {name: "Awadhi", color: awadhiColor, code: "awa", districts: []},
|
awadhi: {name: "Awadhi", color: awadhiColor, code: "awa", districts: []},
|
||||||
unavail: {name: "Unavailable", color: unavailLangColor, code: "unavailable", districts: []},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Credit: https://www.artcraftblend.com/blogs/colors/shades-of-pastel
|
// Credit: https://www.artcraftblend.com/blogs/colors/shades-of-pastel
|
||||||
@@ -71,12 +70,9 @@ const state2lang = {
|
|||||||
"Jharkhand": languages["hindi"], // DEFAULT
|
"Jharkhand": languages["hindi"], // DEFAULT
|
||||||
"West Bengal": languages["bengali"],
|
"West Bengal": languages["bengali"],
|
||||||
"Assam": languages["assamese"],
|
"Assam": languages["assamese"],
|
||||||
"Meghalaya": languages["unavail"], // DEFAULT
|
|
||||||
"Tripura": languages["bengali"],
|
"Tripura": languages["bengali"],
|
||||||
"Mizoram": languages["mizo"],
|
"Mizoram": languages["mizo"],
|
||||||
"Manipur": languages["manipuri"],
|
"Manipur": languages["manipuri"],
|
||||||
"Nagaland": languages["unavail"], // DEFAULT
|
|
||||||
"Arunachal Pradesh": languages["unavail"], // DEFAULT
|
|
||||||
"Sikkim": languages["nepali"],
|
"Sikkim": languages["nepali"],
|
||||||
"Bihar": languages["bhojpuri"],
|
"Bihar": languages["bhojpuri"],
|
||||||
"Madhya Pradesh": languages["hindi"],
|
"Madhya Pradesh": languages["hindi"],
|
||||||
@@ -91,7 +87,6 @@ const state2lang = {
|
|||||||
"Dadra and Nagar Haveli and Daman and Diu": languages["gujarati"],
|
"Dadra and Nagar Haveli and Daman and Diu": languages["gujarati"],
|
||||||
"Puducherry": languages["tamil"],
|
"Puducherry": languages["tamil"],
|
||||||
"Lakshadweep": languages["malayalam"],
|
"Lakshadweep": languages["malayalam"],
|
||||||
"Andaman and Nicobar Islands": languages["unavail"],
|
|
||||||
"Delhi": languages["hindi"],
|
"Delhi": languages["hindi"],
|
||||||
"Chandigarh": languages["hindi"]
|
"Chandigarh": languages["hindi"]
|
||||||
|
|
||||||
@@ -239,15 +234,26 @@ function drawMap(world) {
|
|||||||
.attr("class", d => stateOrDistrictOrLanguage(d))
|
.attr("class", d => stateOrDistrictOrLanguage(d))
|
||||||
.attr("fill", function(d) {
|
.attr("fill", function(d) {
|
||||||
if (stateOrDistrictOrLanguage(d) === "district") {
|
if (stateOrDistrictOrLanguage(d) === "district") {
|
||||||
return district2lang.hasOwnProperty(d.properties.district) ?
|
if (district2lang.hasOwnProperty(d.properties.district)) {
|
||||||
district2lang[d.properties.district].color :
|
return district2lang[d.properties.district].color;
|
||||||
state2lang[d.properties.st_nm].color
|
} else if (state2lang.hasOwnProperty(d.properties.st_nm)) {
|
||||||
|
return state2lang[d.properties.st_nm].color;
|
||||||
|
} else {
|
||||||
|
return defaultColor;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.each(function(d) {
|
.each(function(d) {
|
||||||
if (stateOrDistrictOrLanguage(d) === "district") {
|
if (stateOrDistrictOrLanguage(d) === "district") {
|
||||||
districtLang = district2lang.hasOwnProperty(d.properties.district) ? district2lang[d.properties.district] : state2lang[d.properties.st_nm];
|
let districtLang;
|
||||||
districtLang.districts.push(d)
|
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];
|
||||||
|
}
|
||||||
|
if (typeof districtLang !== 'undefined') {
|
||||||
|
districtLang.districts.push(d)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.append("title") // Tooltip
|
.append("title") // Tooltip
|
||||||
@@ -259,13 +265,19 @@ function drawMap(world) {
|
|||||||
.attr("text-anchor", "middle")
|
.attr("text-anchor", "middle")
|
||||||
.attr("font-size", "12px")
|
.attr("font-size", "12px")
|
||||||
.attr("fill", "black")
|
.attr("fill", "black")
|
||||||
.attr("class", "languageText")
|
.attr("class", "languageText")
|
||||||
.attr("id", d => d.properties.lang_name+"Text")
|
.attr("id", function(d) {
|
||||||
|
if (stateOrDistrictOrLanguage(d) == "language") {
|
||||||
|
return d.properties.lang_code+"Text"
|
||||||
|
} else {
|
||||||
|
d3.select(this).remove()
|
||||||
|
}
|
||||||
|
})
|
||||||
.text(function(d) {
|
.text(function(d) {
|
||||||
if (stateOrDistrictOrLanguage(d) == "language") {
|
if (stateOrDistrictOrLanguage(d) == "language") {
|
||||||
return d.properties.lang_name;
|
return d.properties.lang_name;
|
||||||
} else {
|
} else {
|
||||||
return d.properties.district;
|
d3.select(this).remove() // Only add text if the element is a language
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -291,6 +303,7 @@ function drawMap(world) {
|
|||||||
// let outerBound = getOuterBoundaryPolygon(geojson.features)
|
// let outerBound = getOuterBoundaryPolygon(geojson.features)
|
||||||
// outerBound["id"] = "lang" + lang.name
|
// outerBound["id"] = "lang" + lang.name
|
||||||
// outerBound.properties["lang_name"]= lang.name
|
// outerBound.properties["lang_name"]= lang.name
|
||||||
|
// outerBound.properties["lang_code"]= lang.code
|
||||||
// allLangs.push(outerBound);
|
// allLangs.push(outerBound);
|
||||||
|
|
||||||
// svg.append("path")
|
// svg.append("path")
|
||||||
|
Reference in New Issue
Block a user