Skip to content

Commit

Permalink
es and umd modules and expose getter for default labels
Browse files Browse the repository at this point in the history
  • Loading branch information
joewdavies committed Feb 20, 2025
1 parent 6051f02 commit 4ef6149
Show file tree
Hide file tree
Showing 13 changed files with 153 additions and 31 deletions.
1 change: 1 addition & 0 deletions build/es/index.js

Large diffs are not rendered by default.

23 changes: 17 additions & 6 deletions build/eurostatmap.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions build/eurostatmap.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ map = eurostatmap.map(...)
{ text: 'NORWEGIAN SEA', x: 3850000, y: 4800000, class: 'ocean', letterSpacing: 1 },
{ text: 'BLACK SEA', x: 6300000, y: 2500000, class: 'ocean', letterSpacing: 4 },
],
values: true,
values: true, // label statistical values directly
backgrounds: true, // for better legibility of labelled values
shadows: true,
processValueLabelCentroids: (region, centroid) => {
Expand Down
20 changes: 17 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eurostat-map",
"version": "4.1.7",
"version": "4.1.8",
"description": "Reusable library to quickly create and customise web maps showing Eurostat data directly retrieved from Eurostat database.",
"keywords": [
"eurostat",
Expand All @@ -23,13 +23,26 @@
"url": "https://github.com/eurostat/eurostat-map.git"
},
"main": "build/eurostatmap.min.js",
"module": "build/es/index.js",
"unpkg": "build/eurostatmap.min.js",
"exports": {
".": {
"import": "./build/es/index.js",
"require": "./build/eurostatmap.min.js"
}
},
"files": [
"build/eurostatmap.min.js"
"build/eurostatmap.min.js",
"README.md",
"LICENSE"
],
"scripts": {
"start": "webpack --config webpack/webpack.config.dev.js",
"server": "webpack-dev-server --open --watch",
"build-prod": "webpack --config webpack/webpack.config.prod.js",
"build": "webpack --mode production",
"build:es": "webpack --config webpack/webpack.config.es.js",
"build:umd": "webpack --config webpack/webpack.config.umd.js",
"build-prod": "npm run build:es && npm run build:umd",
"format": "prettier --write .",
"test": "jest"
},
Expand Down Expand Up @@ -63,6 +76,7 @@
"prettier": "^3.4.1",
"style-loader": "^4.0.0",
"webpack": "^5.88.1",
"webpack-bundle-analyzer": "^4.10.2",
"webpack-cli": "^5.0.0",
"webpack-dev-server": "^4.15.1",
"webpack-livereload-plugin": "^3.0.2"
Expand Down
13 changes: 7 additions & 6 deletions src/core/labels.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,12 +341,13 @@ const appendStatLabelCentroidsToMap = function (map, labelsContainer) {
.attr('class', 'em-stat-label-shadow')
}
}

