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.

274 lines
9.9 KiB

8 years ago
/**
* 水平tape布局
* @class BI.HTapeLayout
* @extends BI.Layout
*/
BI.HTapeLayout = BI.inherit(BI.Layout, {
8 years ago
props: function () {
return BI.extend(BI.HTapeLayout.superclass.props.apply(this, arguments), {
4 years ago
baseCls: "bi-h-tape",
4 years ago
verticalAlign: BI.VerticalAlign.Top,
8 years ago
hgap: 0,
vgap: 0,
lgap: 0,
rgap: 0,
tgap: 0,
bgap: 0,
4 years ago
columnSize: [],
items: []
8 years ago
});
},
8 years ago
render: function () {
BI.HTapeLayout.superclass.render.apply(this, arguments);
8 years ago
this.populate(this.options.items);
},
resize: function () {
this.stroke(this.options.items);
},
addItem: function (item) {
// do nothing
7 years ago
throw new Error("cannot be added");
8 years ago
},
stroke: function (items) {
var self = this, o = this.options;
items = BI.compact(items);
BI.each(items, function (i, item) {
4 years ago
if (BI.isEmptyObject(item)) {
return;
}
if (!self.hasWidget(self._getChildName(i))) {
5 years ago
var w = BI._lazyCreateWidget(item);
self.addWidget(self._getChildName(i), w);
8 years ago
} else {
w = self.getWidgetByName(self._getChildName(i));
8 years ago
}
w.element.css({
position: "absolute",
top: ((item.vgap || 0) + (item.tgap || 0) + o.vgap + o.tgap) / BI.pixRatio + BI.pixUnit,
bottom: ((item.bgap || 0) + (item.vgap || 0) + o.vgap + o.bgap) / BI.pixRatio + BI.pixUnit
});
4 years ago
if (o.verticalAlign === BI.VerticalAlign.Middle) {
w.element.css({
marginTop: "auto",
marginBottom: "auto"
});
} else if (o.verticalAlign === BI.VerticalAlign.Bottom) {
w.element.css({
marginTop: "auto"
});
}
8 years ago
});
var left = {}, right = {};
left[0] = 0;
right[items.length - 1] = 0;
BI.any(items, function (i, item) {
4 years ago
if (BI.isEmptyObject(item)) {
return true;
}
var w = self.getWidgetByName(self._getChildName(i));
4 years ago
var columnSize = o.columnSize.length > 0 ? o.columnSize[i] : item.width;
4 years ago
if (o.columnSize.length > 0) {
if (item.width >= 1 && o.columnSize[i] >= 1 && o.columnSize[i] !== item.width) {
columnSize = item.width;
}
}
8 years ago
if (BI.isNull(left[i])) {
4 years ago
var preColumnSize = o.columnSize.length > 0 ? o.columnSize[i - 1] : items[i - 1].width;
4 years ago
left[i] = left[i - 1] + preColumnSize + (items[i - 1].lgap || 0) + (items[i - 1].rgap || 0) + 2 * (items[i - 1].hgap || 0) + o.hgap + o.lgap + o.rgap;
8 years ago
}
4 years ago
if (columnSize < 1 && columnSize > 0) {
4 years ago
w.element.css({
left: (left[i] * 100).toFixed(1) + "%",
4 years ago
width: (columnSize * 100).toFixed(1) + "%"
4 years ago
});
8 years ago
} else {
w.element.css({
left: (left[i] + (item.lgap || 0) + (item.hgap || 0) + o.hgap + o.lgap) / BI.pixRatio + BI.pixUnit,
4 years ago
width: BI.isNumber(columnSize) ? columnSize / BI.pixRatio + BI.pixUnit : ""
8 years ago
});
}
4 years ago
if (columnSize === "" || columnSize === "fill") {
8 years ago
return true;
}
});
BI.backAny(items, function (i, item) {
4 years ago
if (BI.isEmptyObject(item)) {
return true;
}
var w = self.getWidgetByName(self._getChildName(i));
4 years ago
var columnSize = o.columnSize.length > 0 ? o.columnSize[i] : item.width;
8 years ago
if (BI.isNull(right[i])) {
4 years ago
var nextColumnSize = o.columnSize.length > 0 ? o.columnSize[i + 1] : items[i + 1].width;
4 years ago
right[i] = right[i + 1] + nextColumnSize + (items[i + 1].lgap || 0) + (items[i + 1].rgap || 0) + 2 * (items[i + 1].hgap || 0) + o.hgap + o.lgap + o.rgap;
8 years ago
}
4 years ago
if (columnSize < 1 && columnSize > 0) {
4 years ago
w.element.css({
4 years ago
right: (right[i] * 100).toFixed(1) + "%",
4 years ago
width: (columnSize * 100).toFixed(1) + "%"
4 years ago
});
8 years ago
} else {
w.element.css({
right: (right[i] + (item.rgap || 0) + (item.hgap || 0) + o.hgap + o.rgap) / BI.pixRatio + BI.pixUnit,
4 years ago
width: BI.isNumber(columnSize) ? columnSize / BI.pixRatio + BI.pixUnit : ""
8 years ago
});
}
4 years ago
if (columnSize === "" || columnSize === "fill") {
8 years ago
return true;
}
7 years ago
});
8 years ago
},
6 years ago
update: function () {
var updated;
BI.each(this._children, function (i, child) {
updated = child.update() || updated;
});
return updated;
},
8 years ago
populate: function (items) {
BI.HTapeLayout.superclass.populate.apply(this, arguments);
8 years ago
this._mount();
8 years ago
}
});
7 years ago
BI.shortcut("bi.htape", BI.HTapeLayout);
8 years ago
/**
* 垂直tape布局
* @class BI.VTapeLayout
* @extends BI.Layout
*/
BI.VTapeLayout = BI.inherit(BI.Layout, {
8 years ago
props: function () {
return BI.extend(BI.VTapeLayout.superclass.props.apply(this, arguments), {
8 years ago
baseCls: "bi-v-tape-layout",
4 years ago
horizontalAlign: BI.HorizontalAlign.Left,
8 years ago
hgap: 0,
vgap: 0,
lgap: 0,
rgap: 0,
tgap: 0,
bgap: 0,
4 years ago
rowSize: [],
items: []
8 years ago
});
},
8 years ago
render: function () {
BI.VTapeLayout.superclass.render.apply(this, arguments);
8 years ago
this.populate(this.options.items);
},
resize: function () {
this.stroke(this.options.items);
},
addItem: function (item) {
// do nothing
7 years ago
throw new Error("cannot be added");
8 years ago
},
stroke: function (items) {
var self = this, o = this.options;
items = BI.compact(items);
BI.each(items, function (i, item) {
4 years ago
if (BI.isEmptyObject(item)) {
return;
}
if (!self.hasWidget(self._getChildName(i))) {
5 years ago
var w = BI._lazyCreateWidget(item);
self.addWidget(self._getChildName(i), w);
8 years ago
} else {
w = self.getWidgetByName(self._getChildName(i));
8 years ago
}
w.element.css({
position: "absolute",
left: ((item.lgap || 0) + (item.hgap || 0) + o.hgap + o.lgap) / BI.pixRatio + BI.pixUnit,
4 years ago
right: ((item.hgap || 0) + (item.rgap || 0) + o.hgap + o.rgap) / BI.pixRatio + BI.pixUnit
});
4 years ago
if (o.horizontalAlign === BI.HorizontalAlign.Center) {
w.element.css({
marginLeft: "auto",
marginRight: "auto"
});
} else if (o.horizontalAlign === BI.HorizontalAlign.Right) {
w.element.css({
marginLeft: "auto"
});
}
8 years ago
});
var top = {}, bottom = {};
top[0] = 0;
bottom[items.length - 1] = 0;
BI.any(items, function (i, item) {
4 years ago
if (BI.isEmptyObject(item)) {
return true;
}
var w = self.getWidgetByName(self._getChildName(i));
4 years ago
var rowSize = o.rowSize.length > 0 ? o.rowSize[i] : item.height;
4 years ago
if (o.rowSize.length > 0) {
if (item.height >= 1 && o.rowSize[i] >= 1 && o.rowSize[i] !== item.height) {
rowSize = item.height;
}
}
8 years ago
if (BI.isNull(top[i])) {
4 years ago
var preRowSize = o.rowSize.length > 0 ? o.rowSize[i - 1] : items[i - 1].height;
4 years ago
top[i] = top[i - 1] + preRowSize + (items[i - 1].tgap || 0) + (items[i - 1].bgap || 0) + 2 * (items[i - 1].vgap || 0) + o.vgap + o.tgap + o.bgap;
8 years ago
}
4 years ago
if (rowSize < 1 && rowSize > 0) {
4 years ago
w.element.css({
top: (top[i] * 100).toFixed(1) + "%",
4 years ago
height: (rowSize * 100).toFixed(1) + "%"
4 years ago
});
8 years ago
} else {
w.element.css({
top: (top[i] + (item.vgap || 0) + (item.tgap || 0) + o.vgap + o.tgap) / BI.pixRatio + BI.pixUnit,
4 years ago
height: BI.isNumber(rowSize) ? rowSize / BI.pixRatio + BI.pixUnit : ""
8 years ago
});
}
4 years ago
if (rowSize === "" || rowSize === "fill") {
8 years ago
return true;
}
});
BI.backAny(items, function (i, item) {
4 years ago
if (BI.isEmptyObject(item)) {
return true;
}
var w = self.getWidgetByName(self._getChildName(i));
4 years ago
var rowSize = o.rowSize.length > 0 ? o.rowSize[i] : item.height;
8 years ago
if (BI.isNull(bottom[i])) {
4 years ago
var nextRowSize = o.rowSize.length > 0 ? o.rowSize[i + 1] : items[i + 1].height;
4 years ago
bottom[i] = bottom[i + 1] + nextRowSize + (items[i + 1].tgap || 0) + (items[i + 1].bgap || 0) + 2 * (items[i + 1].vgap || 0) + o.vgap + o.tgap + o.bgap;
8 years ago
}
4 years ago
if (rowSize < 1 && rowSize > 0) {
4 years ago
w.element.css({
bottom: (bottom[i] * 100).toFixed(1) + "%",
4 years ago
height: (rowSize * 100).toFixed(1) + "%"
4 years ago
});
8 years ago
} else {
w.element.css({
bottom: (bottom[i] + (item.vgap || 0) + (item.bgap || 0) + o.vgap + o.bgap) / BI.pixRatio + BI.pixUnit,
4 years ago
height: BI.isNumber(rowSize) ? rowSize / BI.pixRatio + BI.pixUnit : ""
8 years ago
});
}
4 years ago
if (rowSize === "" || rowSize === "fill") {
8 years ago
return true;
}
7 years ago
});
8 years ago
},
6 years ago
update: function () {
},
8 years ago
populate: function (items) {
BI.VTapeLayout.superclass.populate.apply(this, arguments);
8 years ago
this._mount();
8 years ago
}
});
5 years ago
BI.shortcut("bi.vtape", BI.VTapeLayout);