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.
113 lines
2.9 KiB
113 lines
2.9 KiB
/** |
|
* 气泡图控制器 |
|
* 控制气泡图的显示方向 |
|
* |
|
* 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() { |
|
this.storeBubbles = {}; |
|
this.storePoppers = {}; |
|
} |
|
|
|
/** |
|
* |
|
* @param name |
|
* @param text |
|
* @param context |
|
* @param offsetStyle center, left, right三种类型, 默认left |
|
* @returns {BubblesController} |
|
*/ |
|
show(name, text, context, opt) { |
|
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; |
|
|
|
if (!this.storeBubbles[name]) { |
|
this.storeBubbles[name] = createWidget({ |
|
type: "bi.text", |
|
cls: `bi-bubble bubble-${level}`, |
|
text, |
|
hgap: 5, |
|
height: 18, |
|
}); |
|
} |
|
const bubble = this.storeBubbles[name]; |
|
if (bubble.getText() !== text) { |
|
bubble.setText(text); |
|
} |
|
|
|
createWidget({ |
|
type: "bi.default", |
|
element: container, |
|
items: [ |
|
{ |
|
el: bubble, |
|
} |
|
], |
|
}); |
|
if (this.storePoppers[name]) { |
|
this.storePoppers[name].destroy(); |
|
} |
|
this.storePoppers[name] = BI.Popper.createPopper(context.element[0], bubble.element[0], { |
|
placement: ({ |
|
left: "top-start", |
|
center: "top", |
|
right: "top-end", |
|
})[offsetStyle], |
|
strategy: "fixed", |
|
modifiers: [ |
|
{ |
|
name: "offset", |
|
options: { |
|
offset: [adjustXOffset, adjustYOffset], |
|
}, |
|
}, |
|
{ |
|
name: "preventOverflow", |
|
enabled: false, |
|
} |
|
], |
|
}); |
|
|
|
return this; |
|
} |
|
|
|
hide(name) { |
|
this.remove(name); |
|
|
|
return this; |
|
} |
|
|
|
has(name) { |
|
return isNotNull(this.storeBubbles[name]); |
|
} |
|
|
|
remove(name) { |
|
if (!this.has(name)) { |
|
return this; |
|
} |
|
this.storeBubbles[name].destroy(); |
|
this.storePoppers[name] && this.storePoppers[name].destroy(); |
|
delete this.storeBubbles[name]; |
|
|
|
return this; |
|
} |
|
|
|
removeAll() { |
|
each(this.storeBubbles, (name, bubble) => bubble.destroy()); |
|
each(this.storePoppers, (name, popper) => popper.destroy()); |
|
this.storeBubbles = {}; |
|
this.storePoppers = {}; |
|
|
|
return this; |
|
} |
|
}
|
|
|