EasyEDA API Examples
Examples
Check Github example
Enjoy it, if you have any questions, do let us know.
modifyTrackVia.js:
//you can get the EasyEDA json objects like https://gist.github.com/071d4680dcdbf6bf9dd6.git
//try to pen a pcb, then run bellow codes.
var json = api('getSource', {type: "json"}),
id;
for(id in json.TRACK){
if(json.TRACK.hasOwnProperty(id)){
json.TRACK[id].strokeWidth = api('edit.unitConvert', {type:'mil2pixel',value:10}); // 10mil
}
}
for(id in json.VIA){
if(json.VIA.hasOwnProperty(id)){
json.VIA[id].holeR = api('edit.unitConvert', {type:'mil2pixel',value:10}); // 10mil
}
}
api('applySource', {source: json, createNew: true});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
schematicShapes.js:
testInsertShape();
function testInsertShape(){
api('insertShape', [
{
shapeTypeName: "path",
fillColor: "none",
pathString: "M520 500 C480 460 550 430 480 410",
strokeColor: "#000000",
strokeStyle: 0,
strokeWidth: "1"
}
]);
api('insertShape', [
{
shapeTypeName: "path",
fillColor: "none",
pathString: shapeLotusFlower(500,550,3,80,40),
strokeColor: "#000000",
strokeStyle: 0,
strokeWidth: "1"
},
{
shapeTypeName: "path",
fillColor: "none",
pathString: shapeLotusFlower(700,500,6,70,30),
strokeColor: "#ff00ff",
strokeStyle: 0,
strokeWidth: "1"
},
{
shapeTypeName: "path",
fillColor: "none",
pathString: shapeFlower2(660,670,4, 14,-Math.PI/4, 63.246,-0.32175, 84.85,Math.PI/4),
strokeColor: "#cccc00",
strokeStyle: 0,
strokeWidth: "2"
}
]);
}
/** Lotus shape path */
function shapeLotusFlower(cx,cy,n,r,r2){
var pathD = '', angle, angle2, x, y, x2, y2;
function p(x,y){
return (x+cx)+' '+(y+cy);
}
for(var i=0; i<n; i++){
angle = i * Math.PI / n;
angle2 = (i / n + 0.5) * Math.PI;
x = r * Math.cos(angle);
y = r * Math.sin(angle);
x2 = r2 * Math.cos(angle2);
y2 = r2 * Math.sin(angle2);
pathD += 'M'+p(x,y)
+'C'+p(x2,y2)+' '+p(-x2,-y2)+' '+p(-x,-y)
+'C'+p(x2,y2)+' '+p(-x2,-y2)+' '+p(x,y);
}
return pathD;
}
/** Petal shape path */
function shapeFlower2(cx,cy,n,r1,a1,r2,a2,r3,a3){
var pathD = '', angle, angle2, angle3, angle4, x, y, x2, y2;
function p(r,thi){
return (r * Math.cos(thi) + cx)+' '+(r * Math.sin(thi) + cy);
}
function polar(r,thi){
return {r:r,thi:thi};
}
for(var i=0; i<n; i++){
angle = i>0 ? angle4 : a1 + i * 2 * Math.PI / n;
angle2 = a2 + i * 2 * Math.PI / n;
angle3 = a3 + i * 2 * Math.PI / n;
angle4 = a1 + (i+1) * 2 * Math.PI / n;
pathD += (i>0 ? '' : 'M'+p(r1,angle))
+'C'+p(r2,angle2)+' '+p(r3,angle3)+' '+p(r1,angle4);
}
return pathD;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79