createjs easal.js制作了一个很简单的链路图

时间:2022-11-21 15:04:15
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body> <canvas id="demoCanvas" width="388" height="218" style="background-color: #243356;"></canvas> <script src="js/lib/jquery-2.1.0.js" type="text/javascript" charset="utf-8"></script>
<script src="js/lib/easal/lib/easeljs-0.8.2.combined.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
var draw = {};
(function(){
var stage = new createjs.Stage('demoCanvas'); //画四方形
function drawRect(param){
var p = $.extend(true, {
x: 0,
y: 0,
width: 80,
height: 20,
fill: 'red'
}, param); var circle = new createjs.Shape();
circle.graphics.beginFill(p.fill).drawRect(p.x,p.y,p.width,p.height);
stage.addChild(circle);
stage.update();
}
//画直线
function drawLine(param){
var p = $.extend(true, {
x: 0,
y: 0,
x1: 10,
y1: 10,
fill: 'red'
} , param); var g= new createjs.Graphics();
g.setStrokeStyle(2);
g.beginStroke("#7FFF00");
//g.beginFill("red");
g.moveTo(p.x,p.y).lineTo(p.x1,p.y1);
g.endStroke(); _drawToCanvas(g);
} //文字
function write(param){
var p = $.extend(true, {
x: 0,
y: 0,
color: "#333",
text: ""
}, param);
var txt = new createjs.Text(p.text , "14px 微软雅黑" , p.color);
txt.lineWidth = 150;
txt.x = p.x;
txt.y = p.y;
stage.addChild(txt);
stage.update();
} function _drawToCanvas(graphics, canvas){
canvas = canvas || 'demoCanvas';
stage = stage || new createjs.Stage(canvas); var shape = new createjs.Shape(graphics); stage.addChild(shape); stage.update();
} draw = {
drawRect: drawRect,
drawLine: drawLine,
write: write
}
})(); draw.drawLine({
x: 190,
y: 40,
x1: 80,
y1: 150
}); draw.drawLine({
x: 190,
y: 40,
x1: 190,
y1: 150
}); draw.drawLine({
x: 190,
y: 40,
x1: 300,
y1: 150
}); draw.drawRect({
fill: 'skyblue',
x: 150,
y: 20
}); draw.drawRect({
fill: 'skyblue',
x: 40,
y: 150
}); draw.drawRect({
fill: 'skyblue',
x: 150,
y: 150
}); draw.drawRect({
fill: 'skyblue',
x: 260,
y: 150
}); draw.write({
text: "宿 迁",
x: 175,
y: 20
}); draw.write({
text: "移 动",
x: 60,
y: 150
}); draw.write({
text: "联 通",
x: 175,
y: 150
}); draw.write({
text: "电 信",
x: 285,
y: 150
});
</script>
</body>
</html>

createjs    easal.js制作了一个很简单的链路图

 <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body> <canvas id="demoCanvas" width="388" height="218" style="background-color: #243356;"></canvas> <script src="js/lib/jquery-2.1.0.js" type="text/javascript" charset="utf-8"></script>
<script src="js/lib/easal/lib/easeljs-0.8.2.combined.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
$(function(){
var draw = {};
(function(){
var stage = new createjs.Stage('demoCanvas'); //画四方形
function drawRect(param){
var p = $.extend(true, {
x: 0,
y: 0,
width: 80,
height: 40,
fill: 'red'
}, param); var circle = new createjs.Shape();
circle.graphics.beginFill(p.fill).drawEllipse(p.x,p.y,p.width,p.height);
stage.addChild(circle);
stage.update();
}
//画直线
function drawLine(param){
var p = $.extend(true, {
x: 0,
y: 0,
x1: 10,
y1: 10,
fill: 'red'
} , param); var g= new createjs.Graphics();
var aaaa = g.setStrokeDash([10,5]);
g.beginStroke("#7FFF00");
//g.beginFill("red");
g.moveTo(p.x,p.y).lineTo(p.x1,p.y1);
g.endStroke();
_drawToCanvas(g);
} //文字
function write(param){
var p = $.extend(true, {
x: 0,
y: 0,
color: "#333",
text: ""
}, param);
var txt = new createjs.Text(p.text , "14px 微软雅黑" , p.color);
txt.lineWidth = 150;
txt.x = p.x;
txt.y = p.y;
stage.addChild(txt);
stage.update();
} function _drawToCanvas(graphics){
//canvas = canvas || 'demoCanvas';
stage = stage || new createjs.Stage(canvas); var shape = new createjs.Shape(graphics); stage.addChild(shape);
var i = 5;
createjs.Ticker.on('tick' , function(){
i--;
graphics._strokeDash.offset = i;
stage.update();
})
stage.update();
} draw = {
drawRect: drawRect,
drawLine: drawLine,
write: write
}
})(); draw.drawLine({
x: 190,
y: 150,
x1: 80,
y1: 40
}); draw.drawLine({
x: 190,
y: 150,
x1: 190,
y1: 40
}); draw.drawLine({
x: 190,
y: 150,
x1: 300,
y1: 40
}); draw.drawRect({
fill: 'skyblue',
x: 150,
y: 150
}); draw.drawRect({
fill: '#007FCC',
x: 40,
y: 20
}); draw.drawRect({
fill: '#DA0009',
x: 150,
y: 20
}); draw.drawRect({
fill: '#7DB926',
x: 260,
y: 20
}); draw.write({
text: "宿 迁",
x: 175,
y: 160
}); draw.write({
text: "移 动",
x: 60,
y: 30
}); draw.write({
text: "联 通",
x: 175,
y: 30
}); draw.write({
text: "电 信",
x: 285,
y: 30
});
}); </script>
</body>
</html>

增加了动态效果