Skip to content

Commit

Permalink
fix thickness rel
Browse files Browse the repository at this point in the history
  • Loading branch information
neocarto committed Apr 15, 2022
1 parent 2df7bfd commit 6e18ed9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {rounding } from "./rounding.js";

const d3 = Object.assign({}, d3array, d3scale, d3selection);

export function legthickness(selection, options = {}) {
export function legthicknessabs(selection, options = {}) {
let x = options.x ?? null;
let y = options.y ?? null;
let valmax = options.valmax;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@ import {rounding } from "./rounding.js";

const d3 = Object.assign({}, d3array, d3scale, d3selection);

export function legthickness2(selection, options = {}) {
export function legthicknessrel(selection, options = {}) {
let x = options.x ? options.x : null;
let y = options.y ? options.y : null;
let w = options.w ? options.w : 30;
let title = options.title ? options.title : null;
let title = options.title ?? null;
let fontSize = options.fontSize ? options.fontSize : 14;
let fontSize2 = options.fontSize2 ? options.fontSize2 : 10;
let stroke = options.stroke ? options.stroke : "black";
let strokeOpacity = options.strokeOpacity ? options.strokeOpacity : 1;
let txtcol = options.txtcol ? options.txtcol : "#363636";
let breaks = options.breaks;
let sizes = options.sizes;
let missing = options.missing;

sizes = d3.reverse(sizes);
breaks = d3.reverse(breaks);
Expand Down
27 changes: 24 additions & 3 deletions src/helpers/legends.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import {legchoro } from "./leg-choro.js"
import {legtypo } from "./leg-typo.js";
import {legthickness } from "./leg-thickness.js";
import {legthicknessabs } from "./leg-thickness-abs.js";
import {legthicknessrel } from "./leg-thickness-rel.js";
import {chorotypo } from "./chorotypo.js";
import {thickness } from "./thickness.js";


export function legends(geojson, selection, fill, stroke, strokeWidth){


Expand Down Expand Up @@ -81,8 +83,8 @@ legtypo(selection, {
});
}

if (typeof strokeWidth == "object" && strokeWidth.values != undefined && strokeWidth.type == "abs") {
legthickness(selection, {
if (typeof strokeWidth == "object" && strokeWidth.values != undefined && (strokeWidth.type == "abs" ||strokeWidth.type == undefined)) {
legthicknessabs(selection, {
x: strokeWidth.leg_x,
y: strokeWidth.leg_y,
valmax: thickness(geojson.features, strokeWidth).valmax,
Expand All @@ -98,5 +100,24 @@ if (typeof strokeWidth == "object" && strokeWidth.values != undefined && strokeW
});
}

if (typeof strokeWidth == "object" && strokeWidth.values != undefined && strokeWidth.type == "rel") {
legthicknessrel(selection, {

x: strokeWidth.leg_x,
y: strokeWidth.leg_y,
breaks:thickness(geojson.features, strokeWidth).breaks,
sizes: thickness(geojson.features, strokeWidth).sizes,
w: strokeWidth.leg_w,
title: strokeWidth.leg_title ?? strokeWidth.values,
fontSize: strokeWidth.leg_fontSize,
fontSize2: strokeWidth.leg_fontSize2,
stroke: strokeWidth.stroke,
strokeOpacity: strokeWidth.strokeOpacity,
txtcol: strokeWidth.leg_txtcol

});

}


}
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ export {outline} from "./layers/outline.js"
export {graticule} from "./layers/graticule.js"

// // TEMP:
export {dots} from "./helpers/dots.js"
//export {dots} from "./helpers/dots.js"

0 comments on commit 6e18ed9

Please sign in to comment.