Skip to content

Commit b2fd2f4

Browse files
committed
RED-1658 Added clone feature.
1 parent 6a0d3e4 commit b2fd2f4

File tree

4 files changed

+113
-40
lines changed

4 files changed

+113
-40
lines changed

FusionCharts/FusionCharts/FusionCharts.cs

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,24 @@ namespace FusionCharts.Charts
1414
/// @version: v3.6
1515
///
1616
/// </summary>
17-
public class Chart
17+
public class Chart : ICloneable
1818
{
1919
private Hashtable __CONFIG__ = null;
20+
private static Hashtable __PARAMMAP__ = null;
2021

2122
public enum ChartParameter
2223
{
23-
type,
24-
id,
25-
width,
26-
height,
24+
chartType,
25+
chartId,
26+
chartWidth,
27+
chartHeight,
2728
dataFormat,
2829
dataSource,
2930
renderAt,
30-
containerBackgroundColor,
31-
containerBackgroundOpacity
31+
bgColor,
32+
bgOpacity
3233
}
3334

34-
3535
#region constractor methods
3636
/// <summary>
3737
///
@@ -41,6 +41,23 @@ public Chart()
4141
__INIT();
4242
}
4343

44+
private void SetParamsMap()
45+
{
46+
if (__PARAMMAP__ == null)
47+
{
48+
__PARAMMAP__ = new Hashtable(StringComparer.InvariantCultureIgnoreCase);
49+
__PARAMMAP__["chartType"] = "type";
50+
__PARAMMAP__["chartId"] = "id";
51+
__PARAMMAP__["chartWidth"] = "width";
52+
__PARAMMAP__["chartHeight"] = "height";
53+
__PARAMMAP__["dataFormat"] = "dataFormat";
54+
__PARAMMAP__["dataSource"] = "dataSource";
55+
__PARAMMAP__["renderAt"] = "renderAt";
56+
__PARAMMAP__["bgColor"] = "containerBackgroundColor";
57+
__PARAMMAP__["bgOpacity"] = "containerBackgroundOpacity";
58+
}
59+
60+
}
4461

4562
/// <param name="chartType">The type of chart that you intend to plot</param>
4663
public Chart(string chartType)
@@ -187,7 +204,7 @@ private string RenderChartALL()
187204
// if the user has provided renderAt then assume that the HTML container is already present in the page.
188205
if (renderAt.Trim().Length == 0)
189206
{
190-
renderAt = chartId + "_Div";
207+
renderAt = chartId + "_div";
191208
// Now create the container div also.
192209
builder.AppendFormat("<div id='{0}' >" + Environment.NewLine, renderAt);
193210
builder.Append("Chart..." + Environment.NewLine);
@@ -212,6 +229,15 @@ private string RenderChartALL()
212229

213230
#region Public Methods
214231

232+
public object Clone()
233+
{
234+
Chart ChartClone = new Chart();
235+
ChartClone.__CONFIG__ = (Hashtable)this.__CONFIG__.Clone();
236+
ChartClone.SetChartParameter("id", ((Hashtable)ChartClone.__CONFIG__["params"])["id"].ToString() + "_clone");
237+
238+
return ChartClone;
239+
}
240+
215241
/// <summary>
216242
/// Public method to generate html code for rendering chart
217243
/// This function assumes that you've already included the FusionCharts JavaScript class in your page
@@ -262,9 +288,12 @@ public string Render(string chartType, string chartId, string chartWidth, string
262288
/// <param name="value">Value of configuration</param>
263289
public void SetChartParameter(ChartParameter param, object value)
264290
{
265-
SetChartParameter(param.ToString(), value);
291+
292+
SetChartParameter(__PARAMMAP__[param.ToString()].ToString(), value);
266293
}
267294

295+
296+
268297
/// <summary>
269298
/// This method set the data for the chart
270299
/// </summary>
@@ -317,13 +346,14 @@ private void __INIT()
317346
param["renderAt"] = "";
318347
param["dataSource"] = "";
319348
param["dataFormat"] = "";
320-
param["id"] = "";
349+
param["id"] = Guid.NewGuid().ToString().Replace("-", "_");
321350
param["containerBackgroundColor"] = "";
322351
param["containerBackgroundOpacity"] = "";
323352

324353
__CONFIG__["params"] = param;
325354

326355
param = null;
356+
SetParamsMap();
327357
}
328358

329359

@@ -368,7 +398,7 @@ private string fc_encodeJSON(Hashtable json, bool enclosed)
368398
}
369399
else if (ds.Key.ToString().Equals("renderAt"))
370400
{
371-
strjson = strjson + Environment.NewLine + "\"renderAt\" : \"" + ((Hashtable)json)["id"].ToString() + "_Div\", ";
401+
strjson = strjson + Environment.NewLine + "\"renderAt\" : \"" + ((Hashtable)json)["id"].ToString() + "_div\", ";
372402
}
373403
}
374404
// remove ending comma
@@ -392,6 +422,7 @@ private Hashtable GetConfigurationGroup(string setting)
392422
}
393423

