1#
2# francy: Interactive Discrete Mathematics in GAP
3#
4#! @Chapter Francy Charts
5#! It is possible to build <C>Charts</C> with simple <C>Datasets</C>.
6#! <P/>
7#! Currently, Francy, supports Bar, Line and Scatter Charts.
8#! <P/>
9#! Please see Francy-JS for client implementation.
10
11
12#! @Section Categories
13#! In this section we show all Francy Chart Categories.
14
15#! @Description
16#! Identifies <C>Chart</C> objects.
17DeclareCategory("IsChart", IsFrancyObject);
18
19#! @Description
20#! Identifies <C>ChartType</C> objects.
21DeclareCategory("IsChartType", IsFrancyTypeObject);
22
23#! @Description
24#! Identifies <C>ChartDefaults</C> objects.
25DeclareCategory("IsChartDefaults", IsFrancyDefaultObject);
26
27#! @Description
28#! Identifies <C>AxisScaleType</C> objects.
29DeclareCategory("IsAxisScaleType", IsFrancyTypeObject);
30
31#! @Description
32#! Identifies <C>XAxis</C> objects.
33DeclareCategory("IsXAxis", IsFrancyObject);
34
35#! @Description
36#! Identifies <C>YAxis</C> objects.
37DeclareCategory("IsYAxis", IsFrancyObject);
38
39#! @Description
40#! Identifies <C>Dataset</C> objects.
41DeclareCategory("IsDataset", IsFrancyObject);
42
43
44#! @Section Families
45#! In this section we show all Francy Chart Families.
46
47#! @Description
48#! This Family identifies all <C>Chart</C> objects
49#! @Returns <C>ChartFamily</C>
50BindGlobal("ChartFamily", NewFamily("ChartFamily", IsChart));
51
52
53#! @Section Representations
54#! In this section we show the Francy Chart Representations.
55
56#! @Description
57#! Checks whether an <C>Object</C> has a <C>Chart</C> internal representation.
58DeclareRepresentation("IsChartRep", IsComponentObjectRep, [], IsChart);
59
60#! @Description
61#! Checks whether an <C>Object</C> has a <C>ChartDefaults</C> internal representation.
62DeclareRepresentation("IsChartDefaultsRep", IsComponentObjectRep, [], IsChartDefaults);
63
64#! @Description
65#! Checks whether an <C>Object</C> has a <C>ChartType</C> internal representation.
66DeclareRepresentation("IsChartTypeRep", IsComponentObjectRep, [], IsChartType);
67
68#! @Description
69#! Checks whether an <C>Object</C> has a <C>AxisScaleType</C> internal representation.
70DeclareRepresentation("IsAxisScaleTypeRep", IsComponentObjectRep, [], IsChartType);
71
72#! @Description
73#! Checks whether an <C>Object</C> has a <C>AxisRep</C> internal representation.
74DeclareRepresentation("IsAxisRep", IsComponentObjectRep, [], IsChartType);
75
76#! @Description
77#! Checks whether an <C>Object</C> has a <C>DatasetRep</C> internal representation.
78DeclareRepresentation("IsDatasetRep", IsComponentObjectRep, [], IsChartType);
79
80#! @Description
81#! Creates a new type for <C>Chart/C> objects.
82BindGlobal("ChartObjectType", NewType(ChartFamily, IsChart and IsChartRep));
83
84#! @Description
85#! Creates a new type for <C>Dataset/C> objects.
86BindGlobal("DatasetObjectType", NewType(ChartFamily, IsDataset and IsDatasetRep));
87
88#! @Description
89#! Creates a new type for <C>XAxis/C> objects.
90BindGlobal("XAxisObjectType", NewType(ChartFamily, IsXAxis and IsAxisRep));
91
92#! @Description
93#! Creates a new type for <C>YAxis/C> objects.
94BindGlobal("YAxisObjectType", NewType(ChartFamily, IsYAxis and IsAxisRep));
95
96#! @Description
97#! Creates a new type for <C>ChartType/C> objects.
98BindGlobal("ChartTypeObjectType",  NewType(ChartFamily, IsChartType and IsChartTypeRep));
99
100#! @Description
101#! Creates a new type for <C>AxisScale/C> objects.
102BindGlobal("AxisScaleTypeObjectType",  NewType(ChartFamily, IsAxisScaleType and IsAxisScaleTypeRep));
103
104
105#! @Section Operations
106#! In this section we show all Francy Chart Operations.
107
108#! @Description
109#! Every object to draw will be a subclass of this object. This will allow
110#! all the objects to contain the same base information.
111#! <P/>
112#! Examples:
113#! <P/>
114#! Create a simple <C>Chart</C> of type <C>ChartType.BAR</C>:
115#! @InsertChunk Example_Create_Chart_1
116#! <P/>
117#! Create a simple <C>Chart</C> of type <C>ChartType.LINE</C>:
118#! @InsertChunk Example_Create_Chart_2
119#! <P/>
120#! Create a simple <C>Chart</C> of type <C>ChartType.SCATTER</C>:
121#! @InsertChunk Example_Create_Chart_3
122#! <P/>
123#! @Arguments IsChartType[, IsChartDefaults]
124#! @Returns <C>Chart</C>
125DeclareOperation("Chart", [IsChartType, IsChartDefaults]);
126
127#! @Description
128#! Adds a <C>Dataset</C> to a specific <C>Chart</C>.
129#! @Arguments IsChart, [IsDataset, List(IsDataset)]
130#! @Returns <C>Chart</C>
131#DeclareOperation("Add", [IsChart, IsDataset]);
132
133#! @Description
134#! Removes a <C>Dataset</C> from a specific <C>Chart</C>.
135#! @Arguments IsChart, [IsDataset, List(IsDataset)]
136#! @Returns <C>Chart</C>
137#DeclareOperation("Remove", [IsChart, IsDataset]);
138
139#! @Description
140#! Creates a dataset.
141#! <P/>
142#! @Arguments IsString(title), IsList(data)
143#! @Returns <C>Dataset</C>
144DeclareOperation("Dataset", [IsString, IsList]);
145
146#! @Description
147#! Returns the default settings for a <C>ChartType</C>
148#! <P/>
149#! @Arguments IsChartType
150#! @Returns <C>rec</C>
151DeclareOperation("DefaultAxis", [IsChartType]);
152
153#! @Description
154#! Creates a XAxis
155#! <P/>
156#! @Arguments IsAxisScaleType, IsString(title), IsList(domain)
157#! @Returns <C>XAxis</C>
158DeclareOperation("XAxis", [IsAxisScaleType, IsString, IsList]);
159
160#! @Description
161#! Creates a YAxis
162#! <P/>
163#! @Arguments IsAxisScaleType, IsString(title), IsList(domain)
164#! @Returns <C>YAxis</C>
165DeclareOperation("YAxis", [IsAxisScaleType, IsString, IsList]);
166
167
168#! @Section Global
169#! In this section we show all Global Chart Francy Records for multi purpose.
170
171#! @Description
172#! The various types of Charts supported.
173#! @Returns <C>rec</C> of <C>GraphType</C>
174BindGlobal("ChartType", rec(
175  LINE    := Objectify(ChartTypeObjectType, rec(value := "line")),
176  BAR     := Objectify(ChartTypeObjectType, rec(value := "bar")),
177  SCATTER := Objectify(ChartTypeObjectType, rec(value := "scatter"))
178));
179
180#! @Description
181#! The various types of Axis Scales supported.
182#! @Returns <C>rec</C> of <C>AxisScaleType</C>
183BindGlobal("AxisScaleType", rec(
184  LINEAR := Objectify(AxisScaleTypeObjectType, rec(value := "linear")),
185  BAND   := Objectify(AxisScaleTypeObjectType, rec(value := "band"))
186));
187
188#! @Description
189#! The various types of Charts Defaults
190#! @Returns <C>rec</C> of <C>ChartDefaults</C>
191BindGlobal("ChartDefaults", Objectify(NewType(ChartFamily, IsChartDefaults and IsChartDefaultsRep), rec(
192  showLegend := true
193)));
194
195
196#! @Section Attributes
197#! In this section we show all Francy Attributes
198
199#! @Description
200#! <C>ShowLegend</C> is a property that enables or disables the legend in the client implementation.
201#! @Returns <C>IsBool</C> True if enabled otherwise False
202DeclareAttribute("ShowLegend", IsChart);
203InstallMethod(ShowLegend, "chart", [IsChart], o -> o!.showLegend);
204#! @Description
205#! <C>ShowLegend</C> is a property that enables or disables the legend in the client implementation.
206#! @Arguments IsChart, IsBool
207InstallMethod(SetShowLegend, "chart, boolean", [IsChart, IsBool], function(o, b) o!.showLegend := b; end);
208
209#! @Description
210#! This title is used to display the X Axis Title in the client implementation.
211#! @Returns <C>IsString</C> with the title of the object
212DeclareAttribute("AxisXTitle", IsChart);
213InstallMethod(AxisXTitle, "chart", [IsChart], o -> o!.axis!.x!.title);
214#! @Description
215#! This title is used to display the X Axis Title in the client implementation.
216#! @Arguments IsChart, IsString
217InstallMethod(SetAxisXTitle, "chart, string", [IsChart, IsString], function(o, s) o!.axis!.x!.title := s; end);
218
219#! @Description
220#! This title is used to display the Y Axis Title in the client implementation.
221#! @Returns <C>IsString</C> with the title of the object
222DeclareAttribute("AxisYTitle", IsChart);
223InstallMethod(AxisYTitle, "chart", [IsChart], o -> o!.axis!.y!.title);
224#! @Description
225#! This title is used to display the Y Axis Title in the client implementation.
226#! @Arguments IsChart, IsString
227InstallMethod(SetAxisYTitle, "chart, string", [IsChart, IsString], function(o, s) o!.axis!.y!.title := s; end);
228
229#! @Description
230#! This is the domain of the X Axis values in the client implementation.
231#! @Returns <C>IsList</C>
232DeclareAttribute("AxisXDomain", IsChart);
233InstallMethod(AxisXDomain, "chart", [IsChart], o -> o!.axis!.x!.domain);
234#! @Description
235#! This is the domain of the X Axis values in the client implementation.
236#! @Arguments IsList, IsList
237InstallMethod(SetAxisXDomain, "chart, list", [IsChart, IsList], function(o, l) o!.axis!.x!.domain := l; end);
238