-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c08f113
commit 697820a
Showing
2 changed files
with
82 additions
and
13 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
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 | ||
} |
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