Skip to content

Commit

Permalink
fix thresholds for choropleths and fix geoCenter deprecation where z …
Browse files Browse the repository at this point in the history
…is undefined
  • Loading branch information
joewdavies committed Dec 18, 2024
1 parent 9617470 commit 15e627a
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 52 deletions.
24 changes: 13 additions & 11 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.

3 changes: 3 additions & 0 deletions docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
**Map elements and methods**<br>
[Title](#map-title-&-subtitle) - [Frame](#map-frame) - [Legend](#map-legend) - [Scalebar](#scalebar) - [Tooltip](#tooltip) - [Styling](#styling) - [Insets](#insets) - [Bottom text & link to source data](#bottom-text-&-link-to-source-data) - [Export](#export) - [Miscellaneous](#miscellaneous) - [Build & update](#build-and-update)

**Version migration**
See https://github.com/eurostat/eurostat-map/blob/master/docs/release-notes.md for any major changes.

Anything unclear or missing? Feel free to [ask](https://github.com/eurostat/eurostat.js/issues/new) !

## Map creation
Expand Down
27 changes: 5 additions & 22 deletions examples/pop-unemploy-bivariate.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,26 @@
<body>
<svg id="map"></svg>
<script src="https://unpkg.com/eurostat-map"></script>
<!-- <script src="../build/eurostatmap.js"></script> -->
<script>
let height = window.innerHeight
const bivariateMap = eurostatmap
.map('chbi')
.map('bivariateChoropleth')
.width(1000)
.height(800)
.titleFontSize(25)
.subtitleFontSize(16)
.title('Unemployment and population density, 2021')
.subtitle('% unemployed persons aged 20-64 years & inhabitants per km²')
.nutsLevel(2)
.nutsLevel('mixed')
.nutsYear(2016)
.stat('v1', { eurostatDatasetCode: 'demo_r_d3dens', unitText: 'inh./km²' })
.stat('v2', {
eurostatDatasetCode: 'lfst_r_lfu3rt',
filters: { age: 'Y20-64', sex: 'T', unit: 'PC', time: 2021 },
unitText: '% unemployed',
})
.clnb(4)
.nutsbnStroke({
0: 'white',
1: 'white',
2: 'white',
co: 'none',
oth: 'white',
})
.cntbnStroke('white')
.nutsbnStrokeWidth({ 0: 1, 1: 0.1, 2: 0.1, 3: 0.1, co: 0 })
.numberOfClasses(4)
.startColor('#f3f3f3')
.color1('#00CBC9')
.color2('#cc5cb0')
Expand All @@ -49,21 +41,12 @@
label2: 'Unemployment',
x: 20,
y: 170,
// axisPadding: { x: 0, y: 0 },
//arrowPadding: 2,
})
.labelling(true)
.labelsToShow(['cc'])
.labelShadow(['cc'])
.drawGraticule(false)
.seaFillStyle('white')
.cntrgFillStyle('#f2f2f2')
.noDataFillStyle('#bfbfbf')
.drawCoastalMargin(false)
.zoomExtent([1, 2])
.frameStrokeWidth(0)
.geoCenter([4900000, 3500000])
.nutsrgSelFillSty('red')
.hoverColor('red')
.build()
</script>
</body>
Expand Down
1 change: 1 addition & 0 deletions examples/population-change.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<body>
<svg id="map"></svg>
<script src="https://unpkg.com/eurostat-map"></script>
<!-- <script src="../build/eurostatmap.js"></script> -->
<!-- for eurostatmap.colorFun() -->
<script src="https://d3js.org/d3-color.v2.min.js"></script>
<script src="https://d3js.org/d3-interpolate.v2.min.js"></script>
Expand Down
9 changes: 5 additions & 4 deletions examples/small_multiple.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ <h1 style="font-family: sans-serif">20 years of GDP change in Europe</h1>
<a href="https://ec.europa.eu/eurostat/databrowser/view/namq_10_gdp/">Eurostat</a>
</p>

<script src="https://unpkg.com/eurostat-map"></script>
<!-- <script src="https://unpkg.com/eurostat-map"></script> -->
<script src="../build/eurostatmap.js"></script>

<!-- for eurostatmap.colorFun() -->
<script src="https://d3js.org/d3-color.v2.min.js"></script>
Expand Down Expand Up @@ -43,9 +44,9 @@ <h1 style="font-family: sans-serif">20 years of GDP change in Europe</h1>
unitText: '%',
})

.colorFun(d3.interpolateRdYlBu)
.classifMethod('threshold')
.threshold([-15, -10, -8, -6, -4, -2, -1, -0.5, 0, 0.5, , 1, 2, 4, 6, 7, 10, 15])
.colorFunction(d3.interpolateRdYlBu)
.classificationMethod('threshold')
.thresholds([-15, -10, -8, -6, -4, -2, -1, -0.5, 0, 0.5, , 1, 2, 4, 6, 7, 10, 15])

