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
|
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="SF_Chart" script:language="StarBasic" script:moduleType="normal">REM =======================================================================================================================
REM === The ScriptForge library and its associated libraries are part of the LibreOffice project. ===
REM === The SFDocuments library is one of the associated libraries. ===
REM === Full documentation is available on https://help.libreoffice.org/ ===
REM =======================================================================================================================
Option Compatible
Option ClassModule
Option Explicit
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''' SF_Chart
''' ========
'''
''' The SF_Chart module is focused on the description of chart documents
''' stored in Calc sheets.
''' With this service, many chart types and chart characteristics available
''' in the user interface can be read or modified.
'''
''' Definitions
''' Charts have 2 distinct names:
''' - an internal name, given by the LibreOffice application
''' - an optional user-defined name
''' In the scope of the ScriptForge libraries, the chart name is the name given by the user.
''' Only when there is no user name, the internal name may be used instead.
'''
''' Service invocation from the "Calc" service
''' Either make a new chart
''' calc.CreateChart(ChartName, SheetName, "SheetX.A1:C8")
''' or select an existing one
''' calc.Charts(SheetName, ChartName)
'''
''' Detailed user documentation:
''' https://help.libreoffice.org/latest/en-US/text/sbasic/shared/03/sf_chart.html?DbPAR=BASIC
'''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
REM ================================================================== EXCEPTIONS
Private Const CHARTEXPORTERROR = "CHARTEXPORTERROR"
REM ============================================================= PRIVATE MEMBERS
Private [Me] As Object
Private [_Parent] As Object ' Parent Calc document
Private ObjectType As String ' Must be CHART
Private ServiceName As String
' Chart description
Private _SheetName As String ' Name of the Calc sheet containing the chart
Private _DrawIndex As Long ' Index of the chart in the sheet's draw page
Private _ChartName As String ' User name
Private _PersistentName As String ' Internal name
Private _Shape As Object ' com.sun.star.drawing.XShape
Private _Chart As Object ' com.sun.star.table.XTableChart
Private _ChartObject As Object ' com.sun.star.lang.XComponent - ScChartObj
Private _Diagram As Object ' com.sun.star.chart.XDiagram
REM ============================================================ MODULE CONSTANTS
REM ====================================================== CONSTRUCTOR/DESTRUCTOR
REM -----------------------------------------------------------------------------
Private Sub Class_Initialize()
Set [Me] = Nothing
Set [_Parent] = Nothing
ObjectType = "CHART"
ServiceName = "SFDocuments.Chart"
_SheetName = ""
_DrawIndex = -1
_ChartName = ""
_PersistentName = ""
Set _Shape = Nothing
Set _Chart = Nothing
Set _ChartObject = Nothing
Set _Diagram = Nothing
End Sub ' SFDocuments.SF_Chart Constructor
REM -----------------------------------------------------------------------------
Private Sub Class_Terminate()
Call Class_Initialize()
End Sub ' SFDocuments.SF_Chart Destructor
REM -----------------------------------------------------------------------------
Public Function Dispose() As Variant
Call Class_Terminate()
Set Dispose = Nothing
End Function ' SFDocuments.SF_Chart Explicit Destructor
REM ================================================================== PROPERTIES
REM -----------------------------------------------------------------------------
Property Get ChartType() As Variant
''' The ChartType property specifies the type of chart as a string among next values:
''' Pie, Bar, Donut, Column, Area, Line, XY, Bubble, Net
ChartType = _PropertyGet("ChartType")
End Property ' SFDocuments.SF_Chart.ChartType (get)
REM -----------------------------------------------------------------------------
Property Let ChartType(Optional ByVal pvChartType As Variant)
''' Set the updatable property ChartType
_PropertySet("ChartType", pvChartType)
End Property ' SFDocuments.SF_Chart.ChartType (let)
REM -----------------------------------------------------------------------------
Property Get Deep() As Variant
''' If True, determines that in a three-dimensional bar chart the bars of each series are arranged behind each other in the z-direction.
''' If False the arrangement of bars is like in two-dimensional bar charts.
''' Bar and Column chart types only
Deep = _PropertyGet("Deep")
End Property ' SFDocuments.SF_Chart.Deep (get)
REM -----------------------------------------------------------------------------
Property Let Deep(Optional ByVal pvDeep As Variant)
''' Set the updatable property Deep
_PropertySet("Deep", pvDeep)
End Property ' SFDocuments.SF_Chart.Deep (let)
REM -----------------------------------------------------------------------------
Property Get Dim3D() As Variant
''' The Dim3D property specifies if the chart is displayed with 3D elements
''' String or Boolean
''' When String, must be 1 of next values: Bar, Cylinder, Cone or Pyramid
''' When Boolean True, Bar is assumed; when False, no 3D to be applied
Dim3D = _PropertyGet("Dim3D")
End Property ' SFDocuments.SF_Chart.Dim3D (get)
REM -----------------------------------------------------------------------------
Property Let Dim3D(Optional ByVal pvDim3D As Variant)
''' Set the updatable property Dim3D
_PropertySet("Dim3D", pvDim3D)
End Property ' SFDocuments.SF_Chart.Dim3D (let)
REM -----------------------------------------------------------------------------
Property Get Exploded() As Variant
''' the offset by which pie segments in a PieDiagram (pie or donut) are dragged outside from the center.
''' This value is given in percent of the radius.
Exploded = _PropertyGet("Exploded")
End Property ' SFDocuments.SF_Chart.Exploded (get)_ChartObject
REM -----------------------------------------------------------------------------
Property Let Exploded(Optional ByVal pvExploded As Variant)
''' Set the updatable property Exploded
_PropertySet("Exploded", pvExploded)
End Property ' SFDocuments.SF_Chart.Exploded (let)
REM -----------------------------------------------------------------------------
Property Get Filled() As Variant
''' When True, the Net diagram is said of FilledNet type
''' Net chart type only
Filled = _PropertyGet("Filled")
End Property ' SFDocuments.SF_Chart.Filled (get)
REM -----------------------------------------------------------------------------
Property Let Filled(Optional ByVal pvFilled As Variant)
''' Set the updatable property Filled
_PropertySet("Filled", pvFilled)
End Property ' SFDocuments.SF_Chart.Filled (let)
REM -----------------------------------------------------------------------------
Property Get Legend() As Variant
''' Specifies if the chart has a legend
Legend = _PropertyGet("Legend")
End Property ' SFDocuments.SF_Chart.Legend (get)
REM -----------------------------------------------------------------------------
Property Let Legend(Optional ByVal pvLegend As Variant)
''' Set the updatable property Legend
_PropertySet("Legend", pvLegend)
End Property ' SFDocuments.SF_Chart.Legend (let)
REM -----------------------------------------------------------------------------
Property Get Percent() As Variant
''' When True, the series of the diagram are stacked and each category sums up to 100%.
''' Area, Bar, Bubble, Column and Net chart types only_ChartObject
Percent = _PropertyGet("Percent")
End Property ' SFDocuments.SF_Chart.Percent (get)
REM -----------------------------------------------------------------------------
Property Let Percent(Optional ByVal pvPercent As Variant)
''' Set the updatable property Percent
_PropertySet("Percent", pvPercent)
End Property ' SFDocuments.SF_Chart.Percent (let)
REM -----------------------------------------------------------------------------
Property Get Stacked() As Variant
''' When True, the series of the diagram are stacked.
''' Area, Bar, Bubble, Column and Net chart types only
Stacked = _PropertyGet("Stacked")
End Property ' SFDocuments.SF_Chart.Stacked (get)
REM -----------------------------------------------------------------------------
Property Let Stacked(Optional ByVal pvStacked As Variant)
''' Set the updatable property Stacked
_PropertySet("Stacked", pvStacked)
End Property ' SFDocuments.SF_Chart.Stacked (let)
REM -----------------------------------------------------------------------------
Property Get Title() As Variant
''' Specifies the main title of the chart
Title = _PropertyGet("Title")
End Property ' SFDocuments.SF_Chart.Title (get)
REM -----------------------------------------------------------------------------
Property Let Title(Optional ByVal pvTitle As Variant)
''' Set the updatable property Title
_PropertySet("Title", pvTitle)
End Property ' SFDocuments.SF_Chart.Title (let)
REM -----------------------------------------------------------------------------
Property Get XTitle() As Variant
''' Specifies the main XTitle of the chart
XTitle = _PropertyGet("XTitle")
End Property ' SFDocuments.SF_Chart.XTitle (get)
REM -----------------------------------------------------------------------------
Property Let XTitle(Optional ByVal pvXTitle As Variant)
''' Set the updatable property XTitle
_PropertySet("XTitle", pvXTitle)
End Property ' SFDocuments.SF_Chart.XTitle (let)
REM -----------------------------------------------------------------------------
Property Get YTitle() As Variant
''' Specifies the main YTitle of the chart
YTitle = _PropertyGet("YTitle")
End Property ' SFDocuments.SF_Chart.YTitle (get)
REM -----------------------------------------------------------------------------
Property Let YTitle(Optional ByVal pvYTitle As Variant)
''' Set the updatable property YTitle
_PropertySet("YTitle", pvYTitle)
End Property ' SFDocuments.SF_Chart.YTitle (let)
REM -----------------------------------------------------------------------------
Property Get XChartObj() As Variant
''' com.sun.star.lang.XComponent - ScChartObj
ChartType = _PropertyGet("XChartObj")
End Property ' SFDocuments.SF_Chart.XChartObj (get)
REM -----------------------------------------------------------------------------
Property Get XDiagram() As Variant
''' com.sun.star.chart.XDiagram
ChartType = _PropertyGet("XDiagram")
End Property ' SFDocuments.SF_Chart.XDiagram (get)
REM -----------------------------------------------------------------------------
Property Get XShape() As Variant
''' com.sun.star.drawing.XShape
ChartType = _PropertyGet("XShape")
End Property ' SFDocuments.SF_Chart.XShape (get)
REM -----------------------------------------------------------------------------
Property Get XTableChart() As Variant
''' com.sun.star.table.XTableChart
ChartType = _PropertyGet("XTableChart")
End Property ' SFDocuments.SF_Chart.XTableChart (get)
REM ===================================================================== METHODS
REM -----------------------------------------------------------------------------
Public Function ExportToFile(Optional ByVal FileName As Variant _
, Optional ByVal ImageType As Variant _
, Optional ByVal Overwrite As Variant _
) As Boolean
''' Store the chart as an image to the given file location
''' Args:
''' FileName: Identifies the file where to save. It must follow the SF_FileSystem.FileNaming notation
''' ImageType: the name of the targeted image type
''' Allowed values: gif, jpeg, png (default), svg and tiff
''' Overwrite: True if the destination file may be overwritten (default = False)
''' Returns:
''' False if the document could not be saved
''' Exceptions:
''' CHARTEXPORTERROR The destination has its readonly attribute set or overwriting rejected
''' Examples:
''' oChart.ExportToFile("C:\Me\Chart2.gif", ImageType := "gif", Overwrite := True)
Dim bSaved As Boolean ' return value
Dim oSfa As Object ' com.sun.star.ucb.SimpleFileAccess
Dim sFile As String ' Alias of FileName
Dim vStoreArguments As Variant ' Array of com.sun.star.beans.PropertyValue
Dim FSO As Object ' SF_FileSystem
Dim oExport As Object ' com.sun.star.drawing.GraphicExportFilter
Dim vImageTypes As Variant ' Array of permitted image types
Dim vMimeTypes As Variant ' Array of corresponding mime types in the same order as vImageTypes
Const cstImageTypes = "gif,jpeg,png,svg,tiff"
Const cstMimeTypes = "image/gif,image/jpeg,image/png,image/svg+xml,image/tiff"
Const cstThisSub = "SFDocuments.Chart.ExportToFile"
Const cstSubArgs = "FileName, [ImageType=""png""|""gif""|""jpeg""|""svg""|""tiff""], [Overwrite=False]"
If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo CatchError
bSaved = False
Check:
If IsMissing(ImageType) Or IsEmpty(ImageType) Then ImageType = "png"
If IsMissing(Overwrite) Or IsEmpty(Overwrite) Then Overwrite = False
vImageTypes = Split(cstImageTypes, ",")
If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
If Not [_Parent]._IsStillAlive() Then GoTo Finally
If Not ScriptForge.SF_Utils._ValidateFile(FileName, "FileName") Then GoTo Finally
If Not ScriptForge.SF_Utils._Validate(ImageType, "ImageType", V_STRING, vImageTypes) Then GoTo Finally
If Not ScriptForge.SF_Utils._Validate(Overwrite, "Overwrite", ScriptForge.V_BOOLEAN) Then GoTo Finally
End If
' Check destination file overwriting
Set FSO = CreateScriptService("FileSystem")
sFile = FSO._ConvertToUrl(FileName)
If FSO.FileExists(FileName) Then
If Overwrite = False Then GoTo CatchError
Set oSfa = ScriptForge.SF_Utils._GetUNOService("FileAccess")
If oSfa.isReadonly(sFile) Then GoTo CatchError
End If
Try:
' Setup arguments
vMimeTypes = Split(cstMimeTypes, ",")
vStoreArguments = Array( _
ScriptForge.SF_Utils._MakePropertyValue("URL", sFile) _
, ScriptForge.SF_Utils._MakePropertyValue("MediaType" _
, vMimeTypes(ScriptForge.SF_Array.IndexOf(vImageTypes, ImageType, CaseSensitive := False))) _
)
' Export with the com.sun.star.drawing.GraphicExportFilter UNO service
Set oExport = ScriptForge.SF_Utils._GetUNOService("GraphicExportFilter")
With oExport
.setSourceDocument(_Shape)
.filter(vStoreArguments)
End With
bSaved = True
Finally:
ExportToFile = bSaved
ScriptForge.SF_Utils._ExitFunction(cstThisSub)
Exit Function
Catch:
GoTo Finally
CatchError:
ScriptForge.SF_Exception.RaiseFatal(CHARTEXPORTERROR, "FileName", FileName, "Overwrite", Overwrite)
GoTo Finally
End Function ' SFDocuments.SF_Chart.ExportToFile
REM -----------------------------------------------------------------------------
Public Function GetProperty(Optional ByVal PropertyName As Variant) As Variant
''' Return the actual value of the given property
''' Args:
''' PropertyName: the name of the property as a string
''' Returns:
''' The actual value of the property
''' If the property does not exist, returns Null
''' Exceptions:
''' ARGUMENTERROR The property does not exist
Const cstThisSub = "SFDocuments.Chart.GetProperty"
Const cstSubArgs = ""
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
GetProperty = Null
Check:
If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
If Not SF_Utils._Validate(PropertyName, "PropertyName", V_STRING, Properties()) Then GoTo Catch
End If
Try:
GetProperty = _PropertyGet(PropertyName)
Finally:
SF_Utils._ExitFunction(cstThisSub)
Exit Function
Catch:
GoTo Finally
End Function ' SFDocuments.SF_Chart.GetProperty
REM -----------------------------------------------------------------------------
Public Function Methods() As Variant
''' Return the list of public methods of the Chart service as an array
Methods = Array( _
"ExportToFile" _
, "Resize" _
)
End Function ' SFDocuments.SF_Chart.Methods
REM -----------------------------------------------------------------------------
Public Function Properties() As Variant
''' Return the list or properties of the Chart class as an array
Properties = Array( _
"ChartType" _
, "Deep" _
, "Dim3D" _
, "Exploded" _
, "Filled" _
, "Legend" _
, "Percent" _
, "Stacked" _
, "Title" _
, "XChartObj" _
, "XDiagram" _
, "XShape" _
, "XTableChart" _
, "XTitle" _
, "YTitle" _
)
End Function ' SFDocuments.SF_Chart.Properties
REM -----------------------------------------------------------------------------
Public Function Resize(Optional ByVal XPos As Variant _
, Optional ByVal YPos As Variant _
, Optional ByVal Width As Variant _
, Optional ByVal Height As Variant _
) As Boolean
''' Move the topleft corner of a chart to new coordinates and/or modify its dimensions
''' All distances are expressed in 1/100th mm
''' Args:
''' XPos : the vertical distance from the topleft corner
''' YPos : the horizontal distance from the topleft corner
''' Width : the horizontal width of the shape containing the chart
''' Height : the vertical height of the shape containing the chart
''' Negative or missing arguments are left unchanged
''' Returns:
''' True when successful
''' Examples:
''' oChart.Resize(1000, 2000, Height := 6000) ' Width is not changed
Dim bResize As Boolean ' Return value
Dim oPosition As Object ' com.sun.star.awt.Point
Dim oSize As Object ' com.sun.star.awt.Size
Const cstThisSub = "SFDocuments.Chart.Resize"
Const cstSubArgs = "[XPos], [YPos], [Width], [Height]"
If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
bResize = False
Check:
If IsMissing(XPos) Or IsEmpty(XPos) Then XPos = -1
If IsMissing(YPos) Or IsEmpty(YPos) Then YPos = -1
If IsMissing(Height) Or IsEmpty(Height) Then Height = -1
If IsMissing(Width) Or IsEmpty(Width) Then Width = -1
If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
If Not [_Parent]._IsStillAlive() Then GoTo Finally
If Not ScriptForge.SF_Utils._Validate(XPos, "XPos", ScriptForge.V_NUMERIC) Then GoTo Finally
If Not ScriptForge.SF_Utils._Validate(YPos, "YPos", ScriptForge.V_NUMERIC) Then GoTo Finally
If Not ScriptForge.SF_Utils._Validate(Width, "Width", ScriptForge.V_NUMERIC) Then GoTo Finally
If Not ScriptForge.SF_Utils._Validate(Height, "Height", ScriptForge.V_NUMERIC) Then GoTo Finally
End If
Try:
With _Shape
' Get the current values
Set oPosition = .Position
Set oSize = .Size
' Modify relevant elements
If XPos >= 0 Then oPosition.X = CLng(XPos)
If YPos >= 0 Then oPosition.Y = CLng(YPos)
If Width > 0 Then oSize.Width = CLng(Width)
If Height > 0 Then oSize.Height = CLng(Height)
' Rewrite
.setPosition(oPosition)
.setSize(oSize)
End With
bResize = True
Finally:
Resize = bResize
ScriptForge.SF_Utils._ExitFunction(cstThisSub)
Exit Function
Catch:
GoTo Finally
End Function ' SF_Documents.SF_Chart.Resize
REM -----------------------------------------------------------------------------
Public Function SetProperty(Optional ByVal PropertyName As Variant _
, Optional ByRef Value As Variant _
) As Boolean
''' Set a new value to the given property
''' Args:
''' PropertyName: the name of the property as a string
''' Value: its new value
''' Exceptions
''' ARGUMENTERROR The property does not exist
Const cstThisSub = "SFDocuments.Chart.SetProperty"
Const cstSubArgs = "PropertyName, Value"
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
SetProperty = False
Check:
If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
If Not ScriptForge.SF_Utils._Validate(PropertyName, "PropertyName", V_STRING, Properties()) Then GoTo Catch
End If
Try:
SetProperty = _PropertySet(PropertyName, Value)
Finally:
SF_Utils._ExitFunction(cstThisSub)
Exit Function
Catch:
GoTo Finally
End Function ' SFDocuments.SF_Chart.SetProperty
REM =========================================================== PRIVATE FUNCTIONS
REM -----------------------------------------------------------------------------
Private Function _PropertyGet(Optional ByVal psProperty As String) As Variant
''' Return the value of the named property
''' Args:
''' psProperty: the name of the property
Static oSession As Object ' Alias of SF_Session
Dim vData As Variant ' Data points array of values
Dim cstThisSub As String
Const cstSubArgs = ""
cstThisSub = "SFDocuments.Chart.get" & psProperty
SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
If Not [_Parent]._IsStillAlive() Then GoTo Finally
If IsNull(oSession) Then Set oSession = ScriptForge.SF_Services.CreateScriptService("Session")
Select Case UCase(psProperty)
Case UCase("ChartType")
With _Diagram
Select Case .DiagramType
Case "com.sun.star.chart.BarDiagram"
If .Vertical Then _PropertyGet = "Bar" Else _PropertyGet = "Column"
Case "com.sun.star.chart.PieDiagram"
_PropertyGet = "Pie"
Case "com.sun.star.chart.DonutDiagram"
_PropertyGet = "Donut"
Case "com.sun.star.chart.AreaDiagram"
_PropertyGet = "Area"
Case "com.sun.star.chart.LineDiagram"
_PropertyGet = "Line"
Case "com.sun.star.chart.XYDiagram"
_PropertyGet = "XY"
Case "com.sun.star.chart.BubbleDiagram"
_PropertyGet = "Bubble"
Case "com.sun.star.chart.NetDiagram", "com.sun.star.chart.FilledNetDiagram"
_PropertyGet = "Net"
Case Else
_PropertyGet = ""
End Select
End With
Case UCase("Deep")
If oSession.HasUnoProperty(_Diagram, "Deep") Then _PropertyGet = _Diagram.Deep Else _PropertyGet = False
Case UCase("Dim3D")
If oSession.HasUnoProperty(_Diagram, "Dim3D") Then
If _Diagram.Dim3D Then
If oSession.HasUnoProperty(_Diagram, "SolidType") Then
Select Case _Diagram.SolidType
Case com.sun.star.chart.ChartSolidType.RECTANGULAR_SOLID : _PropertyGet = "Bar"
Case com.sun.star.chart.ChartSolidType.CYLINDER : _PropertyGet = "Cylinder"
Case com.sun.star.chart.ChartSolidType.CONE : _PropertyGet = "Cone"
Case com.sun.star.chart.ChartSolidType.PYRAMID : _PropertyGet = "Pyramid"
End Select
Else
_PropertyGet = _Diagram.Dim3D
End If
Else
_PropertyGet = False
End If
Else
_PropertyGet = False
End If
Case UCase("Exploded")
If oSession.HasUnoProperty(_ChartObject, "Data") Then
' All data points are presumed exploded with the same coefficient. Determine the (0, 0)th
With _ChartObject
vData = .Data.Data
_PropertyGet = 0
If IsArray(vData) Then
If UBound(vData) >= 0 Then
If IsArray(vData(0)) Then
If UBound(vData(0)) >= 0 Then _PropertyGet = _Diagram.getDataPointProperties(0, 0).SegmentOffset
End If
End If
End If
End With
End If
Case UCase("Filled")
_PropertyGet = ( _Diagram.DiagramType = "com.sun.star.chart.FilledNetDiagram" )
Case UCase("Legend")
If oSession.HasUnoProperty(_ChartObject, "HasLegend") Then _PropertyGet = _ChartObject.HasLegend Else _PropertyGet = False
Case UCase("Percent")
If oSession.HasUnoProperty(_Diagram, "Percent") Then _PropertyGet = _Diagram.Percent Else _PropertyGet = False
Case UCase("Stacked")
If oSession.HasUnoProperty(_Diagram, "Stacked") Then _PropertyGet = _Diagram.Stacked Else _PropertyGet = False
Case UCase("Title")
If oSession.HasUnoProperty(_ChartObject, "HasMainTitle") Then
If _ChartObject.HasMainTitle Then _PropertyGet = _ChartObject.Title.String Else _PropertyGet = ""
End If
Case UCase("XTitle")
If oSession.HasUnoProperty(_Diagram, "HasXAxisTitle") Then
If _Diagram.HasXAxisTitle Then _PropertyGet = _Diagram.XAxisTitle.String Else _PropertyGet = ""
End If
Case UCase("YTitle")
If oSession.HasUnoProperty(_Diagram, "HasYAxisTitle") Then
If _Diagram.HasYAxisTitle Then _PropertyGet = _Diagram.YAxisTitle.String Else _PropertyGet = ""
End If
Case UCase("XChartObj")
Set _PropertyGet = _ChartObject
Case UCase("XDiagram")
Set _PropertyGet = _Diagram
Case UCase("XShape")
Set _PropertyGet = _Shape
Case UCase("XTableChart")
Set _PropertyGet = _Chart
Case Else
_PropertyGet = Null
End Select
Finally:
SF_Utils._ExitFunction(cstThisSub)
Exit Function
End Function ' SFDocuments.SF_Chart._PropertyGet
REM -----------------------------------------------------------------------------
Private Function _PropertySet(Optional ByVal psProperty As String _
, Optional ByVal pvValue As Variant _
) As Boolean
''' Set the new value of the named property
''' Args:
''' psProperty: the name of the property
''' pvValue: the new value of the given property
Dim bSet As Boolean ' Return value
Static oSession As Object ' Alias of SF_Session
Dim sChartType As String ' Diagram type
Dim bDim3D As Boolean ' Alias of Dim3D property of diagram
Dim bVertical As Boolean ' When True, chart type is a bar, not a column
Dim vData As Variant ' Data points array of values
Dim i As Long, j As Long
Const cstChart = "com.sun.star.chart."
Dim cstThisSub As String
Const cstSubArgs = "Value"
If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
bSet = False
cstThisSub = "SFDocuments.Chart.set" & psProperty
ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
If Not [_Parent]._IsStillAlive() Then GoTo Catch
bSet = True
If IsNull(oSession) Then Set oSession = ScriptForge.SF_Services.CreateScriptService("Session")
Select Case UCase(psProperty)
Case UCase("ChartType")
If Not ScriptForge.SF_Utils._Validate(pvValue, "ChartType", V_STRING _
, Array("Bar", "Column", "Pie", "Donut", "Area", "Line", "XY", "Bubble", "Net") _
) Then GoTo Finally
With _Diagram
' Specify the targeted chart type
Select Case UCase(pvValue)
Case "BAR", "COLUMN" : sChartType = cstChart & "BarDiagram"
Case "PIE" : sChartType = cstChart & "PieDiagram"
Case "DONUT" : sChartType = cstChart & "DonutDiagram"
Case "AREA" : sChartType = cstChart & "AreaDiagram"
Case "LINE" : sChartType = cstChart & "LineDiagram"
Case "XY" : sChartType = cstChart & "XYDiagram"
Case "BUBBLE" : sChartType = cstChart & "BubbleDiagram"
Case "NET" : sChartType = cstChart & "NetDiagram"
End Select
' If there is no change, do nothing
If sChartType <> .DiagramType Then
' Some combinations old type => new type require the cancellation of 3D graphs
bDim3D = .Dim3D
.Dim3D = False
_ChartObject.createInstance(sChartType)
Set _Diagram = _ChartObject.Diagram
.Dim3D = bDim3D
End If
If UCase(pvValue) = "BAR" Or UCase(pvValue) = "COLUMN" Then .Vertical = ( UCase(pvValue) = "BAR" )
End With
Case UCase("Deep")
If Not ScriptForge.SF_Utils._Validate(pvValue, "Deep", ScriptForge.V_BOOLEAN) Then GoTo Finally
If oSession.HasUnoProperty(_Diagram, "Deep") Then _Diagram.Deep = pvValue
Case UCase("Dim3D")
If Not ScriptForge.SF_Utils._Validate(pvValue, "Dim3D", Array(ScriptForge.V_Boolean, V_STRING) _
, Array(False, True, "Bar", "Cylinder", "Cone", "Pyramid") _
) Then GoTo Finally
With _Diagram
If oSession.HasUnoProperty(_Diagram, "Dim3D") Then
If _Diagram.DiagramType = "com.sun.star.chart.BubbleDiagram" Then
.Dim3D = False ' Force False value to avoid empty graph
ElseIf VarType(pvValue) = V_STRING Then
bVertical = .Vertical
.Dim3D = True
.Vertical = bVertical
If oSession.HasUnoProperty(_Diagram, "SolidType") Then
If .DiagramType = cstChart & "BarDiagram" Then
Select Case UCase(pvValue)
Case "BAR" : .SolidType = com.sun.star.chart.ChartSolidType.RECTANGULAR_SOLID
Case "CYLINDER" : .SolidType = com.sun.star.chart.ChartSolidType.CYLINDER
Case "CONE" : .SolidType = com.sun.star.chart.ChartSolidType.CONE
Case "PYRAMID" : .SolidType = com.sun.star.chart.ChartSolidType.PYRAMID
End Select
Else
.SolidType = 0
End If
End If
Else ' Boolean
If oSession.HasUnoProperty(_Diagram, "SolidType") Then .SolidType = 0
.Dim3D = pvValue
End If
End If
End With
Case UCase("Exploded")
If oSession.HasUnoProperty(_ChartObject, "Data") And _Diagram.DiagramType <> "com.sun.star.chart.BubbleDiagram" Then
' All data points are presumed exploded with the same coefficient
If Not ScriptForge.SF_Utils._Validate(pvValue, "Exploded", ScriptForge.V_NUMERIC) Then GoTo Finally
With _ChartObject
vData = .Data.Data
If IsArray(vData) Then
For i = 0 To UBound(vData)
If IsArray(vData(i)) Then
For j = 0 To UBound(vData(i))
_Diagram.getDataPointProperties(i, j).SegmentOffset = CLng(pvValue)
Next j
End If
Next i
End If
End With
End If
Case UCase("Filled")
' Flipflop between NetDiagram and FilledNetDiagram
If Not ScriptForge.SF_Utils._Validate(pvValue, "Filled", ScriptForge.V_BOOLEAN) Then GoTo Finally
With _Diagram
' Specify the targeted chart type
sChartType = cstChart & Iif(pvValue, "Filled", "") & "NetDiagram"
' If there is no change, do nothing
If sChartType <> .DiagramType then
' Do not apply if the chart type not = "Net"
If (pvValue And .DiagramType = cstChart & "NetDiagram") _
Or (Not pvValue And .DiagramType = cstChart & "FilledNetDiagram") Then
' Some combinations old type => new type require the cancellation of 3D graphs
bDim3D = .Dim3D
.Dim3D = False
_ChartObject.createInstance(sChartType)
Set _Diagram = _ChartObject.Diagram
.Dim3D = bDim3D
End If
End If
End With
Case UCase("Legend")
If Not ScriptForge.SF_Utils._Validate(pvValue, "Legend", ScriptForge.V_BOOLEAN) Then GoTo Finally
If oSession.HasUnoProperty(_ChartObject, "HasLegend") Then _ChartObject.HasLegend = pvValue
Case UCase("Percent")
If Not ScriptForge.SF_Utils._Validate(pvValue, "Percent", ScriptForge.V_BOOLEAN) Then GoTo Finally
If oSession.HasUnoProperty(_Diagram, "Percent") Then
_Diagram.Stacked = pvValue
_Diagram.Percent = pvValue
End If
Case UCase("Stacked")
If Not ScriptForge.SF_Utils._Validate(pvValue, "Stacked", ScriptForge.V_BOOLEAN) Then GoTo Finally
If oSession.HasUnoProperty(_Diagram, "Stacked") Then
_Diagram.Stacked = pvValue
If Not pvValue Then _Diagram.Percent = False
End If
Case UCase("Title")
If Not ScriptForge.SF_Utils._Validate(pvValue, "Title", V_STRING) Then GoTo Finally
If oSession.HasUnoProperty(_ChartObject, "HasMainTitle") Then
_ChartObject.HasMainTitle = ( Len(pvValue) > 0 )
If Len(pvValue) > 0 Then _ChartObject.Title.String = pvValue
End If
Case UCase("XTitle")
If Not ScriptForge.SF_Utils._Validate(pvValue, "XTitle", V_STRING) Then GoTo Finally
If oSession.HasUnoProperty(_Diagram, "HasXAxisTitle") Then
_Diagram.HasXAxisTitle = ( Len(pvValue) > 0 )
If Len(pvValue) > 0 Then _Diagram.XAxisTitle.String = pvValue
End If
Case UCase("YTitle")
If Not ScriptForge.SF_Utils._Validate(pvValue, "YTitle", V_STRING) Then GoTo Finally
If oSession.HasUnoProperty(_Diagram, "HasYAxisTitle") Then
_Diagram.HasYAxisTitle = ( Len(pvValue) > 0 )
If Len(pvValue) > 0 Then _Diagram.YAxisTitle.String = pvValue
End If
Case Else
bSet = False
End Select
Finally:
_PropertySet = bSet
ScriptForge.SF_Utils._ExitFunction(cstThisSub)
Exit Function
Catch:
bSet = False
GoTo Finally
End Function ' SFDocuments.SF_FormControl._PropertySet
REM -----------------------------------------------------------------------------
Private Function _Repr() As String
''' Convert the Chart instance to a readable string, typically for debugging purposes (DebugPrint ...)
''' Args:
''' Return:
''' "[Chart]: Name - Type
_Repr = "[Chart]: " & ChartName & " - " & ChartType
End Function ' SFDocuments.SF_Chart._Repr
REM ============================================ END OF SFDOCUMENTS.SF_CHART
</script:module>
|