Compare commits
7 Commits
66d88c133b
...
resizeSvg
Author | SHA1 | Date | |
---|---|---|---|
2949c48ed9 | |||
6aedbbc942 | |||
977cd1aa62 | |||
81fe778212 | |||
bf8825294b | |||
6e9e11c41c | |||
f62697d03a |
25
index.html
25
index.html
@@ -19,7 +19,7 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: flex-start;
|
align-items: flex-start;
|
||||||
justify-content: space-evenly;
|
justify-content: space-evenly;
|
||||||
gap: 10% 10%;
|
gap: 2em 2em;
|
||||||
}
|
}
|
||||||
|
|
||||||
svg {
|
svg {
|
||||||
@@ -57,7 +57,7 @@
|
|||||||
.translationText, .romanizationText {
|
.translationText, .romanizationText {
|
||||||
visibility: hidden;
|
visibility: hidden;
|
||||||
font-family: "Noto Sans";
|
font-family: "Noto Sans";
|
||||||
font-size:1.25em;
|
font-size:1.2em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.romanizationText {
|
.romanizationText {
|
||||||
@@ -67,7 +67,7 @@
|
|||||||
.languageText {
|
.languageText {
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
font-size: 1.15em;
|
font-size: 1em;
|
||||||
font-family: sans-serif;
|
font-family: sans-serif;
|
||||||
visibility: hidden;
|
visibility: hidden;
|
||||||
}
|
}
|
||||||
@@ -114,14 +114,14 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Position map load spinner in the middle of the SVG */
|
/* Position map load spinner in the middle of the SVG */
|
||||||
.svgContainer {
|
#svgContainer {
|
||||||
position: relative;
|
position: relative;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
height: 1000px;
|
max-width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.svgContainer .mapLoadSpinner {
|
#svgContainer .mapLoadSpinner {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 40%;
|
top: 40%;
|
||||||
left: 40%;
|
left: 40%;
|
||||||
@@ -181,7 +181,18 @@
|
|||||||
@media only screen and (max-width: 768px) {
|
@media only screen and (max-width: 768px) {
|
||||||
main {
|
main {
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
align-items: stretch;
|
||||||
}
|
}
|
||||||
|
.district {
|
||||||
|
stroke-width: 0.1;
|
||||||
|
}
|
||||||
|
.translationText, .romanizationText {
|
||||||
|
font-size: 0.7em;
|
||||||
|
}
|
||||||
|
.languageText {
|
||||||
|
font-size: 0.6em;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
@@ -202,7 +213,7 @@
|
|||||||
</noscript>
|
</noscript>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section class="svgContainer">
|
<section id="svgContainer">
|
||||||
<div id="mapLoadSpinner" class="mapLoadSpinner"></div>
|
<div id="mapLoadSpinner" class="mapLoadSpinner"></div>
|
||||||
</section>
|
</section>
|
||||||
</main>
|
</main>
|
||||||
|
69
index.js
69
index.js
@@ -1,13 +1,3 @@
|
|||||||
// const mapWidth = document.getElementById("indiaMap").getAttribute("width")
|
|
||||||
// const mapHeight = document.getElementById("indiaMap").getAttribute("height")
|
|
||||||
const mapWidth = window.innerWidth - document.querySelector(".svgContainer").offsetWidth;
|
|
||||||
|
|
||||||
const svg = d3.select(".svgContainer")
|
|
||||||
.append('svg')
|
|
||||||
.attr('width', '100%')
|
|
||||||
.attr('preserveAspectRatio', "xMinYMin meet")
|
|
||||||
.attr('id', 'indiaMap');
|
|
||||||
|
|
||||||
const defaultColor = "#555555"
|
const defaultColor = "#555555"
|
||||||
|
|
||||||
const languages = {
|
const languages = {
|
||||||
@@ -137,6 +127,33 @@ const district2lang = { // Should override state colors
|
|||||||
"Bahraich": languages["awadhi"],
|
"Bahraich": languages["awadhi"],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function responsivefy(svg) {
|
||||||
|
// get container + svg aspect ratio
|
||||||
|
var container = d3.select(svg.node().parentNode),
|
||||||
|
width = parseInt(svg.style("width")),
|
||||||
|
height = parseInt(svg.style("height")),
|
||||||
|
aspect = width / height;
|
||||||
|
|
||||||
|
// add viewBox and preserveAspectRatio properties,
|
||||||
|
// and call resize so that svg resizes on inital page load
|
||||||
|
svg.attr("viewBox", "0 0 " + width + " " + height)
|
||||||
|
.attr("perserveAspectRatio", "xMinYMid")
|
||||||
|
.call(resize);
|
||||||
|
|
||||||
|
// to register multiple listeners for same event type,
|
||||||
|
// you need to add namespace, i.e., 'click.foo'
|
||||||
|
// necessary if you call invoke this function for multiple svgs
|
||||||
|
// api docs: https://github.com/mbostock/d3/wiki/Selections#on
|
||||||
|
d3.select(window).on("resize." + container.attr("id"), resize);
|
||||||
|
|
||||||
|
// get width of container and resize svg to fit it
|
||||||
|
function resize() {
|
||||||
|
var targetWidth = Math.floor(container.node().getBoundingClientRect().width);
|
||||||
|
svg.attr("width", targetWidth);
|
||||||
|
svg.attr("height", Math.round(targetWidth / aspect));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Functions for calculating and dealing with language boundaries
|
// Functions for calculating and dealing with language boundaries
|
||||||
function reverseCoordArrays(coords) {
|
function reverseCoordArrays(coords) {
|
||||||
if (!Array.isArray(coords)) {
|
if (!Array.isArray(coords)) {
|
||||||
@@ -193,10 +210,40 @@ function stateOrDistrictOrLanguage(d) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// const mapWidth = document.getElementById("indiaMap").getAttribute("width")
|
||||||
|
// const mapHeight = document.getElementById("indiaMap").getAttribute("height")
|
||||||
|
const mapWidth = /*window.innerWidth - */document.querySelector("#svgContainer").offsetWidth * 0.85;
|
||||||
|
// const mapHeight = document.querySelector("#svgContainer").offsetHeight;
|
||||||
|
const mapHeight = (window.innerHeight - document.querySelector("#svgContainer").getBoundingClientRect().top);
|
||||||
|
|
||||||
|
const svg = d3.select("#svgContainer")
|
||||||
|
.append('svg')
|
||||||
|
.attr('width', mapWidth.toString())
|
||||||
|
.attr('height', (mapHeight).toString())
|
||||||
|
// .attr('viewbox', '0 0 ' + mapWidth.toString() + ' ' + mapHeight.toString())
|
||||||
|
// .attr('preserveAspectRatio', "xMidYMin")
|
||||||
|
.attr('id', 'indiaMap')
|
||||||
|
// .call(responsivefy);
|
||||||
|
|
||||||
function drawMap(world) {
|
function drawMap(world) {
|
||||||
const projection = d3.geoMercator().fitWidth(mapWidth,world)
|
const projection = d3.geoMercator().fitSize([mapWidth, mapHeight], world)
|
||||||
const path = d3.geoPath().projection(projection);
|
const path = d3.geoPath().projection(projection);
|
||||||
|
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
const newSvg = d3.select('svg');
|
||||||
|
const bbox = newSvg.node().getBBox();
|
||||||
|
const originalWidth = +newSvg.attr("width");
|
||||||
|
newSvg
|
||||||
|
// .attr("viewBox", `${bbox.x} ${bbox.y} ${bbox.width} ${bbox.height}`)
|
||||||
|
.attr("viewBox", `0 ${bbox.y} ${originalWidth} ${bbox.height}`)
|
||||||
|
// .attr("width", mapHeight.toString())
|
||||||
|
.attr("height", bbox.height)
|
||||||
|
// .style("display", "block")
|
||||||
|
// .style("max-height", "100%"); // optional: keep it scalable in a flexbox
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
const states = svg.selectAll("g")
|
const states = svg.selectAll("g")
|
||||||
.data(world.features)
|
.data(world.features)
|
||||||
.enter()
|
.enter()
|
||||||
|
BIN
translations.db
BIN
translations.db
Binary file not shown.
Reference in New Issue
Block a user