Skip to content

Commit 20f356c

Browse files
committed
Use horizontal bar for Top Packages
Signed-off-by: Sampurna Pyne <sampurnapyne1710@gmail.com>
1 parent 44d96e5 commit 20f356c

8 files changed

Lines changed: 42 additions & 27 deletions

File tree

insights/charts/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
collect_fn=collect_ecosystem_distribution,
2626
),
2727
ChartDefinition(
28-
id="pkg-name-donut",
28+
id="pkg-name-bar",
2929
title="Top 10 Packages",
3030
panel="package_panel",
31-
chart_type="donut",
31+
chart_type="colored_bar",
3232
formatter_fn=format_top_packages,
3333
collect_fn=collect_packages,
3434
is_per_package=True,
@@ -54,7 +54,7 @@
5454
),
5555
ChartDefinition(
5656
id="importer-empty-pkg-bar",
57-
title="Affected Package Coverage across Importers",
57+
title="PURL Coverage across Importers",
5858
panel="importer_panel",
5959
chart_type="importer_bar",
6060
formatter_fn=partial(_get_snapshot_data, build_columns_fn=build_importer_package_columns),

insights/charts/package_panel.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,19 @@ def collect_packages(pipeline: Any, package_type: str) -> None:
9898

9999

100100
def build_name_chart_columns(name_counts: dict) -> Dict[str, Any]:
101-
"""Helper to build package name donut charts."""
102-
return {"columns": [[name, count] for name, count in name_counts.items()]}
101+
"""Helper to build package name bar charts."""
102+
names = list(name_counts.keys())
103+
counts = list(name_counts.values())
104+
105+
return {
106+
"columns": [
107+
["x"] + names,
108+
["Advisories"] + counts,
109+
],
110+
"x_label": "Package Name",
111+
"y_label": "Advisories",
112+
"color": "var(--bulma-orange)",
113+
}
103114

104115

105116
def format_top_packages(snapshot: Any) -> Dict[str, Any]:
@@ -162,7 +173,7 @@ def build_cwe_chart_columns(cwe_counts: dict) -> Dict[str, Any]:
162173
sorted_cwes = sorted(cwe_counts.items(), key=lambda item: item[1], reverse=True)
163174
return {
164175
"columns": [
165-
["x"] + [cwe_id for cwe_id, count in sorted_cwes],
176+
["x"] + [f"CWE-{cwe_id}" for cwe_id, count in sorted_cwes],
166177
["Advisories"] + [count for cwe_id, count in sorted_cwes],
167178
],
168179
"full_labels": [get_cwe_label(cwe_id) for cwe_id, count in sorted_cwes],

insights/static/insights/css/insights.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
min-height: 320px;
115115
}
116116

117-
.chart-container.is-pie {
117+
.chart-container.is-tall {
118118
min-height: 420px;
119119
}
120120

insights/static/insights/js/importer_panel.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,15 @@ import { initDropdownChart } from './core.js';
1111
import { formatWholeNumbersOnly, getCssVar, renderers } from './renderers.js';
1212

1313
const names = {
14-
total_advisories: "Total Advisories",
15-
advisories_without_packages: "Advisories without a Package",
16-
advisories_with_packages: "Advisories with a Package",
17-
advisories_without_ghost_packages: "Advisories without a Ghost Package",
18-
advisories_with_ghost_packages: "Advisories with a Ghost Package",
19-
advisories_without_exploits: "Advisories without an Exploit",
20-
advisories_with_exploitdb: "Advisories with Exploit-DB",
21-
advisories_with_metasploit: "Advisories with Metasploit",
22-
advisories_with_kev: "Advisories with KEV",
23-
advisories_with_exploits: "Advisories with an Exploit",
14+
advisories_with_packages: "with a PURL",
15+
advisories_without_packages: "without a PURL",
16+
advisories_without_ghost_packages: "with an existing PURL",
17+
advisories_with_ghost_packages: "with a non-existing PURL",
18+
advisories_with_exploits: "with an Exploit",
19+
advisories_without_exploits: "without an Exploit",
20+
advisories_with_exploitdb: "with a Exploit-DB exploit",
21+
advisories_with_metasploit: "with a Metasploit exploit",
22+
advisories_with_kev: "with a KEV",
2423
};
2524

2625
function renderImporterBar(id, config) {
@@ -57,8 +56,13 @@ function renderImporterBar(id, config) {
5756
bar: { width: { ratio: 0.8 } },
5857
tooltip: {
5958
grouped: true,
59+
order: (a, b) => {
60+
//Keep a stable order of rows
61+
const cols = config.columns.map(c => c[0]);
62+
return cols.indexOf(a.id) - cols.indexOf(b.id);
63+
},
6064
format: {
61-
title: (x) => `${config.x_categories[x]} (Total: ${totals?.[x + 1]?.toLocaleString()})`,
65+
title: (x) => `Advisories from ${config.x_categories[x]} (Total: ${totals?.[x + 1]?.toLocaleString()})`,
6266
value: (val) => val.toLocaleString(),
6367
},
6468
},

insights/static/insights/js/package_panel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ document.addEventListener('insightsDataLoaded', (e) => {
1616
const searchData = document.getElementById("chart-search-data")?.textContent;
1717
const parsedSearch = searchData ? JSON.parse(searchData) : null;
1818

19-
initDropdownChart("pkg-name-donut", snapshotData["pkg-name-donut"], "All Packages");
19+
initDropdownChart("pkg-name-bar", snapshotData["pkg-name-bar"], "All Packages");
2020

2121
renderChartWithData(
2222
"pkg-cwe-bar",

insights/static/insights/js/renderers.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,16 @@ export const renderers = {
6161
},
6262

6363
colored_bar(id, config) {
64-
const monoColor = getCssVar("--bulma-link")
64+
const monoColor = config.color || getCssVar("--bulma-link");
6565
bb.generate({
6666
bindto: `#chart-${id}`,
6767
data: { x: "x", columns: config.columns, type: "bar", color: () => monoColor },
6868
axis: {
6969
rotated: true,
70-
x: { type: "category", label: { text: "CWE", position: "outer-middle" } },
71-
y: { label: { text: "Advisories", position: "outer-center" }, tick: { format: formatWholeNumbersOnly } }
70+
x: { type: "category", label: { text: config.x_label || "CWE", position: "outer-middle" } },
71+
y: { label: { text: config.y_label || "Advisories", position: "outer-center" }, tick: { format: formatWholeNumbersOnly } }
7272
},
73-
tooltip: { format: { title: x => config.full_labels?.[x] || x, value: val => val.toLocaleString() } },
73+
tooltip: { format: { title: x => config.full_labels?.[x] || config.columns[0][x + 1], value: val => val.toLocaleString() } },
7474
legend: { show: false }
7575
});
7676
},
@@ -125,7 +125,7 @@ export const renderers = {
125125
color: (defaultColor, dataPoint) => dataPoint.x !== undefined ? getBucketColors()[dataPoint.x] || defaultColor : defaultColor,
126126
labels: false
127127
},
128-
bubble: { maxR: 45 },
128+
bubble: { maxR: 40 },
129129
axis: {
130130
x: {
131131
type: "category",

insights/templates/insights/components/chart_card.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ <h3 class="card-chart-title {% if chart.has_search %}card-chart-title-with-searc
2828
{% endif %}
2929
</h3>
3030
<div class="chart-container
31-
{% if chart.chart_type == 'donut' or chart.chart_type == 'pie' %}is-pie
31+
{% if chart.chart_type == 'donut' or chart.chart_type == 'pie' %}is-tall
3232
{% endif %}" id="chart-{{ chart.id }}"
3333
data-chart-type="{{ chart.chart_type }}" aria-label="{{ chart.title }}" role="img">
3434
{% if chart.chart_type == 'scatter' %}

insights/templates/insights/components/package_panel_donuts.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
<div class="columns is-desktop mb-0" style="margin: -0.75rem;">
33
<div class="column is-half" style="border-right: 1px solid #e8e8e8; padding: 1rem;">
44
<h3 class="card-chart-title has-text-centered mb-4">{{ panel.charts.0.title }}</h3>
5-
<div class="chart-container is-pie" id="chart-{{ panel.charts.0.id }}" data-chart-type="donut"></div>
5+
<div class="chart-container is-tall" id="chart-{{ panel.charts.0.id }}" data-chart-type="{{ panel.charts.0.chart_type }}"></div>
66
</div>
77
<div class="column is-half" style="padding: 1rem;">
88
<h3 class="card-chart-title has-text-centered mb-4">{{ panel.charts.1.title }}</h3>
9-
<div class="chart-container is-pie" id="chart-{{ panel.charts.1.id }}" data-chart-type="donut"></div>
9+
<div class="chart-container is-tall" id="chart-{{ panel.charts.1.id }}" data-chart-type="{{ panel.charts.1.chart_type }}"></div>
1010
</div>
1111
</div>
1212
</div>

0 commit comments

Comments
 (0)