Skip to content

Commit

Permalink
Version 1.0.1
Browse files Browse the repository at this point in the history
Changes:
 * ApexCharts.NET Test
 * FormatJson Option
 * Test Project
 * small fixes
  • Loading branch information
tolbxela committed Aug 8, 2019
1 parent 6fdefd3 commit 3b1cdc5
Show file tree
Hide file tree
Showing 15 changed files with 174 additions and 27 deletions.
8 changes: 7 additions & 1 deletion ApexCharts.NET.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ VisualStudioVersion = 15.0.28307.757
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApexCharts.NET", "Code\ApexCharts.NET.csproj", "{C136A37E-7883-433A-960E-117B602015D6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ApexCharts.NET Demo", "Demo\ApexCharts.NET Demo.csproj", "{B63AF76F-9628-486C-A8BA-5F805A0EDD94}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApexCharts.NET Demo", "Demo\ApexCharts.NET Demo.csproj", "{B63AF76F-9628-486C-A8BA-5F805A0EDD94}"
ProjectSection(ProjectDependencies) = postProject
{C136A37E-7883-433A-960E-117B602015D6} = {C136A37E-7883-433A-960E-117B602015D6}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ApexCharts.NET Test", "Test\ApexCharts.NET Test.csproj", "{0F7848B7-E9B9-408F-860E-51B813B5C070}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -24,6 +26,10 @@ Global
{B63AF76F-9628-486C-A8BA-5F805A0EDD94}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B63AF76F-9628-486C-A8BA-5F805A0EDD94}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B63AF76F-9628-486C-A8BA-5F805A0EDD94}.Release|Any CPU.Build.0 = Release|Any CPU
{0F7848B7-E9B9-408F-860E-51B813B5C070}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0F7848B7-E9B9-408F-860E-51B813B5C070}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0F7848B7-E9B9-408F-860E-51B813B5C070}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0F7848B7-E9B9-408F-860E-51B813B5C070}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
3 changes: 3 additions & 0 deletions Code/ApexCharts.NET.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageId>ApexCharts.NET</PackageId>
<Product>ApexCharts.NET</Product>
<AssemblyVersion>1.0.1.0</AssemblyVersion>
<FileVersion>1.0.1.0</FileVersion>
<Version>1.0.1</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions Code/Src/ApexChart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ public override string ToString()
{
var jsonOptions = JsonConvert.SerializeObject(
Options,
Formatting.Indented,
(FormatJson) ? Formatting.Indented : Formatting.None,
new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore
}
}
);

jsonChart = $"var {ChartVarName} = new ApexCharts( document.querySelector(\"{HtmlSelector}\"), {jsonOptions} );" +
jsonChart = $"var {ChartVarName} = new ApexCharts(document.querySelector(\"{HtmlSelector}\"), {jsonOptions});" +
Environment.NewLine +
$"{ChartVarName}.render();";
}
Expand Down
8 changes: 8 additions & 0 deletions Code/Src/Enums/StrokeCurve.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Tolbxela.ApexCharts
{
public enum StrokeCurve
{
smooth,
straight
}
}
10 changes: 7 additions & 3 deletions Code/Src/Options/Chart/Chart.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.ComponentModel;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

Expand Down Expand Up @@ -29,13 +30,15 @@ public class Chart
/// Sets the font family for all the text elements of the chart. Defaults to 'Helvetica, Arial, sans-serif'
/// </summary>
[JsonProperty("fontFamily")]
public string FontFamily { get; set; } = "Helvetica, Arial, sans-serif";
[DefaultValue("Helvetica, Arial, sans-serif")]
public string FontFamily { get; set; }

/// <summary>
/// Sets the text color for the chart. Defaults to #373d3f
/// </summary>
[JsonProperty("foreColor")]
public string ForeColor { get; set; } = "373d3f";
[DefaultValue("373d3f")]
public string ForeColor { get; set; }

