fineui是帆软报表和BI产品线所使用的前端框架。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

305 lines
11 KiB

8 years ago
/**
* 气泡图控制器
* 控制气泡图的显示方向
*
* Created by GUY on 2015/8/21.
* @class
*/
BI.BubblesController = BI.inherit(BI.Controller, {
_defaultConfig: function () {
return BI.extend(BI.BubblesController.superclass._defaultConfig.apply(this, arguments), {});
},
_const: {
bubbleHeight: 18
8 years ago
},
_init: function () {
BI.BubblesController.superclass._init.apply(this, arguments);
7 years ago
var self = this;
5 years ago
this.fixedBubblesManager = {};
this.fixedStoreBubbles = {};
8 years ago
this.bubblesManager = {};
this.storeBubbles = {};
7 years ago
BI.Resizers.add("bubbleController" + BI.uniqueId(), function () {
5 years ago
BI.each(self.fixedBubblesManager, function (name) {
7 years ago
self.remove(name);
});
5 years ago
self.fixedBubblesManager = {};
self.fixedStoreBubbles = {};
7 years ago
});
8 years ago
},
5 years ago
_createBubble: function (direct, text, level, height, fixed) {
8 years ago
return BI.createWidget({
5 years ago
type: fixed === false ? "bi.bubble_view" : "bi.bubble",
8 years ago
text: text,
level: level,
height: height || 18,
8 years ago
direction: direct
});
},
8 years ago
_getOffsetLeft: function (name, context, offsetStyle) {
8 years ago
var left = 0;
if ("center" === offsetStyle) {
7 years ago
left = context.element.offset().left + (context.element.bounds().width - this.get(name).element.bounds().width) / 2;
8 years ago
if (left < 0) {
left = 0;
}
return left;
}
if ("right" === offsetStyle) {
7 years ago
left = context.element.offset().left + context.element.bounds().width - this.get(name).element.bounds().width;
8 years ago
if (left < 0) {
left = 0;
}
return left;
}
7 years ago
return context.element.offset().left;
8 years ago
},
8 years ago
_getOffsetTop: function (name, context, offsetStyle) {
8 years ago
var top = 0;
if ("center" === offsetStyle) {
7 years ago
top = context.element.offset().top + (context.element.bounds().height - this.get(name).element.bounds().height) / 2;
8 years ago
if (top < 0) {
top = 0;
}
return top;
} else if ("right" === offsetStyle) {
7 years ago
top = context.element.offset().top + context.element.bounds().height - this.get(name).element.bounds().height;
8 years ago
if (top < 0) {
top = 0;
}
return top;
}
7 years ago
return context.element.offset().top;
8 years ago
},
8 years ago
_getLeftPosition: function (name, context, offsetStyle) {
6 years ago
var position = BI.DOM.getLeftPosition(context, this.get(name));
8 years ago
position.top = this._getOffsetTop(name, context, offsetStyle);
return position;
},
8 years ago
_getBottomPosition: function (name, context, offsetStyle) {
6 years ago
var position = BI.DOM.getBottomPosition(context, this.get(name));
8 years ago
position.left = this._getOffsetLeft(name, context, offsetStyle);
return position;
},
8 years ago
_getTopPosition: function (name, context, offsetStyle) {
6 years ago
var position = BI.DOM.getTopPosition(context, this.get(name));
8 years ago
position.left = this._getOffsetLeft(name, context, offsetStyle);
return position;
},
8 years ago
_getRightPosition: function (name, context, offsetStyle) {
6 years ago
var position = BI.DOM.getRightPosition(context, this.get(name));
8 years ago
position.top = this._getOffsetTop(name, context, offsetStyle);
return position;
},
/**
*
* @param name
* @param text
* @param context
* @param offsetStyle center, left, right三种类型 默认left
* @returns {BI.BubblesController}
*/
show: function (name, text, context, opt) {
opt || (opt = {});
var container = opt.container || context;
5 years ago
var offsetStyle = opt.offsetStyle || "left";
var level = opt.level || "error";
7 years ago
var adjustYOffset = opt.adjustYOffset || 0;
var adjustXOffset = opt.adjustXOffset || 0;
5 years ago
var fixed = opt.fixed !== false;
5 years ago
// 如果是非固定位置(fixed)的bubble
if (fixed === false) {
5 years ago
if (!this.storeBubbles[name]) {
this.storeBubbles[name] = {};
}
if (!this.storeBubbles[name]["top"]) {
this.storeBubbles[name]["top"] = this._createBubble("top", text, level, null, fixed);
}
BI.createWidget({
type: "bi.absolute",
element: container,
items: [{
el: this.storeBubbles[name]["top"]
}]
});
this.set(name, this.storeBubbles[name]["top"]);
5 years ago
var bubble = this.storeBubbles[name]["top"];
var bounds = bubble.element.bounds();
if (BI.DOM.isTopSpaceEnough(context, this.get(name), adjustYOffset)) {
var top = -(bounds.height + adjustYOffset);
switch (offsetStyle) {
case "center":
bubble.element.css({
left: (context.element.bounds().width - bounds.width) / 2 + adjustXOffset,
top: top
});
break;
case "right":
bubble.element.css({
right: adjustXOffset,
top: top
});
break;
default:
bubble.element.css({
left: adjustXOffset,
top: top
});
break;
}
} else {
var bottom = -(bounds.height + adjustYOffset);
switch (offsetStyle) {
case "center":
bubble.element.css({
left: (context.element.bounds().width - bounds.width) / 2 + adjustXOffset,
bottom: bottom
});
break;
case "right":
bubble.element.css({
right: adjustXOffset,
bottom: bottom
});
break;
default:
bubble.element.css({
left: adjustXOffset,
bottom: bottom
});
break;
}
}
5 years ago
} else {
5 years ago
if (!this.fixedStoreBubbles[name]) {
this.fixedStoreBubbles[name] = {};
}
if (!this.fixedStoreBubbles[name]["top"]) {
this.fixedStoreBubbles[name]["top"] = this._createBubble("top", text, level, null, fixed);
}
BI.createWidget({
type: "bi.absolute",
element: container,
items: [{
el: this.fixedStoreBubbles[name]["top"]
}]
});
this.set(name, this.fixedStoreBubbles[name]["top"]);
5 years ago
var position = this._getTopPosition(name, context, offsetStyle);
this.get(name).element.css({left: position.left + adjustXOffset, top: position.top - adjustYOffset});
if (!BI.DOM.isTopSpaceEnough(context, this.get(name), adjustYOffset)) {
5 years ago
this.get(name).invisible();
5 years ago
if (!this.fixedStoreBubbles[name]["bottom"]) {
this.fixedStoreBubbles[name]["bottom"] = this._createBubble("bottom", text, level);
8 years ago
}
BI.createWidget({
type: "bi.absolute",
element: container,
items: [{
5 years ago
el: this.fixedStoreBubbles[name]["bottom"]
8 years ago
}]
8 years ago
});
5 years ago
this.set(name, this.fixedStoreBubbles[name]["bottom"]);
5 years ago
var position = this._getBottomPosition(name, context, offsetStyle);
this.get(name).element.css({left: position.left + adjustXOffset, top: position.top + adjustYOffset});
if (!BI.DOM.isBottomSpaceEnough(context, this.get(name), adjustYOffset)) {
5 years ago
this.get(name).invisible();
5 years ago
if (!this.fixedStoreBubbles[name]["right"]) {
this.fixedStoreBubbles[name]["right"] = this._createBubble("right", text, level);
8 years ago
}
BI.createWidget({
type: "bi.absolute",
element: container,
items: [{
5 years ago
el: this.fixedStoreBubbles[name]["right"]
8 years ago
}]
});
5 years ago
this.set(name, this.fixedStoreBubbles[name]["right"]);
5 years ago
var position = this._getRightPosition(name, context, offsetStyle);
5 years ago
this.get(name).element.css({
5 years ago
left: position.left + adjustXOffset,
5 years ago
top: position.top - adjustYOffset
5 years ago
});
5 years ago
if (!BI.DOM.isRightSpaceEnough(context, this.get(name), adjustXOffset)) {
this.get(name).invisible();
5 years ago
if (!this.fixedStoreBubbles[name]["left"]) {
this.fixedStoreBubbles[name]["left"] = this._createBubble("left", text, level, 30);
5 years ago
}
BI.createWidget({
type: "bi.absolute",
element: container,
items: [{
5 years ago
el: this.fixedStoreBubbles[name]["left"]
5 years ago
}]
});
5 years ago
this.set(name, this.fixedStoreBubbles[name]["left"]);
5 years ago
var position = this._getLeftPosition(name, context, offsetStyle);
this.get(name).element.css({
left: position.left - adjustXOffset,
top: position.top - adjustYOffset
});
}
8 years ago
}
}
}
5 years ago
this.get(name).setText(text);
this.get(name).visible();
8 years ago
return this;
},
8 years ago
hide: function (name) {
if (!this.has(name)) {
return this;
}
this.get(name).invisible();
return this;
},
8 years ago
add: function (name, bubble) {
if (this.has(name)) {
return this;
}
this.set(name, bubble);
return this;
},
get: function (name) {
5 years ago
return this.fixedBubblesManager[name] || this.bubblesManager[name];
8 years ago
},
5 years ago
set: function (name, bubble, fixed) {
fixed === false ? (this.bubblesManager[name] = bubble) : (this.fixedBubblesManager[name] = bubble);
8 years ago
},
has: function (name) {
5 years ago
return this.fixedBubblesManager[name] != null || this.bubblesManager[name] != null;
8 years ago
},
remove: function (name) {
if (!this.has(name)) {
return this;
}
5 years ago
BI.each(this.fixedStoreBubbles[name], function (dir, bubble) {
bubble.destroy();
});
delete this.fixedStoreBubbles[name];
delete this.fixedBubblesManager[name];
8 years ago
BI.each(this.storeBubbles[name], function (dir, bubble) {
bubble.destroy();
});
delete this.storeBubbles[name];
8 years ago
delete this.bubblesManager[name];
return this;
}
5 years ago
});