source: node_modules/d3-shape/src/symbol.js

Last change on this file was e4c61dd, checked in by istevanoska <ilinastevanoska@…>, 6 months ago

Prototype 1.1

  • Property mode set to 100644
File size: 1.8 KB
RevLine 
[e4c61dd]1import constant from "./constant.js";
2import {withPath} from "./path.js";
3import asterisk from "./symbol/asterisk.js";
4import circle from "./symbol/circle.js";
5import cross from "./symbol/cross.js";
6import diamond from "./symbol/diamond.js";
7import diamond2 from "./symbol/diamond2.js";
8import plus from "./symbol/plus.js";
9import square from "./symbol/square.js";
10import square2 from "./symbol/square2.js";
11import star from "./symbol/star.js";
12import triangle from "./symbol/triangle.js";
13import triangle2 from "./symbol/triangle2.js";
14import wye from "./symbol/wye.js";
15import times from "./symbol/times.js";
16
17// These symbols are designed to be filled.
18export 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).
29export const symbolsStroke = [
30 circle,
31 plus,
32 times,
33 triangle2,
34 asterisk,
35 square2,
36 diamond2
37];
38
39export 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}
Note: See TracBrowser for help on using the repository browser.