/// <summary>
/// A small increment in height added to the parent of chart element.
Expand Down Expand Up @@ -76,7 +79,8 @@ public class Chart
/// </summary>
[JsonProperty("type")]
[JsonConverter(typeof(StringEnumConverter))]
public ChartType? Type { get; set; } = ChartType.line;
[DefaultValue(ChartType.line)]
public ChartType? Type { get; set; }

[JsonProperty("zoom")]
public ChartZoom Zoom { get; set; }
Expand Down
6 changes: 4 additions & 2 deletions Code/Src/Options/Chart/Sparkline.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using Newtonsoft.Json;
using System.ComponentModel;
using Newtonsoft.Json;

namespace Tolbxela.ApexCharts
{
public class Sparkline
{

[JsonProperty("enabled")]
public bool? Enabled { get; set; }
[DefaultValue(false)]
public bool? Enabled { get; set; } = false;
}


Expand Down
6 changes: 4 additions & 2 deletions Code/Src/Options/Chart/Toolbar/Toolbar.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using Newtonsoft.Json;
using System.ComponentModel;
using Newtonsoft.Json;

namespace Tolbxela.ApexCharts
{
public class Toolbar
{

[JsonProperty("show")]
public bool? Show { get; set; }
[DefaultValue(true)]
public bool? Show { get; set; } = true;

[JsonProperty("tools")]
public ToolbarTools Tools { get; set; }
Expand Down
10 changes: 9 additions & 1 deletion Code/Src/Options/Chart/Toolbar/ToolbarTools.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,38 @@
using System.Collections.Generic;
using System.ComponentModel;
using Newtonsoft.Json;

namespace Tolbxela.ApexCharts
{
public class ToolbarTools
{
[JsonProperty("download")]
[DefaultValue(true)]
public bool? Download { get; set; }

[JsonProperty("selection")]
[DefaultValue(true)]
public bool? Selection { get; set; }

[JsonProperty("zoom")]
[DefaultValue(true)]
public bool? Zoom { get; set; }

[JsonProperty("zoomin")]
[DefaultValue(true)]
public bool? Zoomin { get; set; }

[JsonProperty("zoomout")]
[DefaultValue(true)]
public bool? Zoomout { get; set; }

[JsonProperty("pan")]
[DefaultValue(true)]
public bool? Pan { get; set; }

[JsonProperty("reset")]
public string Reset { get; set; }
[DefaultValue(true)]
public object Reset { get; set; }

[JsonProperty("customIcons")]
public IList<object> CustomIcons { get; set; }
Expand Down
9 changes: 6 additions & 3 deletions Code/Src/Options/Chart/Zoom/ChartZoom.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
using Newtonsoft.Json;
using System.ComponentModel;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace Tolbxela.ApexCharts
{
public class ChartZoom
{
[JsonProperty("enabled")]
public bool? Enabled { get; set; }
[DefaultValue(false)]
public bool? Enabled { get; set; } = false;

[JsonProperty("type")]
[JsonConverter(typeof(StringEnumConverter))]
public ZoomType? Type { get; set; } = ZoomType.x;
[DefaultValue(ZoomType.x)]
public ZoomType? Type { get; set; }

[JsonProperty("autoScaleYaxis")]
public bool? AutoScaleYaxis { get; set; }
Expand Down
3 changes: 2 additions & 1 deletion Code/Src/Options/Fill/ChartFillGradient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ namespace Tolbxela.ApexCharts
public class ChartFillGradient
{
[JsonProperty("shade")]
public string Shade { get; set; }
[JsonConverter(typeof(StringEnumConverter))]
public ShadeType? Shade { get; set; }

[JsonProperty("type")]
[JsonConverter(typeof(StringEnumConverter))]
Expand Down
9 changes: 6 additions & 3 deletions Code/Src/Options/Stroke.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.ComponentModel;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
Expand All @@ -11,10 +11,13 @@ public class Stroke
public bool? Show { get; set; }

[JsonProperty("curve")]
public string Curve { get; set; }
[JsonConverter(typeof(StringEnumConverter))]
[DefaultValue(StrokeCurve.straight)]
public StrokeCurve? Curve { get; set; }

[JsonProperty("lineCap")]
public string LineCap { get; set; }
[JsonConverter(typeof(StringEnumConverter))]
public LineCap? LineCap { get; set; }

[JsonProperty("colors")]
public IList<object> Colors { get; set; }
Expand Down
6 changes: 3 additions & 3 deletions Demo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ static void Main(string[] args)
}
};

var apexchart = new ApexChart("apexchart", "#ApexChart", options);
var apexchart = new ApexChart("apexchart", "#ApexChart", options, formatJson: true);

Console.WriteLine($"Saving Chart to file '{FileName}'");
File.WriteAllText(FileName, apexchart.ToString());
Expand All @@ -166,8 +166,8 @@ static void Main(string[] args)
proc.StartInfo.FileName = "index.html";
proc.Start();

Console.WriteLine("Press any key...");
Console.ReadKey();
//Console.WriteLine("Press any key...");
//Console.ReadKey();

}
}
Expand Down
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

C# .Net Standard 2.0 wrapper for the ApexCharts Javascript Library - https://apexcharts.com

* [Code](Code) - ApexCharts.NET C# .Net Standard 2.0 Library
* [Demo](Demo) - ApexCharts.NET Demo Chart (.Net Core App)
* [Code](Code) - C# .Net Standard 2.0 Library
* [Demo](Demo) - Demo Chart App (.Net Core App)
* [Test](Test) - xUnit Tests (not completed)

Demo Chart

![Demo Chart](demochart.png)
![Demo Chart](demochart.png)
77 changes: 77 additions & 0 deletions Test/ApexChartTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using System;
using Newtonsoft.Json;
using Tolbxela.ApexCharts;
using Xunit;

namespace Test
{
public class ApexChartTests
{
const string ChartName = "Chart";
const string Selector = "#Selector";

public ApexChartTests()
{
}

[Fact]
public void ApexChartTest_NotNull()
{
var chart = new ApexChart(ChartName, Selector, null, formatJson: false);
Assert.NotNull(chart);
}

[Fact]
public void ApexChartTest_Json()
{
var chart = new ApexChart(ChartName, Selector, null, formatJson: false);
var json = chart.ToString();
Assert.False(string.IsNullOrWhiteSpace(json));
}

[Fact]
public void ApexChartTest_NullOptions()
{
var chart = new ApexChart(ChartName, Selector, null, formatJson: false);
var chartJson = chart.ToString();
var options = "null";
var chartSample = $"var {ChartName} = new ApexCharts(document.querySelector(\"{Selector}\"), {options});" + Environment.NewLine +
$"{ChartName}.render();";

Assert.Equal(chartSample, chartJson);
}

[Fact]
public void ApexChartTest_EmptyOptions()
{
var options = new ChartOptions();

var jsonOptions = JsonConvert.SerializeObject(
options,
Formatting.None,
new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore
}
);

var jsonOptionsSample = "{\"chart\":{}}";

Assert.Equal(jsonOptionsSample, jsonOptions);
}

[Fact]
public void ApexChartTest_EmptyChart()
{
var options = new ChartOptions();

var chart = new ApexChart(ChartName, Selector, options, formatJson: false);
var chartJson = chart.ToString();
var jsonOptionsSample = "{\"chart\":{\"id\":\"" + ChartName + "\"}}";
var chartSample = $"var {ChartName} = new ApexCharts(document.querySelector(\"{Selector}\"), {jsonOptionsSample});" + Environment.NewLine +
$"{ChartName}.render();";

Assert.Equal(chartSample, chartJson);
}
}
}
31 changes: 31 additions & 0 deletions Test/ApexCharts.NET Test.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>

<IsPackable>false</IsPackable>

<Authors>Tolbxela</Authors>

<Copyright>Tolbxela © 2019</Copyright>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="1.0.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.msbuild" Version="2.6.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Code\ApexCharts.NET.csproj" />
</ItemGroup>

</Project>

0 comments on commit 3b1cdc5

Please sign in to comment.