241 lines
No EOL
10 KiB
HTML
241 lines
No EOL
10 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<title>Testing</title>
|
||
|
||
<script type="module">
|
||
|
||
import * as d3 from "https://cdn.jsdelivr.net/npm/d3@7/+esm";
|
||
|
||
let parsedData = {
|
||
"name": "Total Reports",
|
||
"children": [
|
||
{"name": "Working",
|
||
"children": [
|
||
{"name": "Windowing Faults", "size": 0},
|
||
{"name": "Performance Faults", "size": 0},
|
||
{"name": "Save Game Faults", "size": 0},
|
||
{"name": "Graphical Faults", "size": 0},
|
||
{"name": "Audio Faults", "size": 0},
|
||
{"name": "Input Faults", "size": 0},
|
||
{"name": "Stability Faults", "size": 0},
|
||
{"name": "Significant Bugs", "size": 0},
|
||
{"name": "No Issues", "size": 0}
|
||
]},
|
||
{"name": "Nonfunctional", "size": 0}
|
||
]
|
||
};
|
||
|
||
const jsonData = d3.json("http://localhost:8888");
|
||
//const jsonData = d3.json("gamedata.json");
|
||
jsonData.then(function (data){
|
||
let dataset = data.reports;
|
||
processData(dataset);
|
||
});
|
||
|
||
function processData(data) {
|
||
console.log(data);
|
||
for(let i = 0; i < data.length; i++) {
|
||
if(data[i].verdict == 0)
|
||
{
|
||
parsedData.children[1].size++;
|
||
}
|
||
else if(data[i].verdict == 1) {
|
||
if(data[i].windowingFaults == 1) {
|
||
parsedData.children[0].children[0].size++;
|
||
continue;
|
||
}
|
||
if(data[i].performanceFaults == 1) {
|
||
parsedData.children[0].children[1].size++;
|
||
continue;
|
||
}
|
||
if(data[i].saveGameFaults == 1) {
|
||
parsedData.children[0].children[2].size++;
|
||
continue;
|
||
}
|
||
if(data[i].graphicalFaults == 1) {
|
||
parsedData.children[0].children[3].size++;
|
||
continue;
|
||
}
|
||
if(data[i].audioFaults == 1) {
|
||
parsedData.children[0].children[4].size++;
|
||
continue;
|
||
}
|
||
if(data[i].inputFaults == 1) {
|
||
parsedData.children[0].children[5].size++;
|
||
continue;
|
||
}
|
||
if(data[i].stabilityFaults == 1) {
|
||
parsedData.children[0].children[6].size++;
|
||
continue;
|
||
}
|
||
if(data[i].significantBugs == 1) {
|
||
parsedData.children[0].children[7].size++;
|
||
continue;
|
||
}
|
||
if((
|
||
data[i].windowingFaults == 0 &&
|
||
data[i].performanceFaults == 0 &&
|
||
data[i].saveGameFaults == 0 &&
|
||
data[i].graphicalFaults == 0 &&
|
||
data[i].audioFaults == 0 &&
|
||
data[i].inputFaults == 0 &&
|
||
data[i].stabilityFaults == 0 &&
|
||
data[i].significantBugs == 0
|
||
) || (data[i].verdictOOB == 1)
|
||
) {
|
||
parsedData.children[0].children[8].size++;
|
||
}
|
||
}
|
||
}
|
||
|
||
console.log(parsedData);
|
||
let chart = Icicle(parsedData, {
|
||
value: d => d.size, // size of each node (file); null for internal nodes (folders)
|
||
label: d => d.name, // display name for each cell
|
||
title: (d, n) => `${n.ancestors().reverse().map(d => d.data.name).join(".")}\n${n.value.toLocaleString("en")}`, // hover text
|
||
width: 500,
|
||
height: 500
|
||
})
|
||
console.log(chart);
|
||
document.getElementById("dataViz").appendChild(chart);
|
||
}
|
||
|
||
// Copyright 2021 Observable, Inc.
|
||
// Released under the ISC license.
|
||
// https://observablehq.com/@d3/icicle
|
||
function Icicle(data, { // data is either tabular (array of objects) or hierarchy (nested objects)
|
||
path, // as an alternative to id and parentId, returns an array identifier, imputing internal nodes
|
||
id = Array.isArray(data) ? d => d.id : null, // if tabular data, given a d in data, returns a unique identifier (string)
|
||
parentId = Array.isArray(data) ? d => d.parentId : null, // if tabular data, given a node d, returns its parent’s identifier
|
||
children, // if hierarchical data, given a d in data, returns its children
|
||
format = ",", // format specifier string or function for values
|
||
value, // given a node d, returns a quantitative value (for area encoding; null for count)
|
||
sort = (a, b) => d3.descending(a.value, b.value), // how to sort nodes prior to layout
|
||
label, // given a node d, returns the name to display on the rectangle
|
||
title, // given a node d, returns its hover text
|
||
link, // given a node d, its link (if any)
|
||
linkTarget = "_blank", // the target attribute for links (if any)
|
||
width = 640, // outer width, in pixels
|
||
height = 400, // outer height, in pixels
|
||
margin = 0, // shorthand for margins
|
||
marginTop = margin, // top margin, in pixels
|
||
marginRight = margin, // right margin, in pixels
|
||
marginBottom = margin, // bottom margin, in pixels
|
||
marginLeft = margin, // left margin, in pixels
|
||
padding = 1, // cell padding, in pixels
|
||
round = false, // whether to round to exact pixels
|
||
color = d3.interpolateRainbow, // color scheme, if any
|
||
fill = "#ccc", // fill for node rects (if no color encoding)
|
||
fillOpacity = 0.6, // fill opacity for node rects
|
||
} = {}) {
|
||
|
||
// If id and parentId options are specified, or the path option, use d3.stratify
|
||
// to convert tabular data to a hierarchy; otherwise we assume that the data is
|
||
// specified as an object {children} with nested objects (a.k.a. the “flare.json”
|
||
// format), and use d3.hierarchy.
|
||
const root = path != null ? d3.stratify().path(path)(data)
|
||
: id != null || parentId != null ? d3.stratify().id(id).parentId(parentId)(data)
|
||
: d3.hierarchy(data, children);
|
||
|
||
// Compute the values of internal nodes by aggregating from the leaves.
|
||
value == null ? root.count() : root.sum(d => Math.max(0, value(d)));
|
||
|
||
// Compute formats.
|
||
if (typeof format !== "function") format = d3.format(format);
|
||
|
||
// Sort the leaves (typically by descending value for a pleasing layout).
|
||
if (sort != null) root.sort(sort);
|
||
|
||
// Compute the partition layout. Note that x and y are swapped!
|
||
d3.partition()
|
||
.size([height - marginTop - marginBottom, width - marginLeft - marginRight])
|
||
.padding(padding)
|
||
.round(round)
|
||
(root);
|
||
|
||
// Construct a color scale.
|
||
if (color != null) {
|
||
color = d3.scaleSequential([0, root.children.length - 1], color).unknown(fill);
|
||
root.children.forEach((child, i) => child.index = i);
|
||
}
|
||
|
||
const svg = d3.create("svg")
|
||
.attr("viewBox", [-marginLeft, -marginTop, width, height])
|
||
.attr("width", width)
|
||
.attr("height", height)
|
||
.attr("style", "max-width: 100%; height: auto; height: intrinsic;")
|
||
.attr("font-family", "sans-serif")
|
||
.attr("font-size", 10);
|
||
|
||
const cell = svg
|
||
.selectAll("a")
|
||
.data(root.descendants())
|
||
.join("a")
|
||
.attr("xlink:href", link == null ? null : d => link(d.data, d))
|
||
.attr("target", link == null ? null : linkTarget)
|
||
.attr("transform", d => `translate(${d.y0},${d.x0})`);
|
||
|
||
cell.append("rect")
|
||
.attr("width", d => d.y1 - d.y0)
|
||
.attr("height", d => d.x1 - d.x0)
|
||
.attr("fill", color ? d => color(d.ancestors().reverse()[1]?.index) : fill)
|
||
.attr("fill-opacity", fillOpacity);
|
||
|
||
const text = cell.filter(d => d.x1 - d.x0 > 10).append("text")
|
||
.attr("x", 4)
|
||
.attr("y", d => Math.min(9, (d.x1 - d.x0) / 2))
|
||
.attr("dy", "0.32em");
|
||
|
||
if (label != null) text.append("tspan")
|
||
.text(d => label(d.data, d));
|
||
|
||
text.append("tspan")
|
||
.attr("fill-opacity", 0.7)
|
||
.attr("dx", label == null ? null : 3)
|
||
.text(d => format(d.value));
|
||
|
||
if (title != null) cell.append("title")
|
||
.text(d => title(d.data, d));
|
||
|
||
return svg.node();
|
||
}
|
||
|
||
function responsivefy(svg) {
|
||
// get container + svg aspect ratio
|
||
var container = d3.select(svg.node().parentNode),
|
||
width = parseInt(svg.style("width")),
|
||
height = parseInt(svg.style("height")),
|
||
aspect = width / height;
|
||
|
||
// add viewBox and preserveAspectRatio properties,
|
||
// and call resize so that svg resizes on inital page load
|
||
svg.attr("viewBox", "0 0 " + width + " " + height)
|
||
.attr("perserveAspectRatio", "xMinYMid")
|
||
.call(resize);
|
||
|
||
// to register multiple listeners for same event type,
|
||
// you need to add namespace, i.e., 'click.foo'
|
||
// necessary if you call invoke this function for multiple svgs
|
||
// api docs: https://github.com/mbostock/d3/wiki/Selections#on
|
||
d3.select(window).on("resize." + container.attr("id"), resize);
|
||
|
||
// get width of container and resize svg to fit it
|
||
function resize() {
|
||
var targetWidth = parseInt(container.style("width"));
|
||
svg.attr("width", targetWidth);
|
||
svg.attr("height", Math.round(targetWidth / aspect));
|
||
}
|
||
}
|
||
</script>
|
||
|
||
</head>
|
||
<body>
|
||
|
||
<div>
|
||
<svg width="1152" height="2400" id="dataViz"></svg>
|
||
</div>
|
||
|
||
</body>
|
||
</html> |