forked from jgraph/mxgraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmxGraphView.php
More file actions
1422 lines (1242 loc) · 34.5 KB
/
mxGraphView.php
File metadata and controls
1422 lines (1242 loc) · 34.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Copyright (c) 2006-2013, Gaudenz Alder
*/
class mxGraphView extends mxEventSource
{
/**
* Class: mxGraphView
*
* Implements a view for the graph. Fires scale and translate events
* if one of the values change.
*
* This class fires the following events:
*
* mxEvent.SCALE fires after the scale was changed in setScale. The
* <code>scale</code> and <code>previousScale</code> arguments contain the
* new and previous scale.
*
* mxEvent.TRANSLATE fires after the translate was changed in setTranslate. The
* <code>translate</code> and <code>previousTranslate</code> arguments contain
* the new and previous value for translate.
*
* Variable: EMPTY_POINT
*
* An empty <mxPoint> instance.
*/
var $EMPTY_POINT;
/**
* Variable: graph
*
* Holds the <mxGraph>.
*/
var $graph;
/**
* Variable: graphBounds
*
* Holds the bounds of the current view.
*/
var $graphBounds;
/**
* Variable: scale
*
* Holds the current scale.
*/
var $scale = 1;
/**
* Variable: translate
*
* Holds the current translate.
*/
var $translate;
/**
* Variable: states
*
* Maps from cells to states.
*/
var $states = array();
/**
* Constructor: mxGraphView
*
* Constructs a new view for the specified <mxGraph>.
*/
function mxGraphView($graph)
{
$this->EMPTY_POINT = new mxPoint();
$this->graph = $graph;
$this->translate = new mxPoint();
$this->graphBounds = new mxRectangle();
}
/**
* Function: setScale
*
* Sets the scale, revalidates the view and fires
* a scale event.
*/
function setScale($scale)
{
$previous = $this->scale;
if ($this->scale != $scale)
{
$this->scale = $scale;
$this->revalidate();
}
$this->fireEvent(new mxEventObject(mxEvent::$SCALE, "scale", $scale, "previousScale", $previous));
}
/**
* Function: setTranslate
*
* Sets the translation, revalidates the view and
* fires a translate event.
*/
function setTranslate($translate)
{
$previous = $this->translate;
if ($this->translate->x != $translate->x ||
$this->translate->y != $translate->y)
{
$this->translate = $translate;
$this->revalidate();
}
$this->fireEvent(new mxEventObject(mxEvent::$TRANSLATE, "translate", $translate, "previousTranslate", $previous));
}
/**
* Function: getGraphBounds
*
* Returns <graphBounds>.
*/
function getGraphBounds()
{
return $this->graphBounds;
}
/**
* Function: setGraphBounds
*
* Sets <graphBounds>.
*/
function setGraphBounds($value)
{
$this->graphBounds = $value;
}
/**
* Function: getBounds
*
* Returns the bounding for for an array of cells or null, if no cells are
* specified.
*/
function getBounds($cells, $boundingBox = false)
{
$cellCount = sizeof($cells);
$result = null;
if ($cellCount > 0)
{
$model = $this->graph->getModel();
for ($i = 0; $i < $cellCount; $i++)
{
if ($model->isVertex($cells[$i]) || $model->isEdge($cells[$i]))
{
$state = $this->getState($cells[$i]);
if ($state != null)
{
$bounds = ($boundingBox) ? $state->boundingBox : $state;
if ($bounds != null)
{
if ($result == null)
{
$result = new mxRectangle($bounds->x, $bounds->y,
$bounds->width, $bounds->height);
}
else
{
$result->add($bounds);
}
}
}
}
}
}
return $result;
}
/**
* Function: invalidate
*/
function revalidate()
{
$this->invalidate();
$this->validate();
}
/**
* Function: invalidate
*
* Invalidates the cached cell states.
*/
function invalidate()
{
// LATER: Invalidate cell states recursively
$this->states = array();
}
/**
* Function: validate
*
* Calls <validateCell> and <validateCellState> and updates the <graphBounds>
* using <getBoundingBox>. Finally the background is validated using
* <validateBackground>.
*
* Parameters:
*
* cell - Optional <mxCell> to be used as the root of the validation.
* Default is the root of the model.
*/
function validate($cell = null)
{
// Checks if cache is invalid
if (sizeof($this->states) == 0)
{
$graphBounds = $this->getBoundingBox($this->validateCellState(
$this->validateCell(($cell != null) ? $cell : $this->graph->model->root)));
$this->setGraphBounds(isset($graphBounds) ? $graphBounds : new mxRectangle());
}
}
/**
* Function: getBoundingBox
*
* Returns the bounding box of the shape and the label for the given
* <mxCellState> and its children if recurse is true.
*
* Parameters:
*
* state - <mxCellState> whose bounding box should be returned.
* recurse - Optional boolean indicating if the children should be included.
* Default is true.
*/
function getBoundingBox($state, $recurse = true)
{
$bbox = null;
if ($state != null)
{
if ($state->boundingBox != null)
{
$bbox = $state->boundingBox->copy();
}
if ($recurse)
{
$model = $this->graph->getModel();
$childCount = $model->getChildCount($state->cell);
for ($i = 0; $i < $childCount; $i++)
{
$bounds = $this->getBoundingBox($this->getState($model->getChildAt($state->cell, $i)));
if ($bounds != null)
{
if ($bbox == null)
{
$bbox = $bounds;
}
else
{
$bbox->add($bounds);
}
}
}
}
}
return $bbox;
}
/**
* Function: validateCell
*
* Recursively creates the cell state for the given cell if visible is true and
* the given cell is visible. If the cell is not visible but the state exists
* then it is removed using <removeState>.
*
* Parameters:
*
* cell - <mxCell> whose <mxCellState> should be created.
* visible - Optional boolean indicating if the cell should be visible. Default
* is true.
*/
function validateCell($cell, $visible = true)
{
if ($cell != null)
{
$visible = $visible && $this->graph->isCellVisible($cell);
$state = $this->getState($cell, $visible);
if ($state != null && !$visible)
{
$this->removeState($cell);
}
else
{
$model = $this->graph->getModel();
$childCount = $model->getChildCount($cell);
for ($i = 0; $i < $childCount; $i++)
{
$this->validateCell($model->getChildAt($cell, $i), $visible &&
!$this->graph->isCellCollapsed($cell));
}
}
}
return $cell;
}
/**
* Function: validateCellStates
*
* Validates and repaints the <mxCellState> for the given <mxCell>.
*
* Parameters:
*
* cell - <mxCell> whose <mxCellState> should be validated.
* recurse - Optional boolean indicating if the children of the cell should be
* validated. Default is true.
*/
function validateCellState($cell, $recurse = true)
{
$state = null;
if ($cell != null)
{
$state = $this->getState($cell);
if ($state != null)
{
$model = $this->graph->getModel();
if ($state->invalid)
{
$state->invalid = false;
$this->validateCellState($model->getParent($cell), false);
$source = $this->validateCellState($this->getVisibleTerminal($cell, true), false);
$target = $this->validateCellState($this->getVisibleTerminal($cell, false), false);
$this->updateCellState($state, $source, $target);
if ($model->isEdge($cell) || $model->isVertex($cell))
{
$this->updateLabelBounds($state);
$this->updateBoundingBox($state);
}
}
if ($recurse)
{
$childCount = $model->getChildCount($cell);
for ($i = 0; $i < $childCount; $i++)
{
$this->validateCellState($model->getChildAt($cell, $i));
}
}
}
}
return $state;
}
/**
* Function: updateCellState
*
* Updates the given <mxCellState>.
*
* Parameters:
*
* state - <mxCellState> to be updated.
* source - <mxCellState> that represents the visible source.
* target - <mxCellState> that represents the visible target.
*/
function updateCellState($state, $source, $target)
{
$state->absoluteOffset->x = 0;
$state->absoluteOffset->y = 0;
$state->origin->x = 0;
$state->origin->y = 0;
$state->length = 0;
$model = $this->graph->getModel();
$pState = $this->getState($model->getParent($state->cell));
if ($pState != null)
{
$state->origin->x += $pState->origin->x;
$state->origin->y += $pState->origin->y;
}
$offset = $this->graph->getChildOffsetForCell($state->cell);
if ($offset != null)
{
$state->origin->x += $offset->x;
$state->origin->y += $offset->y;
}
$geo = $this->graph->getCellGeometry($state->cell);
if ($geo != null)
{
if (!$model->isEdge($state->cell))
{
$offset = $geo->offset;
if ($offset == null)
{
$offset = $this->EMPTY_POINT;
}
if ($geo->relative && $pState != null)
{
if ($model->isEdge($pState->cell))
{
$origin = $this->getPoint($pState, $geo);
if ($origin != null)
{
$state->origin->x += ($origin->x / $this->scale) - $pState->origin->x - $this->translate->x;
$state->origin->y += ($origin->y / $this->scale) - $pState->origin->y - $this->translate->y;
}
}
else
{
$state->origin->x += $geo->x * $pState->width / $this->scale + $offset->x;
$state->origin->y += $geo->y * $pState->height / $this->scale + $offset->y;
}
}
else
{
$state->absoluteOffset->x = $this->scale * $offset->x;
$state->absoluteOffset->y = $this->scale * $offset->y;
$state->origin->x += $geo->x;
$state->origin->y += $geo->y;
}
}
$state->x = $this->scale * ($this->translate->x + $state->origin->x);
$state->y = $this->scale * ($this->translate->y + $state->origin->y);
$state->width = $this->scale * $geo->width;
$state->height = $this->scale * $geo->height;
if ($model->isVertex($state->cell))
{
$this->updateVertexState($state, $geo);
}
if ($model->isEdge($state->cell))
{
$this->updateEdgeState($state, $geo, $source, $target);
}
}
}
/**
* Function: updateVertexState
*
* Validates the given cell state.
*/
function updateVertexState($state, $geo)
{
// LATER: Add support for rotation
$this->updateVertexLabelOffset($state);
}
/**
* Function: updateEdgeState
*
* Validates the given cell state.
*/
function updateEdgeState($state, $geo, $source, $target)
{
// This will remove edges with no terminals and no terminal points
// as such edges are invalid and produce NPEs in the edge styles.
// Also removes connected edges that have no visible terminals.
if (($this->graph->model->getTerminal($state->cell, true) != null && $source == null) ||
($source == null && $geo->getTerminalPoint(true) == null) ||
($this->graph->model->getTerminal($state->cell, false) != null && $target == null) ||
($target == null && $geo->getTerminalPoint(false) == null))
{
$this->removeState($state->cell, true);
}
else
{
$this->updateFixedTerminalPoints($state, $source, $target);
$this->updatePoints($state, $geo->points, $source, $target);
$this->updateFloatingTerminalPoints($state, $source, $target);
$pts = $state->absolutePoints;
if ($pts == null || sizeof($pts) < 1 || $pts[0] == null || $pts[sizeof($pts) - 1] == null)
{
// This will remove edges with invalid points from the list of states in the view.
// Happens if the one of the terminals and the corresponding terminal point is null.
$this->removeState($state->cell, true);
}
else
{
$this->updateEdgeBounds($state);
$state->absoluteOffset = $this->getPoint($state, $geo);
}
}
}
/**
* Function: updateVertexLabelOffset
*
* Updates the absoluteOffset of the given vertex cell state. This takes
* into account the label position styles.
*
* Parameters:
*
* state - <mxCellState> whose absolute offset should be updated.
*/
function updateVertexLabelOffset($state)
{
$horizontal = mxUtils::getValue($state->style,
mxConstants::$STYLE_LABEL_POSITION,
mxConstants::$ALIGN_CENTER);
if ($horizontal == mxConstants::$ALIGN_LEFT)
{
$state->absoluteOffset->x -= $state->width;
}
else if ($horizontal == mxConstants::$ALIGN_RIGHT)
{
$state->absoluteOffset->x += $state->width;
}
$vertical = mxUtils::getValue($state->style,
mxConstants::$STYLE_VERTICAL_LABEL_POSITION,
mxConstants::$ALIGN_MIDDLE);
if ($vertical == mxConstants::$ALIGN_TOP)
{
$state->absoluteOffset->y -= $state->height;
}
else if ($vertical == mxConstants::$ALIGN_BOTTOM)
{
$state->absoluteOffset->y += $state->height;
}
}
/**
* Function: updateLabelBounds
*
* Updates the label bounds in the given state.
*/
function updateLabelBounds($state)
{
$cell = $state->cell;
$style = $state->style;
if (mxUtils::getValue($style, mxConstants::$STYLE_OVERFLOW) == "fill")
{
$state->labelBounds = new mxRectangle($state->x, $state->y, $state->width, $state->height);
}
else
{
$label = $this->graph->getLabel($cell);
$vertexBounds = (!$this->graph->model->isEdge($cell)) ? $state : null;
$state->labelBounds = mxUtils::getLabelPaintBounds($label, $style,
false, $state->absoluteOffset, $vertexBounds, $this->scale);
}
}
/**
* Function: updateBoundingBox
*
* Updates the bounding box in the given cell state.
*/
function updateBoundingBox($state)
{
// Gets the cell bounds and adds shadows and markers
$rect = new mxRectangle($state->x, $state->y, $state->width, $state->height);
$style = $state->style;
// Adds extra pixels for the marker and stroke assuming
// that the border stroke is centered around the bounds
// and the first pixel is drawn inside the bounds
$strokeWidth = max(1, mxUtils::getNumber($style,
mxConstants::$STYLE_STROKEWIDTH, 1) * $this->scale);
$strokeWidth -= max(1, $strokeWidth / 2);
if ($this->graph->model->isEdge($state->cell))
{
$ms = 0;
if (isset($style[mxConstants::$STYLE_ENDARROW])
|| isset($style[mxConstants::$STYLE_STARTARROW]))
{
$ms = round(mxConstants::$DEFAULT_MARKERSIZE * $this->scale);
}
// Adds the strokewidth
$rect->grow($ms + $strokeWidth);
// Adds worst case border for an arrow shape
if (mxUtils::getValue($style, mxConstants::$STYLE_SHAPE) ==
mxConstants::$SHAPE_ARROW)
{
$rect->grow(mxConstants::$ARROW_WIDTH / 2);
}
}
else
{
$rect->grow($strokeWidth);
}
// Adds extra pixels for the shadow
if (mxUtils::getValue($style, mxConstants::$STYLE_SHADOW, false) == true)
{
$rect->width += mxConstants::$SHADOW_OFFSETX;
$rect->height += mxConstants::$SHADOW_OFFSETY;
}
// Adds oversize images in labels
if (mxUtils::getValue($style, mxConstants::$STYLE_SHAPE) ==
mxConstants::$SHAPE_LABEL)
{
if (mxUtils::getValue($style, mxConstants::$STYLE_IMAGE) != null)
{
$w = mxUtils::$getValue($style,
mxConstants::$STYLE_IMAGE_WIDTH,
mxConstants::$DEFAULT_IMAGESIZE) * $this->scale;
$h = mxUtils::$getValue($style,
mxConstants::$STYLE_IMAGE_HEIGHT,
mxConstants::$DEFAULT_IMAGESIZE) * $this->scale;
$x = $state->x;
$y = 0;
$imgAlign = mxUtils::getValue($style, mxConstants::$STYLE_IMAGE_ALIGN,
mxConstants::$ALIGN_CENTER);
$imgValign = mxUtils::getValue(style,
mxConstants::$STYLE_IMAGE_VERTICAL_ALIGN,
mxConstants::$ALIGN_MIDDLE);
if ($imgAlign == mxConstants::$ALIGN_RIGHT)
{
$x += $state->width - $w;
}
else if ($imgAlign == mxConstants::$ALIGN_CENTER)
{
$x += ($state->width - $w) / 2;
}
if ($imgValign == mxConstants::$ALIGN_TOP)
{
$y = $state->y;
}
else if ($imgValign == mxConstants::$ALIGN_BOTTOM)
{
$y = $state->y + $state->height - $h;
}
else
{
$y = $state->y + ($state->height - $h) / 2;
}
$rect->add(new mxRectangle($x, $y, $w, $h));
}
}
// No need to add rotated rectangle bounds here because
// GD does not support rotation
// Unifies the cell bounds and the label bounds
$rect->add($state->labelBounds);
$state->boundingBox = $rect;
return $rect;
}
/**
* Function: updateFixedTerminalPoints
*
* Sets the initial absolute terminal points in the given state before the edge
* style is computed.
*
* Parameters:
*
* edge - <mxCellState> whose initial terminal points should be updated.
* source - <mxCellState> which represents the source terminal.
* target - <mxCellState> which represents the target terminal.
*/
function updateFixedTerminalPoints($edge, $source, $target)
{
$this->updateFixedTerminalPoint($edge, $source, true,
$this->graph->getConnectionConstraint($edge, $source, true));
$this->updateFixedTerminalPoint($edge, $target, false,
$this->graph->getConnectionConstraint($edge, $target, false));
}
/**
* Function: updateFixedTerminalPoint
*
* Sets the fixed source or target terminal point on the given edge.
*
* Parameters:
*
* edge - <mxCellState> whose terminal point should be updated.
* terminal - <mxCellState> which represents the actual terminal.
* source - Boolean that specifies if the terminal is the source.
* constraint - <mxConnectionConstraint> that specifies the connection.
*/
function updateFixedTerminalPoint($edge, $terminal, $source, $constraint)
{
$pt = null;
if (isset($constraint))
{
$pt = $this->graph->getConnectionPoint($terminal, $constraint);
}
if (!isset($pt) && !isset($terminal))
{
$s = $this->scale;
$tr = $this->translate;
$orig = $edge->origin;
$geo = $this->graph->getCellGeometry($edge->cell);
$pt = $geo->getTerminalPoint($source);
if (isset($pt))
{
$pt = new mxPoint($s * ($tr->x + $pt->x + $orig->x),
$s * ($tr->y + $pt->y + $orig->y));
}
}
if (!is_array($edge->absolutePoints))
{
$edge->absolutePoints = array();
}
$n = sizeof($edge->absolutePoints);
if ($source)
{
if ($n > 0)
{
$state->absolutePoints[0] = $pt;
}
else
{
array_push($edge->absolutePoints, $pt);
}
}
else
{
$n = sizeof($edge->absolutePoints);
if ($n > 1)
{
$edge->absolutePoints[$n - 1] = $pt;
}
else
{
array_push($edge->absolutePoints, $pt);
}
}
}
/**
* Function: updatePoints
*
* Updates the absolute points in the given state using the specified array
* of <mxPoints> as the relative points.
*
* Parameters:
*
* edge - <mxCellState> whose absolute points should be updated.
* points - Array of <mxPoints> that constitute the relative points.
* source - <mxCellState> that represents the source terminal.
* target - <mxCellState> that represents the target terminal.
*/
function updatePoints($edge, $points, $source, $target)
{
if (isset($edge))
{
$pts = array();
array_push($pts, $edge->absolutePoints[0]);
$edgeStyle = $this->getEdgeStyle($edge, $points, $source, $target);
if (isset($edgeStyle))
{
$src = $this->getTerminalPort($edge, $source, true);
$trg = $this->getTerminalPort($edge, $target, false);
$edgeStyle->apply($edge, $src, $trg, $points, $pts);
}
else if (isset($points))
{
for ($i = 0; $i < sizeof($points); $i++)
{
if (isset($points[$i]))
{
$pt = $points[$i]->copy();
array_push($pts, $this->transformControlPoint($edge, $pt));
}
}
}
$n = sizeof($edge->absolutePoints);
array_push($pts, $edge->absolutePoints[$n-1]);
$edge->absolutePoints = $pts;
}
}
/**
* Function: transformControlPoint
*
* Transforms the given control point to an absolute point.
*/
function transformControlPoint($state, $pt)
{
$orig = $state->origin;
return new mxPoint($this->scale * ($pt->x + $this->translate->x + $orig->x),
$this->scale * ($pt->y + $this->translate->y + $orig->y));
}
/**
* Function: getEdgeStyle
*
* Returns the edge style function to be used to render the given edge
* state.
*/
function getEdgeStyle($edge, $points, $source, $target)
{
$edgeStyle = null;
if (isset($source) && $source === $target)
{
$edgeStyle = mxUtils::getValue($edge->style, mxConstants::$STYLE_LOOP);
if (!isset($edgeStyle))
{
$edgeStyle = $this->graph->defaultLoopStyle;
}
}
else if (!mxUtils::getValue($edge->style, mxConstants::$STYLE_NOEDGESTYLE, false))
{
$edgeStyle = mxUtils::getValue($edge->style, mxConstants::$STYLE_EDGE);
}
// Converts string values to objects
if (is_string($edgeStyle))
{
$tmp = mxStyleRegistry::getValue($edgeStyle);
if ($tmp == null && strpos($edgeStyle, ".") !== false)
{
$tmp = mxUtils::evaluate($edgeStyle);
}
$edgeStyle = $tmp;
}
if ($edgeStyle instanceof mxEdgeStyleFunction)
{
return $edgeStyle;
}
return null;
}
/**
* Function: updateFloatingTerminalPoints
*
* Updates the terminal points in the given state after the edge style was
* computed for the edge.
*
* Parameters:
*
* state - <mxCellState> whose terminal points should be updated.
* source - <mxCellState> that represents the source terminal.
* target - <mxCellState> that represents the target terminal.
*/
function updateFloatingTerminalPoints($state, $source, $target)
{
$pts = $state->absolutePoints;
$p0 = $pts[0];
$pe = $pts[sizeof($pts) - 1];
if (!isset($pe) && isset($target))
{
$this->updateFloatingTerminalPoint($state, $target, $source, false);
}
if (!isset($p0) && isset($source))
{
$this->updateFloatingTerminalPoint($state, $source, $target, true);
}
}
/**
* Function: updateFloatingTerminalPoint
*
* Updates the absolute terminal point in the given state for the given
* start and end state, where start is the source if source is true.
*
* Parameters:
*
* edge - <mxCellState> whose terminal point should be updated.
* start - <mxCellState> for the terminal on "this" side of the edge.
* end - <mxCellState> for the terminal on the other side of the edge.
* source - Boolean indicating if start is the source terminal state.
*/
function updateFloatingTerminalPoint($edge, $start, $end, $source)
{
$start = $this->getTerminalPort($edge, $start, $source);
$next = $this->getNextPoint($edge, $end, $source);
$border = mxUtils::getNumber($edge->style, mxConstants::$STYLE_PERIMETER_SPACING);
$border = mxUtils::getNumber($edge->style, ($source) ?
mxConstants::$STYLE_SOURCE_PERIMETER_SPACING :
mxConstants::$STYLE_TARGET_PERIMETER_SPACING);
$pt = $this->getPerimeterPoint($start, $next, $this->graph->isOrthogonal($edge), $border);
$index = ($source) ? 0 : sizeof($edge->absolutePoints) - 1;
$edge->absolutePoints[$index] = $pt;
}
/**
* Function: getTerminalPort
*
* Returns an <mxCellState> that represents the source or target terminal or
* port for the given edge.
*
* Parameters:
*
* state - <mxCellState> that represents the state of the edge.
* terminal - <mxCellState> that represents the terminal.
* source - Boolean indicating if the given terminal is the source terminal.
*/
function getTerminalPort($state, $terminal, $source)
{
$key = ($source) ? mxConstants::$STYLE_SOURCE_PORT
: mxConstants::$STYLE_TARGET_PORT;
$id = mxUtils::getValue($state->style, $key);
if ($id != null)
{
$tmp = $this->getState($this->graph->model->getCell($id));
// Only uses ports where a cell state exists
if (isset($tmp))
{
$terminal = $tmp;
}
}
return $terminal;
}
/**
* Function: getPerimeterPoint
*
* Returns an <mxPoint> that defines the location of the intersection point between
* the perimeter and the line between the center of the shape and the given point.
*
* Parameters:
*
* terminal - <mxCellState> for the source or target terminal.
* next - <mxPoint> that lies outside of the given terminal.
* orthogonal - Boolean that specifies if the orthogonal projection onto
* the perimeter should be returned. If this is false then the intersection
* of the perimeter and the line between the next and the center point is
* returned.
* border - Optional border between the perimeter and the shape.
*/
function getPerimeterPoint($terminal, $next, $orthogonal, $border = null)
{
$point = null;
if ($terminal != null)
{
$perimeter = $this->getPerimeterFunction($terminal);
if (isset($perimeter) && isset($next))
{
$bounds = $this->getPerimeterBounds($terminal, $border);
if ($bounds->width > 0 || $bounds->height > 0)
{
$point = $perimeter->apply($bounds, $terminal, $next, $orthogonal);
}
}
if (!isset($point))
{
$point = $this->getPoint($terminal);