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