394424
#endregion
425+
395426
}
396427
}
397428

sample/App_Code/FusionCharts.cs

Lines changed: 56 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,24 @@ namespace FusionCharts.Charts
1414
/// @version: v3.6
1515
///
1616
/// </summary>
17-
public class Chart
17+
public class Chart: ICloneable
1818
{
1919
private Hashtable __CONFIG__ = null;
20+
private static Hashtable __PARAMMAP__ = null;
2021

2122
public enum ChartParameter
2223
{
23-
type,
24-
id,
25-
width,
26-
height,
24+
chartType,
25+
chartId,
26+
chartWidth,
27+
chartHeight,
2728
dataFormat,
2829
dataSource,
2930
renderAt,
30-
containerBackgroundColor,
31-
containerBackgroundOpacity
31+
bgColor,
32+
bgOpacity
3233
}
3334

34-
3535
#region constractor methods
3636
/// <summary>
3737
///
@@ -41,6 +41,23 @@ public Chart()
4141
__INIT();
4242
}
4343

44+
private void SetParamsMap()
45+
{
46+
if (__PARAMMAP__ == null)
47+
{
48+
__PARAMMAP__ = new Hashtable(StringComparer.InvariantCultureIgnoreCase);
49+
__PARAMMAP__["chartType"] = "type";
50+
__PARAMMAP__["chartId"] = "id";
51+
__PARAMMAP__["chartWidth"] = "width";
52+
__PARAMMAP__["chartHeight"] = "height";
53+
__PARAMMAP__["dataFormat"] = "dataFormat";
54+
__PARAMMAP__["dataSource"] = "dataSource";
55+
__PARAMMAP__["renderAt"] = "renderAt";
56+
__PARAMMAP__["bgColor"] = "containerBackgroundColor";
57+
__PARAMMAP__["bgOpacity"] = "containerBackgroundOpacity";
58+
}
59+
60+
}
4461

4562
/// <param name="chartType">The type of chart that you intend to plot</param>
4663
public Chart(string chartType)
@@ -187,7 +204,7 @@ private string RenderChartALL()
187204
// if the user has provided renderAt then assume that the HTML container is already present in the page.
188205
if (renderAt.Trim().Length == 0)
189206
{
190-
renderAt = chartId + "_Div";
207+
renderAt = chartId + "_div";
191208
// Now create the container div also.
192209
builder.AppendFormat("<div id='{0}' >" + Environment.NewLine, renderAt);
193210
builder.Append("Chart..." + Environment.NewLine);
@@ -212,6 +229,15 @@ private string RenderChartALL()
212229

213230
#region Public Methods
214231

232+
public object Clone()
233+
{
234+
Chart ChartClone = new Chart();
235+
ChartClone.__CONFIG__ = (Hashtable)this.__CONFIG__.Clone();
236+
ChartClone.SetChartParameter("id", ((Hashtable)ChartClone.__CONFIG__["params"])["id"].ToString() + "_clone");
237+
238+
return ChartClone;
239+
}
240+
215241
/// <summary>
216242
/// Public method to generate html code for rendering chart
217243
/// This function assumes that you've already included the FusionCharts JavaScript class in your page
@@ -262,9 +288,12 @@ public string Render(string chartType, string chartId, string chartWidth, string
262288
/// <param name="value">Value of configuration</param>
263289
public void SetChartParameter(ChartParameter param, object value)
264290
{
265-
SetChartParameter(param.ToString(), value);
291+
292+
SetChartParameter(__PARAMMAP__[param.ToString()].ToString(), value);
266293
}
267294

295+
296+
268297
/// <summary>
269298
/// This method set the data for the chart
270299
/// </summary>
@@ -310,20 +339,21 @@ private void SetChartParameter(string setting, object value)
310339
private void __INIT()
311340
{
312341
__CONFIG__ = new Hashtable(StringComparer.InvariantCultureIgnoreCase);
313-
Hashtable param = new Hashtable(StringComparer.InvariantCultureIgnoreCase);
314-
param["type"] = "";
315-
param["width"] = "";
316-
param["height"] = "";
317-
param["renderAt"] = "";
318-
param["dataSource"] = "";
319-
param["dataFormat"] = "";
320-
param["id"] = "";
321-
param["containerBackgroundColor"] = "";
322-
param["containerBackgroundOpacity"] = "";
323-
324-
__CONFIG__["params"] = param;
325-
326-
param = null;
342+
Hashtable param = new Hashtable(StringComparer.InvariantCultureIgnoreCase);
343+
param["type"] = "";
344+
param["width"] = "";
345+
param["height"] = "";
346+
param["renderAt"] = "";
347+
param["dataSource"] = "";
348+
param["dataFormat"] = "";
349+
param["id"] = Guid.NewGuid().ToString().Replace("-", "_");
350+
param["containerBackgroundColor"] = "";
351+
param["containerBackgroundOpacity"] = "";
352+
353+
__CONFIG__["params"] = param;
354+
355+
param = null;
356+
SetParamsMap();
327357
}
328358

329359

@@ -368,7 +398,7 @@ private string fc_encodeJSON(Hashtable json, bool enclosed)
368398
}
369399
else if (ds.Key.ToString().Equals("renderAt"))
370400
{
371-
strjson = strjson + Environment.NewLine + "\"renderAt\" : \"" + ((Hashtable)json)["id"].ToString() + "_Div\", ";
401+
strjson = strjson + Environment.NewLine + "\"renderAt\" : \"" + ((Hashtable)json)["id"].ToString() + "_div\", ";
372402
}
373403
}
374404
// remove ending comma
@@ -392,6 +422,7 @@ private Hashtable GetConfigurationGroup(string setting)
392422
}
393423

