You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.1 KiB

1 year ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. import {path} from "d3-path";
  2. import circle from "./symbol/circle";
  3. import cross from "./symbol/cross";
  4. import diamond from "./symbol/diamond";
  5. import star from "./symbol/star";
  6. import square from "./symbol/square";
  7. import triangle from "./symbol/triangle";
  8. import wye from "./symbol/wye";
  9. import constant from "./constant";
  10. export var symbols = [
  11. circle,
  12. cross,
  13. diamond,
  14. square,
  15. star,
  16. triangle,
  17. wye
  18. ];
  19. export default function() {
  20. var type = constant(circle),
  21. size = constant(64),
  22. context = null;
  23. function symbol() {
  24. var buffer;
  25. if (!context) context = buffer = path();
  26. type.apply(this, arguments).draw(context, +size.apply(this, arguments));
  27. if (buffer) return context = null, buffer + "" || null;
  28. }
  29. symbol.type = function(_) {
  30. return arguments.length ? (type = typeof _ === "function" ? _ : constant(_), symbol) : type;
  31. };
  32. symbol.size = function(_) {
  33. return arguments.length ? (size = typeof _ === "function" ? _ : constant(+_), symbol) : size;
  34. };
  35. symbol.context = function(_) {
  36. return arguments.length ? (context = _ == null ? null : _, symbol) : context;
  37. };
  38. return symbol;
  39. }