COS301-SE-2024 / The-Republic

Imagine a fusion of ‘Eskom se Push’ and ‘X’. The Republic allows users to raise concerns and spread awareness about government services through incident reports, with cool data visualizations providing a dynamic overview of public sentiment on service delivery.
6 stars 0 forks source link

Work on Dot Visualization for the Visualization Page #70

Closed ShamaKamina closed 1 month ago

ShamaKamina commented 1 month ago

We will start with the D3 zoomable circle packing visualization to enhance the visualization page. This will provide users with an interactive and intuitive way to explore the data.

Tasks

Example code

import * as d3 from 'd3';

const width = 932;
const height = width;

const pack = data => d3.pack()
  .size([width - 2, height - 2])
  .padding(3)(d3.hierarchy(data)
  .sum(d => d.value)
  .sort((a, b) => b.value - a.value));

const root = pack(data);

const svg = d3.create("svg")
  .attr("viewBox", `-${width / 2} -${height / 2} ${width} ${height}`)
  .style("display", "block")
  .style("margin", "0 -14px")
  .style("background", "white")
  .style("cursor", "pointer")
  .on("click", (event) => zoom(event, root));

const node = svg.append("g")
  .selectAll("circle")
  .data(root.descendants().slice(1))
  .join("circle")
    .attr("fill", d => d.children ? "lightblue" : "lightgreen")
    .attr("pointer-events", d => !d.children ? "none" : null)
    .on("mouseover", function() { d3.select(this).attr("stroke", "#000"); })
    .on("mouseout", function() { d3.select(this).attr("stroke", null); })
    .on("click", (event, d) => focus !== d && (zoom(event, d), event.stopPropagation()));

// More implementation details...

Documentation

https://observablehq.com/@d3/zoomable-circle-packing

ShamaKamina commented 1 month ago

@TebogoYungMercykay @IRIA7 I added more checkpoints