calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / wizards / source / sfdocuments / SF_Chart.xba
blob0538fb8af7581f51f36750e9612c29ce69cef713
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3 <script:module xmlns:script="http://openoffice.org/2000/script" script:name="SF_Chart" script:language="StarBasic" script:moduleType="normal">REM =======================================================================================================================
4 REM === The ScriptForge library and its associated libraries are part of the LibreOffice project. ===
5 REM === The SFDocuments library is one of the associated libraries. ===
6 REM === Full documentation is available on https://help.libreoffice.org/ ===
7 REM =======================================================================================================================
9 Option Compatible
10 Option ClassModule
12 Option Explicit
14 &apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;
15 &apos;&apos;&apos; SF_Chart
16 &apos;&apos;&apos; ========
17 &apos;&apos;&apos;
18 &apos;&apos;&apos; The SF_Chart module is focused on the description of chart documents
19 &apos;&apos;&apos; stored in Calc sheets.
20 &apos;&apos;&apos; With this service, many chart types and chart characteristics available
21 &apos;&apos;&apos; in the user interface can be read or modified.
22 &apos;&apos;&apos;
23 &apos;&apos;&apos; Definitions
24 &apos;&apos;&apos; Charts have 2 distinct names:
25 &apos;&apos;&apos; - an internal name, given by the LibreOffice application
26 &apos;&apos;&apos; - an optional user-defined name
27 &apos;&apos;&apos; In the scope of the ScriptForge libraries, the chart name is the name given by the user.
28 &apos;&apos;&apos; Only when there is no user name, the internal name may be used instead.
29 &apos;&apos;&apos;
30 &apos;&apos;&apos; Service invocation from the &quot;Calc&quot; service
31 &apos;&apos;&apos; Either make a new chart
32 &apos;&apos;&apos; calc.CreateChart(ChartName, SheetName, &quot;SheetX.A1:C8&quot;)
33 &apos;&apos;&apos; or select an existing one
34 &apos;&apos;&apos; calc.Charts(SheetName, ChartName)
35 &apos;&apos;&apos;
36 &apos;&apos;&apos; Detailed user documentation:
37 &apos;&apos;&apos; https://help.libreoffice.org/latest/en-US/text/sbasic/shared/03/sf_chart.html?DbPAR=BASIC
38 &apos;&apos;&apos;
39 &apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;
41 REM ================================================================== EXCEPTIONS
43 Private Const CHARTEXPORTERROR = &quot;CHARTEXPORTERROR&quot;
45 REM ============================================================= PRIVATE MEMBERS
47 Private [Me] As Object
48 Private [_Parent] As Object &apos; Parent Calc document
49 Private ObjectType As String &apos; Must be CHART
50 Private ServiceName As String
52 &apos; Chart description
53 Private _SheetName As String &apos; Name of the Calc sheet containing the chart
54 Private _DrawIndex As Long &apos; Index of the chart in the sheet&apos;s draw page
55 Private _ChartName As String &apos; User name
56 Private _PersistentName As String &apos; Internal name
57 Private _Shape As Object &apos; com.sun.star.drawing.XShape
58 Private _Chart As Object &apos; com.sun.star.table.XTableChart
59 Private _ChartObject As Object &apos; com.sun.star.lang.XComponent - ScChartObj
60 Private _Diagram As Object &apos; com.sun.star.chart.XDiagram
62 REM ============================================================ MODULE CONSTANTS
65 REM ====================================================== CONSTRUCTOR/DESTRUCTOR
67 REM -----------------------------------------------------------------------------
68 Private Sub Class_Initialize()
69 Set [Me] = Nothing
70 Set [_Parent] = Nothing
71 ObjectType = &quot;CHART&quot;
72 ServiceName = &quot;SFDocuments.Chart&quot;
73 _SheetName = &quot;&quot;
74 _DrawIndex = -1
75 _ChartName = &quot;&quot;
76 _PersistentName = &quot;&quot;
77 Set _Shape = Nothing
78 Set _Chart = Nothing
79 Set _ChartObject = Nothing
80 Set _Diagram = Nothing
81 End Sub &apos; SFDocuments.SF_Chart Constructor
83 REM -----------------------------------------------------------------------------
84 Private Sub Class_Terminate()
85 Call Class_Initialize()
86 End Sub &apos; SFDocuments.SF_Chart Destructor
88 REM -----------------------------------------------------------------------------
89 Public Function Dispose() As Variant
90 Call Class_Terminate()
91 Set Dispose = Nothing
92 End Function &apos; SFDocuments.SF_Chart Explicit Destructor
94 REM ================================================================== PROPERTIES
96 REM -----------------------------------------------------------------------------
97 Property Get ChartType() As Variant
98 &apos;&apos;&apos; The ChartType property specifies the type of chart as a string among next values:
99 &apos;&apos;&apos; Pie, Bar, Donut, Column, Area, Line, XY, Bubble, Net
100 ChartType = _PropertyGet(&quot;ChartType&quot;)
101 End Property &apos; SFDocuments.SF_Chart.ChartType (get)
103 REM -----------------------------------------------------------------------------
104 Property Let ChartType(Optional ByVal pvChartType As Variant)
105 &apos;&apos;&apos; Set the updatable property ChartType
106 _PropertySet(&quot;ChartType&quot;, pvChartType)
107 End Property &apos; SFDocuments.SF_Chart.ChartType (let)
109 REM -----------------------------------------------------------------------------
110 Property Get Deep() As Variant
111 &apos;&apos;&apos; If True, determines that in a three-dimensional bar chart the bars of each series are arranged behind each other in the z-direction.
112 &apos;&apos;&apos; If False the arrangement of bars is like in two-dimensional bar charts.
113 &apos;&apos;&apos; Bar and Column chart types only
114 Deep = _PropertyGet(&quot;Deep&quot;)
115 End Property &apos; SFDocuments.SF_Chart.Deep (get)
117 REM -----------------------------------------------------------------------------
118 Property Let Deep(Optional ByVal pvDeep As Variant)
119 &apos;&apos;&apos; Set the updatable property Deep
120 _PropertySet(&quot;Deep&quot;, pvDeep)
121 End Property &apos; SFDocuments.SF_Chart.Deep (let)
123 REM -----------------------------------------------------------------------------
124 Property Get Dim3D() As Variant
125 &apos;&apos;&apos; The Dim3D property specifies if the chart is displayed with 3D elements
126 &apos;&apos;&apos; String or Boolean
127 &apos;&apos;&apos; When String, must be 1 of next values: Bar, Cylinder, Cone or Pyramid
128 &apos;&apos;&apos; When Boolean True, Bar is assumed; when False, no 3D to be applied
129 Dim3D = _PropertyGet(&quot;Dim3D&quot;)
130 End Property &apos; SFDocuments.SF_Chart.Dim3D (get)
132 REM -----------------------------------------------------------------------------
133 Property Let Dim3D(Optional ByVal pvDim3D As Variant)
134 &apos;&apos;&apos; Set the updatable property Dim3D
135 _PropertySet(&quot;Dim3D&quot;, pvDim3D)
136 End Property &apos; SFDocuments.SF_Chart.Dim3D (let)
138 REM -----------------------------------------------------------------------------
139 Property Get Exploded() As Variant
140 &apos;&apos;&apos; the offset by which pie segments in a PieDiagram (pie or donut) are dragged outside from the center.
141 &apos;&apos;&apos; This value is given in percent of the radius.
142 Exploded = _PropertyGet(&quot;Exploded&quot;)
143 End Property &apos; SFDocuments.SF_Chart.Exploded (get)_ChartObject
145 REM -----------------------------------------------------------------------------
146 Property Let Exploded(Optional ByVal pvExploded As Variant)
147 &apos;&apos;&apos; Set the updatable property Exploded
148 _PropertySet(&quot;Exploded&quot;, pvExploded)
149 End Property &apos; SFDocuments.SF_Chart.Exploded (let)
151 REM -----------------------------------------------------------------------------
152 Property Get Filled() As Variant
153 &apos;&apos;&apos; When True, the Net diagram is said of FilledNet type
154 &apos;&apos;&apos; Net chart type only
155 Filled = _PropertyGet(&quot;Filled&quot;)
156 End Property &apos; SFDocuments.SF_Chart.Filled (get)
158 REM -----------------------------------------------------------------------------
159 Property Let Filled(Optional ByVal pvFilled As Variant)
160 &apos;&apos;&apos; Set the updatable property Filled
161 _PropertySet(&quot;Filled&quot;, pvFilled)
162 End Property &apos; SFDocuments.SF_Chart.Filled (let)
164 REM -----------------------------------------------------------------------------
165 Property Get Legend() As Variant
166 &apos;&apos;&apos; Specifies if the chart has a legend
167 Legend = _PropertyGet(&quot;Legend&quot;)
168 End Property &apos; SFDocuments.SF_Chart.Legend (get)
170 REM -----------------------------------------------------------------------------
171 Property Let Legend(Optional ByVal pvLegend As Variant)
172 &apos;&apos;&apos; Set the updatable property Legend
173 _PropertySet(&quot;Legend&quot;, pvLegend)
174 End Property &apos; SFDocuments.SF_Chart.Legend (let)
176 REM -----------------------------------------------------------------------------
177 Property Get Percent() As Variant
178 &apos;&apos;&apos; When True, the series of the diagram are stacked and each category sums up to 100%.
179 &apos;&apos;&apos; Area, Bar, Bubble, Column and Net chart types only_ChartObject
180 Percent = _PropertyGet(&quot;Percent&quot;)
181 End Property &apos; SFDocuments.SF_Chart.Percent (get)
183 REM -----------------------------------------------------------------------------
184 Property Let Percent(Optional ByVal pvPercent As Variant)
185 &apos;&apos;&apos; Set the updatable property Percent
186 _PropertySet(&quot;Percent&quot;, pvPercent)
187 End Property &apos; SFDocuments.SF_Chart.Percent (let)
189 REM -----------------------------------------------------------------------------
190 Property Get Stacked() As Variant
191 &apos;&apos;&apos; When True, the series of the diagram are stacked.
192 &apos;&apos;&apos; Area, Bar, Bubble, Column and Net chart types only
193 Stacked = _PropertyGet(&quot;Stacked&quot;)
194 End Property &apos; SFDocuments.SF_Chart.Stacked (get)
196 REM -----------------------------------------------------------------------------
197 Property Let Stacked(Optional ByVal pvStacked As Variant)
198 &apos;&apos;&apos; Set the updatable property Stacked
199 _PropertySet(&quot;Stacked&quot;, pvStacked)
200 End Property &apos; SFDocuments.SF_Chart.Stacked (let)
202 REM -----------------------------------------------------------------------------
203 Property Get Title() As Variant
204 &apos;&apos;&apos; Specifies the main title of the chart
205 Title = _PropertyGet(&quot;Title&quot;)
206 End Property &apos; SFDocuments.SF_Chart.Title (get)
208 REM -----------------------------------------------------------------------------
209 Property Let Title(Optional ByVal pvTitle As Variant)
210 &apos;&apos;&apos; Set the updatable property Title
211 _PropertySet(&quot;Title&quot;, pvTitle)
212 End Property &apos; SFDocuments.SF_Chart.Title (let)
214 REM -----------------------------------------------------------------------------
215 Property Get XTitle() As Variant
216 &apos;&apos;&apos; Specifies the main XTitle of the chart
217 XTitle = _PropertyGet(&quot;XTitle&quot;)
218 End Property &apos; SFDocuments.SF_Chart.XTitle (get)
220 REM -----------------------------------------------------------------------------
221 Property Let XTitle(Optional ByVal pvXTitle As Variant)
222 &apos;&apos;&apos; Set the updatable property XTitle
223 _PropertySet(&quot;XTitle&quot;, pvXTitle)
224 End Property &apos; SFDocuments.SF_Chart.XTitle (let)
226 REM -----------------------------------------------------------------------------
227 Property Get YTitle() As Variant
228 &apos;&apos;&apos; Specifies the main YTitle of the chart
229 YTitle = _PropertyGet(&quot;YTitle&quot;)
230 End Property &apos; SFDocuments.SF_Chart.YTitle (get)
232 REM -----------------------------------------------------------------------------
233 Property Let YTitle(Optional ByVal pvYTitle As Variant)
234 &apos;&apos;&apos; Set the updatable property YTitle
235 _PropertySet(&quot;YTitle&quot;, pvYTitle)
236 End Property &apos; SFDocuments.SF_Chart.YTitle (let)
238 REM -----------------------------------------------------------------------------
239 Property Get XChartObj() As Variant
240 &apos;&apos;&apos; com.sun.star.lang.XComponent - ScChartObj
241 ChartType = _PropertyGet(&quot;XChartObj&quot;)
242 End Property &apos; SFDocuments.SF_Chart.XChartObj (get)
244 REM -----------------------------------------------------------------------------
245 Property Get XDiagram() As Variant
246 &apos;&apos;&apos; com.sun.star.chart.XDiagram
247 ChartType = _PropertyGet(&quot;XDiagram&quot;)
248 End Property &apos; SFDocuments.SF_Chart.XDiagram (get)
250 REM -----------------------------------------------------------------------------
251 Property Get XShape() As Variant
252 &apos;&apos;&apos; com.sun.star.drawing.XShape
253 ChartType = _PropertyGet(&quot;XShape&quot;)
254 End Property &apos; SFDocuments.SF_Chart.XShape (get)
256 REM -----------------------------------------------------------------------------
257 Property Get XTableChart() As Variant
258 &apos;&apos;&apos; com.sun.star.table.XTableChart
259 ChartType = _PropertyGet(&quot;XTableChart&quot;)
260 End Property &apos; SFDocuments.SF_Chart.XTableChart (get)
262 REM ===================================================================== METHODS
264 REM -----------------------------------------------------------------------------
265 Public Function ExportToFile(Optional ByVal FileName As Variant _
266 , Optional ByVal ImageType As Variant _
267 , Optional ByVal Overwrite As Variant _
268 ) As Boolean
269 &apos;&apos;&apos; Store the chart as an image to the given file location
270 &apos;&apos;&apos; Args:
271 &apos;&apos;&apos; FileName: Identifies the file where to save. It must follow the SF_FileSystem.FileNaming notation
272 &apos;&apos;&apos; ImageType: the name of the targeted image type
273 &apos;&apos;&apos; Allowed values: gif, jpeg, png (default), svg and tiff
274 &apos;&apos;&apos; Overwrite: True if the destination file may be overwritten (default = False)
275 &apos;&apos;&apos; Returns:
276 &apos;&apos;&apos; False if the document could not be saved
277 &apos;&apos;&apos; Exceptions:
278 &apos;&apos;&apos; CHARTEXPORTERROR The destination has its readonly attribute set or overwriting rejected
279 &apos;&apos;&apos; Examples:
280 &apos;&apos;&apos; oChart.ExportToFile(&quot;C:\Me\Chart2.gif&quot;, ImageType := &quot;gif&quot;, Overwrite := True)
282 Dim bSaved As Boolean &apos; return value
283 Dim oSfa As Object &apos; com.sun.star.ucb.SimpleFileAccess
284 Dim sFile As String &apos; Alias of FileName
285 Dim vStoreArguments As Variant &apos; Array of com.sun.star.beans.PropertyValue
286 Dim FSO As Object &apos; SF_FileSystem
287 Dim oExport As Object &apos; com.sun.star.drawing.GraphicExportFilter
288 Dim vImageTypes As Variant &apos; Array of permitted image types
289 Dim vMimeTypes As Variant &apos; Array of corresponding mime types in the same order as vImageTypes
291 Const cstImageTypes = &quot;gif,jpeg,png,svg,tiff&quot;
292 Const cstMimeTypes = &quot;image/gif,image/jpeg,image/png,image/svg+xml,image/tiff&quot;
294 Const cstThisSub = &quot;SFDocuments.Chart.ExportToFile&quot;
295 Const cstSubArgs = &quot;FileName, [ImageType=&quot;&quot;png&quot;&quot;|&quot;&quot;gif&quot;&quot;|&quot;&quot;jpeg&quot;&quot;|&quot;&quot;svg&quot;&quot;|&quot;&quot;tiff&quot;&quot;], [Overwrite=False]&quot;
297 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo CatchError
298 bSaved = False
300 Check:
301 If IsMissing(ImageType) Or IsEmpty(ImageType) Then ImageType = &quot;png&quot;
302 If IsMissing(Overwrite) Or IsEmpty(Overwrite) Then Overwrite = False
304 vImageTypes = Split(cstImageTypes, &quot;,&quot;)
305 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
306 If Not [_Parent]._IsStillAlive() Then GoTo Finally
307 If Not ScriptForge.SF_Utils._ValidateFile(FileName, &quot;FileName&quot;) Then GoTo Finally
308 If Not ScriptForge.SF_Utils._Validate(ImageType, &quot;ImageType&quot;, V_STRING, vImageTypes) Then GoTo Finally
309 If Not ScriptForge.SF_Utils._Validate(Overwrite, &quot;Overwrite&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
310 End If
312 &apos; Check destination file overwriting
313 Set FSO = CreateScriptService(&quot;FileSystem&quot;)
314 sFile = FSO._ConvertToUrl(FileName)
315 If FSO.FileExists(FileName) Then
316 If Overwrite = False Then GoTo CatchError
317 Set oSfa = ScriptForge.SF_Utils._GetUNOService(&quot;FileAccess&quot;)
318 If oSfa.isReadonly(sFile) Then GoTo CatchError
319 End If
321 Try:
322 &apos; Setup arguments
323 vMimeTypes = Split(cstMimeTypes, &quot;,&quot;)
324 vStoreArguments = Array( _
325 ScriptForge.SF_Utils._MakePropertyValue(&quot;URL&quot;, sFile) _
326 , ScriptForge.SF_Utils._MakePropertyValue(&quot;MediaType&quot; _
327 , vMimeTypes(ScriptForge.SF_Array.IndexOf(vImageTypes, ImageType, CaseSensitive := False))) _
329 &apos; Export with the com.sun.star.drawing.GraphicExportFilter UNO service
330 Set oExport = ScriptForge.SF_Utils._GetUNOService(&quot;GraphicExportFilter&quot;)
331 With oExport
332 .setSourceDocument(_Shape)
333 .filter(vStoreArguments)
334 End With
335 bSaved = True
337 Finally:
338 ExportToFile = bSaved
339 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
340 Exit Function
341 Catch:
342 GoTo Finally
343 CatchError:
344 ScriptForge.SF_Exception.RaiseFatal(CHARTEXPORTERROR, &quot;FileName&quot;, FileName, &quot;Overwrite&quot;, Overwrite)
345 GoTo Finally
346 End Function &apos; SFDocuments.SF_Chart.ExportToFile
348 REM -----------------------------------------------------------------------------
349 Public Function GetProperty(Optional ByVal PropertyName As Variant) As Variant
350 &apos;&apos;&apos; Return the actual value of the given property
351 &apos;&apos;&apos; Args:
352 &apos;&apos;&apos; PropertyName: the name of the property as a string
353 &apos;&apos;&apos; Returns:
354 &apos;&apos;&apos; The actual value of the property
355 &apos;&apos;&apos; If the property does not exist, returns Null
356 &apos;&apos;&apos; Exceptions:
357 &apos;&apos;&apos; ARGUMENTERROR The property does not exist
359 Const cstThisSub = &quot;SFDocuments.Chart.GetProperty&quot;
360 Const cstSubArgs = &quot;&quot;
362 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
363 GetProperty = Null
365 Check:
366 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
367 If Not SF_Utils._Validate(PropertyName, &quot;PropertyName&quot;, V_STRING, Properties()) Then GoTo Catch
368 End If
370 Try:
371 GetProperty = _PropertyGet(PropertyName)
373 Finally:
374 SF_Utils._ExitFunction(cstThisSub)
375 Exit Function
376 Catch:
377 GoTo Finally
378 End Function &apos; SFDocuments.SF_Chart.GetProperty
380 REM -----------------------------------------------------------------------------
381 Public Function Methods() As Variant
382 &apos;&apos;&apos; Return the list of public methods of the Chart service as an array
384 Methods = Array( _
385 &quot;ExportToFile&quot; _
386 , &quot;Resize&quot; _
389 End Function &apos; SFDocuments.SF_Chart.Methods
391 REM -----------------------------------------------------------------------------
392 Public Function Properties() As Variant
393 &apos;&apos;&apos; Return the list or properties of the Chart class as an array
395 Properties = Array( _
396 &quot;ChartType&quot; _
397 , &quot;Deep&quot; _
398 , &quot;Dim3D&quot; _
399 , &quot;Exploded&quot; _
400 , &quot;Filled&quot; _
401 , &quot;Legend&quot; _
402 , &quot;Percent&quot; _
403 , &quot;Stacked&quot; _
404 , &quot;Title&quot; _
405 , &quot;XChartObj&quot; _
406 , &quot;XDiagram&quot; _
407 , &quot;XShape&quot; _
408 , &quot;XTableChart&quot; _
409 , &quot;XTitle&quot; _
410 , &quot;YTitle&quot; _
413 End Function &apos; SFDocuments.SF_Chart.Properties
415 REM -----------------------------------------------------------------------------
416 Public Function Resize(Optional ByVal XPos As Variant _
417 , Optional ByVal YPos As Variant _
418 , Optional ByVal Width As Variant _
419 , Optional ByVal Height As Variant _
420 ) As Boolean
421 &apos;&apos;&apos; Move the topleft corner of a chart to new coordinates and/or modify its dimensions
422 &apos;&apos;&apos; All distances are expressed in 1/100th mm
423 &apos;&apos;&apos; Args:
424 &apos;&apos;&apos; XPos : the vertical distance from the topleft corner
425 &apos;&apos;&apos; YPos : the horizontal distance from the topleft corner
426 &apos;&apos;&apos; Width : the horizontal width of the shape containing the chart
427 &apos;&apos;&apos; Height : the vertical height of the shape containing the chart
428 &apos;&apos;&apos; Negative or missing arguments are left unchanged
429 &apos;&apos;&apos; Returns:
430 &apos;&apos;&apos; True when successful
431 &apos;&apos;&apos; Examples:
432 &apos;&apos;&apos; oChart.Resize(1000, 2000, Height := 6000) &apos; Width is not changed
434 Dim bResize As Boolean &apos; Return value
435 Dim oPosition As Object &apos; com.sun.star.awt.Point
436 Dim oSize As Object &apos; com.sun.star.awt.Size
437 Const cstThisSub = &quot;SFDocuments.Chart.Resize&quot;
438 Const cstSubArgs = &quot;[XPos], [YPos], [Width], [Height]&quot;
440 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
441 bResize = False
443 Check:
444 If IsMissing(XPos) Or IsEmpty(XPos) Then XPos = -1
445 If IsMissing(YPos) Or IsEmpty(YPos) Then YPos = -1
446 If IsMissing(Height) Or IsEmpty(Height) Then Height = -1
447 If IsMissing(Width) Or IsEmpty(Width) Then Width = -1
448 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
449 If Not [_Parent]._IsStillAlive() Then GoTo Finally
450 If Not ScriptForge.SF_Utils._Validate(XPos, &quot;XPos&quot;, ScriptForge.V_NUMERIC) Then GoTo Finally
451 If Not ScriptForge.SF_Utils._Validate(YPos, &quot;YPos&quot;, ScriptForge.V_NUMERIC) Then GoTo Finally
452 If Not ScriptForge.SF_Utils._Validate(Width, &quot;Width&quot;, ScriptForge.V_NUMERIC) Then GoTo Finally
453 If Not ScriptForge.SF_Utils._Validate(Height, &quot;Height&quot;, ScriptForge.V_NUMERIC) Then GoTo Finally
454 End If
456 Try:
457 With _Shape
458 &apos; Get the current values
459 Set oPosition = .Position
460 Set oSize = .Size
461 &apos; Modify relevant elements
462 If XPos &gt;= 0 Then oPosition.X = CLng(XPos)
463 If YPos &gt;= 0 Then oPosition.Y = CLng(YPos)
464 If Width &gt; 0 Then oSize.Width = CLng(Width)
465 If Height &gt; 0 Then oSize.Height = CLng(Height)
466 &apos; Rewrite
467 .setPosition(oPosition)
468 .setSize(oSize)
469 End With
470 bResize = True
472 Finally:
473 Resize = bResize
474 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
475 Exit Function
476 Catch:
477 GoTo Finally
478 End Function &apos; SF_Documents.SF_Chart.Resize
480 REM -----------------------------------------------------------------------------
481 Public Function SetProperty(Optional ByVal PropertyName As Variant _
482 , Optional ByRef Value As Variant _
483 ) As Boolean
484 &apos;&apos;&apos; Set a new value to the given property
485 &apos;&apos;&apos; Args:
486 &apos;&apos;&apos; PropertyName: the name of the property as a string
487 &apos;&apos;&apos; Value: its new value
488 &apos;&apos;&apos; Exceptions
489 &apos;&apos;&apos; ARGUMENTERROR The property does not exist
491 Const cstThisSub = &quot;SFDocuments.Chart.SetProperty&quot;
492 Const cstSubArgs = &quot;PropertyName, Value&quot;
494 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
495 SetProperty = False
497 Check:
498 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
499 If Not ScriptForge.SF_Utils._Validate(PropertyName, &quot;PropertyName&quot;, V_STRING, Properties()) Then GoTo Catch
500 End If
502 Try:
503 SetProperty = _PropertySet(PropertyName, Value)
505 Finally:
506 SF_Utils._ExitFunction(cstThisSub)
507 Exit Function
508 Catch:
509 GoTo Finally
510 End Function &apos; SFDocuments.SF_Chart.SetProperty
512 REM =========================================================== PRIVATE FUNCTIONS
514 REM -----------------------------------------------------------------------------
515 Private Function _PropertyGet(Optional ByVal psProperty As String) As Variant
516 &apos;&apos;&apos; Return the value of the named property
517 &apos;&apos;&apos; Args:
518 &apos;&apos;&apos; psProperty: the name of the property
520 Static oSession As Object &apos; Alias of SF_Session
521 Dim vData As Variant &apos; Data points array of values
523 Dim cstThisSub As String
524 Const cstSubArgs = &quot;&quot;
526 cstThisSub = &quot;SFDocuments.Chart.get&quot; &amp; psProperty
527 SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
528 If Not [_Parent]._IsStillAlive() Then GoTo Finally
530 If IsNull(oSession) Then Set oSession = ScriptForge.SF_Services.CreateScriptService(&quot;Session&quot;)
531 Select Case UCase(psProperty)
532 Case UCase(&quot;ChartType&quot;)
533 With _Diagram
534 Select Case .DiagramType
535 Case &quot;com.sun.star.chart.BarDiagram&quot;
536 If .Vertical Then _PropertyGet = &quot;Bar&quot; Else _PropertyGet = &quot;Column&quot;
537 Case &quot;com.sun.star.chart.PieDiagram&quot;
538 _PropertyGet = &quot;Pie&quot;
539 Case &quot;com.sun.star.chart.DonutDiagram&quot;
540 _PropertyGet = &quot;Donut&quot;
541 Case &quot;com.sun.star.chart.AreaDiagram&quot;
542 _PropertyGet = &quot;Area&quot;
543 Case &quot;com.sun.star.chart.LineDiagram&quot;
544 _PropertyGet = &quot;Line&quot;
545 Case &quot;com.sun.star.chart.XYDiagram&quot;
546 _PropertyGet = &quot;XY&quot;
547 Case &quot;com.sun.star.chart.BubbleDiagram&quot;
548 _PropertyGet = &quot;Bubble&quot;
549 Case &quot;com.sun.star.chart.NetDiagram&quot;, &quot;com.sun.star.chart.FilledNetDiagram&quot;
550 _PropertyGet = &quot;Net&quot;
551 Case Else
552 _PropertyGet = &quot;&quot;
553 End Select
554 End With
555 Case UCase(&quot;Deep&quot;)
556 If oSession.HasUnoProperty(_Diagram, &quot;Deep&quot;) Then _PropertyGet = _Diagram.Deep Else _PropertyGet = False
557 Case UCase(&quot;Dim3D&quot;)
558 If oSession.HasUnoProperty(_Diagram, &quot;Dim3D&quot;) Then
559 If _Diagram.Dim3D Then
560 If oSession.HasUnoProperty(_Diagram, &quot;SolidType&quot;) Then
561 Select Case _Diagram.SolidType
562 Case com.sun.star.chart.ChartSolidType.RECTANGULAR_SOLID : _PropertyGet = &quot;Bar&quot;
563 Case com.sun.star.chart.ChartSolidType.CYLINDER : _PropertyGet = &quot;Cylinder&quot;
564 Case com.sun.star.chart.ChartSolidType.CONE : _PropertyGet = &quot;Cone&quot;
565 Case com.sun.star.chart.ChartSolidType.PYRAMID : _PropertyGet = &quot;Pyramid&quot;
566 End Select
567 Else
568 _PropertyGet = _Diagram.Dim3D
569 End If
570 Else
571 _PropertyGet = False
572 End If
573 Else
574 _PropertyGet = False
575 End If
576 Case UCase(&quot;Exploded&quot;)
577 If oSession.HasUnoProperty(_ChartObject, &quot;Data&quot;) Then
578 &apos; All data points are presumed exploded with the same coefficient. Determine the (0, 0)th
579 With _ChartObject
580 vData = .Data.Data
581 _PropertyGet = 0
582 If IsArray(vData) Then
583 If UBound(vData) &gt;= 0 Then
584 If IsArray(vData(0)) Then
585 If UBound(vData(0)) &gt;= 0 Then _PropertyGet = _Diagram.getDataPointProperties(0, 0).SegmentOffset
586 End If
587 End If
588 End If
589 End With
590 End If
591 Case UCase(&quot;Filled&quot;)
592 _PropertyGet = ( _Diagram.DiagramType = &quot;com.sun.star.chart.FilledNetDiagram&quot; )
593 Case UCase(&quot;Legend&quot;)
594 If oSession.HasUnoProperty(_ChartObject, &quot;HasLegend&quot;) Then _PropertyGet = _ChartObject.HasLegend Else _PropertyGet = False
595 Case UCase(&quot;Percent&quot;)
596 If oSession.HasUnoProperty(_Diagram, &quot;Percent&quot;) Then _PropertyGet = _Diagram.Percent Else _PropertyGet = False
597 Case UCase(&quot;Stacked&quot;)
598 If oSession.HasUnoProperty(_Diagram, &quot;Stacked&quot;) Then _PropertyGet = _Diagram.Stacked Else _PropertyGet = False
599 Case UCase(&quot;Title&quot;)
600 If oSession.HasUnoProperty(_ChartObject, &quot;HasMainTitle&quot;) Then
601 If _ChartObject.HasMainTitle Then _PropertyGet = _ChartObject.Title.String Else _PropertyGet = &quot;&quot;
602 End If
603 Case UCase(&quot;XTitle&quot;)
604 If oSession.HasUnoProperty(_Diagram, &quot;HasXAxisTitle&quot;) Then
605 If _Diagram.HasXAxisTitle Then _PropertyGet = _Diagram.XAxisTitle.String Else _PropertyGet = &quot;&quot;
606 End If
607 Case UCase(&quot;YTitle&quot;)
608 If oSession.HasUnoProperty(_Diagram, &quot;HasYAxisTitle&quot;) Then
609 If _Diagram.HasYAxisTitle Then _PropertyGet = _Diagram.YAxisTitle.String Else _PropertyGet = &quot;&quot;
610 End If
611 Case UCase(&quot;XChartObj&quot;)
612 Set _PropertyGet = _ChartObject
613 Case UCase(&quot;XDiagram&quot;)
614 Set _PropertyGet = _Diagram
615 Case UCase(&quot;XShape&quot;)
616 Set _PropertyGet = _Shape
617 Case UCase(&quot;XTableChart&quot;)
618 Set _PropertyGet = _Chart
619 Case Else
620 _PropertyGet = Null
621 End Select
623 Finally:
624 SF_Utils._ExitFunction(cstThisSub)
625 Exit Function
626 End Function &apos; SFDocuments.SF_Chart._PropertyGet
628 REM -----------------------------------------------------------------------------
629 Private Function _PropertySet(Optional ByVal psProperty As String _
630 , Optional ByVal pvValue As Variant _
631 ) As Boolean
632 &apos;&apos;&apos; Set the new value of the named property
633 &apos;&apos;&apos; Args:
634 &apos;&apos;&apos; psProperty: the name of the property
635 &apos;&apos;&apos; pvValue: the new value of the given property
637 Dim bSet As Boolean &apos; Return value
638 Static oSession As Object &apos; Alias of SF_Session
639 Dim sChartType As String &apos; Diagram type
640 Dim bDim3D As Boolean &apos; Alias of Dim3D property of diagram
641 Dim bVertical As Boolean &apos; When True, chart type is a bar, not a column
642 Dim vData As Variant &apos; Data points array of values
643 Dim i As Long, j As Long
644 Const cstChart = &quot;com.sun.star.chart.&quot;
646 Dim cstThisSub As String
647 Const cstSubArgs = &quot;Value&quot;
649 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
650 bSet = False
652 cstThisSub = &quot;SFDocuments.Chart.set&quot; &amp; psProperty
653 ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
654 If Not [_Parent]._IsStillAlive() Then GoTo Catch
656 bSet = True
657 If IsNull(oSession) Then Set oSession = ScriptForge.SF_Services.CreateScriptService(&quot;Session&quot;)
658 Select Case UCase(psProperty)
659 Case UCase(&quot;ChartType&quot;)
660 If Not ScriptForge.SF_Utils._Validate(pvValue, &quot;ChartType&quot;, V_STRING _
661 , Array(&quot;Bar&quot;, &quot;Column&quot;, &quot;Pie&quot;, &quot;Donut&quot;, &quot;Area&quot;, &quot;Line&quot;, &quot;XY&quot;, &quot;Bubble&quot;, &quot;Net&quot;) _
662 ) Then GoTo Finally
663 With _Diagram
664 &apos; Specify the targeted chart type
665 Select Case UCase(pvValue)
666 Case &quot;BAR&quot;, &quot;COLUMN&quot; : sChartType = cstChart &amp; &quot;BarDiagram&quot;
667 Case &quot;PIE&quot; : sChartType = cstChart &amp; &quot;PieDiagram&quot;
668 Case &quot;DONUT&quot; : sChartType = cstChart &amp; &quot;DonutDiagram&quot;
669 Case &quot;AREA&quot; : sChartType = cstChart &amp; &quot;AreaDiagram&quot;
670 Case &quot;LINE&quot; : sChartType = cstChart &amp; &quot;LineDiagram&quot;
671 Case &quot;XY&quot; : sChartType = cstChart &amp; &quot;XYDiagram&quot;
672 Case &quot;BUBBLE&quot; : sChartType = cstChart &amp; &quot;BubbleDiagram&quot;
673 Case &quot;NET&quot; : sChartType = cstChart &amp; &quot;NetDiagram&quot;
674 End Select
675 &apos; If there is no change, do nothing
676 If sChartType &lt;&gt; .DiagramType Then
677 &apos; Some combinations old type =&gt; new type require the cancellation of 3D graphs
678 bDim3D = .Dim3D
679 .Dim3D = False
680 _ChartObject.createInstance(sChartType)
681 Set _Diagram = _ChartObject.Diagram
682 .Dim3D = bDim3D
683 End If
684 If UCase(pvValue) = &quot;BAR&quot; Or UCase(pvValue) = &quot;COLUMN&quot; Then .Vertical = ( UCase(pvValue) = &quot;BAR&quot; )
685 End With
686 Case UCase(&quot;Deep&quot;)
687 If Not ScriptForge.SF_Utils._Validate(pvValue, &quot;Deep&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
688 If oSession.HasUnoProperty(_Diagram, &quot;Deep&quot;) Then _Diagram.Deep = pvValue
689 Case UCase(&quot;Dim3D&quot;)
690 If Not ScriptForge.SF_Utils._Validate(pvValue, &quot;Dim3D&quot;, Array(ScriptForge.V_Boolean, V_STRING) _
691 , Array(False, True, &quot;Bar&quot;, &quot;Cylinder&quot;, &quot;Cone&quot;, &quot;Pyramid&quot;) _
692 ) Then GoTo Finally
693 With _Diagram
694 If oSession.HasUnoProperty(_Diagram, &quot;Dim3D&quot;) Then
695 If _Diagram.DiagramType = &quot;com.sun.star.chart.BubbleDiagram&quot; Then
696 .Dim3D = False &apos; Force False value to avoid empty graph
697 ElseIf VarType(pvValue) = V_STRING Then
698 bVertical = .Vertical
699 .Dim3D = True
700 .Vertical = bVertical
701 If oSession.HasUnoProperty(_Diagram, &quot;SolidType&quot;) Then
702 If .DiagramType = cstChart &amp; &quot;BarDiagram&quot; Then
703 Select Case UCase(pvValue)
704 Case &quot;BAR&quot; : .SolidType = com.sun.star.chart.ChartSolidType.RECTANGULAR_SOLID
705 Case &quot;CYLINDER&quot; : .SolidType = com.sun.star.chart.ChartSolidType.CYLINDER
706 Case &quot;CONE&quot; : .SolidType = com.sun.star.chart.ChartSolidType.CONE
707 Case &quot;PYRAMID&quot; : .SolidType = com.sun.star.chart.ChartSolidType.PYRAMID
708 End Select
709 Else
710 .SolidType = 0
711 End If
712 End If
713 Else &apos; Boolean
714 If oSession.HasUnoProperty(_Diagram, &quot;SolidType&quot;) Then .SolidType = 0
715 .Dim3D = pvValue
716 End If
717 End If
718 End With
719 Case UCase(&quot;Exploded&quot;)
720 If oSession.HasUnoProperty(_ChartObject, &quot;Data&quot;) And _Diagram.DiagramType &lt;&gt; &quot;com.sun.star.chart.BubbleDiagram&quot; Then
721 &apos; All data points are presumed exploded with the same coefficient
722 If Not ScriptForge.SF_Utils._Validate(pvValue, &quot;Exploded&quot;, ScriptForge.V_NUMERIC) Then GoTo Finally
723 With _ChartObject
724 vData = .Data.Data
725 If IsArray(vData) Then
726 For i = 0 To UBound(vData)
727 If IsArray(vData(i)) Then
728 For j = 0 To UBound(vData(i))
729 _Diagram.getDataPointProperties(i, j).SegmentOffset = CLng(pvValue)
730 Next j
731 End If
732 Next i
733 End If
734 End With
735 End If
736 Case UCase(&quot;Filled&quot;)
737 &apos; Flipflop between NetDiagram and FilledNetDiagram
738 If Not ScriptForge.SF_Utils._Validate(pvValue, &quot;Filled&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
739 With _Diagram
740 &apos; Specify the targeted chart type
741 sChartType = cstChart &amp; Iif(pvValue, &quot;Filled&quot;, &quot;&quot;) &amp; &quot;NetDiagram&quot;
742 &apos; If there is no change, do nothing
743 If sChartType &lt;&gt; .DiagramType then
744 &apos; Do not apply if the chart type not = &quot;Net&quot;
745 If (pvValue And .DiagramType = cstChart &amp; &quot;NetDiagram&quot;) _
746 Or (Not pvValue And .DiagramType = cstChart &amp; &quot;FilledNetDiagram&quot;) Then
747 &apos; Some combinations old type =&gt; new type require the cancellation of 3D graphs
748 bDim3D = .Dim3D
749 .Dim3D = False
750 _ChartObject.createInstance(sChartType)
751 Set _Diagram = _ChartObject.Diagram
752 .Dim3D = bDim3D
753 End If
754 End If
755 End With
756 Case UCase(&quot;Legend&quot;)
757 If Not ScriptForge.SF_Utils._Validate(pvValue, &quot;Legend&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
758 If oSession.HasUnoProperty(_ChartObject, &quot;HasLegend&quot;) Then _ChartObject.HasLegend = pvValue
759 Case UCase(&quot;Percent&quot;)
760 If Not ScriptForge.SF_Utils._Validate(pvValue, &quot;Percent&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
761 If oSession.HasUnoProperty(_Diagram, &quot;Percent&quot;) Then
762 _Diagram.Stacked = pvValue
763 _Diagram.Percent = pvValue
764 End If
765 Case UCase(&quot;Stacked&quot;)
766 If Not ScriptForge.SF_Utils._Validate(pvValue, &quot;Stacked&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
767 If oSession.HasUnoProperty(_Diagram, &quot;Stacked&quot;) Then
768 _Diagram.Stacked = pvValue
769 If Not pvValue Then _Diagram.Percent = False
770 End If
771 Case UCase(&quot;Title&quot;)
772 If Not ScriptForge.SF_Utils._Validate(pvValue, &quot;Title&quot;, V_STRING) Then GoTo Finally
773 If oSession.HasUnoProperty(_ChartObject, &quot;HasMainTitle&quot;) Then
774 _ChartObject.HasMainTitle = ( Len(pvValue) &gt; 0 )
775 If Len(pvValue) &gt; 0 Then _ChartObject.Title.String = pvValue
776 End If
777 Case UCase(&quot;XTitle&quot;)
778 If Not ScriptForge.SF_Utils._Validate(pvValue, &quot;XTitle&quot;, V_STRING) Then GoTo Finally
779 If oSession.HasUnoProperty(_Diagram, &quot;HasXAxisTitle&quot;) Then
780 _Diagram.HasXAxisTitle = ( Len(pvValue) &gt; 0 )
781 If Len(pvValue) &gt; 0 Then _Diagram.XAxisTitle.String = pvValue
782 End If
783 Case UCase(&quot;YTitle&quot;)
784 If Not ScriptForge.SF_Utils._Validate(pvValue, &quot;YTitle&quot;, V_STRING) Then GoTo Finally
785 If oSession.HasUnoProperty(_Diagram, &quot;HasYAxisTitle&quot;) Then
786 _Diagram.HasYAxisTitle = ( Len(pvValue) &gt; 0 )
787 If Len(pvValue) &gt; 0 Then _Diagram.YAxisTitle.String = pvValue
788 End If
789 Case Else
790 bSet = False
791 End Select
793 Finally:
794 _PropertySet = bSet
795 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
796 Exit Function
797 Catch:
798 bSet = False
799 GoTo Finally
800 End Function &apos; SFDocuments.SF_FormControl._PropertySet
802 REM -----------------------------------------------------------------------------
803 Private Function _Repr() As String
804 &apos;&apos;&apos; Convert the Chart instance to a readable string, typically for debugging purposes (DebugPrint ...)
805 &apos;&apos;&apos; Args:
806 &apos;&apos;&apos; Return:
807 &apos;&apos;&apos; &quot;[Chart]: Name - Type
809 _Repr = &quot;[Chart]: &quot; &amp; ChartName &amp; &quot; - &quot; &amp; ChartType
811 End Function &apos; SFDocuments.SF_Chart._Repr
813 REM ============================================ END OF SFDOCUMENTS.SF_CHART
814 </script:module>