// torque‑diagram‑common.js.txt (function(){ "use strict"; window.TorqueDiagramCommon = { draw:function(canvasCtx, resultItem){ const ctx = canvasCtx; const w = canvasCtx.canvas.width; const h = canvasCtx.canvas.height; ctx.clearRect(0,0,w,h); const marginL = 45; const marginR = 12; const marginT = 12; const marginB = 35; const chartW = w-marginL-marginR; const chartH = h-marginT-marginB; let torqueMax = 100; let curveSet = null; const isSR = resultItem.type === "SR"; if(isSR){ curveSet = window.CurveCalc.calcSrCurve( resultItem.air0, resultItem.air90, resultItem.spring0, resultItem.spring90 ); const allVals = [ resultItem.air0,resultItem.air90, resultItem.spring0,resultItem.spring90 ]; torqueMax = Math.max(...allVals) * 1.15; }else{ curveSet = window.CurveCalc.calcDaCurve(resultItem.torqueNm, resultItem.torqueNm); torqueMax = resultItem.torqueNm *1.15; } ctx.strokeStyle="#cccccc"; ctx.lineWidth=1; ctx.beginPath(); ctx.moveTo(marginL, h-marginB); ctx.lineTo(w-marginR, h-marginB); ctx.stroke(); ctx.beginPath(); ctx.moveTo(marginL, h-marginB); ctx.lineTo(marginL, marginT); ctx.stroke(); ctx.fillStyle="#333333"; ctx.font="11px sans-serif"; [0,30,60,90].forEach(function(deg){ const x = marginL + chartW * deg /90; ctx.beginPath(); ctx.moveTo(x, h-marginB); ctx.lineTo(x, h-marginB-4); ctx.stroke(); ctx.fillText(String(deg)+"°", x-8, h-marginB+14); }); if(isSR){ ctx.strokeStyle="#d62828"; ctx.lineWidth=2.2; ctx.beginPath(); curveSet.airStroke.forEach(function(pt,idx){ const x = marginL + chartW * pt.deg / 90; const y = h-marginB- (pt.torque / torqueMax)*chartH; if(idx===0) ctx.moveTo(x,y); else ctx.lineTo(x,y); }); ctx.stroke(); ctx.strokeStyle="#222222"; ctx.lineWidth=1.8; ctx.setLineDash([5,4]); ctx.beginPath(); curveSet.springStroke.forEach(function(pt,idx){ const x = marginL + chartW * pt.deg / 90; const y = h-marginB- (pt.torque / torqueMax)*chartH; if(idx===0) ctx.moveTo(x,y); else ctx.lineTo(x,y); }); ctx.stroke(); ctx.setLineDash([]); ctx.font="11px sans-serif"; ctx.fillStyle="#d62828"; ctx.fillText("Air Stroke", marginL+8, marginT+14); ctx.fillStyle="#222222"; ctx.fillText("Spring Stroke(dash)", marginL+110, marginT+14); }else{ ctx.strokeStyle="#d62828"; ctx.lineWidth=2.2; ctx.beginPath(); curveSet.forEach(function(pt,idx){ const x = marginL + chartW * pt.deg /90; const y = h-marginB- (pt.torque / torqueMax)*chartH; if(idx===0) ctx.moveTo(x,y); else ctx.lineTo(x,y); }); ctx.stroke(); } } }; })();