Skip to content

Commit

Permalink
Merge pull request canonical#13389 from canonical/chiselled-ubuntu
Browse files Browse the repository at this point in the history
  • Loading branch information
akbarkz authored Dec 12, 2023
2 parents 1a419ab + 1c90b5c commit 9c44899
Show file tree
Hide file tree
Showing 5 changed files with 613 additions and 2 deletions.
3 changes: 2 additions & 1 deletion build.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ let entries = {
"kernel-form": "./static/js/src/kernel-form.js",
"random-partner-logos": "./static/js/src/random-partner-logos.js",
"credEnterprisePurchasing": "./static/js/src/advantage/credentials/app.tsx",
activate: "./static/js/src/activate.js"
activate: "./static/js/src/activate.js",
"chiselled-chart": "./static/js/src/charts/chiselled-chart.js"
};

const isDev = process && process.env && process.env.NODE_ENV === "development";
Expand Down
2 changes: 2 additions & 0 deletions navigation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ containers:
- title: What are containers
path: /containers/what-are-containers
- title: Chiselled Ubuntu
path: /containers/chiselled
- title: Chiselled and .NET
path: /containers/chiselled/dotnet

ai:
Expand Down
94 changes: 94 additions & 0 deletions static/js/src/charts/chiselled-chart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { debounce } from "../utils/debounce.js";

function buildChiselledChart(selector, data, isFirst) {
const colors = ["#CBA7B8", "#923A66", "#000000"];

const width = document.querySelector(selector).getBoundingClientRect().width;

const x = d3.scaleLinear().range([0, width]).domain([0, 330]);

const withAxis = screen.width < 1036 || isFirst;

const svg = d3
.select(selector)
.append("svg")
.attr("width", width)
.attr("height", `${2.5 * (data.length + (withAxis ? 1 : 0))}em`); // make the height bigger if it shows with axis

const xAxis = d3.axisTop(x).ticks(3).tickSizeInner(24).tickSizeOuter(0);

const axisG = svg.append("g");

if (withAxis) axisG.style("transform", "translate(0, 2.3rem)");

axisG.call(xAxis);

axisG
.selectAll("text")
.attr("transform", "translate(5, 20)")
.attr("text-anchor", "start")
.style("font-size", "1.6em")
.style("color", "#666666");

axisG
.select(".domain")
.attr("transform", "translate(0, -2)")
.attr("stroke", "#000000")
.attr("stroke-width", "1px")
.attr("opacity", "0.2");

axisG
.selectAll("line")
.attr("transform", "translate(0, -2)")
.attr("stroke", "#000000")
.attr("stroke-width", "1px")
.attr("opacity", "0.2");

const chartG = svg.append("g");

if (withAxis) chartG.style("transform", "translate(0, 2.4em)");

chartG
.selectAll()
.data(data)
.enter()
.append("rect")
.attr("fill", function (d, i) {
if (i === data.length - 1) return colors[colors.length - 1];
return colors[i];
})
.attr("x", 0)
.attr("y", function (d, i) {
return `${2.5 * i}em`;
})
.attr("height", "2.35em")
.attr("width", function (d, i) {
return x(d);
})
.attr("aria-label", function (d, i) {
return `${d} MB`;
});
}

function clearChiselledChart(selector) {
const chart = document.querySelector(selector);
if (chart) {
chart.innerHTML = "";
}
}

window.addEventListener(
"resize",
debounce(function () {
clearChiselledChart("#chiselled-dotnet-chart");
clearChiselledChart("#chiselled-java-chart");
clearChiselledChart("#chiselled-other-chart");
buildChiselledChart("#chiselled-dotnet-chart", [219, 116, 5], true);
buildChiselledChart("#chiselled-java-chart", [215, 113]);
buildChiselledChart("#chiselled-other-chart", [20, 12]);
}, 250)
);

buildChiselledChart("#chiselled-dotnet-chart", [219, 116, 5], true);
buildChiselledChart("#chiselled-java-chart", [215, 113]);
buildChiselledChart("#chiselled-other-chart", [20, 12]);
2 changes: 1 addition & 1 deletion templates/containers/chiselled/_base_chiselled.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends "templates/base.html" %}

{% block meta_copydoc %}https://drive.google.com/drive/folders/1KzbPY6u1J4_F4-sVTR8fGnbD16EpIpAW{% endblock meta_copydoc %}
{% block meta_copydoc %}https://docs.google.com/document/d/1ZkQ-UFTwsPkMnQn8IEEjZOXMy40tkgBscw_-qq9K3nc/edit{% endblock meta_copydoc %}

{% block outer_content %}
{% block content %}{% endblock %}
Expand Down
Loading

0 comments on commit 9c44899

Please sign in to comment.