394424
#endregion
425+
395426
}
396427
}
397428

sample/BasicChart.aspx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
<script type="text/javascript" src="fusioncharts/fusioncharts.js"></script>
99
</head>
1010
<body>
11-
<asp:Literal ID="Literal1" runat="server"></asp:Literal>
11+
<asp:Literal ID="Literal1" runat="server"></asp:Literal>
12+
<asp:Literal ID="Literal2" runat="server"></asp:Literal>
13+
<asp:Literal ID="Literal3" runat="server"></asp:Literal>
14+
<asp:Literal ID="Literal4" runat="server"></asp:Literal>
1215
</body>
1316
</html>

sample/BasicChart.aspx.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,17 @@ protected void Page_Load(object sender, EventArgs e)
2424

2525

2626
//'Create the chart - Column 3D Chart with data from Data/Data.xml
27-
Chart sales = new Chart("column3d");
27+
Chart sales = new Chart();
28+
29+
sales.SetChartParameter(Chart.ChartParameter.chartId, "column3d");
30+
31+
sales.SetChartParameter(Chart.ChartParameter.chartType, "column3d");
32+
2833
sales.SetChartParameter(Chart.ChartParameter.dataSource, "{\"chart\":{\"caption\":\"Monthly\",\"xaxisname\":\"Month\",\"yaxisname\":\"Revenue\",\"numberprefix\":\"$\",\"showvalues\":\"1\",\"animation\":\"0\"},\"data\":[{\"label\":\"Jan\",\"value\":\"420000\"},{\"label\":\"Feb\",\"value\":\"910000\"},{\"label\":\"Mar\",\"value\":\"720000\"},{\"label\":\"Apr\",\"value\":\"550000\"},{\"label\":\"May\",\"value\":\"810000\"},{\"label\":\"Jun\",\"value\":\"510000\"},{\"label\":\"Jul\",\"value\":\"680000\"},{\"label\":\"Aug\",\"value\":\"620000\"},{\"label\":\"Sep\",\"value\":\"610000\"},{\"label\":\"Oct\",\"value\":\"490000\"},{\"label\":\"Nov\",\"value\":\"530000\"},{\"label\":\"Dec\",\"value\":\"330000\"}],\"trendlines\":[{\"line\":[{\"startvalue\":\"700000\",\"istrendzone\":\"1\",\"valueonright\":\"1\",\"tooltext\":\"AYAN\",\"endvalue\":\"900000\",\"color\":\"009933\",\"displayvalue\":\"Target\",\"showontop\":\"1\",\"thickness\":\"5\"}]}],\"styles\":{\"definition\":[{\"name\":\"CanvasAnim\",\"type\":\"animation\",\"param\":\"_xScale\",\"start\":\"0\",\"duration\":\"1\"}],\"application\":[{\"toobject\":\"Canvas\",\"styles\":\"CanvasAnim\"}]}}");
29-
Literal1.Text = sales.Render();
34+
Literal1.Text = sales.Render();
35+
36+
Literal2.Text = ((Chart)sales.Clone()).Render();
37+
3038

3139
}
3240
}

0 commit comments

Comments
 (0)