Gozintograph: Unterschied zwischen den Versionen

Keine Bearbeitungszusammenfassung
 
(Eine dazwischenliegende Version desselben Benutzers wird nicht angezeigt)
Zeile 433: Zeile 433:
Die Pfeile im Gozintographen geben an, wie viele Mengeneinheiten eines Materials zur Produktion einer Mengeneinheit des entstehenden Produkts benötigt werden.
Die Pfeile im Gozintographen geben an, wie viele Mengeneinheiten eines Materials zur Produktion einer Mengeneinheit des entstehenden Produkts benötigt werden.


<!-- GOZINTOGRAPH: Rohstoffe → Zwischenprodukte → Endprodukte -->
<html>
<html>
<style>
<style>
Zeile 451: Zeile 452:
     user-select:none;
     user-select:none;
     background:white;
     background:white;
  }
  .node-rect {
    fill:#3498db;
    stroke:#1f4e78;
    stroke-width:2;
    cursor:grab;
  }
  .node-text,
  .count-text {
    font-family:sans-serif;
    font-size:14px;
    fill:#000;
    pointer-events:none;
  }
  .edge-line {
    stroke:#000;
    stroke-width:2;
    fill:none;
  }
  .edge-arrow {
    fill:#000;
  }
  .count-circle {
    fill:#fff;
    stroke:#000;
    stroke-width:1.5;
   }
   }
</style>
</style>
Zeile 456: Zeile 488:
<div class="gozinto-wrap2">
<div class="gozinto-wrap2">
<svg id="gozinto_svg"
<svg id="gozinto_svg"
     viewBox="0 0 1180 700"
     viewBox="0 0 1180 640"
     preserveAspectRatio="xMinYMin meet">
     preserveAspectRatio="xMinYMin meet">
