diff --git a/index.js b/index.js index f63a2c5..e095633 100644 --- a/index.js +++ b/index.js @@ -161,11 +161,15 @@ function getOuterBoundaryPolygon(features) { -function stateOrDistrict(d) { +function stateOrDistrictOrLanguage(d) { if (typeof d.properties.district !== 'undefined') { return "district" } else { - return "state" + if (typeof d.properties.lang_name !== 'undefined') { + return "language" + } else { + return "state" + } } } @@ -182,12 +186,16 @@ function drawMap(world) { states.append("path") .attr("d", path) - .attr("class", d => stateOrDistrict(d)) - .attr("fill", d => district2lang.hasOwnProperty(d.properties.district) ? - district2lang[d.properties.district].color : - state2lang[d.properties.st_nm].color) + .attr("class", d => stateOrDistrictOrLanguage(d)) + .attr("fill", function(d) { + if (stateOrDistrictOrLanguage(d) == "state" || stateOrDistrictOrLanguage(d) == "district") { + return district2lang.hasOwnProperty(d.properties.district) ? + district2lang[d.properties.district].color : + state2lang[d.properties.st_nm].color + } + }) .each(function(d) { - if (stateOrDistrict(d) == "district") { + if (stateOrDistrictOrLanguage(d) == "district") { districtLang = district2lang.hasOwnProperty(d.properties.district) ? district2lang[d.properties.district] : state2lang[d.properties.st_nm]; districtLang.districts.push(d) } @@ -205,34 +213,32 @@ function drawMap(world) { .attr("id", d => d.properties.district+"Text") .text(d => d.properties.district); +// let allLangs = [] +// +// for (const [langId,lang] of Object.entries(languages)) { +// let geojson = { +// "type": "FeatureCollection", +// "features": lang.districts +// }; +// +// let outerBound = getOuterBoundaryPolygon(geojson.features) +// outerBound["id"] = "lang" + lang.name +// outerBound.properties["lang_name"]= lang.name +// allLangs.push(outerBound); +// +// // Draw the boundary +// svg.append("path") +// .datum(outerBound) +// .attr("d", path) +// .attr("fill", "none") +// .attr("stroke", "red") +// .attr("stroke-width", 2); +// } +// +// console.log(JSON.stringify(allLangs,null,2)) - // for (const lang of languages) { - - - - let geojson = { - "type": "FeatureCollection", - "features": languages["kannada"].districts - }; - - let outerBound = getOuterBoundaryPolygon(geojson.features) - outerBound["id"] = "langKannada" - outerBound.properties["lang_name"]= "Kannada" - console.log(outerBound) - console.log(JSON.stringify(outerBound, null, 2)); - - // Draw the boundary - svg.append("path") - .datum(outerBound) - .attr("d", path) - .attr("fill", "none") - .attr("stroke", "red") - .attr("stroke-width", 2); - - // } d3.json("india_with_districts.json").then(drawMap) -console.log(colorToDistrict)