Skip to content

Commit

Permalink
cleanup and init flow legend
Browse files Browse the repository at this point in the history
  • Loading branch information
joewdavies committed Jan 10, 2025
1 parent c08f113 commit 697820a
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 13 deletions.
80 changes: 80 additions & 0 deletions src/legend/legend-flow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { format } from 'd3-format'
import { select } from 'd3-selection'
import * as Legend from './legend'
import { formatDefaultLocale } from 'd3-format'

//set legend labels locale
formatDefaultLocale({
decimal: '.',
thousands: ' ',
grouping: [3],
currency: ['', '€'],
})

/**
* A legend for proportional symbol map
*
* @param {*} map
*/
export const legend = function (map, config) {
//build generic legend object for the map
const out = Legend.legend(map)

//override attribute values with config values
if (config)
for (let key in config) {
if (key == 'colorLegend' || key == 'sizeLegend') {
for (let p in out[key]) {
//override each property in size and color legend configs
if (config[key][p] !== undefined) {
out[key][p] = config[key][p]
}
}
if (config.colorLegend == false) out.colorLegend = false
} else {
out[key] = config[key]
}
}

//@override
out.update = function () {
const m = out.map
const lgg = out.lgg

// update legend parameters if necessary
if (m.legend_)
for (let key in m.legend_) {
if (key == 'colorLegend' || key == 'sizeLegend') {
for (let p in out[key]) {
//override each property in size and color legend m.legend_
if (m.legend_[key][p] !== undefined) {
out[key][p] = m.legend_[key][p]
}
}
} else {
out[key] = m.legend_[key]
}
}

//remove previous content
lgg.selectAll('*').remove()

//draw legend background box
out.makeBackgroundBox()

buildFlowLegend()

//set legend box dimensions
out.setBoxDimension()
}

/**
* Builds a legend which illustrates the statistical values of different flow symbol sizes
*
* @param {*} map map instance
* @param {*} container parent legend object from core/legend.js
*/
function buildFlowLegend(m) {}

return out
}
15 changes: 2 additions & 13 deletions src/maptypes/map-flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { linkHorizontal } from 'd3-shape'
import { sum, max } from 'd3-array'
import { scaleLinear } from 'd3'
import * as StatMap from '../core/stat-map'
import * as ChoroplethLegend from '../legend/legend-choropleth'
import * as FlowLegend from '../legend/legend-flow'
import { select, selectAll } from 'd3-selection'

/**
Expand Down Expand Up @@ -52,19 +52,8 @@ export const map = function (config) {
//@override
out.getLegendConstructor = function () {
//TODO: define legend
return ChoroplethLegend.legend
return FlowLegend.legend
}

// get regions that are either 'importers' or 'exporters'
function getFlowRegions() {
let regions = allNuts.filter((d) => exporter.value == d.properties.id || importers.has(d.properties.id))

// merge regions with statistical data
let merged = out.flowData_.find((e) => e.target === d.properties.id)
return { ...d, ...data2 }
return features
}

/**
* Function to create a map with Sankey diagram and other elements
* @param {Object} graph - Configuration options and data for the map
Expand Down

0 comments on commit 697820a

Please sign in to comment.