</svg>
</svg>
Zeile 464: Zeile 496:
(function(){
(function(){


const svg=document.getElementById("gozinto_svg");
  const svg = document.getElementById("gozinto_svg");
 
  const scale = 100;
  const yOffset = 0;
  const xOffsetGlobal = 120;
 
  function svgEl(name, attrs){
    const el = document.createElementNS("http://www.w3.org/2000/svg", name);
 
    for(const k in (attrs||{}))
      el.setAttribute(k, attrs[k]);
 
    return el;
  }
 
  function getSVGcoords(evt){
    const pt = svg.createSVGPoint();
 
    pt.x = evt.clientX;
    pt.y = evt.clientY;
 
    return pt.matrixTransform(svg.getScreenCTM().inverse());
  }
 
  // -------------------------------------------------
  // NODE
  // -------------------------------------------------
 
  function createNode(id, cx, cy, w, h, label){
 
    cx += xOffsetGlobal / scale;
 
    const g = svgEl("g", {"data-id":id});
 
    const rect = svgEl("rect", {
      class:"node-rect",
      x:(cx-w/2)*scale,
      y:(cy-h/2)*scale + yOffset,
      width:w*scale,
      height:h*scale,
      rx:6,
      ry:6
    });
 
    const text = svgEl("text", {
      class:"node-text",
      x:cx*scale,
      y:cy*scale+yOffset,
      "text-anchor":"middle",
      "dominant-baseline":"middle"
    });
 
    text.textContent = label;
 
    g.appendChild(rect);
    g.appendChild(text);
 
    svg.appendChild(g);
 
    const node = {id,cx,cy,w,h,rect,text,g};
 
    // Dragging
 
    let dragging=false,start={};
 
    rect.addEventListener("pointerdown", e=>{
 
      rect.setPointerCapture(e.pointerId);
 
      dragging=true;
 
      const p=getSVGcoords(e);
 
      start={
        px:p.x,
        py:p.y,
        cx:node.cx,
        cy:node.cy
      };
    });


const scale=100;
    rect.addEventListener("pointermove", e=>{
const yOffset=0;
const xOffsetGlobal=120;


function svgEl(name,attrs){
      if(!dragging) return;
  const el=document.createElementNS("http://www.w3.org/2000/svg",name);
  for(const k in (attrs||{})) el.setAttribute(k,attrs[k]);
  return el;
}


function createNode(id,cx,cy,w,h,label){
      const p=getSVGcoords(e);


  cx+=xOffsetGlobal/scale;
      node.cx=start.cx+(p.x-start.px)/scale;
      node.cy=start.cy+(p.y-start.py)/scale;


  const g=svgEl("g",{});
      updateNode(node);
      updateAllEdges();
    });


  const rect=svgEl("rect",{
    rect.addEventListener("pointerup", e=>{
    class:"node-rect",
    x:(cx-w/2)*scale,
    y:(cy-h/2)*scale,
    width:w*scale,
    height:h*scale,
    rx:6,
    ry:6
  });


  const text=svgEl("text",{
      dragging=false;
    class:"node-text",
    x:cx*scale,
    y:cy*scale,
    "text-anchor":"middle",
    "dominant-baseline":"middle"
  });


  text.textContent=label;
      rect.releasePointerCapture(e.pointerId);
    });


  g.appendChild(rect);
    return node;
   g.appendChild(text);
   }


   svg.appendChild(g);
   function updateNode(n){


  return {cx,cy,w,h};
    n.rect.setAttribute("x",(n.cx-n.w/2)*scale);
}
    n.rect.setAttribute("y",(n.cy-n.h/2)*scale+yOffset);


function drawArrow(x1,y1,x2,y2,label){
    n.text.setAttribute("x",n.cx*scale);
    n.text.setAttribute("y",n.cy*scale+yOffset);
  }


   const line=svgEl("line",{
   // -------------------------------------------------
    x1,y1,x2,y2,
  // GEOMETRIE
    stroke:"black",
  // -------------------------------------------------
    "stroke-width":"2"
  });


   svg.appendChild(line);
   function intersectRectBorder(node, tx, ty){


  const text=svgEl("text",{
    const cx=node.cx;
     x:(x1+x2)/2,
     const cy=node.cy;
    y:(y1+y2)/2-10,
    class:"count-text",
    "text-anchor":"middle"
  });


  text.textContent=label;
    const w2=node.w/2;
    const h2=node.h/2;


  svg.appendChild(text);
    const dx=tx-cx;
}
    const dy=ty-cy;


const R1=createNode("R1",0,1,1,0.5,"R1");
    let pts=[];
const R2=createNode("R2",2.5,1,1,0.5,"R2");
const R3=createNode("R3",5,1,1,0.5,"R3");


const Z1=createNode("Z1",1.2,3.5,1,0.5,"Z1");
    if(Math.abs(dx)>1e-9){
const Z2=createNode("Z2",3.8,3.5,1,0.5,"Z2");


const E1=createNode("E1",0.5,6,1,0.5,"E1");
      let t1=(-w2)/dx;
const E2=createNode("E2",2.8,6,1,0.5,"E2");
      let y1=cy+t1*dy;
const E3=createNode("E3",5.1,6,1,0.5,"E3");


drawArrow(170,120,240,320,"3");
      if(t1>0 && y1>=cy-h2 && y1<=cy+h2)
drawArrow(420,120,240,320,"4");
        pts.push({x:cx-w2,y:y1,t:t1});


drawArrow(170,120,500,320,"1");
      let t2=(w2)/dx;
drawArrow(420,120,500,320,"2");
      let y2=cy+t2*dy;
drawArrow(670,120,500,320,"3");


drawArrow(240,370,170,570,"2");
      if(t2>0 && y2>=cy-h2 && y2<=cy+h2)
drawArrow(240,370,420,570,"1");
        pts.push({x:cx+w2,y:y2,t:t2});
    }


drawArrow(500,370,170,570,"1");
    if(Math.abs(dy)>1e-9){
drawArrow(500,370,420,570,"3");
 
drawArrow(500,370,670,570,"2");
      let t3=(-h2)/dy;
      let x3=cx+t3*dx;
 
      if(t3>0 && x3>=cx-w2 && x3<=cx+w2)
        pts.push({x:x3,y:cy-h2,t:t3});
 
      let t4=(h2)/dy;
      let x4=cx+t4*dx;
 
      if(t4>0 && x4>=cx-w2 && x4<=cx+w2)
        pts.push({x:x4,y:cy+h2,t:t4});
    }
 
    pts.sort((a,b)=>a.t-b.t);
 
    return pts[0] || {x:cx,y:cy};
  }
 
  function pointOnCircle(cx,cy,R,tx,ty){
 
    const dx=tx-cx;
    const dy=ty-cy;
 
    const d=Math.sqrt(dx*dx+dy*dy);
 
    if(d<1e-9) return {x:cx,y:cy};
 
    return {
      x:cx+R*dx/d,
      y:cy+R*dy/d
    };
  }
 
  function makeArrowHead(x,y,ux,uy,size){
 
    let px=-uy;
    let py=ux;
 
    return `M ${x} ${y}
            L ${x-ux*size+px*size*0.5} ${y-uy*size+py*size*0.5}
            L ${x-ux*size-px*size*0.5} ${y-uy*size-py*size*0.5} Z`;
  }
 
  // -------------------------------------------------
  // KANTEN
  // -------------------------------------------------
 
  const edges=[];
 
  function makeConnection(fromNode,toNode,amount,yMid,xOffset){
 
    const g=svgEl("g",{});
 
    const lineA=svgEl("path",{class:"edge-line"});
    const lineB=svgEl("path",{class:"edge-line"});
 
    const circle=svgEl("circle",{
      class:"count-circle"
    });
 
    const text=svgEl("text",{
      class:"count-text"
    });
 
    const arrow=svgEl("path",{
      class:"edge-arrow"
    });
 
    text.textContent=amount;
 
    g.appendChild(lineA);
    g.appendChild(lineB);
    g.appendChild(circle);
    g.appendChild(text);
    g.appendChild(arrow);
 
    svg.appendChild(g);
 
    let e={
      fromNode,
      toNode,
      amount,
      yMid,
      xOffset,
      circle,
      text,
      lineA,
      lineB,
      arrow
    };
 
    edges.push(e);
 
    updateEdge(e);
  }
 
  function updateEdge(e){
 
    const cx=(e.fromNode.cx+e.toNode.cx)/2+(e.xOffset||0);
    const cy=e.yMid;
 
    const R=0.14;
 
    const pF=intersectRectBorder(e.fromNode,cx,cy);
    const pT=intersectRectBorder(e.toNode,cx,cy);
 
    const pCircleIn=pointOnCircle(cx,cy,R,pF.x,pF.y);
    const pCircleOut=pointOnCircle(cx,cy,R,pT.x,pT.y);
 
    const px=p=>[p.x*scale,p.y*scale+yOffset];
 
    const F=px(pF);
    const Ci=px(pCircleIn);
    const Co=px(pCircleOut);
    const T=px(pT);
 
    e.lineA.setAttribute(
      "d",
      `M ${F[0]} ${F[1]} L ${Ci[0]} ${Ci[1]}`
    );
 
    e.lineB.setAttribute(
      "d",
      `M ${Co[0]} ${Co[1]} L ${T[0]} ${T[1]}`
    );
 
    e.circle.setAttribute("cx",cx*scale);
    e.circle.setAttribute("cy",cy*scale+yOffset);
    e.circle.setAttribute("r",R*scale);
 
    e.text.setAttribute("x",cx*scale-5);
    e.text.setAttribute("y",cy*scale+yOffset+5);
 
    let ux=T[0]-Co[0];
    let uy=T[1]-Co[1];
 
    let L=Math.sqrt(ux*ux+uy*uy);
 
    if(L<1e-6) L=1;
 
    ux/=L;
    uy/=L;
 
    e.arrow.setAttribute(
      "d",
      makeArrowHead(T[0],T[1],ux,uy,10)
    );
  }
 
  function updateAllEdges(){
    edges.forEach(updateEdge);
  }
 
  // -------------------------------------------------
  // NODES
  // -------------------------------------------------
 
  const nodes={};
 
  // Rohstoffe
 
  nodes.R1=createNode("R1",0,0.8,1.0,0.5,"R1");
  nodes.R2=createNode("R2",2.5,0.8,1.0,0.5,"R2");
  nodes.R3=createNode("R3",5.0,0.8,1.0,0.5,"R3");
 
  // Zwischenprodukte
 
  nodes.Z1=createNode("Z1",1.2,3.2,1.0,0.5,"Z1");
  nodes.Z2=createNode("Z2",3.6,3.2,1.0,0.5,"Z2");
 
  // Endprodukte
 
  nodes.E1=createNode("E1",0.5,5.6,1.0,0.5,"E1");
  nodes.E2=createNode("E2",2.8,5.6,1.0,0.5,"E2");
  nodes.E3=createNode("E3",5.1,5.6,1.0,0.5,"E3");
 
  // -------------------------------------------------
  // VERBINDUNGEN
  // -------------------------------------------------
 
  // Rohstoffe -> Zwischenprodukte
 
  makeConnection(nodes.R1,nodes.Z1,"3",1.8,-0.3);
  makeConnection(nodes.R1,nodes.Z2,"1",1.8,0.4);
 
  makeConnection(nodes.R2,nodes.Z1,"4",1.8,-0.2);
  makeConnection(nodes.R2,nodes.Z2,"2",1.8,0.2);
 
  makeConnection(nodes.R3,nodes.Z2,"3",1.8,0.0);
 
  // Zwischenprodukte -> Endprodukte
 
  makeConnection(nodes.Z1,nodes.E1,"2",4.4,-0.2);
  makeConnection(nodes.Z1,nodes.E2,"1",4.4,0.2);
 
  makeConnection(nodes.Z2,nodes.E1,"1",4.4,-0.3);
  makeConnection(nodes.Z2,nodes.E2,"3",4.4,0.0);
  makeConnection(nodes.Z2,nodes.E3,"2",4.4,0.3);
 
  updateAllEdges();


})();
})();
</script>
</script>
</html>
</html>
Die vollständigen Mengen seien wie folgt definiert:
Die vollständigen Mengen seien wie folgt definiert: