dashStyle.js 1.0 KB

123456789101112131415161718192021222324252627
  1. import { isArray, isNumber, map } from '../core/util.js';
  2. export function normalizeLineDash(lineType, lineWidth) {
  3. if (!lineType || lineType === 'solid' || !(lineWidth > 0)) {
  4. return null;
  5. }
  6. return lineType === 'dashed'
  7. ? [4 * lineWidth, 2 * lineWidth]
  8. : lineType === 'dotted'
  9. ? [lineWidth]
  10. : isNumber(lineType)
  11. ? [lineType] : isArray(lineType) ? lineType : null;
  12. }
  13. export function getLineDash(el) {
  14. var style = el.style;
  15. var lineDash = style.lineDash && style.lineWidth > 0 && normalizeLineDash(style.lineDash, style.lineWidth);
  16. var lineDashOffset = style.lineDashOffset;
  17. if (lineDash) {
  18. var lineScale_1 = (style.strokeNoScale && el.getLineScale) ? el.getLineScale() : 1;
  19. if (lineScale_1 && lineScale_1 !== 1) {
  20. lineDash = map(lineDash, function (rawVal) {
  21. return rawVal / lineScale_1;
  22. });
  23. lineDashOffset /= lineScale_1;
  24. }
  25. }
  26. return [lineDash, lineDashOffset];
  27. }