我正在尝试在应用程序内的手风琴内使用draw2d
javascript 库。ui-bootstrap-tpls
angularjs
一个简单的例子:(我会构建一个 plunker,但我无法包含所需的库。在这个例子中,draw2d-canvas
实现为 angularjs 指令。
索引.html:
<body id="myBody" ng-controller="MyDrawCtlr">
<div class="col-xs-12 panel panel-default row">
<div id="canvas1" draw2d-canvas></div>
<uib-accordion close-others="true" class="col-xs-8">
<uib-accordion-group heading="The Chart" is-open="true">
<div id="canvas2" draw2d-canvas></div>
</uib-accordion-group>
</uib-accordion>
</div>
</body>
app.js:(取自作为 draw2d 包的一部分提供的 angularjs 模板)
var app = angular.module('test2dApp', ['draw2d', 'ui.bootstrap']);
app.controller('MyDrawCtlr', function ($scope) {
$scope.jsonDocument1 =
[
{
"type": "draw2d.shape.basic.Rectangle",
"id": "rec1",
"x": 50,
"y": 100,
"width": 201,
"height": 82,
"radius": 5,
"resizeable": true,
"selectable": true
},
{
"type": "draw2d.shape.basic.Label",
"text": "This is a label.",
"id": "myLabel1",
"x": 50,
"y": 50,
"minWidth": 100,
"fontSize": 30,
"padding": 200,
"resizeable": true,
"selectable": true,
"cssClass": "draw2d_shape_basic_Label"
}
];
});
var d2 = angular.module('draw2d', []);
d2.directive("draw2dCanvas", ["$window", "$parse", "$timeout", function ($window, $parse, $timeout) {
return {
restrict: 'E,A',
link: function (scope, element, attrs, controller) {
scope.editor = $.extend(true, {
canvas: {
width: 1000,
height: 1000
},
palette: {
figures: []
},
selection: {
className: null,
figure: null,
attr: null
}
}, scope.editor);
var canvas = new draw2d.Canvas(element.attr("id"), scope.editor.canvas.width, scope.editor.canvas.height);
canvas.setScrollArea("#" + element.attr("id"));
canvas.onDrop = $.proxy(scope.editor.canvas.onDrop, canvas);
var reader = new draw2d.io.json.Reader();
reader.unmarshal(canvas, scope.jsonDocument1);
}
};
}]);
这是显示结果的图形: 顶部图形是预期结果。请注意,文本周围的框大小不正确且位置错误。
除了格式问题(文本未正确定位和框大小不正确)之外,无法像手风琴外的相同标签一样选择和移动标签。
我猜想draw2d库和相应(可能还有其他模板)的ui-bootstrap-tpls在属性命名和/或css中以某种方式发生冲突。
谢谢您的帮助。