.seaFillStyle('#fff')
.drawCoastalMargin(false)
Expand Down
4 changes: 2 additions & 2 deletions examples/world.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

<body style="margin: 0">
<svg id="map"></svg>
<script src="../build/eurostatmap.js"></script>
<!-- <script src="https://unpkg.com/eurostat-map"></script> -->
<!-- <script src="../build/eurostatmap.js"></script> -->
<script src="https://unpkg.com/eurostat-map"></script>
<script>
let data = {
JM: 70,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eurostat-map",
"version": "4.0.6",
"version": "4.0.7",
"description": "Reusable library to quickly create and customise web maps showing Eurostat data directly retrieved from Eurostat database.",
"keywords": [
"eurostat",
Expand Down
2 changes: 1 addition & 1 deletion src/core/deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export const defineDeprecatedFunctions = (out) => {
out.botTxtPadding = (v) => (console.warn('botTxtPadding is now DEPRECATED. Please use the em-footnote CSS class instead.'),out);
out.botTxtTooltipTxt = (v) => (console.warn('botTxtTooltipTxt is now DEPRECATED. Please use footnoteTooltipText() instead.'),out);
out.tooltipShowFlags = (v) =>(console.warn('tooltipShowFlags is now DEPRECATED. Please use out.tooltip({showFlags}) instead.'),out.tooltip_.showFlags = v,out);
out.colorFun = (v) =>(console.warn('colorFun is now DEPRECATED. Please use out.colorFunction() instead.'),out.colorFun_ = v,out);
out.colorFun = (v) =>(console.warn('colorFun is now DEPRECATED. Please use out.colorFunction() instead.'),out.colorFunction_ = v,out);

//labelling
out.labelling = (v) =>(console.warn('labelling is now DEPRECATED. Please use out.labels({}) configuration object instead. See documentation for details.'),out);
Expand Down
4 changes: 3 additions & 1 deletion src/core/map-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -558,9 +558,12 @@ export const mapTemplate = function (config, withCenterPoints) {
if (!out.position_.x || !out.position_.y) {
defineDefaultPosition()
}
out.position_.z = out.position_.z || getDefaultZ()

// d3 projection functions
defineProjection()
definePathFunction()
// d3 zoom
if (out.zoomExtent()) {
defineMapZoom()
}
Expand Down Expand Up @@ -725,7 +728,6 @@ export const mapTemplate = function (config, withCenterPoints) {
// out.position_.x = Geometries.userGeometries
// out.position_.y = Geometries.userGeometries
}
out.position_.z = out.position_.z || getDefaultZ()

// optional: set from URL
setViewFromURL()
Expand Down
4 changes: 2 additions & 2 deletions src/legend/legend-choropleth.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ export const legend = function (map, config) {

if (out.barChart) {
let thresholds =
m.threshold_.length > 1
? m.threshold_
m.thresholds_.length > 1
? m.thresholds_
: Array.from({ length: m.numberOfClasses_ })
.map((_, index) => {
return m.classifier().invertExtent(index)[out.ascending ? 0 : 1]
Expand Down
12 changes: 6 additions & 6 deletions src/maptypes/map-choropleth.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const map = function (config) {
//the classification method
out.classificationMethod_ = 'quantile' // or: equinter, threshold
//the threshold, when the classification method is 'threshold'
out.threshold_ = [0]
out.thresholds_ = [0]
//colors to use for classes
out.colors_ = null
//when computed automatically, ensure the threshold are nice rounded values
Expand All @@ -50,7 +50,7 @@ export const map = function (config) {
;[
'numberOfClasses_',
'classificationMethod_',
'threshold_',
'thresholds_',
'makeClassifNice_',
'colorFunction_',
'classToFillStyle_',
Expand Down Expand Up @@ -81,8 +81,8 @@ export const map = function (config) {
return out
}
out.threshold = function (v) {
if (!arguments.length) return out.threshold_
out.threshold_ = v
if (!arguments.length) return out.thresholds_
out.thresholds_ = v
out.numberOfClasses(v.length + 1)
return out
}
Expand Down Expand Up @@ -146,8 +146,8 @@ export const map = function (config) {
break
}
case 'threshold': {
out.numberOfClasses(out.threshold_.length + 1)
out.classifier(scaleThreshold().domain(out.threshold_).range(generateRange(out.numberOfClasses_)))
out.numberOfClasses(out.thresholds_.length + 1)
out.classifier(scaleThreshold().domain(out.thresholds_).range(generateRange(out.numberOfClasses_)))
break
}
case 'jenks': {
Expand Down

0 comments on commit 15e627a

Please sign in to comment.