المكوّنات · مؤشّر انحراف عن الهدف
مؤشّر انحراف عن الهدف
أشرطة تخرج من صفر في الاتجاهين حسب إشارة الفرق
12 تصاميم من هذه العائلة
<div class="gg ggd">
<span class="k" data-ar="الانحراف عن الميزانية — بند بند" data-en="Budget deviation — by item">الانحراف عن الميزانية — بند بند</span>
<ul class="rows"></ul>
<div class="axis"><span data-ar="تحت الميزانية" data-en="Under">تحت الميزانية</span>
<span data-ar="فوقها" data-en="Over">فوقها</span></div>
</div>
/* pt-scoped */
/* gauge-deviation — مشروع مقاولات */
.ggd{width:100%;height:100%;display:flex;flex-direction:column;
font-size:10px;color:var(--pt-text-secondary);overflow:hidden}
.ggd .k{font-size:8.5px;color:var(--pt-text-muted)}
.ggd .v{font-variant-numeric:tabular-nums;color:var(--pt-text-primary);line-height:1.15}
.ggd .up{color:var(--pt-accent)}
.ggd .dn{color:var(--pt-color-danger-400)}
/* شخصية: محور مركزي، أشرطة ثنائية الاتجاه، بلا حاوية */
.ggd{padding:9px;gap:6px}
.ggd .rows{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:5px;flex:1;
justify-content:center}
.ggd li{display:grid;grid-template-columns:56px 1fr 40px;align-items:center;gap:7px;font-size:9px}
.ggd .nm{color:var(--pt-text-secondary);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.ggd .track{position:relative;height:12px;border-radius:var(--pt-radius-xs);
background:var(--pt-bg-inset)}
.ggd .track::before{content:'';position:absolute;inset-block:0;inset-inline-start:50%;
width:1px;background:var(--pt-border-strong)}
.ggd .fill{position:absolute;inset-block:2px;border-radius:2px;width:0;
transition:width var(--pt-motion-duration-slow) var(--pt-motion-easing-decelerate)}
.ggd .fill.p{inset-inline-start:50%;background:var(--pt-color-danger-400)}
.ggd .fill.n{inset-inline-end:50%;background:var(--pt-accent)}
.ggd .d{font-variant-numeric:tabular-nums;text-align:end;font-size:8.5px}
.ggd .axis{display:flex;justify-content:space-between;font-size:7.5px;
color:var(--pt-text-muted);padding-inline:63px 0}
/* يعمل داخل إطار معزول — لا يعتمد على شيء خارجه */
/* pt-remount — يعاد التركيب عند تبديل اللغة */
(function () {
var host = document.querySelector('.ggd');
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 ITEMS = [
{ ar: 'الخرسانة', plan: 480000, real: 516000 },
{ ar: 'الحديد', plan: 320000, real: 291000 },
{ ar: 'العمالة', plan: 610000, real: 664000 },
{ ar: 'الكهرباء', plan: 145000, real: 138000 },
{ ar: 'التشطيب', plan: 275000, real: 259000 }
];
var devs = ITEMS.map(function (i) { return ((i.real - i.plan) / i.plan) * 100; });
var maxAbs = Math.max.apply(null, devs.map(Math.abs)) || 1;
var ul = root.querySelector('.rows');
ITEMS.forEach(function (it, i) {
var d = devs[i];
var li = document.createElement('li');
li.innerHTML = '<span class="nm">' + it.ar + '</span>' +
'<span class="track"><span class="fill ' + (d >= 0 ? 'p' : 'n') + '"></span></span>' +
'<span class="d ' + (d >= 0 ? 'dn' : 'up') + '">' +
(d >= 0 ? '+' : '−') + nf(Math.abs(d), 1) + '%</span>';
ul.appendChild(li);
// الشريط يخرج من الصفر في اتجاه إشارته — رسم السالب موجبًا يقلب المعنى
requestAnimationFrame(function () {
li.querySelector('.fill').style.width = (Math.abs(d) / maxAbs) * 50 + '%';
});
});
}
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(); });
})();
# Deviation from Target
**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:** Deviation from Target — Bars that grow out of zero in both directions by the sign of the gap
**Why this component matters:** A deviation chart must anchor at zero and grow both ways; drawing negatives as short positive bars is the most common way a dashboard tells the opposite of the truth.
**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.