Попытки в стрелочки х2 неудачные, но чуть боле удачные
This commit is contained in:
parent
5653628cfe
commit
9ff6dd2745
|
@ -76,15 +76,30 @@ class CurvePainter extends CustomPainter {
|
||||||
return Graphs.fromList("1", d, false, false);
|
return Graphs.fromList("1", d, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<int, Offset> getDotPos(int dotsAm, Size size) {
|
int getHighConnections() {
|
||||||
|
int higest = -1;
|
||||||
|
gr.getDots().forEach((element) {
|
||||||
|
if (element.getL().length > higest) {
|
||||||
|
higest = element.num;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return higest;
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<int, Offset> getDotPos(int dotsAm, Size size, int exclude) {
|
||||||
|
dotsAm--;
|
||||||
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;
|
||||||
for (int i = 0; i < dotsAm; i++) {
|
for (int i = 0; i < dotsAm; i++) {
|
||||||
double x = cos(2 * pi * i / dotsAm) * circleRad + width;
|
double x = cos(2 * pi * i / dotsAm) * circleRad + width;
|
||||||
double y = sin(2 * pi * i / dotsAm) * circleRad + height;
|
double y = sin(2 * pi * i / dotsAm) * circleRad + height;
|
||||||
off[i + 1] = Offset(x, y);
|
|
||||||
|
if (i == exclude - 1) add++;
|
||||||
|
off[i + add] = Offset(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
//print(off);
|
//print(off);
|
||||||
return off;
|
return off;
|
||||||
}
|
}
|
||||||
|
@ -101,11 +116,14 @@ class CurvePainter extends CustomPainter {
|
||||||
..strokeJoin = StrokeJoin.round
|
..strokeJoin = StrokeJoin.round
|
||||||
..strokeWidth = width - 1;
|
..strokeWidth = width - 1;
|
||||||
|
|
||||||
|
var length = sqrt((to.dx - from.dx) * (to.dx - from.dx) +
|
||||||
|
(to.dy - from.dy) * (to.dy - from.dy));
|
||||||
|
|
||||||
/// 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(
|
path.relativeCubicTo(0, 0, -(from.dx + to.dx) / length - 40,
|
||||||
0, 0, size.width / 20, 50, to.dx - from.dx, to.dy - from.dy);
|
-(from.dy + to.dy) / length - 40, to.dx - from.dx, to.dy - from.dy);
|
||||||
path =
|
path =
|
||||||
ArrowPath.make(path: path, isDoubleSided: doubleSided, tipLength: 13);
|
ArrowPath.make(path: path, isDoubleSided: doubleSided, tipLength: 13);
|
||||||
canvas.drawPath(path, paint);
|
canvas.drawPath(path, paint);
|
||||||
|
@ -123,11 +141,14 @@ class CurvePainter extends CustomPainter {
|
||||||
..strokeJoin = StrokeJoin.round
|
..strokeJoin = StrokeJoin.round
|
||||||
..strokeWidth = width - 1;
|
..strokeWidth = width - 1;
|
||||||
|
|
||||||
|
var length = sqrt((to.dx - from.dx) * (to.dx - from.dx) +
|
||||||
|
(to.dy - from.dy) * (to.dy - from.dy));
|
||||||
|
|
||||||
/// 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(
|
path.relativeCubicTo(0, 0, (from.dx + to.dx) / length + 60,
|
||||||
0, 0, -size.width / 25, -50, to.dx - from.dx, to.dy - from.dy);
|
(from.dy + to.dy) / length + 0, to.dx - from.dx, to.dy - from.dy);
|
||||||
path = ArrowPath.make(
|
path = ArrowPath.make(
|
||||||
path: path,
|
path: path,
|
||||||
isDoubleSided: doubleSided,
|
isDoubleSided: doubleSided,
|
||||||
|
@ -151,8 +172,8 @@ class CurvePainter extends CustomPainter {
|
||||||
if (gr.getUseLengthBool()) {
|
if (gr.getUseLengthBool()) {
|
||||||
drawDotNames(
|
drawDotNames(
|
||||||
canvas,
|
canvas,
|
||||||
Offset((off[d]!.dx + beg.dx) / 2 - 20,
|
Offset((off[d]!.dx + beg.dx) / 2 - 18,
|
||||||
(off[d]!.dy + beg.dy) / 2 - 20),
|
(off[d]!.dy + beg.dy) / 2 - 18),
|
||||||
i.getL()[d].toString());
|
i.getL()[d].toString());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -160,8 +181,8 @@ class CurvePainter extends CustomPainter {
|
||||||
if (gr.getUseLengthBool()) {
|
if (gr.getUseLengthBool()) {
|
||||||
drawDotNames(
|
drawDotNames(
|
||||||
canvas,
|
canvas,
|
||||||
Offset((off[d]!.dx + beg.dx) / 2 + 25,
|
Offset((off[d]!.dx + beg.dx) / 2 + 30,
|
||||||
(off[d]!.dy + beg.dy) / 2 + 25),
|
(off[d]!.dy + beg.dy) / 2 + 30),
|
||||||
i.getL()[d].toString());
|
i.getL()[d].toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -191,10 +212,14 @@ class CurvePainter extends CustomPainter {
|
||||||
//Offset(size.width, size.height / 2));
|
//Offset(size.width, size.height / 2));
|
||||||
|
|
||||||
//gr = getGraph();
|
//gr = getGraph();
|
||||||
var off = getDotPos(gr.getDotAmount(), size);
|
int higest = getHighConnections();
|
||||||
|
if (higest > -1) {
|
||||||
|
var off = getDotPos(gr.getDotAmount(), size, higest);
|
||||||
|
off[higest] = Offset(size.width / 2, size.height / 2);
|
||||||
for (int i in off.keys) {
|
for (int i in off.keys) {
|
||||||
drawDot(canvas, off[i]!);
|
drawDot(canvas, off[i]!);
|
||||||
drawDotNames(canvas, off[i]!, "${gr.getDots()[i - 1].getName()}:[${i}]");
|
drawDotNames(
|
||||||
|
canvas, off[i]!, "${gr.getDots()[i - 1].getName()}:[${i}]");
|
||||||
}
|
}
|
||||||
//var g = gr.getNoRepeatDots();
|
//var g = gr.getNoRepeatDots();
|
||||||
//print(g);
|
//print(g);
|
||||||
|
@ -204,6 +229,7 @@ class CurvePainter extends CustomPainter {
|
||||||
//drawArrow(canvas, Offset(size.width / 2, size.height / 2),
|
//drawArrow(canvas, Offset(size.width / 2, size.height / 2),
|
||||||
// Offset(size.width / 2 + 50, size.height / 2 + 200));
|
// Offset(size.width / 2 + 50, size.height / 2 + 200));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool shouldRepaint(CustomPainter oldDelegate) {
|
bool shouldRepaint(CustomPainter oldDelegate) {
|
||||||
|
@ -273,9 +299,9 @@ void pringArr(Canvas canvas, Size size) {
|
||||||
/// Use complex path.
|
/// Use complex path.
|
||||||
path = Path();
|
path = Path();
|
||||||
path.moveTo(size.width * 0.25, size.height * 0.3);
|
path.moveTo(size.width * 0.25, size.height * 0.3);
|
||||||
path.relativeCubicTo(0, 0, size.width * 0.25, 50, size.width * 0.5, 50);
|
path.relativeCubicTo(0, 0, size.width * 0.25, 0, size.width * 0.5, 50);
|
||||||
path.relativeCubicTo(0, 0, -size.width * 0.25, 0, -size.width * 0.5, 50);
|
path.relativeCubicTo(0, 0, -size.width * 0.25, 50, -size.width * 0.5, 50);
|
||||||
path.relativeCubicTo(0, 0, size.width * 0.125, 10, size.width * 0.25, -10);
|
//path.relativeCubicTo(0, 0, size.width * 0.125, 10, size.width * 0.25, -10);
|
||||||
path = ArrowPath.make(path: path, isDoubleSided: true);
|
path = ArrowPath.make(path: path, isDoubleSided: true);
|
||||||
canvas.drawPath(path, paint..color = Colors.blue);
|
canvas.drawPath(path, paint..color = Colors.blue);
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ Graphs getGraph() {
|
||||||
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, false);
|
return Graphs.fromList("1", d, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
class DrawingPage extends StatefulWidget {
|
class DrawingPage extends StatefulWidget {
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
1
|
||||||
|
Ориентированный
|
||||||
|
Взвешенный
|
||||||
|
1: 2|5 5|4
|
||||||
|
2:
|
||||||
|
3: 5|4
|
||||||
|
4: 6|5
|
||||||
|
5: 2|4
|
||||||
|
6: 5|4 2|5 1|5
|
||||||
|
7: 2|5
|
||||||
|
END
|
Loading…
Reference in New Issue