/**
* Default labels for country / geographical names.
* Using centroids would clash with proportional symbols, and are generally not ideal placements, so labels are positioned independently
* Labels are provided for all supported languages: "en","fr" and "de" (defined using map.language())
*/
const DEFAULTLABELS = {
export const DEFAULTLABELS = {
EUR_3035: {
cc: [
{ text: 'AL', x: 5100000, y: 2060000, class: 'cc', size: 7 },
Expand Down Expand Up @@ -612,8 +613,8 @@ const DEFAULTSTATLABELPOSITIONS = {
AT: { x: 4670000, y: 2700000 },
BE: { x: 3930000, y: 3060000 },
BG: { x: 5567000, y: 2300000 },
HR: { x: 4707718, y: 2350243 },
CY: { x: 6426000, y: 1530000 },
HR: { x: 4657718, y: 2400243 },
CY: { x: 6426000, y: 1490000 },
CH: { x: 4170000, y: 2600000 },
CZ: { x: 4707000, y: 2950000 },
DK: { x: 4316000, y: 3621000 },
Expand All @@ -631,15 +632,15 @@ const DEFAULTSTATLABELPOSITIONS = {
LU: { x: 4120000, y: 2940000 },
MT: { x: 4900000, y: 1430000 },
ME: { x: 5073000, y: 2185000 },
MK: { x: 5300000, y: 2120000 },
MK: { x: 5300000, y: 2080000 },
NL: { x: 4020000, y: 3208000 },
NO: { x: 4300000, y: 4147000 },
PL: { x: 4964000, y: 3200000 },
PT: { x: 2800000, y: 1990000 },
RO: { x: 5451000, y: 2600000 },
RS: { x: 5200000, y: 2370000 },
SK: { x: 5040000, y: 2880000 },
SI: { x: 4680000, y: 2550000 },
SK: { x: 5040000, y: 2860000 },
SI: { x: 4660000, y: 2520000 },
ES: { x: 3160096, y: 1900000 },
SE: { x: 4630000, y: 4000000 },
TR: { x: 6510000, y: 2100000 },
Expand Down
10 changes: 2 additions & 8 deletions src/core/map-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,10 @@ export const mapTemplate = function (config, withCenterPoints) {
//graticule
out.drawGraticule_ = false

//labelling (country names and geographical features)
// {config, statLabelsPositions, labelsToShow, labelShadows, labelFilterFunction}
//labelling
// see docs\reference.md#labelling
out.labels_ = undefined

// all these settings now go into labels object for cleaner API
// out.labelsConfig_ = DEFAULTLABELS // allow user to override map labels | see ./labels.js for example config
// out.statLabelsPositions = STATLABELPOSITIONS // allow user to override positions of statistical labels
// out.labelsToShow_ = ['countries', 'seas'] //accepted: "countries", "cc","seas", "values"
// out.labelShadowsToShow_ = ['countries', 'seas']

//annotations
out.annotations_ = undefined
out.annotationsAdded = false //simple flag to know when annotations have already been added
Expand Down
5 changes: 5 additions & 0 deletions src/eurostat-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as PieCharts from './maptypes/map-piecharts'
import * as Sparklines from './maptypes/map-sparklines'
import * as FlowMap from './maptypes/map-flow'
import * as mt from './core/stat-map'
import { DEFAULTLABELS } from './core/labels'

/**
* Function returning a eurostat-map object.
Expand Down Expand Up @@ -95,3 +96,7 @@ export const getFillPatternDefinitionFun = function (opts) {
console.warn('getFillPatternDefinitionFun is now DEPRECATED. Please use getFillPatternDefinitionFunction() instead.')
return getFillPatternDefinitionFunction(opts)
}

export const getDefaultLabels = function () {
return DEFAULTLABELS
}
1 change: 1 addition & 0 deletions src/legend/legend-choropleth.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const legend = function (map, config) {
out.pointOfDivergence = undefined
out.pointOfDivegencePadding = 7
out.divergingLineLength = undefined
out.divergingArrowLength = undefined

//show no data
out.noData = true
Expand Down
11 changes: 6 additions & 5 deletions test/test_labels.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,14 @@
labels: { values: true, shadows: true, statLabelsPositions: { MT: { x: 4701000, y: 1430000 } } },
},
])

.build()

setTimeout(()=>{
map.labels({backgrounds:false, shadows:true})
map.updateValuesLabels(map)
},2000)
console.log(eurostatmap.getDefaultLabels())

setTimeout(() => {
map.labels({ backgrounds: false, shadows: true })
map.updateValuesLabels(map)
}, 2000)
</script>
</body>
</html>
62 changes: 62 additions & 0 deletions webpack/webpack.config.debug-size.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
const path = require('path')
const webpack = require('webpack')
const packageJson = require('../package.json')
const TerserPlugin = require('terser-webpack-plugin')
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')

// analyze the bundle size
module.exports = {
mode: 'production',
entry: ['./src/index.js'],
output: {
filename: '[name].min.js', // Dynamic naming for entry points
chunkFilename: '[name].[contenthash].js', // Dynamic naming for split chunks
path: path.resolve(__dirname, '../build'),
library: 'eurostatmap',
libraryTarget: 'umd',
publicPath: '/build/',
},
devtool: false,
plugins: [
new BundleAnalyzerPlugin(),
new webpack.BannerPlugin({
banner: `/*! eurostat-map v${packageJson.version} | ${new Date().getFullYear()} Eurostat | EUPL License. See https://github.com/eurostat/eurostat-map/blob/master/LICENSE */`,
raw: false, // Adds the comment as plain text
}),
],
optimization: {
minimize: true,
concatenateModules: false, // Disable scope hoisting for better analysis
minimizer: [
new TerserPlugin({
extractComments: false, // Disable extracting comments to a separate file
}),
],
splitChunks: {
chunks: 'all', // Split vendor and app code
},
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
babelrc: false,
cacheDirectory: true,
sourceMaps: false,
},
},
},

{
test: /\.css$/i,
use: ['style-loader', 'css-loader'], // For CSS files
},
],
},
watch: false,
}
32 changes: 32 additions & 0 deletions webpack/webpack.config.es.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const path = require('path')

module.exports = {
mode: 'production',
entry: './src/index.js',
output: {
filename: 'index.js',
path: path.resolve(__dirname, '../build/es'),
libraryTarget: 'module', // Output as ES module
},
experiments: {
outputModule: true, // Enable ESM output
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: [['@babel/preset-env', { modules: false }]], // Keep ES Modules
},
},
},
{
test: /\.css$/i,
use: ['style-loader', 'css-loader'], // For CSS files
},
],
},
}
File renamed without changes.

0 comments on commit 4ef6149

Please sign in to comment.