Browse Source

Merge pull request #42 in FUI/fineui from ~GUY/fineui:master to master

* commit '6c06bdf9247133ccf0cf1404207800f7e06fd6e5':
  polyfill移出来
  update
  add
  表格滚动性能优化
  表格加入横向滚动事件
  图表
  滚动帧频率
  周数
es6
guy 7 years ago
parent
commit
cfc5a0a87e
  1. 43
      Gruntfile.js
  2. 365
      bi/base.js
  3. 18
      bi/case.js
  4. 4
      bi/chart.js
  5. 363
      bi/core.js
  6. 34
      demo.html
  7. 365
      docs/base.js
  8. 18
      docs/case.js
  9. 4
      docs/chart.js
  10. 363
      docs/core.js
  11. 1
      docs/index.html
  12. 2
      server.js
  13. 4
      src/addons/chart/chart.js
  14. 195
      src/base/collection/collection.js
  15. 31
      src/base/grid/grid.js
  16. 71
      src/base/table/table.collection.quick.js
  17. 68
      src/base/table/table.grid.quick.js
  18. 23
      src/core/base.js
  19. 259
      src/core/proto/array.js
  20. 20
      src/core/proto/cache.js
  21. 18
      src/core/proto/date.js
  22. 31
      src/polyfill/array.js
  23. 12
      src/polyfill/console.js
  24. 21
      src/polyfill/localStorage.js
  25. 14
      src/polyfill/sort.js

43
Gruntfile.js

