import * as React from "react"; import {ReportItemDesigner} from "./ReportItemDesigner"; import {RectF, SizeF, PointF} from "../../drawing/Unit"; import {autobind} from "core-decorators"; import {KonvaMapping} from "../../drawing/KonvaMapping"; import {LineObjectPool} from "../../drawing/KonvaObjectPools"; import {LineShape} from "../../items/LineShape"; import {LineDirection} from "../../configs/enums"; const adjustPoint = function(pos:number, lineWidth:number):number { return lineWidth === 1 ? Math.floor(pos) + 0.5 : Math.floor(pos); }; export default class LineShapeDesigner extends ReportItemDesigner { private get shapeItem():LineShape { return this.item as LineShape; } private getPoints(bounds:RectF):Array { const points:Array = []; const lineWidth = this.shapeItem.style.strokeWidth.value; switch (this.shapeItem.direction) { case LineDirection.NS: points.push(bounds.center.x, bounds.top); points.push(bounds.center.x, bounds.bottom); break; case LineDirection.EW: points.push(bounds.left, bounds.center.y); points.push(bounds.right, bounds.center.y); break; case LineDirection.NESW: points.push(bounds.left, bounds.bottom); points.push(bounds.right, bounds.top); break; case LineDirection.NWSE: points.push(bounds.left, bounds.top); points.push(bounds.right, bounds.bottom); break; } return points.map(pos => adjustPoint(pos, lineWidth)); } render(bounds: RectF): any { const props = { points:this.getPoints(bounds), stroke: this.shapeItem.style.strokeColor, strokeWidth: this.shapeItem.style.strokeWidth.value, lineJoin: 'round', dash: KonvaMapping.getLineStyleValue(this.shapeItem.style.strokeStyle) }; return LineObjectPool.get(props); } }