|
@@ -2539,6 +2539,7 @@ const SpreadJsObj = {
|
|
|
const stackedBarCellType = function(){};
|
|
|
stackedBarCellType.prototype = new spreadNS.CellTypes.Text();
|
|
|
const indent = 3, defaultR = 0.05, minHeight = 2;
|
|
|
+ const tipsMaxHintWidth = 200, tipsIndent = 15, tipsBorderIndent = 10;
|
|
|
/**
|
|
|
* 画一个长条
|
|
|
* @param {Object} canvas - 画布
|
|
@@ -2608,6 +2609,95 @@ const SpreadJsObj = {
|
|
|
drawBarbefore99(canvas, left, top, width, height, ZhCalc.mul(height, defaultR, 2), bd.color);
|
|
|
}
|
|
|
};
|
|
|
+
|
|
|
+ proto.getTextDisplayWidth = function(hitinfo, str, font) {
|
|
|
+ const xs = hitinfo.sheet.getParent().xs;
|
|
|
+ const ctx = xs.childNodes[0].getContext("2d");
|
|
|
+ if (font && font !== '') {
|
|
|
+ ctx.font = font;
|
|
|
+ } else {
|
|
|
+ ctx.font = hitinfo.cellStyle.font;
|
|
|
+ }
|
|
|
+ return ctx.measureText(str).width;
|
|
|
+ };
|
|
|
+ proto.showTip = function (hitinfo, text) {
|
|
|
+ return text && text !== '';
|
|
|
+ };
|
|
|
+ /**
|
|
|
+ * 获取点击信息
|
|
|
+ * @param {Number} x
|
|
|
+ * @param {Number} y
|
|
|
+ * @param {Object} cellStyle
|
|
|
+ * @param {Object} cellRect
|
|
|
+ * @param {Object} context
|
|
|
+ * @returns {{x: *, y: *, row: *, col: *|boolean|*[]|number|{}|UE.dom.dtd.col, cellStyle: *, cellRect: *, sheet: *|StyleSheet, sheetArea: *}}
|
|
|
+ */
|
|
|
+ proto.getHitInfo = function (x, y, cellStyle, cellRect, context) {
|
|
|
+ return {
|
|
|
+ x: x,
|
|
|
+ y: y,
|
|
|
+ row: context.row,
|
|
|
+ col: context.col,
|
|
|
+ cellStyle: cellStyle,
|
|
|
+ cellRect: cellRect,
|
|
|
+ sheet: context.sheet,
|
|
|
+ sheetArea: context.sheetArea,
|
|
|
+ ctx: context.sheet.getParent().xs,
|
|
|
+ };
|
|
|
+ };
|
|
|
+ /**
|
|
|
+ * 鼠标进入单元格事件 - 显示悬浮提示
|
|
|
+ * @param {Object} hitinfo - 见getHitInfo返回值
|
|
|
+ */
|
|
|
+ proto.processMouseEnter = function (hitinfo) {
|
|
|
+ let text = hitinfo.sheet.getText(hitinfo.row, hitinfo.col);
|
|
|
+ const col = hitinfo.sheet.zh_setting.cols[hitinfo.col];
|
|
|
+ if (col.getTip && Object.prototype.toString.apply(col.getTip) === "[object Function]") {
|
|
|
+ const sortData = SpreadJsObj.getSortData(hitinfo.sheet);
|
|
|
+ text = col.getTip(sortData[hitinfo.row]);
|
|
|
+ }
|
|
|
+ const pos = SpreadJsObj.getObjPos(hitinfo.sheet.getParent().qo);
|
|
|
+ if (pos && this.showTip(hitinfo, text)) {
|
|
|
+ if (!this._toolTipElement) {
|
|
|
+ let div = $('#autoTip')[0];
|
|
|
+ if (!div) {
|
|
|
+ div = document.createElement("div");
|
|
|
+ $(div).css("position", "absolute")
|
|
|
+ .css("border", "1px #C0C0C0 solid")
|
|
|
+ .css("box-shadow", "1px 2px 5px rgba(0,0,0,0.4)")
|
|
|
+ .css("font", "9pt Arial")
|
|
|
+ .css("background", "white")
|
|
|
+ .css("padding", 5)
|
|
|
+ .css("z-index", 999)
|
|
|
+ .css("max-width", tipsMaxHintWidth)
|
|
|
+ .css("word-wrap", "break-word")
|
|
|
+ .attr("id", 'autoTip');
|
|
|
+ document.body.insertBefore(div, null);
|
|
|
+ }
|
|
|
+ const validWidth = $(window).width() - (pos.x + hitinfo.x + tipsIndent) - tipsBorderIndent;
|
|
|
+ const textWidth = this.getTextDisplayWidth(hitinfo, text, "9pt Arial");
|
|
|
+ if (validWidth >= tipsMaxHintWidth || textWidth <= validWidth) {
|
|
|
+ $(div).html(text).css("top", pos.y + hitinfo.y + tipsIndent).css("left", pos.x + hitinfo.x + tipsIndent);
|
|
|
+ } else if (textWidth > tipsMaxHintWidth) {
|
|
|
+ $(div).html(text).css("top", pos.y + hitinfo.y + tipsIndent).css("left", pos.x + hitinfo.x - tipsIndent - tipsMaxHintWidth);
|
|
|
+ } else {
|
|
|
+ $(div).html(text).css("top", pos.y + hitinfo.y + tipsIndent).css("left", pos.x + hitinfo.x - tipsIndent - textWidth);
|
|
|
+ }
|
|
|
+ this._toolTipElement = div;
|
|
|
+ $(div).show("fast");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ /**
|
|
|
+ * 鼠标移出单元格事件 - 隐藏悬浮提示
|
|
|
+ * @param {Object} hitinfo - 见getHitInfo返回值
|
|
|
+ */
|
|
|
+ proto.processMouseLeave = function (hitinfo) {
|
|
|
+ if (this._toolTipElement) {
|
|
|
+ $(this._toolTipElement).hide();
|
|
|
+ this._toolTipElement = null;
|
|
|
+ }
|
|
|
+ };
|
|
|
return new stackedBarCellType();
|
|
|
},
|
|
|
},
|