1
+ @page " /symbolPalette/showTooltip"
2
+
3
+ @using Syncfusion .Blazor .Diagram
4
+ @using Syncfusion .Blazor .Diagram .SymbolPalette
5
+ @using Syncfusion .Blazor .Popups
6
+ @using Syncfusion .Blazor .Buttons
7
+
8
+ <div style =" display :flex ;gap :20px ;" >
9
+ <div style =" width :20% " >
10
+ <div >
11
+ <SfCheckBox @bind-Checked =" showTooltip" Label =" Show Symbol ID as Tooltip" TChecked =" bool" >
12
+ </SfCheckBox >
13
+ </div >
14
+ <div id =" palette-space" class =" sb-mobile-palette" style =" border : 2px solid #b200ff " >
15
+ <SfSymbolPaletteComponent @ref =" symbolPalette" Height =" 1000px" Width =" 300px" GetSymbolInfo =" GetSymbolInfo" Palettes =" Palettes" SymbolHeight =" 60"
16
+ SymbolWidth =" 60" SymbolMargin =" symbolMargin" >
17
+ </SfSymbolPaletteComponent >
18
+ </div >
19
+ </div >
20
+ <div >
21
+ <SfDiagramComponent @ref =" diagram" Height =" 1000px" Width =" 1000px" />
22
+ </div >
23
+ </div >
24
+
25
+ @code {
26
+ // Controls tooltip visibility for symbols at runtime.
27
+ private bool showTooltip = false ;
28
+ private SfSymbolPaletteComponent ? symbolPalette ;
29
+ private SfDiagramComponent ? diagram ;
30
+ private SymbolMargin symbolMargin = new SymbolMargin ()
31
+ {
32
+ Left = 15 ,
33
+ Right = 15 ,
34
+ Top = 15 ,
35
+ Bottom = 15
36
+ };
37
+
38
+ public DiagramObjectCollection <Palette > Palettes { get ; set ; } = new DiagramObjectCollection <Palette >();
39
+ public DiagramObjectCollection <NodeBase > FlowShapesPalette { get ; set ; } = new DiagramObjectCollection <NodeBase >();
40
+ public DiagramObjectCollection <NodeBase > BasicShapesPalette { get ; set ; } = new DiagramObjectCollection <NodeBase >();
41
+ public DiagramObjectCollection <NodeBase > ConnectorsPalette { get ; set ; } = new DiagramObjectCollection <NodeBase >();
42
+
43
+ protected override void OnInitialized ()
44
+ {
45
+ // Initialize all palette models with predefined shapes.
46
+ InitPaletteModel ();
47
+ }
48
+
49
+ protected override async Task OnAfterRenderAsync (bool firstRender )
50
+ {
51
+ if (firstRender && symbolPalette != null && diagram != null )
52
+ {
53
+ // Set diagram as drag-drop target for symbol palette.
54
+ symbolPalette .Targets = new DiagramObjectCollection <SfDiagramComponent > { diagram };
55
+ }
56
+ }
57
+
58
+ // Configures symbol tooltip display based on checkbox state.
59
+ private SymbolInfo GetSymbolInfo (IDiagramObject symbol )
60
+ {
61
+ // Enable/disable tooltip display based on user preference at runtime.
62
+ return new SymbolInfo { ShowTooltip = showTooltip };
63
+ }
64
+
65
+ private void InitPaletteModel ()
66
+ {
67
+ // Add flow shapes to palette.
68
+ AddFlowShape (NodeFlowShapes .Terminator , " Terminator" , 0 );
69
+ AddFlowShape (NodeFlowShapes .Decision , " Decision" , 1 );
70
+ AddFlowShape (NodeFlowShapes .Process , " Process" , 2 );
71
+ AddFlowShape (NodeFlowShapes .Document , " Document" , 3 );
72
+
73
+ // Add basic shapes to palette.
74
+ AddBasicShape (NodeBasicShapes .Rectangle , " Rectangle" , 0 );
75
+ AddBasicShape (NodeBasicShapes .Ellipse , " Ellipse" , 1 );
76
+ AddBasicShape (NodeBasicShapes .Pentagon , " Pentagon" , 2 );
77
+ AddBasicShape (NodeBasicShapes .Hexagon , " Hexagon" , 3 );
78
+
79
+ // Add connectors to palette.
80
+ AddConnector (" Orthogonal" , ConnectorSegmentType .Orthogonal , DecoratorShape .Arrow , 0 );
81
+ AddConnector (" Straight" , ConnectorSegmentType .Straight , DecoratorShape .Arrow , 1 );
82
+ AddConnector (" Bezier" , ConnectorSegmentType .Bezier , DecoratorShape .Arrow , 2 );
83
+ AddConnector (" StraightOpp" , ConnectorSegmentType .Straight , DecoratorShape .None , 3 );
84
+
85
+ // Create palette collection with all shape categories.
86
+ Palettes = new DiagramObjectCollection <Palette >
87
+ {
88
+ new Palette { Symbols = FlowShapesPalette , Title = " Flow Shapes" , ID = " FlowShapes" , IsExpanded = true },
89
+ new Palette { Symbols = BasicShapesPalette , Title = " Basic Shapes" , ID = " BasicShapes" , IsExpanded = true },
90
+ new Palette { Symbols = ConnectorsPalette , Title = " Connectors" , ID = " Connectors" , IsExpanded = true }
91
+ };
92
+ }
93
+
94
+ private void AddFlowShape (NodeFlowShapes shape , string id , int index )
95
+ {
96
+ var node = new Node
97
+ {
98
+ ID = id ,
99
+ Shape = new FlowShape { Type = NodeShapes .Flow , Shape = shape },
100
+ Width = 60 ,
101
+ Height = 60 ,
102
+ Style = new ShapeStyle { Fill = " #6495ED" , StrokeColor = " #6495ED" },
103
+ Constraints = NodeConstraints .Default | NodeConstraints .Tooltip
104
+ };
105
+ // Add tooltip for even-indexed shapes only.
106
+ if (index % 2 == 0 )
107
+ {
108
+ node .Tooltip = new DiagramTooltip
109
+ {
110
+ Content = $" This is {id } (Flow)" ,
111
+ ShowTipPointer = true ,
112
+ Position = Position .RightCenter
113
+ };
114
+ }
115
+ FlowShapesPalette .Add (node );
116
+ }
117
+
118
+ private void AddBasicShape (NodeBasicShapes shapeType , string id , int index )
119
+ {
120
+ var node = new Node
121
+ {
122
+ ID = id ,
123
+ Width = 60 ,
124
+ Height = 60 ,
125
+ Shape = new BasicShape
126
+ {
127
+ Type = NodeShapes .Basic ,
128
+ Shape = shapeType ,
129
+ CornerRadius = 10 // Rounded corners for visual appeal.
130
+ },
131
+ Style = new ShapeStyle { Fill = " #9CCC65" , StrokeColor = " #558B2F" },
132
+ Constraints = NodeConstraints .Default | NodeConstraints .Tooltip
133
+ };
134
+ // Add tooltip for even-indexed shapes only.
135
+ if (index % 2 == 0 )
136
+ {
137
+ node .Tooltip = new DiagramTooltip
138
+ {
139
+ Content = $" This is {id } (Basic)" ,
140
+ ShowTipPointer = true ,
141
+ Position = Position .RightCenter
142
+ };
143
+ }
144
+ BasicShapesPalette .Add (node );
145
+ }
146
+
147
+ private void AddConnector (string id , ConnectorSegmentType type , DecoratorShape decoratorShape , int index )
148
+ {
149
+ var connector = new Connector
150
+ {
151
+ ID = id ,
152
+ Type = type ,
153
+ SourcePoint = new DiagramPoint { X = 0 , Y = 0 },
154
+ TargetPoint = new DiagramPoint { X = 60 , Y = 60 },
155
+ Style = new ShapeStyle { StrokeWidth = 2 , StrokeColor = " #757575" },
156
+ TargetDecorator = new DecoratorSettings
157
+ {
158
+ Shape = decoratorShape ,
159
+ Style = new ShapeStyle { StrokeColor = " #757575" , Fill = " #757575" }
160
+ },
161
+ Constraints = ConnectorConstraints .Default | ConnectorConstraints .Tooltip
162
+ };
163
+ // Add tooltip for even-indexed connectors only.
164
+ if (index % 2 == 0 )
165
+ {
166
+ connector .Tooltip = new DiagramTooltip
167
+ {
168
+ Content = $" This is {id } (Connector)" ,
169
+ Position = Position .RightCenter ,
170
+ ShowTipPointer = true
171
+ };
172
+ }
173
+ ConnectorsPalette .Add (connector );
174
+ }
175
+ }
0 commit comments