المكوّنات · خريطة حرارية أسبوعية
خريطة حرارية أسبوعية
اللون مشتقّ من المدى الفعلي، لا من عتبات مكتوبة
12 تصاميم من هذه العائلة
<div class="gg ggh">
<div class="top"><span class="k" data-ar="الزحام حسب اليوم والساعة" data-en="Traffic by day and hour">الزحام حسب اليوم والساعة</span>
<span class="rng"></span></div>
<div class="grid" role="img" aria-label="خريطة حرارية للزحام"></div>
<div class="lg"><span data-ar="أقلّ" data-en="Low">أقلّ</span>
<span class="ramp"></span><span data-ar="أكثر" data-en="High">أكثر</span></div>
</div>
/* pt-scoped */
/* gauge-heatmap — متجر تجزئة */
.ggh{width:100%;height:100%;display:flex;flex-direction:column;
font-size:10px;color:var(--pt-text-secondary);overflow:hidden}
.ggh .k{font-size:8.5px;color:var(--pt-text-muted)}
.ggh .v{font-variant-numeric:tabular-nums;color:var(--pt-text-primary);line-height:1.15}
.ggh .up{color:var(--pt-accent)}
.ggh .dn{color:var(--pt-color-danger-400)}
/* شخصية: شبكة مربّعات صغيرة، انحناء أدنى، تدرّج مرجعي أسفل */
.ggh{padding:9px;gap:6px}
.ggh .top{display:flex;align-items:baseline;justify-content:space-between;gap:8px}
.ggh .rng{font-size:8px;color:var(--pt-text-muted);font-variant-numeric:tabular-nums}
.ggh .grid{display:grid;grid-template-columns:repeat(8,1fr);gap:2px;flex:1;align-content:center}
.ggh .cell{aspect-ratio:1;border-radius:var(--pt-radius-xs);min-height:9px}
.ggh .hd{font-size:7px;color:var(--pt-text-muted);text-align:center;align-self:center}
.ggh .lg{display:flex;align-items:center;gap:6px;font-size:8px;color:var(--pt-text-muted)}
.ggh .ramp{flex:1;height:5px;border-radius:99px;
background:linear-gradient(to left,
color-mix(in srgb,var(--pt-accent) 8%,var(--pt-bg-inset)),var(--pt-accent))}
[dir=ltr] .ggh .ramp{background:linear-gradient(to right,
color-mix(in srgb,var(--pt-accent) 8%,var(--pt-bg-inset)),var(--pt-accent))}
/* يعمل داخل إطار معزول — لا يعتمد على شيء خارجه */
/* pt-remount — يعاد التركيب عند تبديل اللغة */
(function () {
var host = document.querySelector('.ggh');
if (!host) return;
var snapshot = host.innerHTML;
var timers = [];
var ac = null;
/* الجسم كما كتبه المولِّد. يستقبل بدائل مظلَّلة لـ root وdocument
والمؤقّتات، فينظّف نفسه دون أن يعرف أنه قابل لإعادة التركيب. */
function run(root, document, setTimeout, setInterval) {
function nf(x, d) {
return Number(x).toLocaleString('en-US',
{ minimumFractionDigits: d || 0, maximumFractionDigits: d || 0 });
}
function money(x) {
var ar = document.documentElement.lang !== 'en';
return ar ? nf(Math.round(x * 3.75)) + ' ر.س' : '$' + nf(x);
}
var DAYS = ['أحد', 'إثن', 'ثلا', 'أرب', 'خمي', 'جمع', 'سبت'];
var DATA = [
[12, 18, 24, 31, 28, 19, 9], [10, 16, 22, 29, 33, 21, 11],
[14, 21, 27, 35, 41, 26, 13], [19, 28, 36, 44, 52, 34, 17],
[23, 33, 42, 55, 68, 44, 21], [27, 38, 49, 61, 74, 52, 26],
[18, 25, 31, 38, 46, 33, 16]
];
var flat = DATA.reduce(function (a, r) { return a.concat(r); }, []);
var lo = Math.min.apply(null, flat), hi = Math.max.apply(null, flat);
root.querySelector('.rng').textContent = nf(lo) + ' — ' + nf(hi);
var grid = root.querySelector('.grid');
var HOURS = ['9', '11', '13', '15', '17', '19', '21'];
grid.appendChild(Object.assign(document.createElement('span'), { className: 'hd' }));
DAYS.forEach(function (d) {
grid.appendChild(Object.assign(document.createElement('span'), { className: 'hd', textContent: d }));
});
DATA.forEach(function (row, i) {
grid.appendChild(Object.assign(document.createElement('span'),
{ className: 'hd', textContent: HOURS[i] }));
row.forEach(function (v, j) {
var c = document.createElement('span');
c.className = 'cell';
// النسبة من المدى المرصود — لا عتبة ثابتة تشيخ مع تغيّر المقياس
var t = hi === lo ? 0 : (v - lo) / (hi - lo);
c.style.background = 'color-mix(in srgb, var(--pt-accent) ' +
Math.round(8 + t * 84) + '%, var(--pt-bg-inset))';
c.title = DAYS[j] + ' ' + HOURS[i] + ': ' + nf(v);
grid.appendChild(c);
});
});
}
function mount() {
ac = new AbortController();
var real = window.document;
/* وسيط يمرّر كل شيء إلى المستند الحقيقي، ويعلّق كل مستمع بإشارة
تُقطع عند إعادة التركيب — فلا يبقى مستمع من نسخة ماتت. */
var doc = new Proxy(real, {
get: function (t, k) {
if (k === 'addEventListener') {
return function (type, fn, opts) {
var o = (opts && typeof opts === 'object') ? Object.assign({}, opts)
: { capture: !!opts };
o.signal = ac.signal;
return t.addEventListener(type, fn, o);
};
}
var v = t[k];
return typeof v === 'function' ? v.bind(t) : v;
}
});
function track(fn) {
return function (f, ms) { var id = fn(f, ms); timers.push(id); return id; };
}
run(host, doc, track(window.setTimeout.bind(window)),
track(window.setInterval.bind(window)));
}
function unmount() {
if (ac) ac.abort();
// المعرّفان يتشاركان فضاءً واحدًا في المتصفّح، فالإلغاء المزدوج آمن
timers.forEach(function (id) { window.clearTimeout(id); window.clearInterval(id); });
timers = [];
host.innerHTML = snapshot;
}
mount();
addEventListener('pt-lang', function () { unmount(); mount(); });
})();
# Weekly Heatmap
**Role:** You are an Arabic-first UI designer and front-end engineer. Read the whole
specification before writing a single line, then follow it literally. If two requirements
conflict, favour usability over visual effect.
**Goal:** Weekly Heatmap — Colour derived from the actual range — not from hardcoded thresholds
**Why this component matters:** Fixed colour thresholds break when the data shifts scale: a “hot” day last month becomes cold this month. Normalising against the observed min and max keeps the map readable whatever the numbers do.
**Direction:** Genuine RTL — not a mirrored Latin layout. Use logical properties
(`margin-inline-start`, `padding-inline`, `inset-inline-start`, `text-align: start`),
never physical ones (`margin-left`, `left`). The layout must flip with `dir` on its own,
with no duplicated rules.
**Typography:** Cairo for Arabic, IBM Plex Sans for Latin. Arabic line-height must be
`0.18` higher than the Latin equivalent — dots, hamzas and maddas need more vertical room.
Arabic font-size runs `1.06×` the Latin size at the same optical weight.
**Numerals:** Western digits in both languages (`1,234.50`). Only the currency changes:
`ر.س` **after** the number in Arabic, `$` **before** it in English. Jordanian dinar
uses **three** decimal places, not two.
**Colors:** Dark mode — background `#0D142B` · surfaces `#211F54` · borders `#545C91` · text `#918FC2`.
Accent `#ADA9E8` must never exceed 8% of the screen area.
**Language:** Bilingual — every string carries both Arabic and English, and the layout
flips with `dir` automatically.
**States:** `default` · `hover` · `focus` · `active` · `disabled` · `loading` · `error`.
Do not design the resting state alone.
**Accessibility:** Contrast ratio at least `4.5:1`, complete keyboard navigation,
visible focus rings, and honour `prefers-reduced-motion`.
**Output:** Clean HTML and CSS in two separate files. No frameworks, no libraries,
no external dependencies.