|
@@ -9,7 +9,7 @@ const JpcFigureOutput = {
|
|
|
let ctx = canvas.getContext('2d');
|
|
|
}
|
|
|
},
|
|
|
- _draw: function(ctx, figure, saveAsData = false) {
|
|
|
+ _draw: function(ctx, figure, saveAsData = false, pageIdx = 1) {
|
|
|
if (figure.imageData) {
|
|
|
//直接图形输出
|
|
|
ctx.putImageData(figure.imageData, figure.area.Left + this.offsetX, figure.area.Top + this.offsetY);
|
|
@@ -46,6 +46,10 @@ const JpcFigureOutput = {
|
|
|
const content = figure.contents[ctIdx];
|
|
|
ctx.beginPath();
|
|
|
let firstDraw = true;
|
|
|
+ if (pageIdx === 1 && figure.config.adhocStartPoint) {
|
|
|
+ ctx.moveTo(figure.area.Left + this.offsetX, figure.area.Bottom + this.offsetY);
|
|
|
+ firstDraw = false;
|
|
|
+ }
|
|
|
for (let idx = 0; idx < content.values.length; idx++) {
|
|
|
if (content.values[idx] !== null && content.values[idx] !== undefined) {
|
|
|
let xPos = figure.area.Left + xStepW * idx + xStepW / 2 + this.offsetX;
|
|
@@ -82,18 +86,18 @@ const JpcFigureOutput = {
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
- drawToCanvas: function(canvas, currentPageData) {
|
|
|
+ drawToCanvas: function(canvas, currentPageData, pageIdx = 1) {
|
|
|
//预览用
|
|
|
if (canvas && currentPageData) {
|
|
|
const ctx = canvas.getContext("2d");
|
|
|
if (currentPageData.figure_cells && currentPageData.figure_cells.length > 0) {
|
|
|
for (let figure of currentPageData.figure_cells) {
|
|
|
- this._draw(ctx, figure, false);
|
|
|
+ this._draw(ctx, figure, false, pageIdx);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
- _drawPdf: function(doc, figure) {
|
|
|
+ _drawPdf: function(doc, figure, pageIdx = 1) {
|
|
|
const PDF_SCALE = 0.75;
|
|
|
if (figure.imageData) {
|
|
|
//直接图形输出
|
|
@@ -127,44 +131,51 @@ const JpcFigureOutput = {
|
|
|
for (let ctIdx = 0; ctIdx < figure.contents.length; ctIdx++) {
|
|
|
const content = figure.contents[ctIdx];
|
|
|
let preXPos = 0, preYPos = 0;
|
|
|
+ let firstDraw = true;
|
|
|
for (let idx = 0; idx < content.values.length; idx++) {
|
|
|
- let xPos = figure.area.Left + xStepW * idx + xStepW / 2 + this.offsetX;
|
|
|
- let yPos = figure.area.Bottom - (content.values[idx] / content.maxValue) * height + this.offsetY;
|
|
|
- doc.setLineWidth(0.8);
|
|
|
- doc.setDrawColor(content.color);
|
|
|
- if (content.style === 'dash') doc.setLineDash([10, 5]);
|
|
|
- switch (figure.config.dispType) {
|
|
|
- case 'line':
|
|
|
- //折线图
|
|
|
- if (idx > 0) {
|
|
|
- // ctx.lineTo(xPos, yPos);
|
|
|
- doc.line(preXPos * PDF_SCALE, preYPos * PDF_SCALE, xPos * PDF_SCALE, yPos * PDF_SCALE);
|
|
|
- }
|
|
|
- preXPos = xPos;
|
|
|
- preYPos = yPos;
|
|
|
- break;
|
|
|
- case 'pole':
|
|
|
- //柱图
|
|
|
- break;
|
|
|
- default:
|
|
|
- //....
|
|
|
- break;
|
|
|
- }
|
|
|
+ if (content.values[idx] !== null && content.values[idx] !== undefined) {
|
|
|
+ let xPos = figure.area.Left + xStepW * idx + xStepW / 2 + this.offsetX;
|
|
|
+ let yPos = figure.area.Bottom - (content.values[idx] / content.maxValue) * height + this.offsetY;
|
|
|
+ doc.setLineWidth(0.8);
|
|
|
+ doc.setDrawColor(content.color);
|
|
|
+ if (content.style === 'dash') doc.setLineDash([10, 5]);
|
|
|
+ switch (figure.config.dispType) {
|
|
|
+ case 'line':
|
|
|
+ //折线图
|
|
|
+ if (!firstDraw) {
|
|
|
+ // ctx.lineTo(xPos, yPos);
|
|
|
+ doc.line(preXPos * PDF_SCALE, preYPos * PDF_SCALE, xPos * PDF_SCALE, yPos * PDF_SCALE);
|
|
|
+ } else if (pageIdx === 1 && figure.config.adhocStartPoint) {
|
|
|
+ doc.line((figure.area.Left + this.offsetX) * PDF_SCALE, (figure.area.Bottom + this.offsetY) * PDF_SCALE,
|
|
|
+ xPos * PDF_SCALE, yPos * PDF_SCALE);
|
|
|
+ }
|
|
|
+ preXPos = xPos;
|
|
|
+ preYPos = yPos;
|
|
|
+ firstDraw = false;
|
|
|
+ break;
|
|
|
+ case 'pole':
|
|
|
+ //柱图
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ //....
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
- drawToPdf: function(doc, currentPageData) {
|
|
|
+ drawToPdf: function(doc, currentPageData, pageIdx = 1) {
|
|
|
//导出PDF用
|
|
|
if (doc && currentPageData) {
|
|
|
if (currentPageData.figure_cells && currentPageData.figure_cells.length > 0) {
|
|
|
for (let figure of currentPageData.figure_cells) {
|
|
|
- this._drawPdf(doc, figure);
|
|
|
+ this._drawPdf(doc, figure, pageIdx);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
- _drawSvg: function(figure, isHtoV, actArea) {
|
|
|
+ _drawSvg: function(figure, isHtoV, actArea, pageIdx = 1) {
|
|
|
let rst = [];
|
|
|
if (figure.imageData) {
|
|
|
//直接图形输出
|
|
@@ -175,6 +186,11 @@ const JpcFigureOutput = {
|
|
|
let ySteps = figure.coordinateAxis.axisY.steps;
|
|
|
let xStepW = width / xSteps;
|
|
|
let yStepH = height / ySteps;
|
|
|
+ let HtoVStr = "";
|
|
|
+ if (isHtoV) {
|
|
|
+ //引用了padding后,top坐标不用考虑offset了
|
|
|
+ HtoVStr = ` transform="translate(${(actArea.Bottom - actArea.Top + 2)},0) rotate(90)"`;
|
|
|
+ }
|
|
|
if (figure.coordinateAxis.axisX.isShowLine) {
|
|
|
//画竖线
|
|
|
for (let idx = 0; idx < xSteps; idx++) {
|
|
@@ -191,11 +207,6 @@ const JpcFigureOutput = {
|
|
|
"' style='stroke:rgb(0,0,0);stroke-width:1'" + HtoVStr + "/>")
|
|
|
}
|
|
|
}
|
|
|
- let HtoVStr = "";
|
|
|
- if (isHtoV) {
|
|
|
- //引用了padding后,top坐标不用考虑offset了
|
|
|
- HtoVStr = ` transform="translate(${(actArea.Bottom - actArea.Top + 2)},0) rotate(90)"`;
|
|
|
- }
|
|
|
for (let ctIdx = 0; ctIdx < figure.contents.length; ctIdx++) {
|
|
|
const content = figure.contents[ctIdx];
|
|
|
let pointStr = '';
|
|
@@ -203,38 +214,43 @@ const JpcFigureOutput = {
|
|
|
// ctx.strokeStyle = content.color;
|
|
|
if (content.style === 'dash') stroke_dasharray = `10 5`;
|
|
|
for (let idx = 0; idx < content.values.length; idx++) {
|
|
|
- let xPos = figure.area.Left + xStepW * idx + xStepW / 2 + this.offsetX;
|
|
|
- let yPos = figure.area.Bottom - (content.values[idx] / content.maxValue) * height + this.offsetY;
|
|
|
- if (idx > 0) pointStr = pointStr + ',';
|
|
|
- pointStr = pointStr + `${xPos},${yPos}`;
|
|
|
- switch (figure.config.dispType) {
|
|
|
- case 'line':
|
|
|
- //折线图
|
|
|
- if (idx === content.values.length - 1) {
|
|
|
- // ctx.moveTo(xPos, yPos);
|
|
|
- rst.push("<polyline points='" + pointStr +
|
|
|
- "' style='fill:none;stroke:" + content.color + ";stroke-width:1;stroke-dasharray:" + stroke_dasharray + "'" + HtoVStr + "/>")
|
|
|
- }
|
|
|
- break;
|
|
|
- case 'pole':
|
|
|
- //柱图
|
|
|
- break;
|
|
|
- default:
|
|
|
- //....
|
|
|
- break;
|
|
|
- }
|
|
|
+ if (content.values[idx] !== null && content.values[idx] !== undefined) {
|
|
|
+ let xPos = figure.area.Left + xStepW * idx + xStepW / 2 + this.offsetX;
|
|
|
+ let yPos = figure.area.Bottom - (content.values[idx] / content.maxValue) * height + this.offsetY;
|
|
|
+ if (idx > 0) pointStr = pointStr + ',';
|
|
|
+ pointStr = pointStr + `${xPos},${yPos}`;
|
|
|
+ switch (figure.config.dispType) {
|
|
|
+ case 'line':
|
|
|
+ //折线图
|
|
|
+ if (idx === content.values.length - 1) {
|
|
|
+ if (pageIdx === 1 && figure.config.adhocStartPoint) {
|
|
|
+ pointStr = `${figure.area.Left + this.offsetX},${figure.area.Bottom + this.offsetY},` + pointStr;
|
|
|
+ }
|
|
|
+ // ctx.moveTo(xPos, yPos);
|
|
|
+ rst.push("<polyline points='" + pointStr +
|
|
|
+ "' style='fill:none;stroke:" + content.color + ";stroke-width:1;stroke-dasharray:" + stroke_dasharray + "'" + HtoVStr + "/>")
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 'pole':
|
|
|
+ //柱图
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ //....
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return rst;
|
|
|
},
|
|
|
- toSvgData: function(currentPageData, isHtoV, actArea) {
|
|
|
+ toSvgData: function(currentPageData, isHtoV, actArea, pageIdx = 1) {
|
|
|
//打印用
|
|
|
let rst = [];
|
|
|
if (currentPageData) {
|
|
|
if (currentPageData.figure_cells && currentPageData.figure_cells.length > 0) {
|
|
|
for (let figure of currentPageData.figure_cells) {
|
|
|
- rst = rst.concat(this._drawSvg(figure, isHtoV, actArea));
|
|
|
+ rst = rst.concat(this._drawSvg(figure, isHtoV, actArea, pageIdx));
|
|
|
}
|
|
|
}
|
|
|
}
|