<section id="timeline">
    <h1>Timeline concept</h1>

    <div id="scrollbox">
        <div id="svgOutput"></div>
    </div>

    <div class="data">
        <script>
            const dataset = [{
                "author": "Jane",
                "month": "January",
                "work": "red"
            }, {
                "author": "Jane",
                "month": "February",
                "work": "blue"
            }, {
                "author": "Jane",
                "month": "December",
                "work": "green"
            }, {
                "author": "Bill",
                "month": "March",
                "work": "pink"
            }, {
                "author": "Bill",
                "month": "April",
                "work": "purple"
            }, {
                "author": "Thomas",
                "month": "January",
                "work": "orange"
            }, {
                "author": "Thomas",
                "month": "April",
                "work": "yellow"
            }, {
                "author": "Thomas",
                "month": "May",
                "work": "plaid"
            }, {
                "author": "Thomas",
                "month": "December",
                "work": "else"
            }];
        </script>
    </div>
</section>

<script src="https://d3js.org/d3.v7.min.js"></script>
<script src="../../js/components/timeline.js"></script>
<section id="timeline">
    <h1>Timeline concept</h1>

    <div id="scrollbox">
        <div id="svgOutput"></div>
    </div>

    <div class="data">
        <script>
            const dataset = [{
                "author": "Jane",
                "month": "January",
                "work": "red"
            }, {
                "author": "Jane",
                "month": "February",
                "work": "blue"
            }, {
                "author": "Jane",
                "month": "December",
                "work": "green"
            }, {
                "author": "Bill",
                "month": "March",
                "work": "pink"
            }, {
                "author": "Bill",
                "month": "April",
                "work": "purple"
            }, {
                "author": "Thomas",
                "month": "January",
                "work": "orange"
            }, {
                "author": "Thomas",
                "month": "April",
                "work": "yellow"
            }, {
                "author": "Thomas",
                "month": "May",
                "work": "plaid"
            }, {
                "author": "Thomas",
                "month": "December",
                "work": "else"
            }];
        </script>
    </div>
</section>

<script src="https://d3js.org/d3.v7.min.js"></script>
<script src="{{ path '/js/components/timeline.js' }}"></script>
/* No context defined. */
  • Content:
    (function () {
      document.addEventListener('DOMContentLoaded', function () {
        console.log("timeline active");
    
        // Debug mode?
    
        const debug = false;
    
        // Config
    
        const width = 600;
        const height = 300;
        const margin = {
          "top": 20,
          "bottom": 30,
          "left": 60,
          "right": 40
        }
    
        // Create the svg container
    
        const svg = d3.select("#svgOutput")
          .append("svg")
          .attr("viewBox", [0, 0, width, height])
          .attr("preserveAspectRatio", "xMidYMid meet");
    
        //
        // Do stuff
        //
    
        // Data initialization
    
        function Datapoint(data) {
          this.author = data.author;
          this.month = data.month;
          this.work = data.work;
        }
    
        let datasetArray = [];
    
        for (let i = 0; i < dataset.length; i++) {
          datasetArray.push(new Datapoint(dataset[i]));
        }
    
        // Set up scales
    
        const xScale = d3.scaleBand()
          .domain(datasetArray.map(d => d.month))
          .range([margin.left, width - margin.right])
          .paddingInner(0.15)
          .paddingOuter(0.1);
    
        const yScale = d3.scaleBand()
          .domain(datasetArray.map(d => d.author))
          .range([margin.top, height - margin.bottom])
          .paddingInner(0.15)
          .paddingOuter(0.1);
    
        // Create and draw the axes
    
        const xAxis = d3.axisBottom(xScale);
        const yAxis = d3.axisLeft(yScale).ticks(5);
    
        const gx = svg.append("g")
          .attr('class', 'xAxis')
          .attr("transform", "translate(0, " + (height - margin.bottom) + ")")
          .call(xAxis);
    
        gx.call(g => g.selectAll(".tick text")
          .attr('class', 'x-axis-label')
          .attr('dy', '12'));
    
        gx.call(g => g.selectAll(".tick line").remove());
    
        const gy = svg.append("g")
          .attr('class', 'yAxis')
          .attr("transform", "translate(" + margin.left + ", 0)")
          .call(yAxis);
    
        gy.call(g => g.select('.tick:nth-child(2) line').remove());
    
    
        // Create and draw the dots
    
        const dots = svg.selectAll("circle.dot")
          .data(datasetArray)
          .join('circle');
    
        dots.append('title')
          .text((d) => `Work: ${d.work}`)
    
        dots.attr('class', 'dot')
          .attr('cx', (d) => xScale(d.month) + xScale.bandwidth() / 2)
          .attr("cy", (d) => yScale(d.author) + yScale.bandwidth() / 2)
          .attr('r', () => xScale.bandwidth() * 0.10)
          .attr('fill-opacity', 1);
    
        // bars.transition(tBars)
        //   .duration(barDuration)
        //   .delay((d, i) => ((i + 1) * (barDuration - barsOverlap)))
        //   .attr("y", (d) => yScale(d.percentage))
        //   .attr('height', (d) => yScale(0) - yScale(d.percentage))
        //   .attr('fill-opacity', 1);
    
    
      });
    })();
    
  • URL: /components/raw/timeline/timeline.js
  • Filesystem Path: components/05-timeline-concept/01-timeline/timeline.js
  • Size: 2.6 KB
  • Content:
    #timeline {
      margin: 2rem;
      font-family: var(--system-stack);
    
      #scrollbox {
        max-width: 100%;
        overflow-x: auto;
    
        #svgOutput {
          min-width: 700px;
        }
      }
    
      svg {
        background-color: var(--white);
        border: 1px solid var(--lightred);
    
        * {
          font-family: var(--system-stack);
        }
      }
    }
    
  • URL: /components/raw/timeline/timeline.scss
  • Filesystem Path: components/05-timeline-concept/01-timeline/timeline.scss
  • Size: 320 Bytes

No notes defined.