맞춤 속성과 기능을 사용하여 맞춤 Raphael 요소를 만들고 싶습니다. 이 오브젝트에는 또한 사전 정의 된 Raphael 오브젝트가 있어야합니다. 예를 들어, 텍스트와 다른 요소가 포함 된 원을 포함하는 노드 클래스가 있습니다. 문제는이 새 객체를 세트에 추가하는 것입니다. Raphael이 아닌 오브젝트는 세트에 추가 할 수 없으므로 이러한 요구가 필요합니다. 따라서 Raphael 객체를 포함 할 수있는 사용자 정의 객체는 사용할 수 없습니다.Raphael.js : 새로운 맞춤 요소 추가하기
var Node = function (paper) {
// Coordinates & Dimensions
this.x = 0,
this.y = 0,
this.radius = 0,
this.draw = function() {
this.entireSet = paper.set();
var circle = paper.circle(this.x, this.y, this.radius);
this.circleObj = circle;
this.entireSet.push(circle);
var text = paper.text(this.x, this.y, this.text);
this.entireSet.push(text);
}
// other functions
}
var NodeList = function(paper){
this.nodes = paper.set(),
this.populateList = function(){
// in order to add a node to the set
// the object must be of type Raphael object
// otherwise the set will have no elements
this.nodes.push(// new node)
}
this.nextNode = function(){
// ...
}
this.previousNode = function(){
// ...
}
}
는이 같은 뭔가를 찾고 계십니까 : 현재 지원되지 않는 몇 가지 이유입니다 인스턴스 (종이) 이 예는 AG 요소를 감싸는 라파엘 객체를 생성, 수? http://raphaeljs.com/reference.html#Raphael.fn. .arrow() 또는 원하는 것과 같은 함수의 결과로 복잡한 객체를 만들 수있는 사용자 정의 함수를 추가하는 방법이 설명되어 있습니다. – cabreracanal
내가 아는 한 Raphael.fn은 Raphael 개체를 만들지 않습니다. 따라서 생성 된 오브젝트는 Raphael 세트에 추가 될 수 없습니다. 내 클래스는 다음과 같습니다 VAR 노드 = 함수() { // 좌표 및 치수 this.x = 0, this.y = 0, this.radius = 0, this.stroke = 1, // ... 이것을 반환합니다. } – Claudia
작성한 .fn에 첨부하는 기능입니다. 내부에 텍스트가있는 원을 만들려면 (내 질문을 이해하면)이 예제처럼이 방법을 사용합니다 (https://gist.github.com/1043360). 개체가 경로라면 집합에 추가 할 수 있습니다. 또한 텍스트와 서클을 별도로 만들어 세트에 넣을 수 있습니다. 사용자 정의 속성을이 속성에 지정할 수도 있습니다. – cabreracanal