Position balancing for >3 dots
This commit is contained in:
parent
f82cdf0814
commit
5e872804ac
|
@ -29,7 +29,7 @@ class CurvePainter extends CustomPainter {
|
||||||
|
|
||||||
void drawDot(Canvas canvas, Offset p1) {
|
void drawDot(Canvas canvas, Offset p1) {
|
||||||
var p = Paint();
|
var p = Paint();
|
||||||
p.color = col;
|
p.color = Colors.yellow.shade900;
|
||||||
p.strokeWidth = width;
|
p.strokeWidth = width;
|
||||||
canvas.drawCircle(p1, rad, p);
|
canvas.drawCircle(p1, rad, p);
|
||||||
}
|
}
|
||||||
|
@ -76,13 +76,17 @@ class CurvePainter extends CustomPainter {
|
||||||
return Graphs.fromList("1", d, false, false);
|
return Graphs.fromList("1", d, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
int getHighConnections() {
|
int getHighInputConnections() {
|
||||||
|
if (gr.getDots().length <= 3) return -1;
|
||||||
int higest = -1;
|
int higest = -1;
|
||||||
gr.getDots().forEach((element) {
|
for (var i in gr.getDots()) {
|
||||||
|
if (i.getL().length > higest) higest = i.num;
|
||||||
|
}
|
||||||
|
/*gr.getDots().forEach((element) {
|
||||||
if (element.getL().length > higest) {
|
if (element.getL().length > higest) {
|
||||||
higest = element.num;
|
higest = element.num;
|
||||||
}
|
}
|
||||||
});
|
});*/
|
||||||
return higest;
|
return higest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,12 +94,23 @@ class CurvePainter extends CustomPainter {
|
||||||
Map<int, Offset> off = <int, Offset>{};
|
Map<int, Offset> off = <int, Offset>{};
|
||||||
var width = size.width / 2;
|
var width = size.width / 2;
|
||||||
var height = size.height / 2;
|
var height = size.height / 2;
|
||||||
int add = 1;
|
int add = 0;
|
||||||
|
int h = getHighInputConnections();
|
||||||
for (int i = 0; i < dotsAm; i++) {
|
for (int i = 0; i < dotsAm; i++) {
|
||||||
double x = cos(2 * pi * i / dotsAm) * circleRad + width;
|
if ((i + 1) != h) {
|
||||||
double y = sin(2 * pi * i / dotsAm) * circleRad + height;
|
double x = cos(2 * pi * (i - add) / (dotsAm - add)) * circleRad + width;
|
||||||
|
double y =
|
||||||
|
sin(2 * pi * (i - add) / (dotsAm - add)) * circleRad + height;
|
||||||
|
|
||||||
off[i + add] = Offset(x, y);
|
off[i + 1] = Offset(x, y);
|
||||||
|
} else if ((i + 1) == h) {
|
||||||
|
off[i + 1] = Offset(width + 2, height - 2);
|
||||||
|
add = 1;
|
||||||
|
h = 0;
|
||||||
|
} else {
|
||||||
|
print("GetDotPos error");
|
||||||
|
}
|
||||||
|
print(off.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
//print(off);
|
//print(off);
|
||||||
|
@ -120,8 +135,8 @@ class CurvePainter extends CustomPainter {
|
||||||
/// Draw a single arrow.
|
/// Draw a single arrow.
|
||||||
path = Path();
|
path = Path();
|
||||||
path.moveTo(from.dx, from.dy);
|
path.moveTo(from.dx, from.dy);
|
||||||
path.relativeCubicTo(0, 0, -(from.dx + to.dx) / length - 40,
|
path.relativeCubicTo(0, 0, -(from.dx + to.dx) / length * 2 - 40,
|
||||||
-(from.dy + to.dy) / length - 40, to.dx - from.dx, to.dy - from.dy);
|
-(from.dy + to.dy) / length * 2 - 40, to.dx - from.dx, to.dy - from.dy);
|
||||||
path =
|
path =
|
||||||
ArrowPath.make(path: path, isDoubleSided: doubleSided, tipLength: 16);
|
ArrowPath.make(path: path, isDoubleSided: doubleSided, tipLength: 16);
|
||||||
canvas.drawPath(path, paint);
|
canvas.drawPath(path, paint);
|
||||||
|
|
|
@ -9,9 +9,9 @@ Graphs getGraph() {
|
||||||
d.add(Dot.fromTwoLists("1", [2, 3], [5, 1]));
|
d.add(Dot.fromTwoLists("1", [2, 3], [5, 1]));
|
||||||
d.add(Dot.fromTwoLists("2", [1, 3], [1, 1]));
|
d.add(Dot.fromTwoLists("2", [1, 3], [1, 1]));
|
||||||
d.add(Dot.fromTwoLists("3", [1, 2], [1, 2]));
|
d.add(Dot.fromTwoLists("3", [1, 2], [1, 2]));
|
||||||
d.add(Dot.fromTwoLists("Name1", [], []));
|
//d.add(Dot.fromTwoLists("Name1", [], []));
|
||||||
d.add(Dot.fromTwoLists("Name2", [], []));
|
//d.add(Dot.fromTwoLists("Name2", [], []));
|
||||||
return Graphs.fromList("1", d, true, true);
|
return Graphs.fromList("UMYA", d, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
class DrawingPage extends StatefulWidget {
|
class DrawingPage extends StatefulWidget {
|
||||||
|
@ -47,7 +47,7 @@ class _DrawingPageState extends State<DrawingPage> {
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: const Align(
|
title: const Align(
|
||||||
alignment: Alignment.topLeft,
|
alignment: Alignment.topLeft,
|
||||||
child: Text("Graph\n\n",
|
child: Text("Graph name:\n",
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 18,
|
fontSize: 18,
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
|
@ -96,6 +96,8 @@ class _DrawingPageState extends State<DrawingPage> {
|
||||||
child: ButtonBar(
|
child: ButtonBar(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
|
createButton("Bfs", () {}),
|
||||||
|
createButton("Dfs", () {}),
|
||||||
createButton(data.getUseLengthStr(), changeLength),
|
createButton(data.getUseLengthStr(), changeLength),
|
||||||
createButton(data.getDoubleSidedStr(), changeOriented),
|
createButton(data.getDoubleSidedStr(), changeOriented),
|
||||||
/*Text(_textGrNmController.text,
|
/*Text(_textGrNmController.text,
|
||||||
|
|
|
@ -537,7 +537,7 @@ class Graphs {
|
||||||
}
|
}
|
||||||
|
|
||||||
//************Алгоритмы************
|
//************Алгоритмы************
|
||||||
bool bfsHasPath(int startDot, int goalDot) {
|
/* bool bfsHasPath(int startDot, int goalDot) {
|
||||||
// обход в ширину
|
// обход в ширину
|
||||||
startDot--;
|
startDot--;
|
||||||
goalDot--;
|
goalDot--;
|
||||||
|
@ -564,7 +564,7 @@ class Graphs {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false; // Целевой узел недостижим
|
return false; // Целевой узел недостижим
|
||||||
}
|
}*/
|
||||||
|
|
||||||
List<int>? bfsPath(int startDot, int goalDot) {
|
List<int>? bfsPath(int startDot, int goalDot) {
|
||||||
//if (!bfsHasPath(startDot, goalDot)) return null;
|
//if (!bfsHasPath(startDot, goalDot)) return null;
|
||||||
|
|
Loading…
Reference in New Issue