| 1 | import constant from "./constant.js";
|
|---|
| 2 | import {withPath} from "./path.js";
|
|---|
| 3 | import asterisk from "./symbol/asterisk.js";
|
|---|
| 4 | import circle from "./symbol/circle.js";
|
|---|
| 5 | import cross from "./symbol/cross.js";
|
|---|
| 6 | import diamond from "./symbol/diamond.js";
|
|---|
| 7 | import diamond2 from "./symbol/diamond2.js";
|
|---|
| 8 | import plus from "./symbol/plus.js";
|
|---|
| 9 | import square from "./symbol/square.js";
|
|---|
| 10 | import square2 from "./symbol/square2.js";
|
|---|
| 11 | import star from "./symbol/star.js";
|
|---|
| 12 | import triangle from "./symbol/triangle.js";
|
|---|
| 13 | import triangle2 from "./symbol/triangle2.js";
|
|---|
| 14 | import wye from "./symbol/wye.js";
|
|---|
| 15 | import times from "./symbol/times.js";
|
|---|
| 16 |
|
|---|
| 17 | // These symbols are designed to be filled.
|
|---|
| 18 | export const symbolsFill = [
|
|---|
| 19 | circle,
|
|---|
| 20 | cross,
|
|---|
| 21 | diamond,
|
|---|
| 22 | square,
|
|---|
| 23 | star,
|
|---|
| 24 | triangle,
|
|---|
| 25 | wye
|
|---|
| 26 | ];
|
|---|
| 27 |
|
|---|
| 28 | // These symbols are designed to be stroked (with a width of 1.5px and round caps).
|
|---|
| 29 | export const symbolsStroke = [
|
|---|
| 30 | circle,
|
|---|
| 31 | plus,
|
|---|
| 32 | times,
|
|---|
| 33 | triangle2,
|
|---|
| 34 | asterisk,
|
|---|
| 35 | square2,
|
|---|
| 36 | diamond2
|
|---|
| 37 | ];
|
|---|
| 38 |
|
|---|
| 39 | export default function Symbol(type, size) {
|
|---|
| 40 | let context = null,
|
|---|
| 41 | path = withPath(symbol);
|
|---|
| 42 |
|
|---|
| 43 | type = typeof type === "function" ? type : constant(type || circle);
|
|---|
| 44 | size = typeof size === "function" ? size : constant(size === undefined ? 64 : +size);
|
|---|
| 45 |
|
|---|
| 46 | function symbol() {
|
|---|
| 47 | let buffer;
|
|---|
| 48 | if (!context) context = buffer = path();
|
|---|
| 49 | type.apply(this, arguments).draw(context, +size.apply(this, arguments));
|
|---|
| 50 | if (buffer) return context = null, buffer + "" || null;
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | symbol.type = function(_) {
|
|---|
| 54 | return arguments.length ? (type = typeof _ === "function" ? _ : constant(_), symbol) : type;
|
|---|
| 55 | };
|
|---|
| 56 |
|
|---|
| 57 | symbol.size = function(_) {
|
|---|
| 58 | return arguments.length ? (size = typeof _ === "function" ? _ : constant(+_), symbol) : size;
|
|---|
| 59 | };
|
|---|
| 60 |
|
|---|
| 61 | symbol.context = function(_) {
|
|---|
| 62 | return arguments.length ? (context = _ == null ? null : _, symbol) : context;
|
|---|
| 63 | };
|
|---|
| 64 |
|
|---|
| 65 | return symbol;
|
|---|
| 66 | }
|
|---|