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.

114 lines
2.9 KiB

4 years ago
/**
* 气泡图控制器
* 控制气泡图的显示方向
*
* Created by GUY on 2015/8/21.
*/
import { Controller } from "./0.controller";
import { isNotNull, each } from "../2.base";
import { createWidget } from "../5.inject";
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 {BubblesController}
4 years ago
*/
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] = createWidget({
type: "bi.text",
cls: `bi-bubble bubble-${level}`,
text,
4 years ago
hgap: 5,
height: 18,
4 years ago
});
}
const bubble = this.storeBubbles[name];
if (bubble.getText() !== text) {
bubble.setText(text);
}
4 years ago
createWidget({
4 years ago
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",
4 years ago
})[offsetStyle],
strategy: "fixed",
modifiers: [
{
name: "offset",
options: {
offset: [adjustXOffset, adjustYOffset],
},
},
{
name: "preventOverflow",
enabled: false,
}
],
4 years ago
});
4 years ago
return this;
}
4 years ago
hide(name) {
4 years ago
this.remove(name);
4 years ago
return this;
}
4 years ago
has(name) {
return isNotNull(this.storeBubbles[name]);
}
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];
4 years ago
return this;
}
4 years ago
removeAll() {
each(this.storeBubbles, (name, bubble) => bubble.destroy());
each(this.storePoppers, (name, popper) => popper.destroy());
4 years ago
this.storeBubbles = {};
this.storePoppers = {};
4 years ago
return this;
4 years ago
}
}