@yrest/cli 0.11.0 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/assets/svg/0..1.svg +3 -0
- package/assets/svg/0..n.svg +3 -0
- package/assets/svg/1..1.svg +3 -0
- package/assets/svg/1..n.svg +3 -0
- package/assets/svg/n.svg +3 -0
- package/dist/cli/index.js +141 -67
- package/dist/cli/index.mjs +141 -67
- package/dist/index.js +141 -67
- package/dist/index.mjs +141 -67
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -833,9 +833,15 @@ function generateERData(storage) {
|
|
|
833
833
|
const relations = storage.getRelations();
|
|
834
834
|
const schema = storage.getSchema();
|
|
835
835
|
const pivotTables = /* @__PURE__ */ new Set();
|
|
836
|
+
const pivotFKs = /* @__PURE__ */ new Map();
|
|
836
837
|
for (const fields of Object.values(relations)) {
|
|
837
838
|
for (const def of Object.values(fields)) {
|
|
838
|
-
if (def.type === "many2many")
|
|
839
|
+
if (def.type === "many2many") {
|
|
840
|
+
pivotTables.add(def.through);
|
|
841
|
+
if (!pivotFKs.has(def.through)) pivotFKs.set(def.through, /* @__PURE__ */ new Set());
|
|
842
|
+
pivotFKs.get(def.through).add(def.foreignKey);
|
|
843
|
+
pivotFKs.get(def.through).add(def.otherKey);
|
|
844
|
+
}
|
|
839
845
|
}
|
|
840
846
|
}
|
|
841
847
|
const fkFields = /* @__PURE__ */ new Map();
|
|
@@ -871,6 +877,9 @@ function generateERData(storage) {
|
|
|
871
877
|
for (const [source, fields] of Object.entries(relations)) {
|
|
872
878
|
for (const [key, def] of Object.entries(fields)) {
|
|
873
879
|
if (def.type === "many2many") {
|
|
880
|
+
const throughRels = relations[def.through] ?? {};
|
|
881
|
+
const fkRel = throughRels[def.foreignKey];
|
|
882
|
+
const otherRel = throughRels[def.otherKey];
|
|
874
883
|
erRelations.push({
|
|
875
884
|
source,
|
|
876
885
|
target: def.target,
|
|
@@ -878,9 +887,14 @@ function generateERData(storage) {
|
|
|
878
887
|
label: def.through,
|
|
879
888
|
through: def.through,
|
|
880
889
|
foreignKey: def.foreignKey,
|
|
881
|
-
otherKey: def.otherKey
|
|
890
|
+
otherKey: def.otherKey,
|
|
891
|
+
fkCarDirect: fkRel?.carDirect,
|
|
892
|
+
fkCarInverse: fkRel?.carInverse,
|
|
893
|
+
otherCarDirect: otherRel?.carDirect,
|
|
894
|
+
otherCarInverse: otherRel?.carInverse
|
|
882
895
|
});
|
|
883
896
|
} else {
|
|
897
|
+
if (pivotFKs.get(source)?.has(key)) continue;
|
|
884
898
|
erRelations.push({
|
|
885
899
|
source,
|
|
886
900
|
target: def.target,
|
|
@@ -907,7 +921,15 @@ function erDiagramSection(data) {
|
|
|
907
921
|
|
|
908
922
|
<div class="card" style="padding:0;overflow:hidden;position:relative;">
|
|
909
923
|
<canvas id="er-canvas" style="width:100%;display:block;cursor:grab;"></canvas>
|
|
910
|
-
<
|
|
924
|
+
<div style="position:absolute;top:10px;right:14px;display:flex;gap:6px;align-items:center;">
|
|
925
|
+
<select id="er-scale" title="Download quality" style="background:#161b22;border:1px solid #30363d;color:#7d8590;padding:3px 6px;border-radius:6px;font-size:11px;cursor:pointer;">
|
|
926
|
+
<option value="1">1\xD7</option>
|
|
927
|
+
<option value="2">2\xD7</option>
|
|
928
|
+
<option value="3" selected>3\xD7</option>
|
|
929
|
+
<option value="4">4\xD7</option>
|
|
930
|
+
</select>
|
|
931
|
+
<button id="er-dl" title="Download PNG" style="background:#161b22;border:1px solid #30363d;color:#7d8590;padding:4px 10px;border-radius:6px;font-size:11px;cursor:pointer;line-height:1.4;">\u2193 PNG</button>
|
|
932
|
+
</div>
|
|
911
933
|
</div>
|
|
912
934
|
|
|
913
935
|
<script>${/*js*/
|
|
@@ -917,7 +939,7 @@ function erDiagramSection(data) {
|
|
|
917
939
|
var D=${json};
|
|
918
940
|
|
|
919
941
|
// \u2500\u2500 Constants \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
920
|
-
var NW=178,HH=34,FH=22,FP=10,ROW_GAP=44,COL_GAP=100,BR=
|
|
942
|
+
var NW=178,HH=34,FH=22,FP=10,ROW_GAP=44,COL_GAP=100,BR=12,BO=16,LGH=84,MIN_GAP=10;
|
|
921
943
|
|
|
922
944
|
var C={bg:'#0d1117',nb:'#161b22',nh:'#1c2128',pb:'#0d1117',ph:'#161b22',
|
|
923
945
|
bo:'#30363d',bs:'#58a6ff',tx:'#e6edf3',mu:'#7d8590',
|
|
@@ -957,6 +979,30 @@ function erDiagramSection(data) {
|
|
|
957
979
|
}
|
|
958
980
|
});
|
|
959
981
|
|
|
982
|
+
// \u2500\u2500 Dynamic node width \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
983
|
+
function computeNodeWidths(){
|
|
984
|
+
nodes.forEach(function(n){
|
|
985
|
+
var e=n.e;
|
|
986
|
+
ctx.font='600 12px -apple-system,BlinkMacSystemFont,sans-serif';
|
|
987
|
+
var hdrW=FP+ctx.measureText(e.name).width+FP;
|
|
988
|
+
if(e.isPivot){
|
|
989
|
+
ctx.font='9px monospace';
|
|
990
|
+
hdrW+=ctx.measureText('pivot').width+FP;
|
|
991
|
+
}
|
|
992
|
+
var maxRow=hdrW;
|
|
993
|
+
e.fields.forEach(function(f){
|
|
994
|
+
var leftPad=FP+(f.pk||f.fk?16:0);
|
|
995
|
+
var rightPad=(f.required&&!f.pk?14:0)+FP;
|
|
996
|
+
ctx.font=(f.required&&!f.pk?'600 ':'')+'11px monospace';
|
|
997
|
+
var nw=ctx.measureText(f.name).width;
|
|
998
|
+
ctx.font='10px monospace';
|
|
999
|
+
var tw=ctx.measureText(f.type).width;
|
|
1000
|
+
maxRow=Math.max(maxRow,leftPad+nw+MIN_GAP+tw+rightPad);
|
|
1001
|
+
});
|
|
1002
|
+
n.w=Math.max(NW,Math.ceil(maxRow));
|
|
1003
|
+
});
|
|
1004
|
+
}
|
|
1005
|
+
|
|
960
1006
|
// \u2500\u2500 Layered layout (simplified Sugiyama) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
961
1007
|
var groups=[];
|
|
962
1008
|
|
|
@@ -995,7 +1041,8 @@ function erDiagramSection(data) {
|
|
|
995
1041
|
median(adj[b].map(function(x){return np[x]!=null?np[x]:0;}));
|
|
996
1042
|
});
|
|
997
1043
|
}
|
|
998
|
-
var
|
|
1044
|
+
var maxNW=nodes.reduce(function(m,n){return Math.max(m,n.w);},NW);
|
|
1045
|
+
var colW=maxNW+COL_GAP;
|
|
999
1046
|
var totalW=(maxL+1)*colW-COL_GAP;
|
|
1000
1047
|
var startX=Math.max(20,(W-totalW)/2);
|
|
1001
1048
|
for(var l=0;l<=maxL;l++){
|
|
@@ -1043,37 +1090,37 @@ function erDiagramSection(data) {
|
|
|
1043
1090
|
|
|
1044
1091
|
var badges=[];
|
|
1045
1092
|
|
|
1046
|
-
|
|
1047
|
-
|
|
1093
|
+
// \u2500\u2500 SVG cardinality badges via Path2D \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
1094
|
+
// SVG orientation: LEFT side touches the node, RIGHT side connects to the line.
|
|
1095
|
+
// Rotation = Math.atan2(uy,ux) aligns local +x with the outward (away-from-node) direction.
|
|
1096
|
+
var P2D={
|
|
1097
|
+
'1..1':new Path2D('M75 40C75 59.33 59.33 75 40 75C20.67 75 5 59.33 5 40C5 20.67 20.67 5 40 5C59.33 5 75 20.67 75 40ZM41 26C41 24.3431 39.6569 23 38 23C36.3431 23 35 24.3431 35 26V37H26V26C26 24.3431 24.6569 23 23 23C21.3431 23 20 24.3431 20 26V37H15C13.3431 37 12 38.3431 12 40C12 41.6569 13.3431 43 15 43H20V54C20 55.6569 21.3431 57 23 57C24.6569 57 26 55.6569 26 54V43H35V54C35 55.6569 36.3431 57 38 57C39.6569 57 41 55.6569 41 54V43H66C67.6569 43 69 41.6569 69 40C69 38.3431 67.6569 37 66 37H41V26Z'),
|
|
1098
|
+
'1..n':new Path2D('M40 75C59.33 75 75 59.33 75 40C75 20.67 59.33 5 40 5C20.67 5 5 20.67 5 40C5 59.33 20.67 75 40 75ZM44.9862 42.9025L18.6801 58.0904C17.2452 58.9188 15.4105 58.4272 14.582 56.9923C13.7536 55.5574 14.2452 53.7227 15.6801 52.8942L32.9862 42.9025H17C15.3431 42.9025 14 41.5594 14 39.9025C14 38.2457 15.3431 36.9025 17 36.9025H32.9862L15.5981 26.5986C14.1632 25.7702 13.6716 23.9354 14.5 22.5005C15.3284 21.0656 17.1632 20.574 18.5981 21.4024L44.9862 36.9025H46V26C46 24.3431 47.3431 23 49 23C50.6569 23 52 24.3431 52 26V36.9025H68C69.6569 36.9025 71 38.2457 71 39.9025C71 41.5594 69.6569 42.9025 68 42.9025H52V53C52 54.6569 50.6569 56 49 56C47.3431 56 46 54.6569 46 53V42.9025H44.9862Z'),
|
|
1099
|
+
'0..1':new Path2D('M75 40C75 59.33 59.33 75 40 75C20.67 75 5 59.33 5 40C5 20.67 20.67 5 40 5C59.33 5 75 20.67 75 40ZM23 57C24.6569 57 26 55.6569 26 54V43H33.3781C34.7102 48.1757 39.4085 52 45 52C50.5915 52 55.2898 48.1757 56.6219 43H66C67.6569 43 69 41.6569 69 40C69 38.3431 67.6569 37 66 37H56.6219C55.2898 31.8243 50.5915 28 45 28C39.4085 28 34.7102 31.8243 33.3781 37H26V26C26 24.3431 24.6569 23 23 23C21.3431 23 20 24.3431 20 26V37H15C13.3431 37 12 38.3431 12 40C12 41.6569 13.3431 43 15 43H20V54C20 55.6569 21.3431 57 23 57ZM51 40C51 41.0929 50.7078 42.1175 50.1973 43C49.1599 44.7934 47.2208 46 45 46C42.7792 46 40.8401 44.7934 39.8027 43C39.2922 42.1175 39 41.0929 39 40C39 38.9071 39.2922 37.8825 39.8027 37C40.8401 35.2066 42.7792 34 45 34C47.2208 34 49.1599 35.2066 50.1973 37C50.7078 37.8825 51 38.9071 51 40Z'),
|
|
1100
|
+
'0..n':new Path2D('M40 75C59.33 75 75 59.33 75 40C75 20.67 59.33 5 40 5C20.67 5 5 20.67 5 40C5 59.33 20.67 75 40 75ZM17 42.9025C15.3431 42.9025 14 41.5594 14 39.9025C14 38.2457 15.3431 36.9025 17 36.9025H32.9862L15.5981 26.5986C14.1632 25.7702 13.6716 23.9354 14.5 22.5005C15.3284 21.0656 17.1632 20.574 18.5981 21.4024L45.4091 36.8818L45.4036 36.9025H45.445L45.4091 36.8818C46.7819 31.7662 51.4511 28 57 28C62.579 28 67.2687 31.8072 68.6129 36.9652C69.9758 37.2481 71 38.4557 71 39.9025C71 41.331 70.0017 42.5262 68.6647 42.8286C67.3931 48.091 62.6531 52 57 52C51.3734 52 46.6513 48.1276 45.3534 42.9025H44.9862L18.6801 58.0904C17.2452 58.9188 15.4105 58.4272 14.582 56.9923C13.7536 55.5574 14.2452 53.7227 15.6801 52.8942L32.9862 42.9025H17ZM62.1397 36.9025C61.0891 35.163 59.1804 34 57 34C54.8196 34 52.9109 35.163 51.8603 36.9025C51.3142 37.8067 51 38.8667 51 40C51 41.0529 51.2712 42.0424 51.7475 42.9025C52.7704 44.7496 54.7392 46 57 46C59.2608 46 61.2296 44.7496 62.2525 42.9025C62.7288 42.0424 63 41.0529 63 40C63 38.8667 62.6858 37.8067 62.1397 36.9025Z'),
|
|
1101
|
+
'n':new Path2D('M40 75C59.33 75 75 59.33 75 40C75 20.67 59.33 5 40 5C20.67 5 5 20.67 5 40C5 59.33 20.67 75 40 75ZM17 36.9025H33.0677L15.5981 26.5986C14.1632 25.7702 13.6716 23.9354 14.5 22.5005C15.3284 21.0656 17.1632 20.574 18.5981 21.4024L44.9862 36.9025H68C69.6569 36.9025 71 38.2457 71 39.9025C71 41.5594 69.6569 42.9025 68 42.9025H44.9862L18.6801 58.0904C17.2452 58.9188 15.4105 58.4272 14.582 56.9923C13.7536 55.5574 14.2452 53.7227 15.6801 52.8942L32.9862 42.9025H17C15.3431 42.9025 14 41.5594 14 39.9025C14 38.2457 15.3431 36.9025 17 36.9025Z')
|
|
1102
|
+
};
|
|
1103
|
+
|
|
1104
|
+
function pushBadge(x,y,ux,uy,car,col){
|
|
1105
|
+
badges.push({x:x,y:y,ux:ux,uy:uy,car:car,col:col});
|
|
1048
1106
|
}
|
|
1049
1107
|
|
|
1050
|
-
// Badge: solid colored circle; crow's foot (many) or double-bar (one) in dark ink inside.
|
|
1051
|
-
// ux,uy points outward from the node \u2014 badge is offset BO px into the gap.
|
|
1052
|
-
// Crow's foot tines open toward the node (-x in rotated frame), tip toward line (+x).
|
|
1053
1108
|
function drawBadge(b){
|
|
1054
|
-
var
|
|
1055
|
-
ctx.
|
|
1056
|
-
ctx.
|
|
1057
|
-
ctx.
|
|
1058
|
-
ctx.
|
|
1059
|
-
ctx.
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
ctx.moveTo(-5,4);ctx.lineTo(5,0); // lower tine \u2192 tip
|
|
1063
|
-
ctx.moveTo(-5,0);ctx.lineTo(5,0); // center line
|
|
1064
|
-
ctx.moveTo(-5,-4);ctx.lineTo(-5,4); // base bar (near node)
|
|
1065
|
-
}else{
|
|
1066
|
-
ctx.moveTo(-3,-5);ctx.lineTo(-3,5); // near bar
|
|
1067
|
-
ctx.moveTo(2,-5);ctx.lineTo(2,5); // far bar
|
|
1068
|
-
}
|
|
1069
|
-
ctx.stroke();
|
|
1109
|
+
var p=P2D[b.car]||P2D['n'],sc=BR/40;
|
|
1110
|
+
ctx.save();
|
|
1111
|
+
ctx.translate(b.x+b.ux*BO,b.y+b.uy*BO);
|
|
1112
|
+
ctx.rotate(Math.atan2(b.uy,b.ux));
|
|
1113
|
+
ctx.scale(sc,sc);
|
|
1114
|
+
ctx.translate(-40,-40);
|
|
1115
|
+
ctx.fillStyle=b.col;
|
|
1116
|
+
ctx.fill(p,'evenodd');
|
|
1070
1117
|
ctx.restore();
|
|
1071
1118
|
}
|
|
1072
1119
|
|
|
1073
1120
|
function ecol(t){return t==='one2one'?C.o2o:t==='many2many'?C.m2m:C.m2o;}
|
|
1074
1121
|
|
|
1075
1122
|
// offset: pixels to shift perpendicular to the edge direction (for parallel edges)
|
|
1076
|
-
function drawEdgeLine(a,b,col,dashed,label,
|
|
1123
|
+
function drawEdgeLine(a,b,col,dashed,label,carA,carB,off){
|
|
1077
1124
|
var p1=edgePt(a,b.x+b.w/2,b.y+b.h/2);
|
|
1078
1125
|
var p2=edgePt(b,a.x+a.w/2,a.y+a.h/2);
|
|
1079
1126
|
var dx=p2.x-p1.x,dy=p2.y-p1.y,d=Math.sqrt(dx*dx+dy*dy)||1;
|
|
@@ -1084,13 +1131,19 @@ function erDiagramSection(data) {
|
|
|
1084
1131
|
ctx.setLineDash(dashed?[5,4]:[]);
|
|
1085
1132
|
ctx.beginPath();ctx.moveTo(q1x,q1y);ctx.lineTo(q2x,q2y);ctx.stroke();
|
|
1086
1133
|
ctx.setLineDash([]);
|
|
1087
|
-
pushBadge(q1x,q1y,ux,uy,
|
|
1088
|
-
pushBadge(q2x,q2y,-ux,-uy,
|
|
1134
|
+
pushBadge(q1x,q1y,ux,uy,carA,col);
|
|
1135
|
+
pushBadge(q2x,q2y,-ux,-uy,carB,col);
|
|
1089
1136
|
if(label){
|
|
1090
1137
|
var mx=(q1x+q2x)/2,my=(q1y+q2y)/2;
|
|
1138
|
+
var la=Math.atan2(uy,ux);
|
|
1139
|
+
if(la>Math.PI/2||la<-Math.PI/2)la+=Math.PI; // keep text readable
|
|
1140
|
+
var ls=off>0?11:-11; // alternate above/below for parallel edges
|
|
1141
|
+
ctx.save();
|
|
1142
|
+
ctx.translate(mx,my);
|
|
1143
|
+
ctx.rotate(la);
|
|
1091
1144
|
ctx.fillStyle=C.mu;ctx.font='10px monospace';ctx.textAlign='center';ctx.textBaseline='middle';
|
|
1092
|
-
ctx.fillText(label,
|
|
1093
|
-
ctx.
|
|
1145
|
+
ctx.fillText(label,0,ls);
|
|
1146
|
+
ctx.restore();
|
|
1094
1147
|
}
|
|
1095
1148
|
}
|
|
1096
1149
|
|
|
@@ -1106,14 +1159,14 @@ function erDiagramSection(data) {
|
|
|
1106
1159
|
var col=ecol(r.type);
|
|
1107
1160
|
if(r.type==='many2many'&&r.through&&nIdx[r.through]!=null){
|
|
1108
1161
|
var sn=nodes[nIdx[r.source]],pn=nodes[nIdx[r.through]],tn=nodes[nIdx[r.target]];
|
|
1109
|
-
if(sn&&pn)edges.push({a:sn,b:pn,col:col,dashed:true,label:r.foreignKey||'',
|
|
1110
|
-
if(tn&&pn)edges.push({a:tn,b:pn,col:col,dashed:true,label:r.otherKey||'',
|
|
1162
|
+
if(sn&&pn)edges.push({a:sn,b:pn,col:col,dashed:true,label:r.foreignKey||'',carA:r.fkCarDirect||'1..1',carB:r.fkCarInverse||'0..n',off:0});
|
|
1163
|
+
if(tn&&pn)edges.push({a:tn,b:pn,col:col,dashed:true,label:r.otherKey||'',carA:r.otherCarDirect||'1..1',carB:r.otherCarInverse||'0..n',off:0});
|
|
1111
1164
|
}else{
|
|
1112
1165
|
var sn=nodes[nIdx[r.source]],tn=nodes[nIdx[r.target]];
|
|
1113
1166
|
if(sn&&tn&&sn!==tn){
|
|
1114
|
-
var
|
|
1115
|
-
var
|
|
1116
|
-
edges.push({a:sn,b:tn,col:col,dashed:false,label:r.label,
|
|
1167
|
+
var carA=r.carInverse||(r.type!=='one2one'?'1..n':'1..1');
|
|
1168
|
+
var carB=r.carDirect||(r.type==='many2many'?'1..n':'1..1');
|
|
1169
|
+
edges.push({a:sn,b:tn,col:col,dashed:false,label:r.label,carA:carA,carB:carB,off:0});
|
|
1117
1170
|
}
|
|
1118
1171
|
}
|
|
1119
1172
|
});
|
|
@@ -1172,12 +1225,24 @@ function erDiagramSection(data) {
|
|
|
1172
1225
|
|
|
1173
1226
|
function drawLegend(){
|
|
1174
1227
|
var cvW=cv.width/dpr,cvH=cv.height/dpr;
|
|
1175
|
-
var
|
|
1228
|
+
var yL=cvH-LGH,y1=yL+13,y2=yL+35,y3=yL+62;
|
|
1176
1229
|
|
|
1177
1230
|
ctx.fillStyle='#161b22';
|
|
1178
|
-
ctx.fillRect(0,
|
|
1231
|
+
ctx.fillRect(0,yL,cvW,LGH);
|
|
1179
1232
|
ctx.strokeStyle='#30363d';ctx.lineWidth=1;
|
|
1180
|
-
ctx.beginPath();ctx.moveTo(0,
|
|
1233
|
+
ctx.beginPath();ctx.moveTo(0,yL);ctx.lineTo(cvW,yL);ctx.stroke();
|
|
1234
|
+
|
|
1235
|
+
function legendBadge(cx,cy,car,col,angle){
|
|
1236
|
+
var p=P2D[car]||P2D['n'],sc=8/40;
|
|
1237
|
+
ctx.save();
|
|
1238
|
+
ctx.translate(cx,cy);
|
|
1239
|
+
ctx.rotate(angle);
|
|
1240
|
+
ctx.scale(sc,sc);
|
|
1241
|
+
ctx.translate(-40,-40);
|
|
1242
|
+
ctx.fillStyle=col;
|
|
1243
|
+
ctx.fill(p,'evenodd');
|
|
1244
|
+
ctx.restore();
|
|
1245
|
+
}
|
|
1181
1246
|
|
|
1182
1247
|
// Row 1: relation line types
|
|
1183
1248
|
var types=[
|
|
@@ -1196,42 +1261,43 @@ function erDiagramSection(data) {
|
|
|
1196
1261
|
x+=18+ctx.measureText(it.l).width+22;
|
|
1197
1262
|
});
|
|
1198
1263
|
|
|
1199
|
-
// Row 2:
|
|
1200
|
-
function badge2(cx,cy,many,col){
|
|
1201
|
-
ctx.fillStyle=col;ctx.strokeStyle=col;ctx.lineWidth=1;
|
|
1202
|
-
ctx.beginPath();ctx.arc(cx,cy,6,0,Math.PI*2);ctx.fill();
|
|
1203
|
-
ctx.save();ctx.translate(cx,cy);
|
|
1204
|
-
ctx.strokeStyle=C.bg;ctx.lineWidth=1.2;ctx.lineCap='round';
|
|
1205
|
-
ctx.beginPath();
|
|
1206
|
-
if(many){
|
|
1207
|
-
ctx.moveTo(-4,-3);ctx.lineTo(4,0);ctx.moveTo(-4,3);ctx.lineTo(4,0);
|
|
1208
|
-
ctx.moveTo(-4,0);ctx.lineTo(4,0);ctx.moveTo(-4,-3);ctx.lineTo(-4,3);
|
|
1209
|
-
}else{
|
|
1210
|
-
ctx.moveTo(-2,-3);ctx.lineTo(-2,3);ctx.moveTo(2,-3);ctx.lineTo(2,3);
|
|
1211
|
-
}
|
|
1212
|
-
ctx.stroke();ctx.restore();
|
|
1213
|
-
}
|
|
1214
|
-
|
|
1215
|
-
ctx.font='10px monospace';ctx.textAlign='left';ctx.textBaseline='middle';
|
|
1264
|
+
// Row 2: relation type examples (pair of badges + line)
|
|
1216
1265
|
x=14;
|
|
1217
1266
|
var pairs=[
|
|
1218
|
-
{
|
|
1219
|
-
{
|
|
1220
|
-
{
|
|
1267
|
+
{carA:'1..n',carB:'1..1',col:C.m2o,l:'many2one (N:1)'},
|
|
1268
|
+
{carA:'1..1',carB:'1..1',col:C.o2o,l:'one2one (1:1)'},
|
|
1269
|
+
{carA:'1..1',carB:'0..n',col:C.m2m,l:'pivot edge (1:0..N)'}
|
|
1221
1270
|
];
|
|
1222
1271
|
pairs.forEach(function(p){
|
|
1223
1272
|
ctx.strokeStyle=p.col+'55';ctx.lineWidth=1.2;ctx.setLineDash(p.col===C.m2m?[4,3]:[]);
|
|
1224
1273
|
ctx.beginPath();ctx.moveTo(x+8,y2);ctx.lineTo(x+56,y2);ctx.stroke();
|
|
1225
1274
|
ctx.setLineDash([]);
|
|
1226
|
-
|
|
1227
|
-
|
|
1275
|
+
legendBadge(x+8,y2,p.carA,p.col,0);
|
|
1276
|
+
legendBadge(x+56,y2,p.carB,p.col,Math.PI);
|
|
1228
1277
|
ctx.fillStyle=C.mu;ctx.font='10px monospace';ctx.textAlign='left';ctx.textBaseline='middle';
|
|
1229
1278
|
ctx.fillText(p.l,x+66,y2);
|
|
1230
1279
|
x+=66+ctx.measureText(p.l).width+24;
|
|
1231
1280
|
});
|
|
1232
1281
|
|
|
1282
|
+
// Row 3: individual symbol meanings
|
|
1283
|
+
var symbols=[
|
|
1284
|
+
{car:'1..1',l:'exactly one'},
|
|
1285
|
+
{car:'0..1',l:'zero or one'},
|
|
1286
|
+
{car:'1..n',l:'one or more'},
|
|
1287
|
+
{car:'0..n',l:'zero or more'},
|
|
1288
|
+
{car:'n', l:'many (pivot)'}
|
|
1289
|
+
];
|
|
1290
|
+
x=14;
|
|
1291
|
+
ctx.font='10px monospace';ctx.textAlign='left';ctx.textBaseline='middle';
|
|
1292
|
+
symbols.forEach(function(s){
|
|
1293
|
+
legendBadge(x+8,y3,s.car,C.mu,0);
|
|
1294
|
+
ctx.fillStyle=C.mu;
|
|
1295
|
+
ctx.fillText(s.l,x+20,y3);
|
|
1296
|
+
x+=20+ctx.measureText(s.l).width+18;
|
|
1297
|
+
});
|
|
1298
|
+
|
|
1233
1299
|
ctx.fillStyle='#3d444d';ctx.font='10px monospace';ctx.textAlign='right';ctx.textBaseline='middle';
|
|
1234
|
-
ctx.fillText('drag \xB7 scroll to zoom \xB7 dbl-click to reset',cvW-14,
|
|
1300
|
+
ctx.fillText('drag \xB7 scroll to zoom \xB7 dbl-click to reset',cvW-14,y1);
|
|
1235
1301
|
ctx.textBaseline='alphabetic';
|
|
1236
1302
|
}
|
|
1237
1303
|
|
|
@@ -1243,7 +1309,7 @@ function erDiagramSection(data) {
|
|
|
1243
1309
|
ctx.save();ctx.translate(pan.x,pan.y);ctx.scale(zm,zm);
|
|
1244
1310
|
badges=[];
|
|
1245
1311
|
var edges=collectEdges();
|
|
1246
|
-
edges.forEach(function(e){drawEdgeLine(e.a,e.b,e.col,e.dashed,e.label,e.
|
|
1312
|
+
edges.forEach(function(e){drawEdgeLine(e.a,e.b,e.col,e.dashed,e.label,e.carA,e.carB,e.off);});
|
|
1247
1313
|
nodes.forEach(function(n){drawNode(n);});
|
|
1248
1314
|
badges.forEach(function(b){drawBadge(b);});
|
|
1249
1315
|
ctx.restore();
|
|
@@ -1289,14 +1355,21 @@ function erDiagramSection(data) {
|
|
|
1289
1355
|
});
|
|
1290
1356
|
|
|
1291
1357
|
document.getElementById('er-dl').addEventListener('click',function(){
|
|
1292
|
-
var SCALE=3;
|
|
1293
|
-
var
|
|
1358
|
+
var SCALE=parseInt(document.getElementById('er-scale').value,10)||3;
|
|
1359
|
+
var pad=36;
|
|
1360
|
+
var bx0=1e9,by0=1e9,bx1=-1e9,by1=-1e9;
|
|
1361
|
+
nodes.forEach(function(n){
|
|
1362
|
+
bx0=Math.min(bx0,n.x);by0=Math.min(by0,n.y);
|
|
1363
|
+
bx1=Math.max(bx1,n.x+n.w);by1=Math.max(by1,n.y+n.h);
|
|
1364
|
+
});
|
|
1365
|
+
var cw=bx1-bx0+pad*2,ch=by1-by0+pad*2+LGH;
|
|
1294
1366
|
var oc=document.createElement('canvas');
|
|
1295
1367
|
oc.width=Math.round(cw*SCALE);oc.height=Math.round(ch*SCALE);
|
|
1296
|
-
var sav={cv:cv,ctx:ctx,dpr:dpr};
|
|
1368
|
+
var sav={cv:cv,ctx:ctx,dpr:dpr,px:pan.x,py:pan.y,zm:zm};
|
|
1297
1369
|
cv=oc;ctx=oc.getContext('2d');dpr=SCALE;
|
|
1370
|
+
pan.x=pad-bx0;pan.y=pad-by0;zm=1;
|
|
1298
1371
|
draw();
|
|
1299
|
-
cv=sav.cv;ctx=sav.ctx;dpr=sav.dpr;
|
|
1372
|
+
cv=sav.cv;ctx=sav.ctx;dpr=sav.dpr;pan.x=sav.px;pan.y=sav.py;zm=sav.zm;
|
|
1300
1373
|
var a=document.createElement('a');
|
|
1301
1374
|
a.download='er-diagram.png';a.href=oc.toDataURL('image/png');a.click();
|
|
1302
1375
|
});
|
|
@@ -1304,6 +1377,7 @@ function erDiagramSection(data) {
|
|
|
1304
1377
|
// \u2500\u2500 Init \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
1305
1378
|
requestAnimationFrame(function(){
|
|
1306
1379
|
resize();
|
|
1380
|
+
computeNodeWidths();
|
|
1307
1381
|
var r=cv.getBoundingClientRect();
|
|
1308
1382
|
computeLayout(r.width,r.height);
|
|
1309
1383
|
var h=requiredH();
|
package/package.json
CHANGED