Skip to content

Commit

Permalink
Merge pull request #27 from mattosaurus/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
mattosaurus authored Mar 29, 2019
2 parents a02fcff + 3485f0f commit 5731e59
Show file tree
Hide file tree
Showing 81 changed files with 100 additions and 381 deletions.
21 changes: 8 additions & 13 deletions ChartJSCoreTest/Program.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
using ChartJSCore.Helpers;
using ChartJSCore.Models;
using ChartJSCore.Models;
using ChartJSCore.Models.Bar;
using ChartJSCore.Plugins;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace ChartJSCoreTest
{
Expand Down Expand Up @@ -34,7 +29,7 @@ public static void Main(string[] args)
public static string GenerateBarChart()
{
Chart chart = new Chart();
chart.Type = "bar";
chart.Type = Enums.ChartType.Bar;

Data data = new Data();
data.Labels = new List<string>() { "Red", "Blue", "Yellow", "Green", "Purple", "Orange" };
Expand Down Expand Up @@ -113,7 +108,7 @@ public static string GenerateBarChart()
public static string GenerateLineChart()
{
Chart chart = new Chart();
chart.Type = "line";
chart.Type = Enums.ChartType.Line;

Data data = new Data();
data.Labels = new List<string>() { "January", "February", "March", "April", "May", "June", "July" };
Expand Down Expand Up @@ -183,7 +178,7 @@ public static string GenerateLineChart()
public static string GenerateLineScatterChart()
{
Chart chart = new Chart();
chart.Type = "line";
chart.Type = Enums.ChartType.Line;

Data data = new Data();

Expand Down Expand Up @@ -247,7 +242,7 @@ public static string GenerateLineScatterChart()
public static string GenerateRadarChart()
{
Chart chart = new Chart();
chart.Type = "radar";
chart.Type = Enums.ChartType.Radar;

Data data = new Data();
data.Labels = new List<string>() { "Eating", "Drinking", "Sleeping", "Designing", "Coding", "Cycling", "Running" };
Expand Down Expand Up @@ -290,7 +285,7 @@ public static string GenerateRadarChart()
public static string GeneratePolarChart()
{
Chart chart = new Chart();
chart.Type = "polarArea";
chart.Type = Enums.ChartType.PolarArea;

Data data = new Data();
data.Labels = new List<string>() { "Red", "Green", "Yellow", "Grey", "Blue" };
Expand All @@ -315,7 +310,7 @@ public static string GeneratePolarChart()
public static string GeneratePieChart()
{
Chart chart = new Chart();
chart.Type = "pie";
chart.Type = Enums.ChartType.Pie;

Data data = new Data();
data.Labels = new List<string>() { "Red", "Blue", "Yellow" };
Expand All @@ -341,7 +336,7 @@ public static string GeneratePieChart()
public static string GenerateBubbleChart()
{
Chart chart = new Chart();
chart.Type = "bubble";
chart.Type = Enums.ChartType.Bubble;

Data data = new Data();

Expand Down
1 change: 0 additions & 1 deletion ChartJSCoreTest/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
Expand Down
8 changes: 4 additions & 4 deletions src/ChartJSCore/ChartJSCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<Version>1.3.2</Version>
<Version>1.4.0</Version>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<RepositoryUrl>https://github.com/mattosaurus/ChartJSCore</RepositoryUrl>
<PackageTags>Chart.js chart graph chartjs</PackageTags>
<PackageProjectUrl>https://github.com/mattosaurus/ChartJSCore</PackageProjectUrl>
<Platforms>AnyCPU;x64</Platforms>
<AssemblyVersion>1.3.2.0</AssemblyVersion>
<FileVersion>1.3.2.0</FileVersion>
<PackageReleaseNotes>Version 1.3.2 - Updated framework targeting</PackageReleaseNotes>
<AssemblyVersion>1.4.0.0</AssemblyVersion>
<FileVersion>1.4.0.0</FileVersion>
<PackageReleaseNotes>Version 1.4.0 - Breaking change, chart type changed from string to enum</PackageReleaseNotes>
<Authors>mattosaurus</Authors>
<PackOnBuild>true</PackOnBuild>
</PropertyGroup>
Expand Down
2 changes: 0 additions & 2 deletions src/ChartJSCore/Helpers/BoolIntStringConverter.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;

namespace ChartJSCore.Helpers
{
Expand Down
2 changes: 0 additions & 2 deletions src/ChartJSCore/Helpers/CamelcaseContractResolver.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using Newtonsoft.Json.Serialization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace ChartJSCore.Helpers
{
Expand Down
2 changes: 0 additions & 2 deletions src/ChartJSCore/Helpers/DoubleStringConverter.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;

namespace ChartJSCore.Helpers
{
Expand Down
2 changes: 0 additions & 2 deletions src/ChartJSCore/Helpers/PaddingConverter.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using ChartJSCore.Models;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;

namespace ChartJSCore.Helpers
{
Expand Down
3 changes: 0 additions & 3 deletions src/ChartJSCore/Helpers/PlainJsonStringConverter.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Text;

namespace ChartJSCore.Helpers
{
Expand Down
1 change: 0 additions & 1 deletion src/ChartJSCore/Helpers/PluginDynamicConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ChartJSCore.Helpers
{
Expand Down
2 changes: 0 additions & 2 deletions src/ChartJSCore/Helpers/SingleOrArrayConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace ChartJSCore.Helpers
{
Expand Down
5 changes: 1 addition & 4 deletions src/ChartJSCore/Models/Bar/BarDataset.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using ChartJSCore.Helpers;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace ChartJSCore.Models
{
Expand All @@ -12,7 +9,7 @@ public class BarDataset : Dataset
/// <summary>
/// The type of the dataset
/// </summary>
public string Type { get; set; } = "bar";
public Enums.ChartType Type { get; set; } = Enums.ChartType.Bar;

/// <summary>
/// The ID of the x axis to plot this dataset on.
Expand Down
7 changes: 1 addition & 6 deletions src/ChartJSCore/Models/Bar/BarOptions.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace ChartJSCore.Models.Bar
namespace ChartJSCore.Models.Bar
{
public class BarOptions : Options
{
Expand Down
2 changes: 0 additions & 2 deletions src/ChartJSCore/Models/Base.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;

namespace ChartJSCore.Models
{
Expand Down
7 changes: 1 addition & 6 deletions src/ChartJSCore/Models/Bubble/BubbleData.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace ChartJSCore.Models
namespace ChartJSCore.Models
{
public class BubbleData : Base
{
Expand Down
5 changes: 1 addition & 4 deletions src/ChartJSCore/Models/Bubble/BubbleDataset.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using ChartJSCore.Helpers;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace ChartJSCore.Models
{
Expand All @@ -12,7 +9,7 @@ public class BubbleDataset : Dataset
/// <summary>
/// The type of the dataset
/// </summary>
public string Type { get; set; } = "bubble";
public Enums.ChartType Type { get; set; } = Enums.ChartType.Bubble;

/// <summary>
/// The data to plot in the bubble chart.
Expand Down
17 changes: 7 additions & 10 deletions src/ChartJSCore/Models/Chart.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
using ChartJSCore.Helpers;
using ChartJSCore.Plugins;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Newtonsoft.Json.Converters;

namespace ChartJSCore.Models
{
public class Chart : Base
{
public string Type { get; set; }
public Enums.ChartType Type { get; set; }

public Data Data { get; set; }

Expand All @@ -26,6 +21,7 @@ public string SerializeBody()
JsonSerializerSettings settings = new JsonSerializerSettings();
settings.ContractResolver = new CamelcaseContractResolver();
settings.NullValueHandling = NullValueHandling.Ignore;
settings.Converters.Add(new StringEnumConverter(true));

string json = JsonConvert.SerializeObject(this, settings);

Expand All @@ -34,17 +30,18 @@ public string SerializeBody()

public string CreateChartCode(string canvasId)
{
string code = "var " + canvasId + "Element = document.getElementById(\"" + canvasId + "\");\r\n";
code += "var " + canvasId + " = new Chart(" + canvasId + "Element, ";
string code = $"var {canvasId}Element = document.getElementById(\"{canvasId}\");\r\n";
code += $"var {canvasId} = new Chart({canvasId}Element, ";

// keys need to be camel case to match data contract so use custom serializer to alter
JsonSerializerSettings settings = new JsonSerializerSettings();
settings.ContractResolver = new CamelcaseContractResolver();
settings.NullValueHandling = NullValueHandling.Ignore;
settings.Converters.Add(new StringEnumConverter(true));

string json = JsonConvert.SerializeObject(this, settings);

code += json + "\r\n";
code += $"{json}\r\n";
code += ");";

return code;
Expand Down
5 changes: 1 addition & 4 deletions src/ChartJSCore/Models/Data.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Collections.Generic;

namespace ChartJSCore.Models
{
Expand Down
5 changes: 1 addition & 4 deletions src/ChartJSCore/Models/Dataset.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Collections.Generic;

namespace ChartJSCore.Models
{
Expand Down
16 changes: 16 additions & 0 deletions src/ChartJSCore/Models/Enums.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace ChartJSCore.Models
{
public static class Enums
{
public enum ChartType : byte
{
Bar = 0,
Bubble = 1,
Radar = 2,
PolarArea = 3,
Pie = 4,
Line = 5,
Doughnut = 6
}
}
}
4 changes: 0 additions & 4 deletions src/ChartJSCore/Models/Layout/Layout.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using ChartJSCore.Helpers;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace ChartJSCore.Models
{
Expand Down
6 changes: 1 addition & 5 deletions src/ChartJSCore/Models/Layout/Padding.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace ChartJSCore.Models
namespace ChartJSCore.Models
{
public class Padding : Base
{
Expand Down
6 changes: 1 addition & 5 deletions src/ChartJSCore/Models/Layout/PaddingObject.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace ChartJSCore.Models
namespace ChartJSCore.Models
{
public class PaddingObject : Base
{
Expand Down
11 changes: 4 additions & 7 deletions src/ChartJSCore/Models/Line/LineDataset.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
using ChartJSCore.Helpers;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace ChartJSCore.Models
{
public class LineDataset : Dataset
{
/// <summary>
/// The type of the dataset
/// </summary>
public string Type { get; set; } = "line";
/// <summary>
/// The type of the dataset
/// </summary>
public Enums.ChartType Type { get; set; } = Enums.ChartType.Line;

/// <summary>
/// The ID of the x axis to plot this dataset on.
Expand Down
7 changes: 1 addition & 6 deletions src/ChartJSCore/Models/Line/LineOptions.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace ChartJSCore.Models
namespace ChartJSCore.Models
{
public class LineOptions : Options
{
Expand Down
4 changes: 0 additions & 4 deletions src/ChartJSCore/Models/Line/LineScatterData.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using ChartJSCore.Helpers;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace ChartJSCore.Models
{
Expand Down
5 changes: 1 addition & 4 deletions src/ChartJSCore/Models/Line/LineScatterDataset.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Collections.Generic;

namespace ChartJSCore.Models
{
Expand Down
Loading

0 comments on commit 5731e59

Please sign in to comment.