Skip to content

Commit 627ea78

Browse files
Replace image resizing sample with chartist sample
1 parent 3162946 commit 627ea78

File tree

11 files changed

+42
-113
lines changed

11 files changed

+42
-113
lines changed

samples/misc/NodeServicesExamples/Controllers/HomeController.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Threading.Tasks;
22
using Microsoft.AspNetCore.Mvc;
3+
using Microsoft.AspNetCore.NodeServices;
34

45
namespace NodeServicesExamples.Controllers
56
{
@@ -15,8 +16,21 @@ public IActionResult ES2015Transpilation()
1516
return View();
1617
}
1718

18-
public IActionResult ImageResizing()
19+
public async Task<IActionResult> Chart([FromServices] INodeServices nodeServices)
1920
{
21+
var options = new { width = 400, height = 200, showArea = true, showPoint = true, fullWidth = true };
22+
var data = new
23+
{
24+
labels = new[] { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" },
25+
series = new[] {
26+
new[] { 1, 5, 2, 5, 4, 3 },
27+
new[] { 2, 3, 4, 8, 1, 2 },
28+
new[] { 5, 4, 3, 2, 1, 0 }
29+
}
30+
};
31+
32+
ViewData["ChartMarkup"] = await nodeServices.InvokeAsync<string>("./Node/renderChart", "line", options, data);
33+
2034
return View();
2135
}
2236

samples/misc/NodeServicesExamples/Controllers/ResizeImage.cs

Lines changed: 0 additions & 64 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
var generate = require('node-chartist');
2+
3+
module.exports = function (callback, type, options, data) {
4+
generate(type, options, data).then(
5+
result => callback(null, result), // Success case
6+
error => callback(error) // Error case
7+
);
8+
};

samples/misc/NodeServicesExamples/Node/resizeImage.js

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<h1>Server-rendered chart</h1>
2+
3+
<p>
4+
This sample demonstrates how arbitrary NPM modules can be invoked from .NET code.
5+
</p>
6+
<p>
7+
In this case, we use <code>node-chartist</code> to render the following chart on the server. The output is
8+
identical to what you'd get if you used <a href='https://gionkunz.github.io/chartist-js/'>chartist.js</a>
9+
on the client, except that in this example, we're not executing any client-side code at all.
10+
</p>
11+
12+
@Html.Raw(ViewData["ChartMarkup"])

samples/misc/NodeServicesExamples/Views/Home/ImageResizing.cshtml

Lines changed: 0 additions & 34 deletions
This file was deleted.

samples/misc/NodeServicesExamples/Views/Home/Index.cshtml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
</p>
88

99
<ul>
10-
<li><a asp-action="ES2015Transpilation">ES2015 transpilation</a>
11-
<li><a asp-action="ImageResizing">Image resizing</a>
12-
</li>
13-
10+
<li><a asp-action="ES2015Transpilation">ES2015 transpilation</a></li>
11+
<li><a asp-action="Chart">Server-side chart rendering</a></li>
12+
</ul>

samples/misc/NodeServicesExamples/Views/Shared/_Layout.cshtml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
<!doctype html>
1+
<!doctype html>
22
<html>
33
<head>
44
<meta charset="utf-8" />
55
<title>NodeServices Examples</title>
6+
<link rel="stylesheet" href="~/css/chartist.min.css" />
67
</head>
78
<body>
89
@RenderBody()

samples/misc/NodeServicesExamples/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
"dependencies": {
55
"babel-core": "^6.7.4",
66
"babel-preset-es2015": "^6.6.0",
7-
"sharp": "^0.15.0"
7+
"node-chartist": "^1.0.2"
88
}
99
}

samples/misc/NodeServicesExamples/wwwroot/css/chartist.min.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)