@ -7,6 +7,10 @@ module.exports = function (grunt) {
options: {
separator: ''
},
polyfillJs: {
src: ['src/polyfill/**/*.js'],
dest: 'docs/polyfill.js'
},
coreJs: {
src: [
'src/core/jquery.js',
@ -30,41 +34,7 @@ module.exports = function (grunt) {
],
dest: 'docs/core.js'
},
biCoreJs: {
src: [
'src/core/underscore.js',
'src/core/foundation.js',
'src/core/mvc/**/*.js',
'src/core/base.js',
'src/core/alias.js',
'src/core/events.js',
'src/core/var.js',
'src/core/ob.js',
'src/core/widget.js',
'src/core/model.js',
'src/core/view.js',
'src/core/shortcut.js',
'src/core/plugin.js',
'src/core/controller.js',
'src/core/proto/**/*.js',
'src/core/utils/**/*.js',
'src/core/behavior/behavior.js',
'src/core/wrapper/layout.js',
'src/core/action/**/*.js',
'src/core/adapter/**/*.js',
'src/core/controller/**/*.js',
'src/core/event/**/*.js',
'src/core/func/**/*.js',
'src/core/listener/**/*.js',
'src/core/loader/**/*.js',
'src/core/logic/**/*.js',
'src/data/data.js',
'src/data/**/*.js',
'src/config.js'
],
dest: 'bi/core.js'
},
//最基础的控件
baseJs: {
src: [
@ -137,6 +107,11 @@ module.exports = function (grunt) {
dest: 'docs/demo.css'
},
bi_polyfillJs: {
src: ['src/polyfill/**/*.js'],
dest: 'bi/polyfill.js'
},
bi_coreJs: {
src: [
'src/core/foundation.js',

365
bi/base.js

@ -2539,10 +2539,11 @@ BI.Collection = BI.inherit(BI.Widget, {
var self = this, o = this.options;
this.renderedCells = [];
this.renderedKeys = [];
this.renderRange = {};
this._scrollLock = false;
this._debounceRelease = BI.debounce(function () {
self._scrollLock = false;
}, 150);
}, 1000 / 60);
this.container = BI.createWidget({
type: "bi.absolute"
});
@ -2588,12 +2589,10 @@ BI.Collection = BI.inherit(BI.Widget, {
for (var index = 0, len = o.items.length; index < len; index++) {
var cellMetadatum = o.cellSizeAndPositionGetter(index);
if (
cellMetadatum.height == null || isNaN(cellMetadatum.height) ||
if (cellMetadatum.height == null || isNaN(cellMetadatum.height) ||
cellMetadatum.width == null || isNaN(cellMetadatum.width) ||
cellMetadatum.x == null || isNaN(cellMetadatum.x) ||
cellMetadatum.y == null || isNaN(cellMetadatum.y)
) {
cellMetadatum.y == null || isNaN(cellMetadatum.y)) {
throw Error();
}
@ -2634,75 +2633,134 @@ BI.Collection = BI.inherit(BI.Widget, {
var top = Math.max(0, scrollTop - o.verticalOverscanSize);
var right = Math.min(this._width, scrollLeft + o.width + o.horizontalOverscanSize);
var bottom = Math.min(this._height, scrollTop + o.height + o.verticalOverscanSize);
var childrenToDisplay = this._cellRenderers(bottom - top, right - left, left, top);
var renderedCells = [], renderedKeys = [];
for (var i = 0, len = childrenToDisplay.length; i < len; i++) {
var datum = childrenToDisplay[i];
var index = BI.deepIndexOf(this.renderedKeys, datum.index);
if (index > -1) {
if (datum.width !== this.renderedCells[index]._width) {
this.renderedCells[index]._width = datum.width;
this.renderedCells[index].el.setWidth(datum.width);
if (right > 0 && bottom > 0) {
//如果滚动的区间并没有超出渲染的范围
if (top >= this.renderRange.minY && bottom <= this.renderRange.maxY && left >= this.renderRange.minX && right <= this.renderRange.maxX) {
return;
}
var childrenToDisplay = this._cellRenderers(bottom - top, right - left, left, top);
var renderedCells = [], renderedKeys = [];
//存储所有的left和top
var lefts = {}, tops = {};
for (var i = 0, len = childrenToDisplay.length; i < len; i++) {
var datum = childrenToDisplay[i];
lefts[datum.x] = datum.x;
lefts[datum.x + datum.width] = datum.x + datum.width;
tops[datum.y] = datum.y;
tops[datum.y + datum.height] = datum.y + datum.height;
}
lefts = BI.toArray(lefts);
tops = BI.toArray(tops);
var leftMap = BI.invert(lefts);
var topMap = BI.invert(tops);
//存储上下左右四个边界
var leftBorder = {}, rightBorder = {}, topBorder = {}, bottomBorder = {};
var assertMinBorder = function (border, offset) {
if (border[offset] == null) {
border[offset] = Number.MAX_VALUE;
}
};
var assertMaxBorder = function (border, offset) {
if (border[offset] == null) {
border[offset] = 0;
}
if (datum.height !== this.renderedCells[index]._height) {
this.renderedCells[index]._height = datum.height;
this.renderedCells[index].el.setHeight(datum.height);
};
for (var i = 0, len = childrenToDisplay.length; i < len; i++) {
var datum = childrenToDisplay[i];
var index = BI.deepIndexOf(this.renderedKeys, datum.index);
if (index > -1) {
if (datum.width !== this.renderedCells[index]._width) {
this.renderedCells[index]._width = datum.width;
this.renderedCells[index].el.setWidth(datum.width);
}
if (datum.height !== this.renderedCells[index]._height) {
this.renderedCells[index]._height = datum.height;
this.renderedCells[index].el.setHeight(datum.height);
}
if (this.renderedCells[index].left !== datum.x) {
this.renderedCells[index].el.element.css("left", datum.x + "px");
}
if (this.renderedCells[index].top !== datum.y) {
this.renderedCells[index].el.element.css("top", datum.y + "px");
}
renderedCells.push(this.renderedCells[index]);
} else {
var child = BI.createWidget(BI.extend({
type: "bi.label",
width: datum.width,
height: datum.height
}, o.items[datum.index], {
cls: (o.items[datum.index].cls || "") + " container-cell" + (datum.y === 0 ? " first-row" : "") + (datum.x === 0 ? " first-col" : ""),
_left: datum.x,
_top: datum.y
}));
renderedCells.push({
el: child,
left: datum.x,
top: datum.y,
_width: datum.width,
_height: datum.height
});
}
if (this.renderedCells[index].left !== datum.x) {
this.renderedCells[index].el.element.css("left", datum.x + "px");
var startTopIndex = topMap[datum.y] | 0;
var endTopIndex = topMap[datum.y + datum.height] | 0;
for (var k = startTopIndex; k <= endTopIndex; k++) {
var t = tops[k];
assertMinBorder(leftBorder, t);
assertMaxBorder(rightBorder, t);
leftBorder[t] = Math.min(leftBorder[t], datum.x);
rightBorder[t] = Math.max(rightBorder[t], datum.x + datum.width);
}
if (this.renderedCells[index].top !== datum.y) {
this.renderedCells[index].el.element.css("top", datum.y + "px");
var startLeftIndex = leftMap[datum.x] | 0;
var endLeftIndex = leftMap[datum.x + datum.width] | 0;
for (var k = startLeftIndex; k <= endLeftIndex; k++) {
var l = lefts[k];
assertMinBorder(topBorder, l);
assertMaxBorder(bottomBorder, l);
topBorder[l] = Math.min(topBorder[l], datum.y);
bottomBorder[l] = Math.max(bottomBorder[l], datum.y + datum.height);
}
renderedCells.push(this.renderedCells[index]);
} else {
var child = BI.createWidget(BI.extend({
type: "bi.label",
width: datum.width,
height: datum.height
}, o.items[datum.index], {
cls: (o.items[datum.index].cls || "") + " container-cell" + (datum.y === 0 ? " first-row" : "") + (datum.x === 0 ? " first-col" : ""),
_left: datum.x,
_top: datum.y
}));
renderedCells.push({
el: child,
left: datum.x,
top: datum.y,
_width: datum.width,
_height: datum.height
});
renderedKeys.push(datum.index);
}
renderedKeys.push(datum.index);
//已存在的, 需要添加的和需要删除的
var existSet = {}, addSet = {}, deleteArray = [];
BI.each(renderedKeys, function (i, key) {
if (BI.deepContains(self.renderedKeys, key)) {
existSet[i] = key;
} else {
addSet[i] = key;
}
});
BI.each(this.renderedKeys, function (i, key) {
if (BI.deepContains(existSet, key)) {
return;
}
if (BI.deepContains(addSet, key)) {
return;
}
deleteArray.push(i);
});
BI.each(deleteArray, function (i, index) {
self.renderedCells[index].el.destroy();
});
var addedItems = [];
BI.each(addSet, function (index) {
addedItems.push(renderedCells[index])
});
this.container.addItems(addedItems);
this.renderedCells = renderedCells;
this.renderedKeys = renderedKeys;
//Todo 左右比较特殊
var minX = BI.min(leftBorder);
var maxX = BI.max(rightBorder);
var minY = BI.max(topBorder);
var maxY = BI.min(bottomBorder);
this.renderRange = {minX: minX, minY: minY, maxX: maxX, maxY: maxY};
}
//已存在的, 需要添加的和需要删除的
var existSet = {}, addSet = {}, deleteArray = [];
BI.each(renderedKeys, function (i, key) {
if (BI.deepContains(self.renderedKeys, key)) {
existSet[i] = key;
} else {
addSet[i] = key;
}
});
BI.each(this.renderedKeys, function (i, key) {
if (BI.deepContains(existSet, key)) {
return;
}
if (BI.deepContains(addSet, key)) {
return;
}
deleteArray.push(i);
});
BI.each(deleteArray, function (i, index) {
self.renderedCells[index].el.destroy();
});
var addedItems = [];
BI.each(addSet, function (index) {
addedItems.push(renderedCells[index])
});
this.container.addItems(addedItems);
this.renderedCells = renderedCells;
this.renderedKeys = renderedKeys;
},
_getMaxScrollLeft: function () {
@ -2789,6 +2847,7 @@ BI.Collection = BI.inherit(BI.Widget, {
});
this.renderedCells = [];
this.renderedKeys = [];
this.renderRange = {};
this._scrollLock = false;
},
@ -14613,10 +14672,11 @@ BI.Grid = BI.inherit(BI.Widget, {
var self = this, o = this.options;
this.renderedCells = [];
this.renderedKeys = [];
this.renderRange = {};
this._scrollLock = false;
this._debounceRelease = BI.debounce(function () {
self._scrollLock = false;
}, 150);
}, 1000 / 60);
this.container = BI.createWidget({
type: "bi.absolute"
});
@ -14661,13 +14721,17 @@ BI.Grid = BI.inherit(BI.Widget, {
_calculateChildrenToRender: function () {
var self = this, o = this.options;
var width = o.width, height = o.height, scrollLeft = BI.clamp(o.scrollLeft, 0, this._getMaxScrollLeft()), scrollTop = BI.clamp(o.scrollTop, 0, this._getMaxScrollTop()),
var width = o.width, height = o.height, scrollLeft = BI.clamp(o.scrollLeft, 0, this._getMaxScrollLeft()),
scrollTop = BI.clamp(o.scrollTop, 0, this._getMaxScrollTop()),
overscanColumnCount = o.overscanColumnCount, overscanRowCount = o.overscanRowCount;
if (height > 0 && width > 0) {
var visibleColumnIndices = this._columnSizeAndPositionManager.getVisibleCellRange(width, scrollLeft);
var visibleRowIndices = this._rowSizeAndPositionManager.getVisibleCellRange(height, scrollTop);
if (BI.isEmpty(visibleColumnIndices) || BI.isEmpty(visibleRowIndices)) {
return;
}
var horizontalOffsetAdjustment = this._columnSizeAndPositionManager.getOffsetAdjustment(width, scrollLeft);
var verticalOffsetAdjustment = this._rowSizeAndPositionManager.getOffsetAdjustment(height, scrollTop);
@ -14685,8 +14749,22 @@ BI.Grid = BI.inherit(BI.Widget, {
var rowStartIndex = overscanRowIndices.overscanStartIndex;
var rowStopIndex = overscanRowIndices.overscanStopIndex;
var renderedCells = [], renderedKeys = [];
//算区间size
var minRowDatum = this._rowSizeAndPositionManager.getSizeAndPositionOfCell(rowStartIndex);
var minColumnDatum = this._columnSizeAndPositionManager.getSizeAndPositionOfCell(columnStartIndex);
var maxRowDatum = this._rowSizeAndPositionManager.getSizeAndPositionOfCell(rowStopIndex);
var maxColumnDatum = this._columnSizeAndPositionManager.getSizeAndPositionOfCell(columnStopIndex);
var top = minRowDatum.offset + verticalOffsetAdjustment;
var left = minColumnDatum.offset + horizontalOffsetAdjustment;
var bottom = maxRowDatum.offset + verticalOffsetAdjustment + maxRowDatum.size;
var right = maxColumnDatum.offset + horizontalOffsetAdjustment + maxColumnDatum.size;
//如果滚动的区间并没有超出渲染的范围
if (top >= this.renderRange.minY && bottom <= this.renderRange.maxY && left >= this.renderRange.minX && right <= this.renderRange.maxX) {
return;
}
var renderedCells = [], renderedKeys = [];
var minX = this._getMaxScrollLeft(), minY = this._getMaxScrollTop(), maxX = 0, maxY = 0;
for (var rowIndex = rowStartIndex; rowIndex <= rowStopIndex; rowIndex++) {
var rowDatum = this._rowSizeAndPositionManager.getSizeAndPositionOfCell(rowIndex);
@ -14731,6 +14809,10 @@ BI.Grid = BI.inherit(BI.Widget, {
_height: rowDatum.size
});
}
minX = Math.min(minX, columnDatum.offset + horizontalOffsetAdjustment);
maxX = Math.max(maxX, columnDatum.offset + horizontalOffsetAdjustment + columnDatum.size);
minY = Math.min(minY, rowDatum.offset + verticalOffsetAdjustment);
maxY = Math.max(maxY, rowDatum.offset + verticalOffsetAdjustment + rowDatum.size);
renderedKeys.push(key);
}
}
@ -14762,6 +14844,7 @@ BI.Grid = BI.inherit(BI.Widget, {
this.container.addItems(addedItems);
this.renderedCells = renderedCells;
this.renderedKeys = renderedKeys;
this.renderRange = {minX: minX, minY: minY, maxX: maxX, maxY: maxY};
}
},
@ -14865,6 +14948,7 @@ BI.Grid = BI.inherit(BI.Widget, {
});
this.renderedCells = [];
this.renderedKeys = [];
this.renderRange = {};
this._scrollLock = false;
},
@ -29036,26 +29120,54 @@ BI.QuickCollectionTable = BI.inherit(BI.CollectionTable, {
mounted: function () {
BI.QuickCollectionTable.superclass.mounted.apply(this, arguments);
var self = this;
this._leftWheelHandler = new BI.WheelHandler(
BI.bind(this._onWheelY, this),
BI.bind(this._shouldHandleX, this),
this._topLeftWheelHandler = new BI.WheelHandler(
BI.bind(this._onWheelLeft, this),
BI.bind(this._shouldHandleLeftX, this),
BI.bind(this._shouldHandleY, this)
);
this._rightWheelHandler = new BI.WheelHandler(
BI.bind(this._onWheelY, this),
BI.bind(this._shouldHandleX, this),
this._topRightWheelHandler = new BI.WheelHandler(
BI.bind(this._onWheelRight, this),
BI.bind(this._shouldHandleRightX, this),
BI.bind(this._shouldHandleY, this)
);
this._bottomLeftWheelHandler = new BI.WheelHandler(
BI.bind(this._onWheelLeft, this),
BI.bind(this._shouldHandleLeftX, this),
BI.bind(this._shouldHandleY, this)
);
this._bottomRightWheelHandler = new BI.WheelHandler(
BI.bind(this._onWheelRight, this),
BI.bind(this._shouldHandleRightX, this),
BI.bind(this._shouldHandleY, this)
);
this.topLeftCollection.element.mousewheel(function (e) {
self._topLeftWheelHandler.onWheel(e.originalEvent);
});
this.topRightCollection.element.mousewheel(function (e) {
self._topRightWheelHandler.onWheel(e.originalEvent);
});
this.bottomLeftCollection.element.mousewheel(function (e) {
self._leftWheelHandler.onWheel(e.originalEvent);
self._bottomLeftWheelHandler.onWheel(e.originalEvent);
});
this.bottomRightCollection.element.mousewheel(function (e) {
self._rightWheelHandler.onWheel(e.originalEvent);
self._bottomRightWheelHandler.onWheel(e.originalEvent);
});
},
_shouldHandleX: function (delta) {
return false;
_shouldHandleLeftX: function (delta) {
if (delta > 0) {
return this.bottomLeftCollection.getScrollLeft() < this.bottomLeftCollection.getMaxScrollLeft();
} else {
return this.bottomLeftCollection.getScrollLeft() > 0;
}
},
_shouldHandleRightX: function (delta) {
if (delta > 0) {
return this.bottomRightCollection.getScrollLeft() < this.bottomRightCollection.getMaxScrollLeft();
} else {
return this.bottomRightCollection.getScrollLeft() > 0;
}
},
_shouldHandleY: function (delta) {
@ -29066,19 +29178,38 @@ BI.QuickCollectionTable = BI.inherit(BI.CollectionTable, {
}
},
_onWheelY: function (deltaX, deltaY) {
_onWheelLeft: function (deltaX, deltaY) {
var self = this;
var scrollTop = this.bottomLeftCollection.getScrollTop();
var scrollLeft = this.bottomLeftCollection.getScrollLeft();
scrollTop += deltaY;
scrollLeft += deltaX;
this.bottomLeftCollection.setScrollTop(scrollTop);
this.bottomRightCollection.setScrollTop(scrollTop);
this.topLeftCollection.setScrollLeft(scrollLeft);
this.bottomLeftCollection.setScrollLeft(scrollLeft);
self._populateScrollbar();
this.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments);
},
_onWheelRight: function (deltaX, deltaY) {
var self = this;
var scrollTop = this.bottomRightCollection.getScrollTop();
var scrollLeft = this.bottomRightCollection.getScrollLeft();
scrollTop += deltaY;
scrollLeft += deltaX;
this.bottomLeftCollection.setScrollTop(scrollTop);
this.bottomRightCollection.setScrollTop(scrollTop);
this.topRightCollection.setScrollLeft(scrollLeft);
this.bottomRightCollection.setScrollLeft(scrollLeft);
self._populateScrollbar();
this.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments);
},
_populateTable: function () {
var self = this, o = this.options;
var regionSize = this.getRegionSize(), totalLeftColumnSize = 0, totalRightColumnSize = 0, totalColumnSize = 0, summaryColumnSizeArray = [], totalRowSize = o.items.length * o.rowSize;
var regionSize = this.getRegionSize(), totalLeftColumnSize = 0, totalRightColumnSize = 0, totalColumnSize = 0,
summaryColumnSizeArray = [], totalRowSize = o.items.length * o.rowSize;
var freezeColLength = this._getFreezeColLength();
BI.each(o.columnSize, function (i, size) {
if (o.isNeedFreeze === true && o.freezeCols.contains(i)) {
@ -29691,26 +29822,54 @@ BI.QuickGridTable = BI.inherit(BI.GridTable, {
mounted: function () {
BI.QuickGridTable.superclass.mounted.apply(this, arguments);
var self = this;
this._leftWheelHandler = new BI.WheelHandler(
BI.bind(this._onWheelY, this),
BI.bind(this._shouldHandleX, this),
this._topLeftWheelHandler = new BI.WheelHandler(
BI.bind(this._onWheelLeft, this),
BI.bind(this._shouldHandleLeftX, this),
BI.bind(this._shouldHandleY, this)
);
this._rightWheelHandler = new BI.WheelHandler(
BI.bind(this._onWheelY, this),
BI.bind(this._shouldHandleX, this),
this._topRightWheelHandler = new BI.WheelHandler(
BI.bind(this._onWheelRight, this),
BI.bind(this._shouldHandleRightX, this),
BI.bind(this._shouldHandleY, this)
);
this._bottomLeftWheelHandler = new BI.WheelHandler(
BI.bind(this._onWheelLeft, this),
BI.bind(this._shouldHandleLeftX, this),
BI.bind(this._shouldHandleY, this)
);
this._bottomRightWheelHandler = new BI.WheelHandler(
BI.bind(this._onWheelRight, this),
BI.bind(this._shouldHandleRightX, this),
BI.bind(this._shouldHandleY, this)
);
this.topLeftGrid.element.mousewheel(function (e) {
self._topLeftWheelHandler.onWheel(e.originalEvent);
});
this.topRightGrid.element.mousewheel(function (e) {
self._topRightWheelHandler.onWheel(e.originalEvent);
});
this.bottomLeftGrid.element.mousewheel(function (e) {
self._leftWheelHandler.onWheel(e.originalEvent);
self._bottomLeftWheelHandler.onWheel(e.originalEvent);
});
this.bottomRightGrid.element.mousewheel(function (e) {
self._rightWheelHandler.onWheel(e.originalEvent);
self._bottomRightWheelHandler.onWheel(e.originalEvent);
});
},
_shouldHandleX: function (delta) {
return false;
_shouldHandleLeftX: function (delta) {
if (delta > 0) {
return this.bottomLeftGrid.getScrollLeft() < this.bottomLeftGrid.getMaxScrollLeft();
} else {
return this.bottomLeftGrid.getScrollLeft() > 0;
}
},
_shouldHandleRightX: function (delta) {
if (delta > 0) {
return this.bottomRightGrid.getScrollLeft() < this.bottomRightGrid.getMaxScrollLeft();
} else {
return this.bottomRightGrid.getScrollLeft() > 0;
}
},
_shouldHandleY: function (delta) {
@ -29721,12 +29880,30 @@ BI.QuickGridTable = BI.inherit(BI.GridTable, {
}
},
_onWheelY: function (deltaX, deltaY) {
_onWheelLeft: function (deltaX, deltaY) {
var self = this;
var scrollTop = this.bottomLeftGrid.getScrollTop();
var scrollLeft = this.bottomLeftGrid.getScrollLeft();
scrollTop += deltaY;
scrollLeft += deltaX;
this.bottomLeftGrid.setScrollTop(scrollTop);
this.bottomRightGrid.setScrollTop(scrollTop);
this.topLeftGrid.setScrollLeft(scrollLeft);
this.bottomLeftGrid.setScrollLeft(scrollLeft);
self._populateScrollbar();
this.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments);
},
_onWheelRight: function (deltaX, deltaY) {
var self = this;
var scrollTop = this.bottomRightGrid.getScrollTop();
var scrollLeft = this.bottomRightGrid.getScrollLeft();
scrollTop += deltaY;
scrollLeft += deltaX;
this.bottomLeftGrid.setScrollTop(scrollTop);
this.bottomRightGrid.setScrollTop(scrollTop);
this.topRightGrid.setScrollLeft(scrollLeft);
this.bottomRightGrid.setScrollLeft(scrollLeft);
self._populateScrollbar();
this.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments);
},

18
bi/case.js

@ -9118,18 +9118,18 @@ BI.DynamicSummaryLayerTreeTable = BI.inherit(BI.Widget, {
var vDeep = this._getVDeep();
var header = this._createHeader(vDeep);
var data = this._formatItems(o.items, header, deep);
// var columnSize = o.columnSize.slice();
// var minColumnSize = o.minColumnSize.slice();
// var maxColumnSize = o.maxColumnSize.slice();
// BI.removeAt(columnSize, data.deletedCols);
// BI.removeAt(minColumnSize, data.deletedCols);
// BI.removeAt(maxColumnSize, data.deletedCols);
var columnSize = o.columnSize.slice();
var minColumnSize = o.minColumnSize.slice();
var maxColumnSize = o.maxColumnSize.slice();
BI.removeAt(columnSize, data.deletedCols);
BI.removeAt(minColumnSize, data.deletedCols);
BI.removeAt(maxColumnSize, data.deletedCols);
return {
header: data.header,
items: data.items,
columnSize: this._formatColumnSize(o.columnSize, deep),
minColumnSize: this._formatColumns(o.minColumnSize, deep),
maxColumnSize: this._formatColumns(o.maxColumnSize, deep),
columnSize: this._formatColumnSize(columnSize, deep),
minColumnSize: this._formatColumns(minColumnSize, deep),
maxColumnSize: this._formatColumns(maxColumnSize, deep),
freezeCols: this._formatFreezeCols()
}
},

4
bi/chart.js

@ -19,7 +19,9 @@ BI.Chart = BI.inherit(BI.Pane, {
this.vanCharts = VanCharts.init(self.element[0]);
this._resizer = BI.debounce(function () {
self.vanCharts.resize();
if (self.element.width() > 0 && self.element.height() > 0) {
self.vanCharts.resize();
}
}, 30);
BI.ResizeDetector.addResizeListener(this, function (e) {
self._resizer();

363
bi/core.js

@ -2163,6 +2163,29 @@ if (!window.BI) {
return true;
},
backFindKey: function (obj, predicate, context) {
predicate = BI.iteratee(predicate, context);
var keys = _.keys(obj), key;
for (var i = keys.length - 1; i >= 0; i--) {
key = keys[i];
if (predicate(obj[key], key, obj)) {
return key;
}
}
},
backFind: function (obj, predicate, context) {
var key;
if (BI.isArray(obj)) {
key = BI.findLastIndex(obj, predicate, context);
} else {
key = BI.backFindKey(obj, predicate, context);
}
if (key !== void 0 && key !== -1) {
return obj[key];
}
},
remove: function (obj, target, context) {
var isFunction = BI.isFunction(target);
target = isFunction || BI.isArray(target) ? target : [target];
@ -5820,34 +5843,6 @@ $.extend(Array.prototype, {
contains: function (o) {
return this.indexOf(o) > -1;
},
/**
* 检查指定的值是否在数组中
* @param {Object} o 要检查的值
* @return {Number} o在数组中的索引如果不在数组中则返回-1
*/
indexOf: function (o) {
for (var i = 0, len = this.length; i < len; i++) {
if (_.isEqual(o, this[i])) {
return i;
}
}
return -1;
},
/**
* 检查指定的值是否在数组中
* ie67不支持数组的这个方法
* @param {Object} o 要检查的值
* @return {Number} o在数组中的索引如果不在数组中则返回-1
*/
lastIndexOf: function (o) {
for (var len = this.length, i = len - 1; i >= 0; i--) {
if (_.isEqual(o, this[i])) {
return i;
}
}
return -1;
},
/**
* 从数组中移除指定的值如果值不在数组中则不产生任何效果
@ -5856,265 +5851,29 @@ $.extend(Array.prototype, {
*/
remove: function (o) {
var index = this.indexOf(o);
if (index != -1) {
if (index !== -1) {
this.splice(index, 1);
}
return this;
},
/**
* 移除数组中的所有元素
*/
clear: function () {
while (this.length > 0) {
this.pop();
}
}
});
/**
* Array原型拓展
* Created by wang on 15/6/23.
*/
!function () {
Array.prototype.pushArray = function (array) {
pushArray: function (array) {
for (var i = 0; i < array.length; i++) {
this.push(array[i]);
}
};
Array.prototype.pushDistinct = function (obj) {
},
pushDistinct: function (obj) {
if (!this.contains(obj)) {
this.push(obj);
}
};
Array.prototype.pushDistinctArray = function (array) {
},
pushDistinctArray: function (array) {
for (var i = 0, len = array.length; i < len; i++) {
this.pushDistinct(array[i]);
}
};
}();
/**
* 规定bi的数组分为两种其中value和type值为key值
* 1[{"text":1,"value":2,"children":[]}]
* 2[{"name":1,"type":2,"children":[]}]
* guy
* 对数组的操作
* @type {{}}
*/
ArrayUtils = {};
$.extend(ArrayUtils, {
/**
* 遍历方法
* @param array
* @param back
*/
traversal: function (array, back) {
if (BI.isNull(array)) {
return;
}
var self = this;
BI.each(array, function (i, item) {
if (back(i, item) === BI.Status.END) {
return false;
}
self.traversal(item.children, back);
})
},
getAllChildNames: function (array) {
var names = [];
this.traversal(array, function (i, item) {
if (BI.isNotEmptyArray(item.children)) {
return BI.Status.RUNNING;
}
names.push(item.text || item.name);
});
return names;
},
/**
* 获取第一个子节点
* @param array
*/
getFirstChild: function (array) {
var first = {};
this.traversal(array, function (i, item) {
if (BI.isNotEmptyArray(item.children)) {
return;
}
first = item;
return BI.Status.END;
})
return first;
},
/**
* 获取最后一个子节点
* @param array
*/
getLastChild: function (array) {
var first = {};
this.traversal(array, function (i, item) {
if (item.children && item.children.length > 0) {
return;
}
first = item;
})
return first;
},
getTextByValue: function (array, value) {
if (!array) {
return value;
}
var text = "";
this.traversal(array, function (i, item) {
if (BI.isEqual(item.value, value)) {
text = item.text;
return BI.Status.END;
}
});
return text;
},
getNameByType: function (array, type) {
if (!array) {
return type;
}
var name = "";
this.traversal(array, function (i, item) {
if (BI.isEqual(item.type, type)) {
name = item.name;
return BI.Status.END;
}
});
return name;
},
getItemByText: function (array, text) {
var res = void 0;
this.traversal(array, function (i, item) {
if (BI.isCapitalEqual(item.text, text)) {
res = item;
return BI.Status.END;
}
});
return res;
},
getIndexByText: function (array, text) {
var res = -1;
this.traversal(array, function (i, item) {
if (BI.isCapitalEqual(item.text, text)) {
res = i;
return BI.Status.END;
}
});
return res;
},
getItemByValue: function (array, value) {
var res = void 0;
this.traversal(array, function (i, item) {
if (BI.isEqual(item.value, value)) {
res = item;
return BI.Status.END;
}
});
return res;
},
getIndexByValue: function (array, value) {
var res = -1;
this.traversal(array, function (i, item) {
if (BI.isEqual(item.value, value)) {
res = i;
return BI.Status.END;
}
});
return res;
},
getItemByName: function (array, name) {
var res = void 0;
this.traversal(array, function (i, item) {
if (BI.isCapitalEqual(item.name, name)) {
res = item;
return BI.Status.END;
}
});
return res;
},
getIndexByName: function (array, name) {
var res = -1;
this.traversal(array, function (i, item) {
if (BI.isCapitalEqual(item.name, name)) {
res = i;
return BI.Status.END;
}
});
return res;
},
getItemByType: function (array, type) {
var res = void 0;
this.traversal(array, function (i, item) {
if (BI.isEqual(item.type, type)) {
res = item;
return BI.Status.END;
}
});
return res;
},
getIndexByType: function (array, type) {
var res = -1;
this.traversal(array, function (i, item) {
if (BI.isEqual(item.type, type)) {
res = i;
return BI.Status.END;
}
});
return res;
},
deleteItemByType: function (array, type) {
var item = this.getItemByType(array, type);
array.remove(item);
},
deleteItemByName: function (array, name) {
var item = this.getItemByName(array, name);
array.remove(item);
},
deleteItemByValue: function (array, value) {
var item = this.getItemByValue(array, value);
array.remove(item);
}
});/*
* 前端缓存
*/
window.localStorage || (window.localStorage = {
items: {},
setItem: function (k, v) {
BI.Cache.addCookie(k, v);
},
getItem: function (k) {
return BI.Cache.getCookie(k);
},
removeItem: function (k) {
BI.Cache.deleteCookie(k);
},
key: function () {
},
clear: function () {
this.items = {};
}
});
BI.Cache = {
_prefix: "bi",
setUsername: function (username) {
@ -6249,7 +6008,6 @@ Date._QN = ["", BI.i18nText("BI-Quarter_1"),
BI.i18nText("BI-Quarter_4")];
/** Adds the number of days array to the Date object. */
Date._MD = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
@ -6284,12 +6042,19 @@ Date.prototype.getDayOfYear = function () {
/** Returns the number of the week in year, as defined in ISO 8601. */
Date.prototype.getWeekNumber = function () {
var d = new Date(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0);
var DoW = d.getDay();
d.setDate(d.getDate() - (DoW + 6) % 7 + 3); // Nearest Thu
var week = d.getDay();
if (this.getMonth() === 0 && this.getDate() <= week) {
return 1;
}
d.setDate(this.getDate() - week);
var ms = d.valueOf(); // GMT
d.setMonth(0);
d.setDate(4); // Thu in Week 1
return Math.round((ms - d.valueOf()) / (7 * 864e5)) + 1;
d.setDate(1);
var offset = Math.floor((ms - d.valueOf()) / (7 * 864e5)) + 1;
if (d.getDay() > 0) {
offset++;
}
return offset;
};
//离当前时间多少天的时间
@ -6381,7 +6146,7 @@ Date.prototype.getOffsetMonth = function (n) {
var dt = new Date(this.getTime());
var day = dt.getDate();
var monthDay = new Date(dt.getFullYear(), dt.getMonth() + parseInt(n), 1).getMonthDays();
if(day > monthDay){
if (day > monthDay) {
day = monthDay;
}
dt.setDate(day);
@ -7065,50 +6830,6 @@ function accDiv(arg1, arg2) {
Number.prototype.div = function (arg) {
return accDiv(this, arg);
};/**
* 特殊情况
* Created by wang on 15/6/23.
*/
//解决console未定义问题 guy
window.console = window.console || (function () {
var c = {};
c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile
= c.clear = c.exception = c.trace = c.assert = function () {
};
return c;
})();
//修复ie9下sort方法的bug
!function (window) {
var ua = window.navigator.userAgent.toLowerCase(),
reg = /msie|applewebkit.+safari/;
if (reg.test(ua)) {
var _sort = Array.prototype.sort;
Array.prototype.sort = function (fn) {
if (!!fn && typeof fn === 'function') {
if (this.length < 2) {
return this;
}
var i = 0, j = i + 1, l = this.length, tmp, r = false, t = 0;
for (; i < l; i++) {
for (j = i + 1; j < l; j++) {
t = fn.call(this, this[i], this[j]);
r = (typeof t === 'number' ? t :
!!t ? 1 : 0) > 0;
if (r === true) {
tmp = this[i];
this[i] = this[j];
this[j] = tmp;
}
}
}
return this;
} else {
return _sort.call(this);
}
};
}
}(window);/**
* 对字符串对象的扩展
* @class String
*/

34
demo.html

@ -1,34 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" type="text/css"
href="docs/core.css"/>
<link rel="stylesheet" type="text/css"
href="docs/base.css"/>
<link rel="stylesheet" type="text/css"
href="docs/widget.css"/>
<link rel="stylesheet" type="text/css"
href="docs/resource.css"/>
<link rel="stylesheet" type="text/css"
href="docs/demo.css"/>
<script src="docs/core.js"></script>
<script src="docs/base.js"></script>
<script src="docs/case.js"></script>
<script src="docs/widget.js"></script>
<!--图表-->
<script src="docs/vancharts-all.js"></script>
<script src="docs/biconst.js"></script><!--图表用到的常量(直接拿的bi的常量)-->
<script src="docs/chart.js"></script>
<script src="docs/demo.js"></script>
</head>
<body>
<div id="wrapper"></div>
</body>
</html>

365
docs/base.js

@ -2539,10 +2539,11 @@ BI.Collection = BI.inherit(BI.Widget, {
var self = this, o = this.options;
this.renderedCells = [];
this.renderedKeys = [];
this.renderRange = {};
this._scrollLock = false;
this._debounceRelease = BI.debounce(function () {
self._scrollLock = false;
}, 150);
}, 1000 / 60);
this.container = BI.createWidget({
type: "bi.absolute"
});
@ -2588,12 +2589,10 @@ BI.Collection = BI.inherit(BI.Widget, {
for (var index = 0, len = o.items.length; index < len; index++) {
var cellMetadatum = o.cellSizeAndPositionGetter(index);
if (
cellMetadatum.height == null || isNaN(cellMetadatum.height) ||
if (cellMetadatum.height == null || isNaN(cellMetadatum.height) ||
cellMetadatum.width == null || isNaN(cellMetadatum.width) ||
cellMetadatum.x == null || isNaN(cellMetadatum.x) ||
cellMetadatum.y == null || isNaN(cellMetadatum.y)
) {
cellMetadatum.y == null || isNaN(cellMetadatum.y)) {
throw Error();
}
@ -2634,75 +2633,134 @@ BI.Collection = BI.inherit(BI.Widget, {
var top = Math.max(0, scrollTop - o.verticalOverscanSize);
var right = Math.min(this._width, scrollLeft + o.width + o.horizontalOverscanSize);
var bottom = Math.min(this._height, scrollTop + o.height + o.verticalOverscanSize);
var childrenToDisplay = this._cellRenderers(bottom - top, right - left, left, top);
var renderedCells = [], renderedKeys = [];
for (var i = 0, len = childrenToDisplay.length; i < len; i++) {
var datum = childrenToDisplay[i];
var index = BI.deepIndexOf(this.renderedKeys, datum.index);
if (index > -1) {
if (datum.width !== this.renderedCells[index]._width) {
this.renderedCells[index]._width = datum.width;
this.renderedCells[index].el.setWidth(datum.width);
if (right > 0 && bottom > 0) {
//如果滚动的区间并没有超出渲染的范围
if (top >= this.renderRange.minY && bottom <= this.renderRange.maxY && left >= this.renderRange.minX && right <= this.renderRange.maxX) {
return;
}
var childrenToDisplay = this._cellRenderers(bottom - top, right - left, left, top);
var renderedCells = [], renderedKeys = [];
//存储所有的left和top
var lefts = {}, tops = {};
for (var i = 0, len = childrenToDisplay.length; i < len; i++) {
var datum = childrenToDisplay[i];
lefts[datum.x] = datum.x;
lefts[datum.x + datum.width] = datum.x + datum.width;
tops[datum.y] = datum.y;
tops[datum.y + datum.height] = datum.y + datum.height;
}
lefts = BI.toArray(lefts);
tops = BI.toArray(tops);
var leftMap = BI.invert(lefts);
var topMap = BI.invert(tops);
//存储上下左右四个边界
var leftBorder = {}, rightBorder = {}, topBorder = {}, bottomBorder = {};
var assertMinBorder = function (border, offset) {
if (border[offset] == null) {
border[offset] = Number.MAX_VALUE;
}
};
var assertMaxBorder = function (border, offset) {
if (border[offset] == null) {
border[offset] = 0;
}
if (datum.height !== this.renderedCells[index]._height) {
this.renderedCells[index]._height = datum.height;
this.renderedCells[index].el.setHeight(datum.height);
};
for (var i = 0, len = childrenToDisplay.length; i < len; i++) {
var datum = childrenToDisplay[i];
var index = BI.deepIndexOf(this.renderedKeys, datum.index);
if (index > -1) {
if (datum.width !== this.renderedCells[index]._width) {
this.renderedCells[index]._width = datum.width;
this.renderedCells[index].el.setWidth(datum.width);
}
if (datum.height !== this.renderedCells[index]._height) {
this.renderedCells[index]._height = datum.height;
this.renderedCells[index].el.setHeight(datum.height);
}
if (this.renderedCells[index].left !== datum.x) {
this.renderedCells[index].el.element.css("left", datum.x + "px");
}
if (this.renderedCells[index].top !== datum.y) {
this.renderedCells[index].el.element.css("top", datum.y + "px");
}
renderedCells.push(this.renderedCells[index]);
} else {
var child = BI.createWidget(BI.extend({
type: "bi.label",
width: datum.width,
height: datum.height
}, o.items[datum.index], {
cls: (o.items[datum.index].cls || "") + " container-cell" + (datum.y === 0 ? " first-row" : "") + (datum.x === 0 ? " first-col" : ""),
_left: datum.x,
_top: datum.y
}));
renderedCells.push({
el: child,
left: datum.x,
top: datum.y,
_width: datum.width,
_height: datum.height
});
}
if (this.renderedCells[index].left !== datum.x) {
this.renderedCells[index].el.element.css("left", datum.x + "px");
var startTopIndex = topMap[datum.y] | 0;
var endTopIndex = topMap[datum.y + datum.height] | 0;
for (var k = startTopIndex; k <= endTopIndex; k++) {
var t = tops[k];
assertMinBorder(leftBorder, t);
assertMaxBorder(rightBorder, t);
leftBorder[t] = Math.min(leftBorder[t], datum.x);
rightBorder[t] = Math.max(rightBorder[t], datum.x + datum.width);
}
if (this.renderedCells[index].top !== datum.y) {
this.renderedCells[index].el.element.css("top", datum.y + "px");
var startLeftIndex = leftMap[datum.x] | 0;
var endLeftIndex = leftMap[datum.x + datum.width] | 0;
for (var k = startLeftIndex; k <= endLeftIndex; k++) {
var l = lefts[k];
assertMinBorder(topBorder, l);
assertMaxBorder(bottomBorder, l);
topBorder[l] = Math.min(topBorder[l], datum.y);
bottomBorder[l] = Math.max(bottomBorder[l], datum.y + datum.height);
}
renderedCells.push(this.renderedCells[index]);
} else {
var child = BI.createWidget(BI.extend({
type: "bi.label",
width: datum.width,
height: datum.height
}, o.items[datum.index], {
cls: (o.items[datum.index].cls || "") + " container-cell" + (datum.y === 0 ? " first-row" : "") + (datum.x === 0 ? " first-col" : ""),
_left: datum.x,
_top: datum.y
}));
renderedCells.push({
el: child,
left: datum.x,
top: datum.y,
_width: datum.width,
_height: datum.height
});
renderedKeys.push(datum.index);
}
renderedKeys.push(datum.index);
//已存在的, 需要添加的和需要删除的
var existSet = {}, addSet = {}, deleteArray = [];
BI.each(renderedKeys, function (i, key) {
if (BI.deepContains(self.renderedKeys, key)) {
existSet[i] = key;
} else {
addSet[i] = key;
}
});
BI.each(this.renderedKeys, function (i, key) {
if (BI.deepContains(existSet, key)) {
return;
}
if (BI.deepContains(addSet, key)) {
return;
}
deleteArray.push(i);
});
BI.each(deleteArray, function (i, index) {
self.renderedCells[index].el.destroy();
});
var addedItems = [];
BI.each(addSet, function (index) {
addedItems.push(renderedCells[index])
});
this.container.addItems(addedItems);
this.renderedCells = renderedCells;
this.renderedKeys = renderedKeys;
//Todo 左右比较特殊
var minX = BI.min(leftBorder);
var maxX = BI.max(rightBorder);
var minY = BI.max(topBorder);
var maxY = BI.min(bottomBorder);
this.renderRange = {minX: minX, minY: minY, maxX: maxX, maxY: maxY};
}
//已存在的, 需要添加的和需要删除的
var existSet = {}, addSet = {}, deleteArray = [];
BI.each(renderedKeys, function (i, key) {
if (BI.deepContains(self.renderedKeys, key)) {
existSet[i] = key;
} else {
addSet[i] = key;
}
});
BI.each(this.renderedKeys, function (i, key) {
if (BI.deepContains(existSet, key)) {
return;
}
if (BI.deepContains(addSet, key)) {
return;
}
deleteArray.push(i);
});
BI.each(deleteArray, function (i, index) {
self.renderedCells[index].el.destroy();
});
var addedItems = [];
BI.each(addSet, function (index) {
addedItems.push(renderedCells[index])
});
this.container.addItems(addedItems);
this.renderedCells = renderedCells;
this.renderedKeys = renderedKeys;
},
_getMaxScrollLeft: function () {
@ -2789,6 +2847,7 @@ BI.Collection = BI.inherit(BI.Widget, {
});
this.renderedCells = [];
this.renderedKeys = [];
this.renderRange = {};
this._scrollLock = false;
},
@ -14613,10 +14672,11 @@ BI.Grid = BI.inherit(BI.Widget, {
var self = this, o = this.options;
this.renderedCells = [];
this.renderedKeys = [];
this.renderRange = {};
this._scrollLock = false;
this._debounceRelease = BI.debounce(function () {
self._scrollLock = false;
}, 150);
}, 1000 / 60);
this.container = BI.createWidget({
type: "bi.absolute"
});
@ -14661,13 +14721,17 @@ BI.Grid = BI.inherit(BI.Widget, {
_calculateChildrenToRender: function () {
var self = this, o = this.options;
var width = o.width, height = o.height, scrollLeft = BI.clamp(o.scrollLeft, 0, this._getMaxScrollLeft()), scrollTop = BI.clamp(o.scrollTop, 0, this._getMaxScrollTop()),
var width = o.width, height = o.height, scrollLeft = BI.clamp(o.scrollLeft, 0, this._getMaxScrollLeft()),
scrollTop = BI.clamp(o.scrollTop, 0, this._getMaxScrollTop()),
overscanColumnCount = o.overscanColumnCount, overscanRowCount = o.overscanRowCount;
if (height > 0 && width > 0) {
var visibleColumnIndices = this._columnSizeAndPositionManager.getVisibleCellRange(width, scrollLeft);
var visibleRowIndices = this._rowSizeAndPositionManager.getVisibleCellRange(height, scrollTop);
if (BI.isEmpty(visibleColumnIndices) || BI.isEmpty(visibleRowIndices)) {
return;
}
var horizontalOffsetAdjustment = this._columnSizeAndPositionManager.getOffsetAdjustment(width, scrollLeft);
var verticalOffsetAdjustment = this._rowSizeAndPositionManager.getOffsetAdjustment(height, scrollTop);
@ -14685,8 +14749,22 @@ BI.Grid = BI.inherit(BI.Widget, {
var rowStartIndex = overscanRowIndices.overscanStartIndex;
var rowStopIndex = overscanRowIndices.overscanStopIndex;
var renderedCells = [], renderedKeys = [];
//算区间size
var minRowDatum = this._rowSizeAndPositionManager.getSizeAndPositionOfCell(rowStartIndex);
var minColumnDatum = this._columnSizeAndPositionManager.getSizeAndPositionOfCell(columnStartIndex);
var maxRowDatum = this._rowSizeAndPositionManager.getSizeAndPositionOfCell(rowStopIndex);
var maxColumnDatum = this._columnSizeAndPositionManager.getSizeAndPositionOfCell(columnStopIndex);
var top = minRowDatum.offset + verticalOffsetAdjustment;
var left = minColumnDatum.offset + horizontalOffsetAdjustment;
var bottom = maxRowDatum.offset + verticalOffsetAdjustment + maxRowDatum.size;
var right = maxColumnDatum.offset + horizontalOffsetAdjustment + maxColumnDatum.size;
//如果滚动的区间并没有超出渲染的范围
if (top >= this.renderRange.minY && bottom <= this.renderRange.maxY && left >= this.renderRange.minX && right <= this.renderRange.maxX) {
return;
}
var renderedCells = [], renderedKeys = [];
var minX = this._getMaxScrollLeft(), minY = this._getMaxScrollTop(), maxX = 0, maxY = 0;
for (var rowIndex = rowStartIndex; rowIndex <= rowStopIndex; rowIndex++) {
var rowDatum = this._rowSizeAndPositionManager.getSizeAndPositionOfCell(rowIndex);
@ -14731,6 +14809,10 @@ BI.Grid = BI.inherit(BI.Widget, {
_height: rowDatum.size
});
}
minX = Math.min(minX, columnDatum.offset + horizontalOffsetAdjustment);
maxX = Math.max(maxX, columnDatum.offset + horizontalOffsetAdjustment + columnDatum.size);
minY = Math.min(minY, rowDatum.offset + verticalOffsetAdjustment);
maxY = Math.max(maxY, rowDatum.offset + verticalOffsetAdjustment + rowDatum.size);
renderedKeys.push(key);
}
}
@ -14762,6 +14844,7 @@ BI.Grid = BI.inherit(BI.Widget, {
this.container.addItems(addedItems);
this.renderedCells = renderedCells;
this.renderedKeys = renderedKeys;
this.renderRange = {minX: minX, minY: minY, maxX: maxX, maxY: maxY};
}
},
@ -14865,6 +14948,7 @@ BI.Grid = BI.inherit(BI.Widget, {
});
this.renderedCells = [];
this.renderedKeys = [];
this.renderRange = {};
this._scrollLock = false;
},
@ -29036,26 +29120,54 @@ BI.QuickCollectionTable = BI.inherit(BI.CollectionTable, {
mounted: function () {
BI.QuickCollectionTable.superclass.mounted.apply(this, arguments);
var self = this;
this._leftWheelHandler = new BI.WheelHandler(
BI.bind(this._onWheelY, this),
BI.bind(this._shouldHandleX, this),
this._topLeftWheelHandler = new BI.WheelHandler(
BI.bind(this._onWheelLeft, this),
BI.bind(this._shouldHandleLeftX, this),
BI.bind(this._shouldHandleY, this)
);
this._rightWheelHandler = new BI.WheelHandler(
BI.bind(this._onWheelY, this),
BI.bind(this._shouldHandleX, this),
this._topRightWheelHandler = new BI.WheelHandler(
BI.bind(this._onWheelRight, this),
BI.bind(this._shouldHandleRightX, this),
BI.bind(this._shouldHandleY, this)
);
this._bottomLeftWheelHandler = new BI.WheelHandler(
BI.bind(this._onWheelLeft, this),
BI.bind(this._shouldHandleLeftX, this),
BI.bind(this._shouldHandleY, this)
);
this._bottomRightWheelHandler = new BI.WheelHandler(
BI.bind(this._onWheelRight, this),
BI.bind(this._shouldHandleRightX, this),
BI.bind(this._shouldHandleY, this)
);
this.topLeftCollection.element.mousewheel(function (e) {
self._topLeftWheelHandler.onWheel(e.originalEvent);
});
this.topRightCollection.element.mousewheel(function (e) {
self._topRightWheelHandler.onWheel(e.originalEvent);
});
this.bottomLeftCollection.element.mousewheel(function (e) {
self._leftWheelHandler.onWheel(e.originalEvent);
self._bottomLeftWheelHandler.onWheel(e.originalEvent);
});
this.bottomRightCollection.element.mousewheel(function (e) {
self._rightWheelHandler.onWheel(e.originalEvent);
self._bottomRightWheelHandler.onWheel(e.originalEvent);
});
},
_shouldHandleX: function (delta) {
return false;
_shouldHandleLeftX: function (delta) {
if (delta > 0) {
return this.bottomLeftCollection.getScrollLeft() < this.bottomLeftCollection.getMaxScrollLeft();
} else {
return this.bottomLeftCollection.getScrollLeft() > 0;
}
},
_shouldHandleRightX: function (delta) {
if (delta > 0) {
return this.bottomRightCollection.getScrollLeft() < this.bottomRightCollection.getMaxScrollLeft();
} else {
return this.bottomRightCollection.getScrollLeft() > 0;
}
},
_shouldHandleY: function (delta) {
@ -29066,19 +29178,38 @@ BI.QuickCollectionTable = BI.inherit(BI.CollectionTable, {
}
},
_onWheelY: function (deltaX, deltaY) {
_onWheelLeft: function (deltaX, deltaY) {
var self = this;
var scrollTop = this.bottomLeftCollection.getScrollTop();
var scrollLeft = this.bottomLeftCollection.getScrollLeft();
scrollTop += deltaY;
scrollLeft += deltaX;
this.bottomLeftCollection.setScrollTop(scrollTop);
this.bottomRightCollection.setScrollTop(scrollTop);
this.topLeftCollection.setScrollLeft(scrollLeft);
this.bottomLeftCollection.setScrollLeft(scrollLeft);
self._populateScrollbar();
this.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments);
},
_onWheelRight: function (deltaX, deltaY) {
var self = this;
var scrollTop = this.bottomRightCollection.getScrollTop();
var scrollLeft = this.bottomRightCollection.getScrollLeft();
scrollTop += deltaY;
scrollLeft += deltaX;
this.bottomLeftCollection.setScrollTop(scrollTop);
this.bottomRightCollection.setScrollTop(scrollTop);
this.topRightCollection.setScrollLeft(scrollLeft);
this.bottomRightCollection.setScrollLeft(scrollLeft);
self._populateScrollbar();
this.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments);
},
_populateTable: function () {
var self = this, o = this.options;
var regionSize = this.getRegionSize(), totalLeftColumnSize = 0, totalRightColumnSize = 0, totalColumnSize = 0, summaryColumnSizeArray = [], totalRowSize = o.items.length * o.rowSize;
var regionSize = this.getRegionSize(), totalLeftColumnSize = 0, totalRightColumnSize = 0, totalColumnSize = 0,
summaryColumnSizeArray = [], totalRowSize = o.items.length * o.rowSize;
var freezeColLength = this._getFreezeColLength();
BI.each(o.columnSize, function (i, size) {
if (o.isNeedFreeze === true && o.freezeCols.contains(i)) {
@ -29691,26 +29822,54 @@ BI.QuickGridTable = BI.inherit(BI.GridTable, {
mounted: function () {
BI.QuickGridTable.superclass.mounted.apply(this, arguments);
var self = this;
this._leftWheelHandler = new BI.WheelHandler(
BI.bind(this._onWheelY, this),
BI.bind(this._shouldHandleX, this),
this._topLeftWheelHandler = new BI.WheelHandler(
BI.bind(this._onWheelLeft, this),
BI.bind(this._shouldHandleLeftX, this),
BI.bind(this._shouldHandleY, this)
);
this._rightWheelHandler = new BI.WheelHandler(
BI.bind(this._onWheelY, this),
BI.bind(this._shouldHandleX, this),
this._topRightWheelHandler = new BI.WheelHandler(
BI.bind(this._onWheelRight, this),
BI.bind(this._shouldHandleRightX, this),
BI.bind(this._shouldHandleY, this)
);
this._bottomLeftWheelHandler = new BI.WheelHandler(
BI.bind(this._onWheelLeft, this),
BI.bind(this._shouldHandleLeftX, this),
BI.bind(this._shouldHandleY, this)
);
this._bottomRightWheelHandler = new BI.WheelHandler(
BI.bind(this._onWheelRight, this),
BI.bind(this._shouldHandleRightX, this),
BI.bind(this._shouldHandleY, this)
);
this.topLeftGrid.element.mousewheel(function (e) {
self._topLeftWheelHandler.onWheel(e.originalEvent);
});
this.topRightGrid.element.mousewheel(function (e) {
self._topRightWheelHandler.onWheel(e.originalEvent);
});
this.bottomLeftGrid.element.mousewheel(function (e) {
self._leftWheelHandler.onWheel(e.originalEvent);
self._bottomLeftWheelHandler.onWheel(e.originalEvent);
});
this.bottomRightGrid.element.mousewheel(function (e) {
self._rightWheelHandler.onWheel(e.originalEvent);
self._bottomRightWheelHandler.onWheel(e.originalEvent);
});
},
_shouldHandleX: function (delta) {
return false;
_shouldHandleLeftX: function (delta) {
if (delta > 0) {
return this.bottomLeftGrid.getScrollLeft() < this.bottomLeftGrid.getMaxScrollLeft();
} else {
return this.bottomLeftGrid.getScrollLeft() > 0;
}
},
_shouldHandleRightX: function (delta) {
if (delta > 0) {
return this.bottomRightGrid.getScrollLeft() < this.bottomRightGrid.getMaxScrollLeft();
} else {
return this.bottomRightGrid.getScrollLeft() > 0;
}
},
_shouldHandleY: function (delta) {
@ -29721,12 +29880,30 @@ BI.QuickGridTable = BI.inherit(BI.GridTable, {
}
},
_onWheelY: function (deltaX, deltaY) {
_onWheelLeft: function (deltaX, deltaY) {
var self = this;
var scrollTop = this.bottomLeftGrid.getScrollTop();
var scrollLeft = this.bottomLeftGrid.getScrollLeft();
scrollTop += deltaY;
scrollLeft += deltaX;
this.bottomLeftGrid.setScrollTop(scrollTop);
this.bottomRightGrid.setScrollTop(scrollTop);
this.topLeftGrid.setScrollLeft(scrollLeft);
this.bottomLeftGrid.setScrollLeft(scrollLeft);
self._populateScrollbar();
this.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments);
},
_onWheelRight: function (deltaX, deltaY) {
var self = this;
var scrollTop = this.bottomRightGrid.getScrollTop();
var scrollLeft = this.bottomRightGrid.getScrollLeft();
scrollTop += deltaY;
scrollLeft += deltaX;
this.bottomLeftGrid.setScrollTop(scrollTop);
this.bottomRightGrid.setScrollTop(scrollTop);
this.topRightGrid.setScrollLeft(scrollLeft);
this.bottomRightGrid.setScrollLeft(scrollLeft);
self._populateScrollbar();
this.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments);
},

18
docs/case.js

@ -9118,18 +9118,18 @@ BI.DynamicSummaryLayerTreeTable = BI.inherit(BI.Widget, {
var vDeep = this._getVDeep();
var header = this._createHeader(vDeep);
var data = this._formatItems(o.items, header, deep);
// var columnSize = o.columnSize.slice();
// var minColumnSize = o.minColumnSize.slice();
// var maxColumnSize = o.maxColumnSize.slice();
// BI.removeAt(columnSize, data.deletedCols);
// BI.removeAt(minColumnSize, data.deletedCols);
// BI.removeAt(maxColumnSize, data.deletedCols);
var columnSize = o.columnSize.slice();
var minColumnSize = o.minColumnSize.slice();
var maxColumnSize = o.maxColumnSize.slice();
BI.removeAt(columnSize, data.deletedCols);
BI.removeAt(minColumnSize, data.deletedCols);
BI.removeAt(maxColumnSize, data.deletedCols);
return {
header: data.header,
items: data.items,
columnSize: this._formatColumnSize(o.columnSize, deep),
minColumnSize: this._formatColumns(o.minColumnSize, deep),
maxColumnSize: this._formatColumns(o.maxColumnSize, deep),
columnSize: this._formatColumnSize(columnSize, deep),
minColumnSize: this._formatColumns(minColumnSize, deep),
maxColumnSize: this._formatColumns(maxColumnSize, deep),
freezeCols: this._formatFreezeCols()
}
},

4
docs/chart.js

@ -19,7 +19,9 @@ BI.Chart = BI.inherit(BI.Pane, {
this.vanCharts = VanCharts.init(self.element[0]);
this._resizer = BI.debounce(function () {
self.vanCharts.resize();
if (self.element.width() > 0 && self.element.height() > 0) {
self.vanCharts.resize();
}
}, 30);
BI.ResizeDetector.addResizeListener(this, function (e) {
self._resizer();

363
docs/core.js

@ -13305,6 +13305,29 @@ if (!window.BI) {
return true;
},
backFindKey: function (obj, predicate, context) {
predicate = BI.iteratee(predicate, context);
var keys = _.keys(obj), key;
for (var i = keys.length - 1; i >= 0; i--) {
key = keys[i];
if (predicate(obj[key], key, obj)) {
return key;
}
}
},
backFind: function (obj, predicate, context) {
var key;
if (BI.isArray(obj)) {
key = BI.findLastIndex(obj, predicate, context);
} else {
key = BI.backFindKey(obj, predicate, context);
}
if (key !== void 0 && key !== -1) {
return obj[key];
}
},
remove: function (obj, target, context) {
var isFunction = BI.isFunction(target);
target = isFunction || BI.isArray(target) ? target : [target];
@ -23303,34 +23326,6 @@ $.extend(Array.prototype, {
contains: function (o) {
return this.indexOf(o) > -1;
},
/**
* 检查指定的值是否在数组中
* @param {Object} o 要检查的值
* @return {Number} o在数组中的索引如果不在数组中则返回-1
*/
indexOf: function (o) {
for (var i = 0, len = this.length; i < len; i++) {
if (_.isEqual(o, this[i])) {
return i;
}
}
return -1;
},
/**
* 检查指定的值是否在数组中
* ie67不支持数组的这个方法
* @param {Object} o 要检查的值
* @return {Number} o在数组中的索引如果不在数组中则返回-1
*/
lastIndexOf: function (o) {
for (var len = this.length, i = len - 1; i >= 0; i--) {
if (_.isEqual(o, this[i])) {
return i;
}
}
return -1;
},
/**
* 从数组中移除指定的值如果值不在数组中则不产生任何效果
@ -23339,265 +23334,29 @@ $.extend(Array.prototype, {
*/
remove: function (o) {
var index = this.indexOf(o);
if (index != -1) {
if (index !== -1) {
this.splice(index, 1);
}
return this;
},
/**
* 移除数组中的所有元素
*/
clear: function () {
while (this.length > 0) {
this.pop();
}
}
});
/**
* Array原型拓展
* Created by wang on 15/6/23.
*/
!function () {
Array.prototype.pushArray = function (array) {
pushArray: function (array) {
for (var i = 0; i < array.length; i++) {
this.push(array[i]);
}
};
Array.prototype.pushDistinct = function (obj) {
},
pushDistinct: function (obj) {
if (!this.contains(obj)) {
this.push(obj);
}
};
Array.prototype.pushDistinctArray = function (array) {
},
pushDistinctArray: function (array) {
for (var i = 0, len = array.length; i < len; i++) {
this.pushDistinct(array[i]);
}
};
}();
/**
* 规定bi的数组分为两种其中value和type值为key值
* 1[{"text":1,"value":2,"children":[]}]
* 2[{"name":1,"type":2,"children":[]}]
* guy
* 对数组的操作
* @type {{}}
*/
ArrayUtils = {};
$.extend(ArrayUtils, {
/**
* 遍历方法
* @param array
* @param back
*/
traversal: function (array, back) {
if (BI.isNull(array)) {
return;
}
var self = this;
BI.each(array, function (i, item) {
if (back(i, item) === BI.Status.END) {
return false;
}
self.traversal(item.children, back);
})
},
getAllChildNames: function (array) {
var names = [];
this.traversal(array, function (i, item) {
if (BI.isNotEmptyArray(item.children)) {
return BI.Status.RUNNING;
}
names.push(item.text || item.name);
});
return names;
},
/**
* 获取第一个子节点
* @param array
*/
getFirstChild: function (array) {
var first = {};
this.traversal(array, function (i, item) {
if (BI.isNotEmptyArray(item.children)) {
return;
}
first = item;
return BI.Status.END;
})
return first;
},
/**
* 获取最后一个子节点
* @param array
*/
getLastChild: function (array) {
var first = {};
this.traversal(array, function (i, item) {
if (item.children && item.children.length > 0) {
return;
}
first = item;
})
return first;
},
getTextByValue: function (array, value) {
if (!array) {
return value;
}
var text = "";
this.traversal(array, function (i, item) {
if (BI.isEqual(item.value, value)) {
text = item.text;
return BI.Status.END;
}
});
return text;
},
getNameByType: function (array, type) {
if (!array) {
return type;
}
var name = "";
this.traversal(array, function (i, item) {
if (BI.isEqual(item.type, type)) {
name = item.name;
return BI.Status.END;
}
});
return name;
},
getItemByText: function (array, text) {
var res = void 0;
this.traversal(array, function (i, item) {
if (BI.isCapitalEqual(item.text, text)) {
res = item;
return BI.Status.END;
}
});
return res;
},
getIndexByText: function (array, text) {
var res = -1;
this.traversal(array, function (i, item) {
if (BI.isCapitalEqual(item.text, text)) {
res = i;
return BI.Status.END;
}
});
return res;
},
getItemByValue: function (array, value) {
var res = void 0;
this.traversal(array, function (i, item) {
if (BI.isEqual(item.value, value)) {
res = item;
return BI.Status.END;
}
});
return res;
},
getIndexByValue: function (array, value) {
var res = -1;
this.traversal(array, function (i, item) {
if (BI.isEqual(item.value, value)) {
res = i;
return BI.Status.END;
}
});
return res;
},
getItemByName: function (array, name) {
var res = void 0;
this.traversal(array, function (i, item) {
if (BI.isCapitalEqual(item.name, name)) {
res = item;
return BI.Status.END;
}
});
return res;
},
getIndexByName: function (array, name) {
var res = -1;
this.traversal(array, function (i, item) {
if (BI.isCapitalEqual(item.name, name)) {
res = i;
return BI.Status.END;
}
});
return res;
},
getItemByType: function (array, type) {
var res = void 0;
this.traversal(array, function (i, item) {
if (BI.isEqual(item.type, type)) {
res = item;
return BI.Status.END;
}
});
return res;
},
getIndexByType: function (array, type) {
var res = -1;
this.traversal(array, function (i, item) {
if (BI.isEqual(item.type, type)) {
res = i;
return BI.Status.END;
}
});
return res;
},
deleteItemByType: function (array, type) {
var item = this.getItemByType(array, type);
array.remove(item);
},
deleteItemByName: function (array, name) {
var item = this.getItemByName(array, name);
array.remove(item);
},
deleteItemByValue: function (array, value) {
var item = this.getItemByValue(array, value);
array.remove(item);
}
});/*
* 前端缓存
*/
window.localStorage || (window.localStorage = {
items: {},
setItem: function (k, v) {
BI.Cache.addCookie(k, v);
},
getItem: function (k) {
return BI.Cache.getCookie(k);
},
removeItem: function (k) {
BI.Cache.deleteCookie(k);
},
key: function () {
},
clear: function () {
this.items = {};
}
});
BI.Cache = {
_prefix: "bi",
setUsername: function (username) {
@ -23732,7 +23491,6 @@ Date._QN = ["", BI.i18nText("BI-Quarter_1"),
BI.i18nText("BI-Quarter_4")];
/** Adds the number of days array to the Date object. */
Date._MD = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
@ -23767,12 +23525,19 @@ Date.prototype.getDayOfYear = function () {
/** Returns the number of the week in year, as defined in ISO 8601. */
Date.prototype.getWeekNumber = function () {
var d = new Date(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0);
var DoW = d.getDay();
d.setDate(d.getDate() - (DoW + 6) % 7 + 3); // Nearest Thu
var week = d.getDay();
if (this.getMonth() === 0 && this.getDate() <= week) {
return 1;
}
d.setDate(this.getDate() - week);
var ms = d.valueOf(); // GMT
d.setMonth(0);
d.setDate(4); // Thu in Week 1
return Math.round((ms - d.valueOf()) / (7 * 864e5)) + 1;
d.setDate(1);
var offset = Math.floor((ms - d.valueOf()) / (7 * 864e5)) + 1;
if (d.getDay() > 0) {
offset++;
}
return offset;
};
//离当前时间多少天的时间
@ -23864,7 +23629,7 @@ Date.prototype.getOffsetMonth = function (n) {
var dt = new Date(this.getTime());
var day = dt.getDate();
var monthDay = new Date(dt.getFullYear(), dt.getMonth() + parseInt(n), 1).getMonthDays();
if(day > monthDay){
if (day > monthDay) {
day = monthDay;
}
dt.setDate(day);
@ -24548,50 +24313,6 @@ function accDiv(arg1, arg2) {
Number.prototype.div = function (arg) {
return accDiv(this, arg);
};/**
* 特殊情况
* Created by wang on 15/6/23.
*/
//解决console未定义问题 guy
window.console = window.console || (function () {
var c = {};
c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile
= c.clear = c.exception = c.trace = c.assert = function () {
};
return c;
})();
//修复ie9下sort方法的bug
!function (window) {
var ua = window.navigator.userAgent.toLowerCase(),
reg = /msie|applewebkit.+safari/;
if (reg.test(ua)) {
var _sort = Array.prototype.sort;
Array.prototype.sort = function (fn) {
if (!!fn && typeof fn === 'function') {
if (this.length < 2) {
return this;
}
var i = 0, j = i + 1, l = this.length, tmp, r = false, t = 0;
for (; i < l; i++) {
for (j = i + 1; j < l; j++) {
t = fn.call(this, this[i], this[j]);
r = (typeof t === 'number' ? t :
!!t ? 1 : 0) > 0;
if (r === true) {
tmp = this[i];
this[i] = this[j];
this[j] = tmp;
}
}
}
return this;
} else {
return _sort.call(this);
}
};
}
}(window);/**
* 对字符串对象的扩展
* @class String
*/

1
docs/index.html

@ -15,6 +15,7 @@
<link rel="stylesheet" type="text/css"
href="demo.css"/>
<script src="polyfill.js"></script>
<script src="core.js"></script>
<script src="base.js"></script>
<script src="case.js"></script>

2
server.js

@ -9,5 +9,5 @@ const port = 3000;
app.use(express.static("./"));
app.listen(port, function() {
console.log("server start");
open('http://localhost:' + port + '/demo.html');
open('http://localhost:' + port + '/docs/index.html');
});

4
src/addons/chart/chart.js

@ -19,7 +19,9 @@ BI.Chart = BI.inherit(BI.Pane, {
this.vanCharts = VanCharts.init(self.element[0]);
this._resizer = BI.debounce(function () {
self.vanCharts.resize();
if (self.element.width() > 0 && self.element.height() > 0) {
self.vanCharts.resize();
}
}, 30);
BI.ResizeDetector.addResizeListener(this, function (e) {
self._resizer();

195
src/base/collection/collection.js

@ -27,10 +27,11 @@ BI.Collection = BI.inherit(BI.Widget, {
var self = this, o = this.options;
this.renderedCells = [];
this.renderedKeys = [];
this.renderRange = {};
this._scrollLock = false;
this._debounceRelease = BI.debounce(function () {
self._scrollLock = false;
}, 150);
}, 1000 / 60);
this.container = BI.createWidget({
type: "bi.absolute"
});
@ -76,12 +77,10 @@ BI.Collection = BI.inherit(BI.Widget, {
for (var index = 0, len = o.items.length; index < len; index++) {
var cellMetadatum = o.cellSizeAndPositionGetter(index);
if (
cellMetadatum.height == null || isNaN(cellMetadatum.height) ||
if (cellMetadatum.height == null || isNaN(cellMetadatum.height) ||
cellMetadatum.width == null || isNaN(cellMetadatum.width) ||
cellMetadatum.x == null || isNaN(cellMetadatum.x) ||
cellMetadatum.y == null || isNaN(cellMetadatum.y)
) {
cellMetadatum.y == null || isNaN(cellMetadatum.y)) {
throw Error();
}
@ -122,75 +121,134 @@ BI.Collection = BI.inherit(BI.Widget, {
var top = Math.max(0, scrollTop - o.verticalOverscanSize);
var right = Math.min(this._width, scrollLeft + o.width + o.horizontalOverscanSize);
var bottom = Math.min(this._height, scrollTop + o.height + o.verticalOverscanSize);
var childrenToDisplay = this._cellRenderers(bottom - top, right - left, left, top);
var renderedCells = [], renderedKeys = [];
for (var i = 0, len = childrenToDisplay.length; i < len; i++) {
var datum = childrenToDisplay[i];
var index = BI.deepIndexOf(this.renderedKeys, datum.index);
if (index > -1) {
if (datum.width !== this.renderedCells[index]._width) {
this.renderedCells[index]._width = datum.width;
this.renderedCells[index].el.setWidth(datum.width);
if (right > 0 && bottom > 0) {
//如果滚动的区间并没有超出渲染的范围
if (top >= this.renderRange.minY && bottom <= this.renderRange.maxY && left >= this.renderRange.minX && right <= this.renderRange.maxX) {
return;
}
var childrenToDisplay = this._cellRenderers(bottom - top, right - left, left, top);
var renderedCells = [], renderedKeys = [];
//存储所有的left和top
var lefts = {}, tops = {};
for (var i = 0, len = childrenToDisplay.length; i < len; i++) {
var datum = childrenToDisplay[i];
lefts[datum.x] = datum.x;
lefts[datum.x + datum.width] = datum.x + datum.width;
tops[datum.y] = datum.y;
tops[datum.y + datum.height] = datum.y + datum.height;
}
lefts = BI.toArray(lefts);
tops = BI.toArray(tops);
var leftMap = BI.invert(lefts);
var topMap = BI.invert(tops);
//存储上下左右四个边界
var leftBorder = {}, rightBorder = {}, topBorder = {}, bottomBorder = {};
var assertMinBorder = function (border, offset) {
if (border[offset] == null) {
border[offset] = Number.MAX_VALUE;
}
if (datum.height !== this.renderedCells[index]._height) {
this.renderedCells[index]._height = datum.height;
this.renderedCells[index].el.setHeight(datum.height);
};
var assertMaxBorder = function (border, offset) {
if (border[offset] == null) {
border[offset] = 0;
}
if (this.renderedCells[index].left !== datum.x) {
this.renderedCells[index].el.element.css("left", datum.x + "px");
};
for (var i = 0, len = childrenToDisplay.length; i < len; i++) {
var datum = childrenToDisplay[i];
var index = BI.deepIndexOf(this.renderedKeys, datum.index);
if (index > -1) {
if (datum.width !== this.renderedCells[index]._width) {
this.renderedCells[index]._width = datum.width;
this.renderedCells[index].el.setWidth(datum.width);
}
if (datum.height !== this.renderedCells[index]._height) {
this.renderedCells[index]._height = datum.height;
this.renderedCells[index].el.setHeight(datum.height);
}
if (this.renderedCells[index].left !== datum.x) {
this.renderedCells[index].el.element.css("left", datum.x + "px");
}
if (this.renderedCells[index].top !== datum.y) {
this.renderedCells[index].el.element.css("top", datum.y + "px");
}
renderedCells.push(this.renderedCells[index]);
} else {
var child = BI.createWidget(BI.extend({
type: "bi.label",
width: datum.width,
height: datum.height
}, o.items[datum.index], {
cls: (o.items[datum.index].cls || "") + " container-cell" + (datum.y === 0 ? " first-row" : "") + (datum.x === 0 ? " first-col" : ""),
_left: datum.x,
_top: datum.y
}));
renderedCells.push({
el: child,
left: datum.x,
top: datum.y,
_width: datum.width,
_height: datum.height
});
}
if (this.renderedCells[index].top !== datum.y) {
this.renderedCells[index].el.element.css("top", datum.y + "px");
var startTopIndex = topMap[datum.y] | 0;
var endTopIndex = topMap[datum.y + datum.height] | 0;
for (var k = startTopIndex; k <= endTopIndex; k++) {
var t = tops[k];
assertMinBorder(leftBorder, t);
assertMaxBorder(rightBorder, t);
leftBorder[t] = Math.min(leftBorder[t], datum.x);
rightBorder[t] = Math.max(rightBorder[t], datum.x + datum.width);
}
renderedCells.push(this.renderedCells[index]);
} else {
var child = BI.createWidget(BI.extend({
type: "bi.label",
width: datum.width,
height: datum.height
}, o.items[datum.index], {
cls: (o.items[datum.index].cls || "") + " container-cell" + (datum.y === 0 ? " first-row" : "") + (datum.x === 0 ? " first-col" : ""),
_left: datum.x,
_top: datum.y
}));
renderedCells.push({
el: child,
left: datum.x,
top: datum.y,
_width: datum.width,
_height: datum.height
});
var startLeftIndex = leftMap[datum.x] | 0;
var endLeftIndex = leftMap[datum.x + datum.width] | 0;
for (var k = startLeftIndex; k <= endLeftIndex; k++) {
var l = lefts[k];
assertMinBorder(topBorder, l);
assertMaxBorder(bottomBorder, l);
topBorder[l] = Math.min(topBorder[l], datum.y);
bottomBorder[l] = Math.max(bottomBorder[l], datum.y + datum.height);
}
renderedKeys.push(datum.index);
}
renderedKeys.push(datum.index);
//已存在的, 需要添加的和需要删除的
var existSet = {}, addSet = {}, deleteArray = [];
BI.each(renderedKeys, function (i, key) {
if (BI.deepContains(self.renderedKeys, key)) {
existSet[i] = key;
} else {
addSet[i] = key;
}
});
BI.each(this.renderedKeys, function (i, key) {
if (BI.deepContains(existSet, key)) {
return;
}
if (BI.deepContains(addSet, key)) {
return;
}
deleteArray.push(i);
});
BI.each(deleteArray, function (i, index) {
self.renderedCells[index].el.destroy();
});
var addedItems = [];
BI.each(addSet, function (index) {
addedItems.push(renderedCells[index])
});
this.container.addItems(addedItems);
this.renderedCells = renderedCells;
this.renderedKeys = renderedKeys;
//Todo 左右比较特殊
var minX = BI.min(leftBorder);
var maxX = BI.max(rightBorder);
var minY = BI.max(topBorder);
var maxY = BI.min(bottomBorder);
this.renderRange = {minX: minX, minY: minY, maxX: maxX, maxY: maxY};
}
//已存在的, 需要添加的和需要删除的
var existSet = {}, addSet = {}, deleteArray = [];
BI.each(renderedKeys, function (i, key) {
if (BI.deepContains(self.renderedKeys, key)) {
existSet[i] = key;
} else {
addSet[i] = key;
}
});
BI.each(this.renderedKeys, function (i, key) {
if (BI.deepContains(existSet, key)) {
return;
}
if (BI.deepContains(addSet, key)) {
return;
}
deleteArray.push(i);
});
BI.each(deleteArray, function (i, index) {
self.renderedCells[index].el.destroy();
});
var addedItems = [];
BI.each(addSet, function (index) {
addedItems.push(renderedCells[index])
});
this.container.addItems(addedItems);
this.renderedCells = renderedCells;
this.renderedKeys = renderedKeys;
},
_getMaxScrollLeft: function () {
@ -277,6 +335,7 @@ BI.Collection = BI.inherit(BI.Widget, {
});
this.renderedCells = [];
this.renderedKeys = [];
this.renderRange = {};
this._scrollLock = false;
},

31
src/base/grid/grid.js

@ -30,10 +30,11 @@ BI.Grid = BI.inherit(BI.Widget, {
var self = this, o = this.options;
this.renderedCells = [];
this.renderedKeys = [];
this.renderRange = {};
this._scrollLock = false;
this._debounceRelease = BI.debounce(function () {
self._scrollLock = false;
}, 150);
}, 1000 / 60);
this.container = BI.createWidget({
type: "bi.absolute"
});
@ -78,13 +79,17 @@ BI.Grid = BI.inherit(BI.Widget, {
_calculateChildrenToRender: function () {
var self = this, o = this.options;
var width = o.width, height = o.height, scrollLeft = BI.clamp(o.scrollLeft, 0, this._getMaxScrollLeft()), scrollTop = BI.clamp(o.scrollTop, 0, this._getMaxScrollTop()),
var width = o.width, height = o.height, scrollLeft = BI.clamp(o.scrollLeft, 0, this._getMaxScrollLeft()),
scrollTop = BI.clamp(o.scrollTop, 0, this._getMaxScrollTop()),
overscanColumnCount = o.overscanColumnCount, overscanRowCount = o.overscanRowCount;
if (height > 0 && width > 0) {
var visibleColumnIndices = this._columnSizeAndPositionManager.getVisibleCellRange(width, scrollLeft);
var visibleRowIndices = this._rowSizeAndPositionManager.getVisibleCellRange(height, scrollTop);
if (BI.isEmpty(visibleColumnIndices) || BI.isEmpty(visibleRowIndices)) {
return;
}
var horizontalOffsetAdjustment = this._columnSizeAndPositionManager.getOffsetAdjustment(width, scrollLeft);
var verticalOffsetAdjustment = this._rowSizeAndPositionManager.getOffsetAdjustment(height, scrollTop);
@ -102,8 +107,22 @@ BI.Grid = BI.inherit(BI.Widget, {
var rowStartIndex = overscanRowIndices.overscanStartIndex;
var rowStopIndex = overscanRowIndices.overscanStopIndex;
var renderedCells = [], renderedKeys = [];
//算区间size
var minRowDatum = this._rowSizeAndPositionManager.getSizeAndPositionOfCell(rowStartIndex);
var minColumnDatum = this._columnSizeAndPositionManager.getSizeAndPositionOfCell(columnStartIndex);
var maxRowDatum = this._rowSizeAndPositionManager.getSizeAndPositionOfCell(rowStopIndex);
var maxColumnDatum = this._columnSizeAndPositionManager.getSizeAndPositionOfCell(columnStopIndex);
var top = minRowDatum.offset + verticalOffsetAdjustment;
var left = minColumnDatum.offset + horizontalOffsetAdjustment;
var bottom = maxRowDatum.offset + verticalOffsetAdjustment + maxRowDatum.size;
var right = maxColumnDatum.offset + horizontalOffsetAdjustment + maxColumnDatum.size;
//如果滚动的区间并没有超出渲染的范围
if (top >= this.renderRange.minY && bottom <= this.renderRange.maxY && left >= this.renderRange.minX && right <= this.renderRange.maxX) {
return;
}
var renderedCells = [], renderedKeys = [];
var minX = this._getMaxScrollLeft(), minY = this._getMaxScrollTop(), maxX = 0, maxY = 0;
for (var rowIndex = rowStartIndex; rowIndex <= rowStopIndex; rowIndex++) {
var rowDatum = this._rowSizeAndPositionManager.getSizeAndPositionOfCell(rowIndex);
@ -148,6 +167,10 @@ BI.Grid = BI.inherit(BI.Widget, {
_height: rowDatum.size
});
}
minX = Math.min(minX, columnDatum.offset + horizontalOffsetAdjustment);
maxX = Math.max(maxX, columnDatum.offset + horizontalOffsetAdjustment + columnDatum.size);
minY = Math.min(minY, rowDatum.offset + verticalOffsetAdjustment);
maxY = Math.max(maxY, rowDatum.offset + verticalOffsetAdjustment + rowDatum.size);
renderedKeys.push(key);
}
}
@ -179,6 +202,7 @@ BI.Grid = BI.inherit(BI.Widget, {
this.container.addItems(addedItems);
this.renderedCells = renderedCells;
this.renderedKeys = renderedKeys;
this.renderRange = {minX: minX, minY: minY, maxX: maxX, maxY: maxY};
}
},
@ -282,6 +306,7 @@ BI.Grid = BI.inherit(BI.Widget, {
});
this.renderedCells = [];
this.renderedKeys = [];
this.renderRange = {};
this._scrollLock = false;
},

71
src/base/table/table.collection.quick.js

@ -28,26 +28,54 @@ BI.QuickCollectionTable = BI.inherit(BI.CollectionTable, {
mounted: function () {
BI.QuickCollectionTable.superclass.mounted.apply(this, arguments);
var self = this;
this._leftWheelHandler = new BI.WheelHandler(
BI.bind(this._onWheelY, this),
BI.bind(this._shouldHandleX, this),
this._topLeftWheelHandler = new BI.WheelHandler(
BI.bind(this._onWheelLeft, this),
BI.bind(this._shouldHandleLeftX, this),
BI.bind(this._shouldHandleY, this)
);
this._rightWheelHandler = new BI.WheelHandler(
BI.bind(this._onWheelY, this),
BI.bind(this._shouldHandleX, this),
this._topRightWheelHandler = new BI.WheelHandler(
BI.bind(this._onWheelRight, this),
BI.bind(this._shouldHandleRightX, this),
BI.bind(this._shouldHandleY, this)
);
this._bottomLeftWheelHandler = new BI.WheelHandler(
BI.bind(this._onWheelLeft, this),
BI.bind(this._shouldHandleLeftX, this),
BI.bind(this._shouldHandleY, this)
);
this._bottomRightWheelHandler = new BI.WheelHandler(
BI.bind(this._onWheelRight, this),
BI.bind(this._shouldHandleRightX, this),
BI.bind(this._shouldHandleY, this)
);
this.topLeftCollection.element.mousewheel(function (e) {
self._topLeftWheelHandler.onWheel(e.originalEvent);
});
this.topRightCollection.element.mousewheel(function (e) {
self._topRightWheelHandler.onWheel(e.originalEvent);
});
this.bottomLeftCollection.element.mousewheel(function (e) {
self._leftWheelHandler.onWheel(e.originalEvent);
self._bottomLeftWheelHandler.onWheel(e.originalEvent);
});
this.bottomRightCollection.element.mousewheel(function (e) {
self._rightWheelHandler.onWheel(e.originalEvent);
self._bottomRightWheelHandler.onWheel(e.originalEvent);
});
},
_shouldHandleX: function (delta) {
return false;
_shouldHandleLeftX: function (delta) {
if (delta > 0) {
return this.bottomLeftCollection.getScrollLeft() < this.bottomLeftCollection.getMaxScrollLeft();
} else {
return this.bottomLeftCollection.getScrollLeft() > 0;
}
},
_shouldHandleRightX: function (delta) {
if (delta > 0) {
return this.bottomRightCollection.getScrollLeft() < this.bottomRightCollection.getMaxScrollLeft();
} else {
return this.bottomRightCollection.getScrollLeft() > 0;
}
},
_shouldHandleY: function (delta) {
@ -58,19 +86,38 @@ BI.QuickCollectionTable = BI.inherit(BI.CollectionTable, {
}
},
_onWheelY: function (deltaX, deltaY) {
_onWheelLeft: function (deltaX, deltaY) {
var self = this;
var scrollTop = this.bottomLeftCollection.getScrollTop();
var scrollLeft = this.bottomLeftCollection.getScrollLeft();
scrollTop += deltaY;
scrollLeft += deltaX;
this.bottomLeftCollection.setScrollTop(scrollTop);
this.bottomRightCollection.setScrollTop(scrollTop);
this.topLeftCollection.setScrollLeft(scrollLeft);
this.bottomLeftCollection.setScrollLeft(scrollLeft);
self._populateScrollbar();
this.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments);
},
_onWheelRight: function (deltaX, deltaY) {
var self = this;
var scrollTop = this.bottomRightCollection.getScrollTop();
var scrollLeft = this.bottomRightCollection.getScrollLeft();
scrollTop += deltaY;
scrollLeft += deltaX;
this.bottomLeftCollection.setScrollTop(scrollTop);
this.bottomRightCollection.setScrollTop(scrollTop);
this.topRightCollection.setScrollLeft(scrollLeft);
this.bottomRightCollection.setScrollLeft(scrollLeft);
self._populateScrollbar();
this.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments);
},
_populateTable: function () {
var self = this, o = this.options;
var regionSize = this.getRegionSize(), totalLeftColumnSize = 0, totalRightColumnSize = 0, totalColumnSize = 0, summaryColumnSizeArray = [], totalRowSize = o.items.length * o.rowSize;
var regionSize = this.getRegionSize(), totalLeftColumnSize = 0, totalRightColumnSize = 0, totalColumnSize = 0,
summaryColumnSizeArray = [], totalRowSize = o.items.length * o.rowSize;
var freezeColLength = this._getFreezeColLength();
BI.each(o.columnSize, function (i, size) {
if (o.isNeedFreeze === true && o.freezeCols.contains(i)) {

68
src/base/table/table.grid.quick.js

@ -28,26 +28,54 @@ BI.QuickGridTable = BI.inherit(BI.GridTable, {
mounted: function () {
BI.QuickGridTable.superclass.mounted.apply(this, arguments);
var self = this;
this._leftWheelHandler = new BI.WheelHandler(
BI.bind(this._onWheelY, this),
BI.bind(this._shouldHandleX, this),
this._topLeftWheelHandler = new BI.WheelHandler(
BI.bind(this._onWheelLeft, this),
BI.bind(this._shouldHandleLeftX, this),
BI.bind(this._shouldHandleY, this)
);
this._rightWheelHandler = new BI.WheelHandler(
BI.bind(this._onWheelY, this),
BI.bind(this._shouldHandleX, this),
this._topRightWheelHandler = new BI.WheelHandler(
BI.bind(this._onWheelRight, this),
BI.bind(this._shouldHandleRightX, this),
BI.bind(this._shouldHandleY, this)
);
this._bottomLeftWheelHandler = new BI.WheelHandler(
BI.bind(this._onWheelLeft, this),
BI.bind(this._shouldHandleLeftX, this),
BI.bind(this._shouldHandleY, this)
);
this._bottomRightWheelHandler = new BI.WheelHandler(
BI.bind(this._onWheelRight, this),
BI.bind(this._shouldHandleRightX, this),
BI.bind(this._shouldHandleY, this)
);
this.topLeftGrid.element.mousewheel(function (e) {
self._topLeftWheelHandler.onWheel(e.originalEvent);
});
this.topRightGrid.element.mousewheel(function (e) {
self._topRightWheelHandler.onWheel(e.originalEvent);
});
this.bottomLeftGrid.element.mousewheel(function (e) {
self._leftWheelHandler.onWheel(e.originalEvent);
self._bottomLeftWheelHandler.onWheel(e.originalEvent);
});
this.bottomRightGrid.element.mousewheel(function (e) {
self._rightWheelHandler.onWheel(e.originalEvent);
self._bottomRightWheelHandler.onWheel(e.originalEvent);
});
},
_shouldHandleX: function (delta) {
return false;
_shouldHandleLeftX: function (delta) {
if (delta > 0) {
return this.bottomLeftGrid.getScrollLeft() < this.bottomLeftGrid.getMaxScrollLeft();
} else {
return this.bottomLeftGrid.getScrollLeft() > 0;
}
},
_shouldHandleRightX: function (delta) {
if (delta > 0) {
return this.bottomRightGrid.getScrollLeft() < this.bottomRightGrid.getMaxScrollLeft();
} else {
return this.bottomRightGrid.getScrollLeft() > 0;
}
},
_shouldHandleY: function (delta) {
@ -58,12 +86,30 @@ BI.QuickGridTable = BI.inherit(BI.GridTable, {
}
},
_onWheelY: function (deltaX, deltaY) {
_onWheelLeft: function (deltaX, deltaY) {
var self = this;
var scrollTop = this.bottomLeftGrid.getScrollTop();
var scrollLeft = this.bottomLeftGrid.getScrollLeft();
scrollTop += deltaY;
scrollLeft += deltaX;
this.bottomLeftGrid.setScrollTop(scrollTop);
this.bottomRightGrid.setScrollTop(scrollTop);
this.topLeftGrid.setScrollLeft(scrollLeft);
this.bottomLeftGrid.setScrollLeft(scrollLeft);
self._populateScrollbar();
this.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments);
},
_onWheelRight: function (deltaX, deltaY) {
var self = this;
var scrollTop = this.bottomRightGrid.getScrollTop();
var scrollLeft = this.bottomRightGrid.getScrollLeft();
scrollTop += deltaY;
scrollLeft += deltaX;
this.bottomLeftGrid.setScrollTop(scrollTop);
this.bottomRightGrid.setScrollTop(scrollTop);
this.topRightGrid.setScrollLeft(scrollLeft);
this.bottomRightGrid.setScrollLeft(scrollLeft);
self._populateScrollbar();
this.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments);
},

23
src/core/base.js

@ -268,6 +268,29 @@ if (!window.BI) {
return true;
},
backFindKey: function (obj, predicate, context) {
predicate = BI.iteratee(predicate, context);
var keys = _.keys(obj), key;
for (var i = keys.length - 1; i >= 0; i--) {
key = keys[i];
if (predicate(obj[key], key, obj)) {
return key;
}
}
},
backFind: function (obj, predicate, context) {
var key;
if (BI.isArray(obj)) {
key = BI.findLastIndex(obj, predicate, context);
} else {
key = BI.backFindKey(obj, predicate, context);
}
if (key !== void 0 && key !== -1) {
return obj[key];
}
},
remove: function (obj, target, context) {
var isFunction = BI.isFunction(target);
target = isFunction || BI.isArray(target) ? target : [target];

259
src/core/proto/array.js

@ -6,34 +6,6 @@ $.extend(Array.prototype, {
contains: function (o) {
return this.indexOf(o) > -1;
},
/**
* 检查指定的值是否在数组中
* @param {Object} o 要检查的值
* @return {Number} o在数组中的索引如果不在数组中则返回-1
*/
indexOf: function (o) {
for (var i = 0, len = this.length; i < len; i++) {
if (_.isEqual(o, this[i])) {
return i;
}
}
return -1;
},
/**
* 检查指定的值是否在数组中
* ie67不支持数组的这个方法
* @param {Object} o 要检查的值
* @return {Number} o在数组中的索引如果不在数组中则返回-1
*/
lastIndexOf: function (o) {
for (var len = this.length, i = len - 1; i >= 0; i--) {
if (_.isEqual(o, this[i])) {
return i;
}
}
return -1;
},
/**
* 从数组中移除指定的值如果值不在数组中则不产生任何效果
@ -42,242 +14,25 @@ $.extend(Array.prototype, {
*/
remove: function (o) {
var index = this.indexOf(o);
if (index != -1) {
if (index !== -1) {
this.splice(index, 1);
}
return this;
},
/**
* 移除数组中的所有元素
*/
clear: function () {
while (this.length > 0) {
this.pop();
}
}
});
/**
* Array原型拓展
* Created by wang on 15/6/23.
*/
!function () {
Array.prototype.pushArray = function (array) {
pushArray: function (array) {
for (var i = 0; i < array.length; i++) {
this.push(array[i]);
}
};
Array.prototype.pushDistinct = function (obj) {
},
pushDistinct: function (obj) {
if (!this.contains(obj)) {
this.push(obj);
}
};
Array.prototype.pushDistinctArray = function (array) {
},
pushDistinctArray: function (array) {
for (var i = 0, len = array.length; i < len; i++) {
this.pushDistinct(array[i]);
}
};
}();
/**
* 规定bi的数组分为两种其中value和type值为key值
* 1[{"text":1,"value":2,"children":[]}]
* 2[{"name":1,"type":2,"children":[]}]
* guy
* 对数组的操作
* @type {{}}
*/
ArrayUtils = {};
$.extend(ArrayUtils, {
/**
* 遍历方法
* @param array
* @param back
*/
traversal: function (array, back) {
if (BI.isNull(array)) {
return;
}
var self = this;
BI.each(array, function (i, item) {
if (back(i, item) === BI.Status.END) {
return false;
}
self.traversal(item.children, back);
})
},
getAllChildNames: function (array) {
var names = [];
this.traversal(array, function (i, item) {
if (BI.isNotEmptyArray(item.children)) {
return BI.Status.RUNNING;
}
names.push(item.text || item.name);
});
return names;
},
/**
* 获取第一个子节点
* @param array
*/
getFirstChild: function (array) {
var first = {};
this.traversal(array, function (i, item) {
if (BI.isNotEmptyArray(item.children)) {
return;
}
first = item;
return BI.Status.END;
})
return first;
},
/**
* 获取最后一个子节点
* @param array
*/
getLastChild: function (array) {
var first = {};
this.traversal(array, function (i, item) {
if (item.children && item.children.length > 0) {
return;
}
first = item;
})
return first;
},
getTextByValue: function (array, value) {
if (!array) {
return value;
}
var text = "";
this.traversal(array, function (i, item) {
if (BI.isEqual(item.value, value)) {
text = item.text;
return BI.Status.END;
}
});
return text;
},
getNameByType: function (array, type) {
if (!array) {
return type;
}
var name = "";
this.traversal(array, function (i, item) {
if (BI.isEqual(item.type, type)) {
name = item.name;
return BI.Status.END;
}
});
return name;
},
getItemByText: function (array, text) {
var res = void 0;
this.traversal(array, function (i, item) {
if (BI.isCapitalEqual(item.text, text)) {
res = item;
return BI.Status.END;
}
});
return res;
},
getIndexByText: function (array, text) {
var res = -1;
this.traversal(array, function (i, item) {
if (BI.isCapitalEqual(item.text, text)) {
res = i;
return BI.Status.END;
}
});
return res;
},
getItemByValue: function (array, value) {
var res = void 0;
this.traversal(array, function (i, item) {
if (BI.isEqual(item.value, value)) {
res = item;
return BI.Status.END;
}
});
return res;
},
getIndexByValue: function (array, value) {
var res = -1;
this.traversal(array, function (i, item) {
if (BI.isEqual(item.value, value)) {
res = i;
return BI.Status.END;
}
});
return res;
},
getItemByName: function (array, name) {
var res = void 0;
this.traversal(array, function (i, item) {
if (BI.isCapitalEqual(item.name, name)) {
res = item;
return BI.Status.END;
}
});
return res;
},
getIndexByName: function (array, name) {
var res = -1;
this.traversal(array, function (i, item) {
if (BI.isCapitalEqual(item.name, name)) {
res = i;
return BI.Status.END;
}
});
return res;
},
getItemByType: function (array, type) {
var res = void 0;
this.traversal(array, function (i, item) {
if (BI.isEqual(item.type, type)) {
res = item;
return BI.Status.END;
}
});
return res;
},
getIndexByType: function (array, type) {
var res = -1;
this.traversal(array, function (i, item) {
if (BI.isEqual(item.type, type)) {
res = i;
return BI.Status.END;
}
});
return res;
},
deleteItemByType: function (array, type) {
var item = this.getItemByType(array, type);
array.remove(item);
},
deleteItemByName: function (array, name) {
var item = this.getItemByName(array, name);
array.remove(item);
},
deleteItemByValue: function (array, value) {
var item = this.getItemByValue(array, value);
array.remove(item);
}
});
});

20
src/core/proto/cache.js

@ -1,24 +1,4 @@
/*
* 前端缓存
*/
window.localStorage || (window.localStorage = {
items: {},
setItem: function (k, v) {
BI.Cache.addCookie(k, v);
},
getItem: function (k) {
return BI.Cache.getCookie(k);
},
removeItem: function (k) {
BI.Cache.deleteCookie(k);
},
key: function () {
},
clear: function () {
this.items = {};
}
});
BI.Cache = {
_prefix: "bi",
setUsername: function (username) {

18
src/core/proto/date.js

@ -56,7 +56,6 @@ Date._QN = ["", BI.i18nText("BI-Quarter_1"),
BI.i18nText("BI-Quarter_4")];
/** Adds the number of days array to the Date object. */
Date._MD = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
@ -91,12 +90,19 @@ Date.prototype.getDayOfYear = function () {
/** Returns the number of the week in year, as defined in ISO 8601. */
Date.prototype.getWeekNumber = function () {
var d = new Date(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0);
var DoW = d.getDay();
d.setDate(d.getDate() - (DoW + 6) % 7 + 3); // Nearest Thu
var week = d.getDay();
if (this.getMonth() === 0 && this.getDate() <= week) {
return 1;
}
d.setDate(this.getDate() - week);
var ms = d.valueOf(); // GMT
d.setMonth(0);
d.setDate(4); // Thu in Week 1
return Math.round((ms - d.valueOf()) / (7 * 864e5)) + 1;
d.setDate(1);
var offset = Math.floor((ms - d.valueOf()) / (7 * 864e5)) + 1;
if (d.getDay() > 0) {
offset++;
}
return offset;
};
//离当前时间多少天的时间
@ -188,7 +194,7 @@ Date.prototype.getOffsetMonth = function (n) {
var dt = new Date(this.getTime());
var day = dt.getDate();
var monthDay = new Date(dt.getFullYear(), dt.getMonth() + parseInt(n), 1).getMonthDays();
if(day > monthDay){
if (day > monthDay) {
day = monthDay;
}
dt.setDate(day);

31
src/polyfill/array.js

@ -0,0 +1,31 @@
if(![].indexOf){
/**
* 检查指定的值是否在数组中
* @param {Object} o 要检查的值
* @return {Number} o在数组中的索引如果不在数组中则返回-1
*/
[].indexOf = function (o) {
for (var i = 0, len = this.length; i < len; i++) {
if (_.isEqual(o, this[i])) {
return i;
}
}
return -1;
}
}
if(![].lastIndexOf){
/**
* 检查指定的值是否在数组中
* ie67不支持数组的这个方法
* @param {Object} o 要检查的值
* @return {Number} o在数组中的索引如果不在数组中则返回-1
*/
[].lastIndexOf = function (o) {
for (var len = this.length, i = len - 1; i >= 0; i--) {
if (_.isEqual(o, this[i])) {
return i;
}
}
return -1;
}
}

12
src/polyfill/console.js

@ -0,0 +1,12 @@
/**
* 特殊情况
* Created by wang on 15/6/23.
*/
//解决console未定义问题 guy
window.console = window.console || (function () {
var c = {};
c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile
= c.clear = c.exception = c.trace = c.assert = function () {
};
return c;
})();

21
src/polyfill/localStorage.js

@ -0,0 +1,21 @@
/*
* 前端缓存
*/
window.localStorage || (window.localStorage = {
items: {},
setItem: function (k, v) {
BI.Cache.addCookie(k, v);
},
getItem: function (k) {
return BI.Cache.getCookie(k);
},
removeItem: function (k) {
BI.Cache.deleteCookie(k);
},
key: function () {
},
clear: function () {
this.items = {};
}
});

14
src/core/proto/special.js → src/polyfill/sort.js

@ -1,17 +1,3 @@
/**
* 特殊情况
* Created by wang on 15/6/23.
*/
//解决console未定义问题 guy
window.console = window.console || (function () {
var c = {};
c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile
= c.clear = c.exception = c.trace = c.assert = function () {
};
return c;
})();
//修复ie9下sort方法的bug
!function (window) {
var ua = window.navigator.userAgent.toLowerCase(),
Loading…
Cancel
Save