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.

108 lines
2.8 KiB

4 years ago
/**
* 气泡图控制器
* 控制气泡图的显示方向
*
* Created by GUY on 2015/8/21.
* @class
*/
import { Controller } from "./0.controller";
export class BubblesController extends Controller {
init() {
4 years ago
this.storeBubbles = {};
this.storePoppers = {};
}
4 years ago
/**
*
* @param name
* @param text
* @param context
* @param offsetStyle center, left, right三种类型 默认left
* @returns {BI.BubblesController}
*/
show(name, text, context, opt) {
4 years ago
opt || (opt = {});
const container = opt.container || context;
const offsetStyle = opt.offsetStyle || "left";
const level = opt.level || "error";
const adjustYOffset = opt.adjustYOffset || 0;
const adjustXOffset = opt.adjustXOffset || 0;
// const fixed = opt.fixed !== false;
4 years ago
if (!this.storeBubbles[name]) {
this.storeBubbles[name] = BI.createWidget({
type: "bi.text",
4 years ago
cls: "bi-bubble" + " bubble-" + level,
text: text,
hgap: 5,
height: 18
});
}
const bubble = this.storeBubbles[name];
if (bubble.getText() !== text) {
bubble.setText(text);
}
4 years ago
BI.createWidget({
type: "bi.default",
element: container,
items: [
{
el: bubble
}
]
4 years ago
});
if (this.storePoppers[name]) {
this.storePoppers[name].destroy();
}
this.storePoppers[name] = BI.Popper.createPopper(context.element[0], bubble.element[0], {
4 years ago
placement: ({
left: "top-start",
center: "top",
right: "top-end"
})[offsetStyle],
strategy: "fixed",
modifiers: [
{
name: "offset",
options: {
offset: [adjustXOffset, adjustYOffset]
}
},
{
name: "preventOverflow",
enabled: false
}
4 years ago
]
});
return this;
}
4 years ago
hide(name) {
4 years ago
this.remove(name);
return this;
}
4 years ago
has(name) {
4 years ago
return this.storeBubbles[name] != null;
}
4 years ago
remove(name) {
4 years ago
if (!this.has(name)) {
return this;
}
this.storeBubbles[name].destroy();
this.storePoppers[name] && this.storePoppers[name].destroy();
4 years ago
delete this.storeBubbles[name];
return this;
}
4 years ago
removeAll() {
BI.each(this.storeBubbles, (name, bubble) => bubble.destroy());
BI.each(this.storePoppers, (name, popper) => popper.destroy());
4 years ago
this.storeBubbles = {};
this.storePoppers = {};
4 years ago
return this;
4 years ago
}
}