Skip to content

Commit 727219f

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

7 files changed

Lines changed: 24 additions & 13 deletions

File tree

insights/charts/__init__.py

Lines changed: 2 additions & 2 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,

insights/charts/package_panel.py

Lines changed: 13 additions & 2 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]:

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/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: 4 additions & 4 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
},

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)