freeCodeCamp/curriculum/challenges/arabic/04-data-visualization/data-visualization-with-d3/invert-svg-elements.arabic.md

4.7 KiB

id title challengeType videoUrl localeTitle
587d7fa9367417b2b2512bd0 Invert SVG Elements 6 عكس عناصر SVG

Description

ربما لاحظت أن المخطط الشريطي يبدو كما لو كان مقلوبًا أو مقلوبًا. هذا بسبب كيفية استخدام SVG للإحداثيات (x، y). في SVG ، تكون نقطة الأصل للإحداثيات في الزاوية العلوية اليسرى. يقوم إحداثي x من 0 بوضع شكل على الحافة اليسرى لمنطقة SVG. تقوم إحداثي y من 0 بوضع شكل على الحافة العلوية لمنطقة SVG. تدفع قيم x الأعلى المستطيل إلى اليمين. تدفع قيم y الأعلى المستطيل لأسفل. لجعل القضبان في الجانب الأيمن ، تحتاج إلى تغيير الطريقة التي يتم بها حساب الإحداثي y . ويحتاج إلى حساب كل من ارتفاع الشريط والارتفاع الكلي لمنطقة SVG. ارتفاع منطقة SVG هو 100. إذا كان لديك نقطة بيانات من 0 في المجموعة ، فإنك تريد أن يبدأ الشريط في الجزء السفلي من منطقة SVG (وليس أعلى). للقيام بذلك ، يحتاج تنسيق y إلى قيمة 100. إذا كانت قيمة نقطة البيانات 1 ، فستبدأ y لـ 100 لتعيين الشريط في الأسفل. ثم تحتاج إلى حساب ارتفاع شريط 1 ، بحيث يكون التنسيق y النهائي هو 99. إن إحداثي y الذي هو y = heightOfSVG - heightOfBar قد يضع القضبان في الجانب الأيمن لأعلى.

Instructions

تغيير وظيفة رد الاتصال للسمة y لتعيين القضبان الجانب الأيمن لأعلى. تذكر أن height الشريط 3 أضعاف قيمة البيانات d . ملحوظة
بشكل عام ، العلاقة هي y = h - m * d ، حيث m هو الثابت الذي يقوم بتحجيم نقاط البيانات.

Tests

tests:
  - text: يجب أن يكون <code>rect</code> الأول قيمة <code>y</code> تبلغ 64.
    testString: 'assert($("rect").eq(0).attr("y") == h - (dataset[0] * 3), "The first <code>rect</code> should have a <code>y</code> value of 64.");'
  - text: يجب أن يكون <code>rect</code> الثاني قيمة <code>y</code> 7.
    testString: 'assert($("rect").eq(1).attr("y") == h - (dataset[1] * 3), "The second <code>rect</code> should have a <code>y</code> value of 7.");'
  - text: ''
    testString: 'assert($("rect").eq(2).attr("y") == h - (dataset[2] * 3), "The third <code>rect</code> should have a <code>y</code> value of 34.");'
  - text: ''
    testString: 'assert($("rect").eq(3).attr("y") == h - (dataset[3] * 3), "The fourth <code>rect</code> should have a <code>y</code> value of 49.");'
  - text: ''
    testString: 'assert($("rect").eq(4).attr("y") == h - (dataset[4] * 3), "The fifth <code>rect</code> should have a <code>y</code> value of 25.");'
  - text: ''
    testString: 'assert($("rect").eq(5).attr("y") == h - (dataset[5] * 3), "The sixth <code>rect</code> should have a <code>y</code> value of 46.");'
  - text: ''
    testString: 'assert($("rect").eq(6).attr("y") == h - (dataset[6] * 3), "The seventh <code>rect</code> should have a <code>y</code> value of 13.");'
  - text: ''
    testString: 'assert($("rect").eq(7).attr("y") == h - (dataset[7] * 3), "The eighth <code>rect</code> should have a <code>y</code> value of 58.");'
  - text: ''
    testString: 'assert($("rect").eq(8).attr("y") == h - (dataset[8] * 3), "The ninth <code>rect</code> should have a <code>y</code> value of 73.");'

Challenge Seed

<body>
  <script>
    const dataset = [12, 31, 22, 17, 25, 18, 29, 14, 9];

    const w = 500;
    const h = 100;

    const svg = d3.select("body")
                  .append("svg")
                  .attr("width", w)
                  .attr("height", h);

    svg.selectAll("rect")
       .data(dataset)
       .enter()
       .append("rect")
       .attr("x", (d, i) => i * 30)
       .attr("y", (d, i) => {
         // Add your code below this line



         // Add your code above this line
       })
       .attr("width", 25)
       .attr("height", (d, i) => 3 * d);
  </script>
</body>

Solution

// solution required