Public
Edited
Sep 29, 2024
2 forks
Importers
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
new CustomIcon({
flip: true,
symbol: femalePath,
fillColor: defaultColorFemale
}).render
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
new CustomIcon({
flag: { iso: "gb-sct", opacity: 1 },
symbol: malePath,
fillColor: {
hair: "orange",
face: "pink",
shirt: "olive",
background: "teal"
},
texture: {
show: true,
shirt: textures.lines().orientation("3/8", "7/8").stroke("DarkGreen")
},
strokeColor: {
hair: "DarkOrange",
face: "PaleVioletRed",
shirt: "DarkGreen",
background: "black",
border: "black"
},
strokeWidth: {
hair: "3px",
face: "2px",
shirt: "3px",
background: "0px",
border: "3px"
}
}).render
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
new CustomIcon({
flip: true,
flag: { iso: "gb-sct", opacity: 1 },
symbol: femalePath,
fillColor: defaultColorMale
}).render
Insert cell
new CustomIcon({
flag: { iso: "mx", opacity: 0.6 },
symbol: femalePath,
fillColor: familyStyleC,
strokeColor: {
hair: "black",
face: "black",
shirt: "black",
background: "black",
border: "black"
},
strokeWidth: {
hair: "2px",
face: "2px",
shirt: "2px",
background: "0px",
border: "1px"
}
}).render
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
class CustomIcon {
constructor(
props = {
symbol: null,
fillColor: null,
strokeColor: null,
strokeWidth: null,
borderColor: null,
borderWidth: null,
borderStyle: null,
label: null,
texture: null,
flip: null,
flag: null,
size: null,
customSize:null,
}
) {
this.size = props.size ? props.size : 120;
this.flag = props.flag ? props.flag : { show: false };
this.flip = props.flip ? props.flip : false;
this.texture = props.texture ? props.texture : { show: false };
this.symbol = props.symbol ? props.symbol : null;
this.borderStyle = props.borderStyle ? props.borderStyle : "solid";
this.fillColor = props.fillColor
? props.fillColor
: {
face: "red",
hair: "green",
shirt: "blue",
background: "purple",
border: "none"
};
this.strokeColor = props.strokeColor
? props.strokeColor
: {
face: "red",
hair: "green",
shirt: "blue",
background: "purple",
border: "black"
};
this.strokeWidth = props.strokeWidth
? props.strokeWidth
: {
face: "0px",
hair: "0px",
shirt: "0px",
background: "0px",
border: "0px"
};
this.borderColor = props.borderColor ? props.borderColor : "none";
this.borderWidth = props.borderWidth ? props.borderWidth : "none";
this.label = props.label ? props.label : "label";
}
get render() {
let uid = Math.random().toString(36).substr(2, 5);
let label = this.label;
let fillColor = this.fillColor;
let strokeColor = this.strokeColor;
let strokeWidth = this.strokeWidth;
let borderWidth = this.borderWidth;
let borderStyle = this.borderStyle;
let borderColor = this.borderColor;
let texture = this.texture;
let flip = this.flip;
let flag = this.flag;
let size = this.size;
let customSize = this.customSize

let iso = "";
if (flag.show) {
iso = flag.iso;
}

let symbol = this.symbol;
let svg;
let dy = 0;

var stringToHTML = function (str) {
var dom = document.createElementNS("http://www.w3.org/2000/svg", "svg");
dom.innerHTML = str;
return dom;
};

symbol = d3.select(stringToHTML(symbol)).attr("id", `symbol-${uid}`);

svg = DOM.svg(size, size);
let g;
if (flip) {
g = d3
.select(svg)
.style("box-sizing", "content-box")
.style("transform", "scaleX(-1)")
//.style("border", `${borderWidth} ${borderStyle} ${borderColor}`)
.attr("id", uid);
} else {
g = d3
.select(svg)
.style("box-sizing", "content-box")
//.style("border", `${borderWidth} ${borderStyle} ${borderColor}`)
.attr("id", uid);
}

g.append("svg")
.attr("class", `target-${uid}`)
.attr("width", customSize)
.attr("height", size)
.attr("viewBox", `0 0 ${size} ${size}`)
.html(symbol.node().outerHTML);

if (texture.show) {
for (let k of Object.keys(texture)) {
if (
k !== "show" &&
["background", "hair", "shirt", "face"].indexOf(k) > -1
) {
g.call(texture[k]);
g.select(`#texture-${k}`).style("fill", texture[k].url());
}
}
}
if (flag != null) {
if (flip) {
g.select("#icon")
.insert("image", "#texture-background")
.style("opacity", flag.opacity ? flag.opacity : "1")
.style("transform", "scaleX(-1)")
.style("transform-origin", "bottom")
.attr("href", flagLink[flag.iso])
.attr("width", size)
.attr("height", size);
} else {
g.select("#icon")
.insert("image", "#texture-background")
.style("opacity", flag.opacity ? flag.opacity : "1")
.attr("href", flagLink[flag.iso])
.attr("width", size)
.attr("height", size);
}
}

g.select("#face").style("fill", fillColor.face);
g.select("#hair").style("fill", fillColor.hair);
g.select("#shirt").style("fill", fillColor.shirt);
g.select("#background").style("fill", fillColor.background);
g.select("#border").style("fill", fillColor.border);

g.select("#face").style("stroke", strokeColor.face);
g.select("#hair").style("stroke", strokeColor.hair);
g.select("#shirt").style("stroke", strokeColor.shirt);
g.select("#background").style("stroke", strokeColor.background);
g.select("#border").style("stroke", strokeColor.border);

g.select("#face").style("stroke-width", strokeWidth.face);
g.select("#hair").style("stroke-width", strokeWidth.hair);
g.select("#shirt").style("stroke-width", strokeWidth.shirt);
g.select("#background").style("stroke-width", strokeWidth.background);
g.select("#border").style("stroke-width", strokeWidth.border);

return g.node();
}
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
import { legend, swatches } from "@d3/color-legend"
Insert cell
import { ramp } from "@mbostock/color-ramp"
Insert cell
tc = require("tinycolor2")
Insert cell
import {
sec5color1,
sec5color2,
sec5color3,
sec5color4,
sec5color5,
displayPalettes
} from "@mbrickmaps/colors"
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more