Skip to content

Commit 5e02738

Browse files
Merge pull request #227 from JocaPC/master
Updated product-catalog samples for Virtal Pass demo
2 parents 72558a1 + 7104348 commit 5e02738

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2645
-2
lines changed

samples/features/json/product-catalog/dotnet-jquery-bootstrap-app/Controllers/ProductController.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,40 @@ public async Task Delete(int id)
8888
cmd.Parameters.AddWithValue("id", id);
8989
await sqlCmd.ExecuteNonQuery(cmd);
9090
}
91+
92+
// GET api/Product/Report1
93+
[HttpGet("Report1")]
94+
public async Task Report1()
95+
{
96+
await sqlQuery.Stream(
97+
@"select Color as [key],
98+
AVG( Price ) as value
99+
from Product
100+
group by Color
101+
FOR JSON PATH", Response.Body, "[]");
102+
}
103+
104+
// GET api/Product/Report2
105+
[HttpGet("Report2")]
106+
public async Task Report2()
107+
{
108+
await sqlQuery.Stream(@"
109+
select Color as x,
110+
AVG (Price) / MAX(Price) as y
111+
from Product
112+
group by Color
113+
FOR JSON PATH", Response.Body, "[]");
114+
}
115+
116+
[HttpGet("Report3")]
117+
public async Task Report3()
118+
{
119+
await sqlQuery.Stream(@"
120+
select Color as x,
121+
AVG (Price) / MAX(Price) as y
122+
from Product
123+
group by Color
124+
FOR JSON PATH", Response.Body, "[]");
125+
}
91126
}
92127
}

samples/features/json/product-catalog/dotnet-jquery-bootstrap-app/sql-scripts/demo.sql

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,24 @@ group by JSON_VALUE(Data, '$.Type'), Color
1919
having JSON_VALUE(Data, '$.Type') is not null
2020
order by JSON_VALUE(Data, '$.Type')
2121

22+
-- Indexing JSON data
23+
drop index if exists json_index on Product
24+
25+
alter table product
26+
add Type AS JSON_VALUE(Data, '$.Type'),
27+
ManufacturingCost AS cast(JSON_VALUE(Data, '$.ManufacturingCost') as float)
28+
29+
create index json_index on Product(Type, Color)
30+
include (ManufacturingCost)
31+
32+
--Query uses index on JSON and relational columns
33+
select JSON_VALUE(Data, '$.Type') as Type, Color,
34+
AVG( cast(JSON_VALUE(Data, '$.ManufacturingCost') as float) ) as Cost
35+
from Product
36+
group by JSON_VALUE(Data, '$.Type'), Color
37+
having JSON_VALUE(Data, '$.Type') is not null
38+
order by JSON_VALUE(Data, '$.Type')
39+
2240
--Update JSON Data
2341
--Current values in row:
2442
select Data,Tags

samples/features/json/product-catalog/dotnet-jquery-bootstrap-app/sql-scripts/setup.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ SET IDENTITY_INSERT Product ON
2929
GO
3030

3131
DECLARE @products NVARCHAR(MAX) =
32-
N'[{"ProductID":15,"Name":"Adjustable Race","Color":"Magenta","Size":"62","Price":100.0000,"Quantity":75,"Data":{"Type":"Part","MadeIn":"China"}},{"ProductID":16,"Name":"Bearing Ball","Color":"Magenta","Size":"62","Price":15.9900,"Quantity":90,"Data":{"ManufacturingCost":11.672700,"Type":"Part","MadeIn":"China"},"Tags":["promo"]},{"ProductID":17,"Name":"BB Ball Bearing","Color":"Magenta","Size":"62","Price":28.9900,"Quantity":80,"Data":{"ManufacturingCost":21.162700,"Type":"Part","MadeIn":"China"}},{"ProductID":18,"Name":"Blade","Color":"Magenta","Size":"62","Price":18.0000,"Quantity":45,"Data":{},"Tags":["new"]},{"ProductID":19,"Name":"Sport-100 Helmet, Red","Color":"Red","Size":"72","Price":41.9900,"Quantity":38,"Data":{"ManufacturingCost":30.652700,"Type":"Еquipment","MadeIn":"China"},"Tags":["promo"]},{"ProductID":20,"Name":"Sport-100 Helmet, Black","Color":"Black","Size":"72","Price":31.4900,"Quantity":60,"Data":{"ManufacturingCost":22.987700,"Type":"Еquipment","MadeIn":"China"},"Tags":["new","promo"]},{"ProductID":21,"Name":"Mountain Bike Socks, M","Color":"White","Size":"M","Price":560.9900,"Quantity":30,"Data":{"Type":"Clothes"},"Tags":["sales","promo"]},{"ProductID":22,"Name":"Mountain Bike Socks, L","Color":"White","Size":"L","Price":120.9900,"Quantity":20,"Data":{"ManufacturingCost":88.322700,"Type":"Clothes"},"Tags":["sales","promo"]},{"ProductID":23,"Name":"Long-Sleeve Logo Jersey, XL","Color":"Multi","Size":"XL","Price":44.9900,"Quantity":60,"Data":{"ManufacturingCost":32.842700,"Type":"Clothes"},"Tags":["sales","promo"]},{"ProductID":24,"Name":"Road-650 Black, 52","Color":"Black","Size":"52","Price":704.6900,"Quantity":70,"Data":{"Type":"Bike","MadeIn":"UK"}},{"ProductID":25,"Name":"Mountain-100 Silver, 38","Color":"Silver","Size":"38","Price":359.9900,"Quantity":45,"Data":{"ManufacturingCost":262.792700,"Type":"Bike","MadeIn":"UK"},"Tags":["promo"]},{"ProductID":26,"Name":"Road-250 Black, 48","Color":"Black","Size":"48","Price":299.0200,"Quantity":25,"Data":{"ManufacturingCost":218.284600,"Type":"Bike","MadeIn":"UK"},"Tags":["new","promo"]},{"ProductID":27,"Name":"ML Bottom Bracket","Price":101.2400,"Quantity":50,"Data":{"Type":"Part","MadeIn":"China"}},{"ProductID":28,"Name":"HL Bottom Bracket","Price":121.4900,"Quantity":65,"Data":{"ManufacturingCost":88.687700,"Type":"Part","MadeIn":"China"}}]'
32+
N'[{"ProductID":15,"Name":"Adjustable Race","Color":"Magenta","Size":"62","Price":100.0000,"Quantity":75,"Data":{"Type":"Part","MadeIn":"China"}},{"ProductID":16,"Name":"Bearing Ball","Color":"Magenta","Size":"62","Price":15.9900,"Quantity":90,"Data":{"ManufacturingCost":11.672700,"Type":"Part","MadeIn":"China"},"Tags":["promo"]},{"ProductID":17,"Name":"BB Ball Bearing","Color":"Magenta","Size":"62","Price":28.9900,"Quantity":80,"Data":{"ManufacturingCost":21.162700,"Type":"Part","MadeIn":"China"}},{"ProductID":18,"Name":"Blade","Color":"Magenta","Size":"62","Price":18.0000,"Quantity":45,"Data":{},"Tags":["new"]},{"ProductID":19,"Name":"Sport-100 Helmet, Red","Color":"Red","Size":"72","Price":41.9900,"Quantity":38,"Data":{"ManufacturingCost":30.652700,"Type":"Еquipment","MadeIn":"China"},"Tags":["promo"]},{"ProductID":20,"Name":"Sport-100 Helmet, Black","Color":"Black","Size":"72","Price":31.4900,"Quantity":60,"Data":{"ManufacturingCost":22.987700,"Type":"Еquipment","MadeIn":"China"},"Tags":["new","promo"]},{"ProductID":21,"Name":"Mountain Bike Socks, M","Color":"White","Size":"M","Price":560.9900,"Quantity":30,"Data":{"Type":"Clothes"},"Tags":["sales","promo"]},{"ProductID":22,"Name":"Mountain Bike Socks, L","Color":"White","Size":"L","Price":120.9900,"Quantity":20,"Data":{"ManufacturingCost":88.322700,"Type":"Clothes"},"Tags":["sales","promo"]},{"ProductID":23,"Name":"Long-Sleeve Logo Jersey, XL","Color":"Multi","Size":"XL","Price":44.9900,"Quantity":60,"Data":{"ManufacturingCost":32.842700,"Type":"Clothes"},"Tags":["sales","promo"]},{"ProductID":24,"Name":"Road-650 Black, 52","Color":"Black","Size":"52","Price":704.6900,"Quantity":70,"Data":{"Type":"Bike","MadeIn":"UK","Tyres":["300c","35C"],"Weight":9.5,"Gender":"M"}},{"ProductID":25,"Name":"Mountain-100 Silver, 38","Color":"Silver","Size":"38","Price":359.9900,"Quantity":45,"Data":{"ManufacturingCost":262.792700,"Type":"Bike","MadeIn":"UK","Gears":20,"Weight":9.5,"Gender":"M"},"Tags":["promo"]},{"ProductID":26,"Name":"Road-250 Black, 48","Color":"Black","Size":"48","Price":299.0200,"Quantity":25,"Data":{"ManufacturingCost":218.284600,"Type":"Bike","MadeIn":"UK"},"Tags":["new","promo"]},{"ProductID":27,"Name":"ML Bottom Bracket","Price":101.2400,"Quantity":50,"Data":{"Type":"Part","MadeIn":"China"}},{"ProductID":28,"Name":"HL Bottom Bracket","Price":121.4900,"Quantity":65,"Data":{"ManufacturingCost":88.687700,"Type":"Part","MadeIn":"China"}},{"ProductID":29,"Name":"Sport Helmet","Color":"Black","Size":"72","Price":55.9900,"Quantity":20,"Data":{"Visor":true, "WxDxH": [32,26.4,22]},"Tags":["promo"]},{"ProductID":30,"Name":"Hybrid Car XLV","Color":"Silver","Price":29500.0000,"Quantity":5,"Data":{"Type":"Car","Doors":4,"Seats":5,"MPG":29}},{"ProductID":31,"Name":"Car, Hybrid (OM)","Color":"White","Price":35000.0000,"Quantity":2,"Data":{"Type":"Car","Doors":2,"Seats":2,"MPG":35},"Tags":["promo"]}]'
3333
INSERT INTO Product (ProductID, Name, Color, Size, Price, Quantity, Data, Tags)
3434
SELECT ProductID, Name, Color, Size, Price, Quantity, Data, Tags
3535
FROM OPENJSON (@products) WITH(
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<script src="/media/js/jquery.js"></script>
5+
<script src="/media/js/d3/d3.v4.min.js"></script>
6+
<script src="/media/js/d3/pie.js"></script>
7+
<script src="/media/js/d3/barChart.js"></script>
8+
<style>
9+
.bar {
10+
fill: steelblue;
11+
}
12+
.bar:hover {
13+
fill: brown;
14+
}
15+
</style>
16+
</head>
17+
<body>
18+
19+
<h1>Dashboard</h1>
20+
21+
<svg id="pie" width="600" height="400"></svg>
22+
23+
<svg id="chart" width="600" height="400"></svg>
24+
25+
<svg id="chart2" width="600" height="400"></svg>
26+
27+
<script>
28+
29+
$(function () {
30+
31+
$.getJSON("/api/Product/Report1")
32+
.done(function (data) {
33+
var c = new Pie("svg#pie", { "innerRadius": 100 });
34+
c.Data(data);
35+
});
36+
37+
$.getJSON("/api/Product/Report2")
38+
.done(function (data) {
39+
var c = new BarChart("svg#chart", { "innerRadius": 100 });
40+
c.Data(data);
41+
});
42+
43+
$.getJSON("/api/Product/Report3")
44+
.done(function (data) {
45+
var c = new BarChart("svg#chart2", { "innerRadius": 20 });
46+
c.Data(data);
47+
});
48+
49+
});
50+
</script>
51+
</body>
52+
</html>
1.12 KB
Binary file not shown.
1.12 KB
Binary file not shown.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* D3 BarChart Control.
3+
* Encapsulated example from: https://bl.ocks.org/mbostock/3885304
4+
* Licence: GNU General Public License, version 3
5+
* Authors: Mike Bostock, Jovan Popovic
6+
**************************************************************************/
7+
8+
var BarChart = function(target, options) {
9+
10+
options = options || {};
11+
this.options = options;
12+
13+
var svg = d3.select(target),
14+
margin = options.margin || {top: 20, right: 20, bottom: 30, left: 40},
15+
width = (options.width||0)+svg.attr("width") - margin.left - margin.right,
16+
height = (options.height||0)+svg.attr("height") - margin.top - margin.bottom;
17+
18+
var x = d3.scaleBand().rangeRound([0, width]).padding(0.1),
19+
y = d3.scaleLinear().rangeRound([height, 0]);
20+
21+
var g = svg.append("g")
22+
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
23+
24+
25+
this.Data = function(data) {
26+
27+
x.domain(data.map(function(d) { return d.x; }));
28+
y.domain([0, d3.max(data, function(d) { return d.y; })]);
29+
30+
g.append("g")
31+
.attr("class", "axis axis--x")
32+
.attr("transform", "translate(0," + height + ")")
33+
.call(d3.axisBottom(x));
34+
35+
g.append("g")
36+
.attr("class", "axis axis--y")
37+
.call(d3.axisLeft(y).ticks(10, "%"))
38+
.append("text")
39+
.attr("transform", "rotate(-90)")
40+
.attr("y", 6)
41+
.attr("dy", "0.71em")
42+
.attr("text-anchor", "end")
43+
.text("Frequency");
44+
45+
g.selectAll(".bar")
46+
.data(data)
47+
.enter().append("rect")
48+
.attr("class", "bar")
49+
.attr("x", function(d) { return x(d.x); })
50+
.attr("y", function(d) { return y(d.y); })
51+
.attr("width", x.bandwidth())
52+
.attr("height", function(d) { return height - y(d.y); });
53+
}
54+
55+
};
56+
57+
58+
59+

samples/features/json/product-catalog/dotnet-jquery-bootstrap-app/wwwroot/media/js/d3/d3.v4.min.js

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* D3 PieChart Control.
3+
* Encapsulated example from: https://bl.ocks.org/mbostock/3887235
4+
* Licence: GNU General Public License, version 3
5+
* Authors: Mike Bostock, Jovan Popovic
6+
**************************************************************************/
7+
8+
var Pie = function(target, options) {
9+
10+
options = options || {};
11+
this.options = options;
12+
var _fnGetDate = options.date || function(d) { return d.Date; };
13+
var _fnGetValue = options.value || function(d) { return d[0].Value; };
14+
15+
var svg = d3.select(target),
16+
width = options.width||0+svg.attr("width"),
17+
height = options.height||0+svg.attr("height"),
18+
radius = Math.min(width, height) / 2,
19+
g = svg.append("g").attr("transform", "translate(" + width / 2 + "," + height / 2 + ")");
20+
21+
var color = d3.scaleOrdinal(options.colors || ["#98abc5", "#8a89a6", "#7b6888", "#6b486b", "#a05d56", "#d0743c", "#ff8c00"]);
22+
23+
var pie = d3.pie()
24+
.sort(null)
25+
.value(function(d) { return d.value; });
26+
27+
var path = d3.arc()
28+
.outerRadius(radius - 10)
29+
.innerRadius(options.innerRadius || 0);
30+
31+
var label = d3.arc()
32+
.outerRadius(radius - 40)
33+
.innerRadius(radius - 40);
34+
35+
this.Data = function(data) {
36+
var arc = g.selectAll(".arc")
37+
.data(pie(data))
38+
.enter().append("g")
39+
.attr("class", "arc");
40+
41+
arc.append("path")
42+
.attr("d", path)
43+
.attr("fill", function(d) { return color(d.data.key); });
44+
45+
arc.append("text")
46+
.attr("transform", function(d) { return "translate(" + label.centroid(d) + ")"; })
47+
.attr("dy", "0.35em")
48+
.text(function(d) { return d.data.key; });
49+
}
50+
51+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.vs/*
2+
node_modules/*
3+
bin/*.dll
4+
obj/*
5+
*.sln
6+
*.log

0 commit comments

Comments
 (0)