-
-
Notifications
You must be signed in to change notification settings - Fork 383
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Make contries map responsive (#9003)
* deps(vscode): Remove deprecated extension * fix: Make map responsive * deps(npm): Migrate from jvectormap to jsvectormap jvectormap (and jvectormap-next for that matter) seem to be unmaintained. jsvectormap is a fork, which doesn't depend on jQuery any more, and is actually updated regularly. Also, `updateSize` doesn't seem to work in jvectormap. This change also moves the map initialization code from Display.pm to it's own JS file, so that it can be linted correctly. * chg: Use new `visualizeData` for the regions Has better styling for the different countries. * chg: Update jsvectormap styling Now uses a few OFF colours from _variables.scss.
- Loading branch information
Showing
9 changed files
with
5,901 additions
and
14,800 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// This file is part of Product Opener. | ||
// | ||
// Product Opener | ||
// Copyright (C) 2011-2023 Association Open Food Facts | ||
// Contact: [email protected] | ||
// Address: 21 rue des Iles, 94100 Saint-Maur des Fossés, France | ||
// | ||
// Product Opener is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as | ||
// published by the Free Software Foundation, either version 3 of the | ||
// License, or (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/*exported displayWorldMap*/ | ||
/*global lang jsVectorMap*/ | ||
|
||
function getServerDomain() { | ||
return window.location.href.match(/^https?:\/\/([^/?#]+)(?:[/?#]|$)/i)[1]; | ||
} | ||
|
||
function displayWorldMap(selector, countries) { | ||
const countries_map_data = countries.data; | ||
const countries_map_links = countries.links; | ||
const countries_map_names = countries.names; | ||
const products = lang().products; | ||
const direction = getComputedStyle(document.querySelector(selector)).direction; | ||
|
||
const map = new jsVectorMap({ | ||
selector: selector, | ||
map: "world_merc", | ||
visualizeData: { | ||
values: countries_map_data, | ||
scale: ["#008C8C", "#ff8714"] | ||
}, | ||
onRegionTooltipShow: (_e, tooltip, index) => { | ||
let label = countries_map_names[index]; | ||
if (countries_map_data[index] > 0) { | ||
label = | ||
direction === "rtl" | ||
? `(${products} ${countries_map_data[index]}) ${label}` | ||
: `${label} (${countries_map_data[index]} ${products})`; | ||
} | ||
tooltip.text(label); | ||
}, | ||
onRegionClick: (_e, code) => { | ||
if (countries_map_links[code]) { | ||
window.location.href = `//${getServerDomain()}${countries_map_links[code]}`; | ||
} | ||
}, | ||
}); | ||
|
||
window.addEventListener("resize", () => { | ||
map.updateSize(); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.