forked from extnet/Ext.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChart.cs
More file actions
537 lines (486 loc) · 17.7 KB
/
Chart.cs
File metadata and controls
537 lines (486 loc) · 17.7 KB
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
/********
* @version : 2.1.1 - Ext.NET Pro License
* @author : Ext.NET, Inc. http://www.ext.net/
* @date : 2012-12-10
* @copyright : Copyright (c) 2007-2012, Ext.NET, Inc. (http://www.ext.net/). All rights reserved.
* @license : See license.txt and http://www.ext.net/license/.
********/
using System;
using System.ComponentModel;
using System.Web.UI;
using Ext.Net.Utilities;
namespace Ext.Net
{
/// <summary>
/// Charts provide a flexible way to achieve a wide range of data visualization capablitities. Each Chart gets its data directly from a Store, and automatically updates its display whenever data in the Store changes. In addition, the look and feel of a Chart can be customized using Themes.
/// Every Chart has three key parts - a Store that contains the data, an array of Axes which define the boundaries of the Chart, and one or more Series to handle the visual rendering of the data points.
/// Axes are the lines that define the boundaries of the data points that a Chart can display.
/// Series are responsible for the visual representation of the data points contained in the Store.
/// </summary>
[Meta]
public partial class Chart : AbstractDrawComponent, IStore<Store>
{
/// <summary>
///
/// </summary>
public Chart()
{
}
/// <summary>
///
/// </summary>
[Category("0. About")]
[Description("")]
public override string XType
{
get
{
return "chart";
}
}
/// <summary>
///
/// </summary>
[Category("0. About")]
[Description("")]
public override string InstanceOf
{
get
{
return "Ext.chart.Chart";
}
}
/// <summary>
///
/// </summary>
[Description("")]
protected override void OnBeforeClientInitHandler()
{
if (this.StoreID.IsNotEmpty() && this.Store.Primary != null)
{
throw new Exception(string.Format("Please do not set both the StoreID property on {0} and <Store> inner property at the same time.", this.ID));
}
base.OnBeforeClientInitHandler();
}
private AxisCollection axes;
/// <summary>
/// Array of Axis instances or config objects.
/// </summary>
[Meta]
[ConfigOption(JsonMode.AlwaysArray)]
[NotifyParentProperty(true)]
[PersistenceMode(PersistenceMode.InnerProperty)]
public AxisCollection Axes
{
get
{
if (this.axes == null)
{
this.axes = new AxisCollection();
this.axes.AfterItemAdd += Axes_AfterAxisAdd;
}
return this.axes;
}
}
protected virtual void Axes_AfterAxisAdd(AbstractAxis axis)
{
axis.Owner = this;
}
/// <summary>
/// The amount of inset padding in pixels for the chart. Defaults to 10.
/// </summary>
[Meta]
[ConfigOption]
[Category("5. Chart")]
[DefaultValue(10)]
[Description("The amount of inset padding in pixels for the chart. Defaults to 10.")]
public virtual int InsetPadding
{
get
{
return this.State.Get<int>("InsetPadding", 10);
}
set
{
this.State.Set("InsetPadding", value);
}
}
/// <summary>
/// True for the default animation (easing: 'ease' and duration: 500) or a standard animation config object to be used for default chart animations. Defaults to false.
/// </summary>
[Meta]
[ConfigOption]
[DefaultValue(false)]
[Description("True for the default animation (easing: 'ease' and duration: 500) or a standard animation config object to be used for default chart animations. Defaults to false.")]
public virtual bool Animate
{
get
{
if (this.AnimateConfig != null)
{
return false;
}
return this.State.Get<bool>("Animate", false);
}
set
{
this.State.Set("Animate", value);
}
}
private AnimConfig animateConfig;
/// <summary>
/// Animation config
/// </summary>
[Meta]
[ConfigOption("animate", JsonMode.Object)]
[DefaultValue(null)]
[PersistenceMode(PersistenceMode.InnerProperty)]
[Description("Animation config")]
public virtual AnimConfig AnimateConfig
{
get
{
return this.animateConfig;
}
set
{
this.animateConfig = value;
}
}
/// <summary>
/// True for the default legend display or a legend config object. Defaults to false.
/// </summary>
[Meta]
[ConfigOption]
[DefaultValue(false)]
[Description("True for the default legend display or a legend config object. Defaults to false.")]
public virtual bool Legend
{
get
{
if (this.LegendConfig != null)
{
return false;
}
return this.State.Get<bool>("Legend", false);
}
set
{
this.State.Set("Legend", value);
}
}
private ChartLegend legendConfig;
/// <summary>
/// Legend config object
/// </summary>
[Meta]
[ConfigOption("legend", JsonMode.ObjectAllowEmpty)]
[DefaultValue(null)]
[PersistenceMode(PersistenceMode.InnerProperty)]
[Description("Legend config object")]
public virtual ChartLegend LegendConfig
{
get
{
return this.legendConfig;
}
set
{
this.legendConfig = value;
}
}
private SeriesCollection series;
/// <summary>
/// Array of Series instances or config objects.
/// </summary>
[Meta]
[ConfigOption(JsonMode.AlwaysArray)]
[NotifyParentProperty(true)]
[PersistenceMode(PersistenceMode.InnerProperty)]
public SeriesCollection Series
{
get
{
if (this.series == null)
{
this.series = new SeriesCollection();
this.series.AfterItemAdd += Series_AfterSeriesAdd;
}
return this.series;
}
}
protected virtual void Series_AfterSeriesAdd(AbstractSeries series)
{
series.Owner = this;
series.InitTips(true);
}
/// <summary>
/// The name of the theme to be used. A theme defines the colors and other visual displays of tick marks on axis, text, title text, line colors, marker colors and styles, etc.
/// Possible theme values are 'Base', 'Green', 'Sky', 'Red', 'Purple', 'Blue', 'Yellow' and also six category themes 'Category1' to 'Category6'. Default value is 'Base'.
/// </summary>
[Meta]
[ConfigOption]
[Category("5. Chart")]
[DefaultValue("")]
[Description("The name of the theme to be used. A theme defines the colors and other visual displays of tick marks on axis, text, title text, line colors, marker colors and styles, etc.")]
public virtual string Theme
{
get
{
return this.State.Get<string>("Theme", "");
}
set
{
this.State.Set("Theme", value);
}
}
/// <summary>
/// The name of the standard theme to be used. Possible theme values are 'Base', 'Green', 'Sky', 'Red', 'Purple', 'Blue', 'Yellow' and also six category themes 'Category1' to 'Category6'. Default value is 'Base'.
/// </summary>
[Meta]
[ConfigOption("theme", JsonMode.ToString)]
[Category("5. Chart")]
[DefaultValue(StandardChartTheme.Base)]
[Description("The name of the standard theme to be used. Possible theme values are 'Base', 'Green', 'Sky', 'Red', 'Purple', 'Blue', 'Yellow' and also six category themes 'Category1' to 'Category6'. Default value is 'Base'.")]
public virtual StandardChartTheme StandardTheme
{
get
{
return this.State.Get<StandardChartTheme>("StandardTheme", StandardChartTheme.Base);
}
set
{
this.State.Set("StandardTheme", value);
}
}
/// <summary>
/// Defines a mask for a chart's series. The 'chart' member must be set prior to rendering.
/// A Mask can be used to select a certain region in a chart. When enabled, the select event will be triggered when a region is selected by the mask, allowing the user to perform other tasks like zooming on that region, etc.
/// In order to use the mask one has to set the Chart mask option to true, vertical or horizontal.
/// </summary>
[Meta]
[Category("5. Chart")]
[DefaultValue(ChartMask.None)]
[Description("Defines a mask for a chart's series.")]
public virtual ChartMask Mask
{
get
{
return this.State.Get<ChartMask>("Mask", ChartMask.None);
}
set
{
this.State.Set("Mask", value);
}
}
[ConfigOption("mask", JsonMode.Raw)]
[DefaultValue("")]
protected virtual string MaskProxy
{
get
{
switch (this.Mask)
{
case ChartMask.Horizontal:
case ChartMask.Vertical:
return JSON.Serialize(this.Mask.ToString().ToLowerInvariant());
case ChartMask.Box:
return "true";
case ChartMask.None:
default:
return "";
}
}
}
/// <summary>
/// The store that supplies data to this chart.
/// </summary>
[Meta]
[ConfigOption("store", JsonMode.ToClientID)]
[Category("5. Chart")]
[DefaultValue("")]
[IDReferenceProperty(typeof(Store))]
[Description("The store that supplies data to this chart.")]
public virtual string StoreID
{
get
{
return this.State.Get<string>("StoreID", "");
}
set
{
this.State.Set("StoreID", value);
}
}
private StoreCollection<Store> store;
/// <summary>
/// The store that supplies data to this chart.
/// </summary>
[Meta]
[ConfigOption("store>Primary")]
[Category("5. Chart")]
[PersistenceMode(PersistenceMode.InnerProperty)]
[Description("The store that supplies data to this chart.")]
public virtual StoreCollection<Store> Store
{
get
{
if (this.store == null)
{
this.store = new StoreCollection<Store>();
this.store.AfterItemAdd += this.AfterItemAdd;
this.store.AfterItemRemove += this.AfterItemRemove;
}
return this.store;
}
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public Store GetStore()
{
if (this.Store.Primary != null)
{
return this.Store.Primary;
}
if (this.StoreID.IsNotEmpty())
{
return ControlUtils.FindControl<Store>(this, this.StoreID, true);
}
return null;
}
private ChartListeners listeners;
/// <summary>
/// Client-side JavaScript Event Handlers
/// </summary>
[Meta]
[ConfigOption("listeners", JsonMode.Object)]
[Category("2. Observable")]
[NotifyParentProperty(true)]
[PersistenceMode(PersistenceMode.InnerProperty)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[Description("Client-side JavaScript Event Handlers")]
public ChartListeners Listeners
{
get
{
if (this.listeners == null)
{
this.listeners = new ChartListeners();
}
return this.listeners;
}
}
private ChartDirectEvents directEvents;
/// <summary>
/// Server-side DirectEvent Handlers
/// </summary>
[Meta]
[Category("2. Observable")]
[NotifyParentProperty(true)]
[PersistenceMode(PersistenceMode.InnerProperty)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[ConfigOption("directEvents", JsonMode.Object)]
[Description("Server-side DirectEventHandlers")]
public ChartDirectEvents DirectEvents
{
get
{
if (this.directEvents == null)
{
this.directEvents = new ChartDirectEvents(this);
}
return this.directEvents;
}
}
/// <summary>
/// Changes the data store bound to this chart and refreshes it.
/// </summary>
/// <param name="store">The store to bind to this chart</param>
public virtual void BindStore(Store store)
{
this.Call("bindStore", store.ToConfig(LazyMode.Instance));
}
/// <summary>
/// Redraws the chart. If animations are set this will animate the chart too.
/// </summary>
/// <param name="resize">flag which changes the default origin points of the chart for animations.</param>
public virtual void Redraw(bool resize)
{
this.Call("redraw", resize);
}
/// <summary>
/// Redraws the chart. If animations are set this will animate the chart too.
/// </summary>
public virtual void Redraw()
{
this.Call("redraw");
}
/// <summary>
/// Restores the zoom to the original value. This can be used to reset the previous zoom state set by setZoom.
/// </summary>
public virtual void RestoreZoom()
{
this.Call("restoreZoom");
}
/// <summary>
/// Zooms the chart to the specified selection range. Can be used with a selection mask.
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="width"></param>
/// <param name="height"></param>
public virtual void SetZoom(int x, int y, int width, int height)
{
this.Call("setZoom", new { x, y, width, height });
}
/// <summary>
/// Used with line series only
/// </summary>
/// <param name="markerIndex"></param>
public virtual void SetMarkerIndex(int markerIndex)
{
this.Set("markerIndex", markerIndex);
}
private string ExportTypeToString(ChartExportType type)
{
switch (type)
{
case ChartExportType.JPEG:
return "image/jpeg";
case ChartExportType.PNG:
return "image/png";
case ChartExportType.SVG:
return "image/svg+xml";
}
throw new Exception("Not supported export type");
}
/// <summary>
/// Saves the chart by either triggering a download or returning a string containing the chart data. The action depends on the export type specified in the passed configuration.
/// </summary>
/// <param name="type"></param>
public virtual void Save(ChartExportType type)
{
this.Call("save", new { type = this.ExportTypeToString(type)});
}
/// <summary>
/// Saves the chart by either triggering a download or returning a string containing the chart data. The action depends on the export type specified in the passed configuration.
/// </summary>
/// <param name="type"></param>
/// <param name="width"></param>
/// <param name="height"></param>
public virtual void Save(ChartExportType type, int width, int height)
{
this.Call("save", new { type = this.ExportTypeToString(type), width, height });
}
/// <summary>
/// Toggle legend
/// </summary>
/// <param name="show">Whether to show or hide the legend.</param>
public virtual void ToggleLegend(bool show)
{
this.Call("legend.toggle", show);
}
}
}