FxSVG
Functional SVG Handling Library
API
$$getSVG
내부적으로 사용하는 svg 객체를 반환합니다.
$$setSVG
함수로 설정하지 않은 경우 document.createElementNS
를 실행합니다.
해당 함수를 실행하지 못하는 환경인 경우 $$setSVG
함수로 사용할 svg 객체를 설정합니다.
console.log($$getSVG());
$$setSVG
내부적으로 사용하는 svg 객체를 설정한 후 설정한 svg 객체를 반환합니다.
console.log(
$$setSVG(document.createElementNS("http://www.w3.org/2000/svg", "svg"))
);
$$els
svg 문자열을 받아 svg 객체를 담은 배열을 생성합니다.
console.log($$els('<rect x="0" y="0" width="10" height="10"></rect>'));
console.log(
$$els(
'<rect x="0" y="0" width="10" height="10"></rect><circle cx="1" cy="1" r="5"></circle>'
)
);
$$el
svg 문자열을 받아 svg 객체를 생성합니다.
console.log($$el('<rect x="0" y="0" width="10" height="10"></rect>'));
console.log(
$$el(
'<rect x="0" y="0" width="10" height="10"></rect><circle cx="1" cy="1" r="5"></circle>'
)
);
$$createSVGPoint
SVGPoint
객체를 생성합니다.
console.log($$createSVGPoint());
console.log($$createSVGPoint({ x: 10 }));
console.log($$createSVGPoint({ y: 10 }));
console.log($$createSVGPoint({ x: 10, y: 10 }));
$$createSVGRect
SVGRect
객체를 생성합니다.
console.log($$createSVGRect());
console.log($$createSVGRect({ x: 10 }));
console.log($$createSVGRect({ width: 100 }));
console.log($$createSVGRect({ x: 10, y: 10, width: 100, height: 100 }));
$$createSVGMatrix
SVGMatrix
객체를 생성합니다.
console.log($$createSVGMatrix());
console.log($$createSVGMatrix({ e: 10, f: 20 }));
console.log($$createSVGMatrix({ a: 2, b: 0, c: 0, d: 4, e: 10, f: 20 }));
$$createSVGTransform
SVGTransform
객체를 생성합니다.
console.log($$createSVGTransform());
$$createSVGTransformTranslate
type
이 SVGTransform.SVG_TRANSFORM_TRANSLATE
인 SVGTransform
객체를 생성합니다.
tx
로 x축 방향으로 이동할 값, ty
로 y축 방향으로 이동할 값을 설정합니다.
console.log($$createSVGTransformTranslate());
console.log($$createSVGTransformTranslate({ tx: 10 }));
console.log($$createSVGTransformTranslate({ tx: 10, ty: 20 }));
$$createSVGTransformRotate
type
이 SVGTransform.SVG_TRANSFORM_ROTATE
인 SVGTransform
객체를 생성합니다.
cx
, cy
로 회전할 중심의 좌포를 설정하고 angle
로 회전할 각도(deg
단위)를 설정합니다.
cx
, cy
를 설정하지 않으면 (0, 0)
으로 설정합니다.
console.log($$createSVGTransformRotate());
console.log($$createSVGTransformRotate({ angle: 45 }));
console.log($$createSVGTransformRotate({ cx: 10, cy: 10, angle: 30 }));
$$createSVGTransformScale
type
이 SVGTransform.SVG_TRANSFORM_SCALE
인 SVGTransform
객체를 생성합니다.
sx
로 x축 방향으로 확대할 비율을, sy
로 y축 방향으로 확대할 비율을 설정합니다.
sx
, sy
가 음수일 경우 해당 축을 기준으로 대칭이동합니다.
console.log($$createSVGTransformScale());
console.log($$createSVGTransformScale({ sx: 2 }));
console.log($$createSVGTransformScale({ sx: 2, sy: 4 }));
$$createSVGTransformMatrix
type
이 SVGTransform.SVG_TRANSFORM_MATRIX
인 SVGTransform
객체를 생성합니다.
SVGTransform
에 인자로 받은 SVGMatrix
를 설정합니다.
console.log($$createSVGTransformMatrix($$createSVGMatrix()));
console.log(
$$createSVGTransformMatrix(
$$createSVGMatrix({ a: 2, b: 3, c: 4, d: 5, e: 6, f: 7 })
)
);
$$isTranslateSVGTransform
해당 SVGTransform
의 type
이 SVGTransform.SVG_TRANSFORM_TRANSLATE
인지 여부를 판단합니다.
console.log($$isTranslateSVGTransform($$createSVGTransformTranslate()));
console.log($$isTranslateSVGTransform($$createSVGTransformRotate()));
$$isRotateSVGTransform
해당 SVGTransform
의 type
이 SVGTransform.SVG_TRANSFORM_ROTATE
인지 여부를 판단합니다.
console.log($$isRotateSVGTransform($$createSVGTransformRotate()));
console.log($$isRotateSVGTransform($$createSVGTransformTranslate()));
$$isScaleSVGTransform
해당 SVGTransform
의 type
이 SVGTransform.SVG_TRANSFORM_SCALE
인지 여부를 판단합니다.
console.log($$isScaleSVGTransform($$createSVGTransformScale()));
console.log($$isScaleSVGTransform($$createSVGTransformTranslate()));
$$getBaseTransformList
입력받은 svg 객체의 transform.baseVal
값을 반환합니다.
SVGGraphicsElement
인터페이스는 transform
속성으로 SVGAnimatedTransformList
객체를 가지고 있고
해당 객체는 baseVal
속성으로 SVGTransformList
객체를 가지고 있습니다.
const $el = $$el(`
<rect
x="0"
y="0"
width="10"
height="20"
transform="translate(10, 20) rotate(45, 100, 200) scale(2, 3)"
></rect>
`);
console.log($$getBaseTransformList($el));
$$getAnimTransformList
입력받은 svg 객체의 transform.animVal
값을 반환합니다.
SVGGraphicsElement
인터페이스는 transform
속성으로 SVGAnimatedTransformList
객체를 가지고 있고
해당 객체는 animVal
속성으로 SVGTransformList
객체를 가지고 있습니다.
animVal
은 SMIL 애니메이션이 적용된 경우에만 baseVal
과 다릅니다. 특별한 상황이 아닌 한 동일한 값을 가집니다.
하지만 값은 동일해도 다른 래퍼런스를 가리킵니다.
const $el = $$el(`
<rect
x="0"
y="0"
width="10"
height="20"
transform="translate(10, 20) rotate(45, 100, 200) scale(2, 3)"
></rect>
`);
console.log($$getAnimTransformList($el));
$$getBoxPoints
svg 객체의 영역에 해당하는 SVGPoint
들을 반환합니다. 해당 svg 객체는 DOM 트리의 <svg></svg>
태그에 속해 있어야 합니다.
original
속성은 svg 객체가 transform
하기 전 영역입니다.
transformed
속성은 svg 객체가 transform
한 후 영역입니다.
bounding
속성은 svg 객체가 transform
한 후 영역을 덮는 최소 직사각형 영역입니다.
const $el = $$el(`
<rect
x="10"
y="20"
width="100"
height="200"
transform="translate(400, 500)"
>
</rect>
`);
$svg.appendChild($el);
console.log($$getBoxPoints($el));
$$getCenterPoint
svg 객체의 중심에 해당하는 SVGPoint
를 반환합니다. 해당 svg 객체는 DOM 트리의 <svg></svg>
태그에 속해 있어야 합니다.
original
속성은 svg 객체가 transform
하기 전 중심입니다.
transformed
속성은 svg 객체가 transform
한 후 중심입니다.
const $el = $$el(`
<rect
x="10"
y="20"
width="100"
height="200"
transform="translate(400, 500)"
>
</rect>
`);
$svg.appendChild($el);
console.log($$getCenterPoint($el));