forked from fanruan/fineui
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.
102 lines
2.7 KiB
102 lines
2.7 KiB
/** |
|
* 气泡图控制器 |
|
* 控制气泡图的显示方向 |
|
* |
|
* Created by GUY on 2015/8/21. |
|
* @class |
|
*/ |
|
import Controller from "./0.controller"; |
|
export default class BubblesController extends Controller { |
|
init() { |
|
this.storeBubbles = {}; |
|
this.storePoppers = {}; |
|
} |
|
|
|
/** |
|
* |
|
* @param name |
|
* @param text |
|
* @param context |
|
* @param offsetStyle center, left, right三种类型, 默认left |
|
* @returns {BI.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] = BI.createWidget({ |
|
type: "bi.text", |
|
cls: "bi-bubble" + " bubble-" + level, |
|
text: text, |
|
hgap: 5, |
|
height: 18 |
|
}); |
|
} |
|
const bubble = this.storeBubbles[name]; |
|
if (bubble.getText() !== text) { |
|
bubble.setText(text); |
|
} |
|
|
|
BI.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] |
|
} |
|
} |
|
] |
|
}); |
|
return this; |
|
} |
|
|
|
hide(name) { |
|
this.remove(name); |
|
return this; |
|
} |
|
|
|
has(name) { |
|
return this.storeBubbles[name] != null; |
|
} |
|
|
|
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() { |
|
BI.each(this.storeBubbles, (name, bubble) => bubble.destroy()); |
|
BI.each(this.storePoppers, (name, popper) => popper.destroy()); |
|
this.storeBubbles = {}; |
|
this.storePoppers = {}; |
|
return this; |
|
} |
|
} |
|
BI.extend(BI, { BubblesController });
|
|
|