Skip to content

Commit 0ac7466

Browse files
authored
Merge pull request #33 from MrIbrahem/update
Update
2 parents 52784f2 + 9f0f38a commit 0ac7466

File tree

17 files changed

+632
-823
lines changed

17 files changed

+632
-823
lines changed

python/src/app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,13 @@ def features_chart() -> str:
174174
@app.route("/list", methods=["GET"])
175175
def list_lexemes() -> str:
176176
"""Page for listing lexemes"""
177-
return render_template("list.html")
177+
return render_template("list.html", title="قائمة المفردات", page_type="list")
178178

179179

180180
@app.route("/new", methods=["GET"])
181181
def new_lexemes() -> str:
182182
"""Page for creating new lexemes"""
183-
return render_template("new.html")
183+
return render_template("list.html", title="أحدث المفردات", page_type="new")
184184

185185

186186
@app.route("/P11038", methods=["GET"])

python/src/static/js/chart.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ function createChart(ctx, { labels, data }, title) {
130130
maintainAspectRatio: false,
131131
plugins: {
132132
legend: {
133+
display: false,
133134
position: 'right',
134135
// fullSize: true,
135136
rtl: true,
@@ -175,6 +176,12 @@ async function one_chart(n, query, labelKey, labelKey2, countKey) {
175176
// رسم المخطط وإخفاء مؤشر التحميل الخاص به
176177
if (char1Data.labels.length > 0) {
177178
createChart(ctx2d, char1Data, titles[n - 1]);
179+
// إضافة الـ legend داخل card
180+
const chartColors = getChartColors(char1Data.labels.length);
181+
const legendContainer = document.getElementById(`legend${n}`);
182+
if (legendContainer) {
183+
legendContainer.innerHTML = createLegendHTML(char1Data.labels, chartColors);
184+
}
178185
}
179186
// ---
180187
const all_lemmas = document.getElementById(`all_lemmas_${n}`);
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
2+
function generateColor(index) {
3+
const baseColors = [
4+
[54, 162, 235], [255, 99, 132],
5+
[255, 206, 86], [75, 192, 192],
6+
[153, 102, 255], [255, 159, 64],
7+
[46, 204, 113], [231, 76, 60],
8+
[52, 73, 94], [241, 196, 15]
9+
];
10+
11+
const base = baseColors[index % baseColors.length];
12+
const variation = Math.floor((index / baseColors.length) * 50); // فرق بسيط في اللون
13+
const r = Math.min(base[0] + variation, 255);
14+
const g = Math.min(base[1] + variation, 255);
15+
const b = Math.min(base[2] + variation, 255);
16+
return `rgba(${r}, ${g}, ${b}, 0.8)`;
17+
}
18+
19+
function getChartColors(n) {
20+
const colors = [];
21+
for (let i = 0; i < n; i++) {
22+
colors.push(generateColor(i));
23+
}
24+
return colors;
25+
}
26+
27+
function createLegendHTML(labels, colors) {
28+
const totalItems = labels.length;
29+
let numColumns = 1;
30+
31+
if (totalItems > 10) {
32+
numColumns = Math.ceil(totalItems / 10);
33+
} else if (totalItems === 10) {
34+
numColumns = 2;
35+
}
36+
37+
const itemsPerColumn = Math.ceil(totalItems / numColumns);
38+
39+
let html = `<div class="row custom-legend">`;
40+
41+
for (let col = 0; col < numColumns; col++) {
42+
html += `<div class="col">`; // عمود bootstrap
43+
html += `<ul class="list-group list-group-flushx">`;
44+
45+
const start = col * itemsPerColumn;
46+
const end = Math.min(start + itemsPerColumn, totalItems);
47+
48+
for (let i = start; i < end; i++) {
49+
html += `
50+
<li class="list-group-item p-1">
51+
<span style="display:inline-block;width:20px;height:20px;background-color:${colors[i]};margin-right:8px;border:1px solid #333;"></span>
52+
<span>${labels[i]}</span>
53+
</li>
54+
`;
55+
}
56+
57+
html += `</ul></div>`; // نهاية العمود
58+
}
59+
60+
html += `</div>`; // نهاية row
61+
return html;
62+
}

python/src/static/js/features_chart.js

Lines changed: 40 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,6 @@ const queries = {
2323
`,
2424
};
2525

26-
const baseColors = [
27-
[54, 162, 235], [255, 99, 132],
28-
[255, 206, 86], [75, 192, 192],
29-
[153, 102, 255], [255, 159, 64],
30-
[46, 204, 113], [231, 76, 60],
31-
[52, 73, 94], [241, 196, 15]
32-
];
33-
34-
function generateColor(index) {
35-
const base = baseColors[index % baseColors.length];
36-
const variation = Math.floor((index / baseColors.length) * 50); // فرق بسيط في اللون
37-
const r = Math.min(base[0] + variation, 255);
38-
const g = Math.min(base[1] + variation, 255);
39-
const b = Math.min(base[2] + variation, 255);
40-
return `rgba(${r}, ${g}, ${b}, 0.8)`;
41-
}
42-
43-
function getChartColors(n) {
44-
const colors = [];
45-
for (let i = 0; i < n; i++) {
46-
colors.push(generateColor(i));
47-
}
48-
return colors;
49-
}
5026
function createChart(ctx, { labels, data }, title, pos, maintainAspectRatio = true) {
5127
const chartColors = getChartColors(labels.length);
5228

@@ -69,6 +45,7 @@ function createChart(ctx, { labels, data }, title, pos, maintainAspectRatio = tr
6945
aspectRatio: 2,
7046
plugins: {
7147
legend: {
48+
display: false,
7249
position: pos,
7350
rtl: true,
7451
textDirection: "rtl",
@@ -136,10 +113,8 @@ async function make_main_data(json) {
136113
const sortedFeatures = Array.from(featureMap.values())
137114
.sort((a, b) => b.count - a.count);
138115

139-
const featureArray = Array.from(sortedFeatures.values());
140-
const uzz = aggregateOthers(featureArray, 21);
141116

142-
return uzz;
117+
return aggregateOthers(sortedFeatures, 19);
143118
}
144119

145120
async function make_category_feature_data(json) {
@@ -186,32 +161,34 @@ async function make_category_feature_data(json) {
186161
return result;
187162
}
188163

189-
async function one_chart(n, char1Data, title, pos, maintainAspectRatio = true) {
164+
async function one_chart(n, char1Data, maintainAspectRatio) {
190165
// ---
191166
const loader = document.getElementById(`loader${n}`);
192167
let ctx = document.getElementById(`chart${n}`);
193168
// ---
169+
let pos = (char1Data.labels.length > 15) ? "bottom" : "right";
170+
// ---
194171
if (!ctx) return;
195172
// ---
196173
let ctx2d = ctx.getContext('2d');
197174
// ---
198175
// رسم المخطط وإخفاء مؤشر التحميل الخاص به
199176
if (char1Data.labels.length > 0) {
200-
createChart(ctx2d, char1Data, title, pos, maintainAspectRatio);
177+
createChart(ctx2d, char1Data, "", pos, maintainAspectRatio);
201178
// ---
179+
// إضافة الـ legend داخل card
180+
const chartColors = getChartColors(char1Data.labels.length);
181+
const legendContainer = document.getElementById(`legend${n}`);
182+
if (legendContainer) {
183+
legendContainer.innerHTML = createLegendHTML(char1Data.labels, chartColors);
184+
}
202185
}
203186
// ---
204187
// تحديث إجمالي عدد المفردات
205188
const all_lemmas = document.getElementById(`all_lemmas_${n}`);
206189
// ---
207190
if (all_lemmas) {
208-
// sum achar1Data.data
209-
let total = char1Data.data.reduce((a, b) => a + b, 0);
210-
// ---
211-
// format total
212-
total = total.toLocaleString();
213-
// ---
214-
all_lemmas.innerHTML = ` (${total}) `
191+
all_lemmas.innerHTML = ` (${char1Data.labels.length.toLocaleString()}) `
215192
}
216193
// ---
217194
if (loader) {
@@ -229,16 +206,25 @@ function make_card(index, title, height) {
229206
</h2>
230207
</div>
231208
<div class="card-body">
232-
<div class="position-relative" style="min-height: ${height}; width: 100%;">
233-
<div id="loader${index}" class="loader">
234-
<div class="d-flex align-items-center">
235-
<div class="spinner-border text-primary" role="status">
236-
<span class="visually-hidden">Loading...</span>
209+
<div class="row">
210+
<div class="col-md-7 col-sm-12">
211+
<div id="legend${index}" class="ms-1 mt-1">
212+
<!-- Legend سيضاف هنا -->
213+
</div>
214+
</div>
215+
<div class="col-md-5 col-sm-12">
216+
<div class="position-relative" style="height: ${height}; width: 100%;">
217+
<div id="loader${index}" class="loader">
218+
<div class="align-items-center">
219+
<div class="spinner-border text-primary" role="status">
220+
<span class="visually-hidden">Loading...</span>
221+
</div>
222+
<span class="ms-3 h5 fw-semibold text-secondary">جاري تحميل البيانات...</span>
223+
</div>
237224
</div>
238-
<span class="ms-3 h5 fw-semibold text-secondary">جاري تحميل البيانات...</span>
225+
<canvas id="chart${index}"></canvas>
239226
</div>
240227
</div>
241-
<canvas id="chart${index}"></canvas>
242228
</div>
243229
</div>
244230
</div>
@@ -325,6 +311,11 @@ function change_labels(data) {
325311
return data;
326312
}
327313

314+
315+
function hideLoading() {
316+
document.getElementById("loading").classList.add("d-none");
317+
}
318+
328319
async function initializeCharts() {
329320
let title = ' إجمالي استخدامات الميزات النحوية في المفردات العربية <span id="all_lemmas_00"></span>';
330321
// ---
@@ -336,12 +327,11 @@ async function initializeCharts() {
336327
// ---
337328
let main_data = await make_main_data(json);
338329
// ---
339-
let pos = (main_data.labels.length > 15) ? "bottom" : "right";
340-
let height = "320px"; //(main_data.labels.length > 15) ? "400px" : "220px";
330+
let height = "15rem"; //(main_data.labels.length > 15) ? "400px" : "220px";
341331
// ---
342332
$("#canvas_container").append(make_card(0, title, height));
343333
// ---
344-
await one_chart(0, main_data, title, "right", false);
334+
await one_chart(0, main_data, false);
345335
// ---
346336
let all_categories_data = await make_category_feature_data(json);
347337
// ---
@@ -356,12 +346,12 @@ async function initializeCharts() {
356346
<span id="all_lemmas_${index2}"></span>
357347
`;
358348
// ---
359-
let pos = (categoryData.labels.length > 20) ? "bottom" : "right";
360-
let height = (categoryData.labels.length > 20) ? "400px" : "220px";
361-
let maintainAspectRatio = (categoryData.labels.length > 20) ? true : false;
349+
let height = "15rem";
362350
// ---
363351
$("#canvas_container").append(make_card(index2, title, height));
364352
// ---
365-
await one_chart(index2, categoryData, title, pos, false);
353+
await one_chart(index2, categoryData, false);
366354
}
355+
// ---
356+
hideLoading();
367357
}

0 commit comments

Comments
 (0)