Commit e033d621 authored by amarcic's avatar amarcic
Browse files

comment cleaning

parent 9be637a1
......@@ -2,7 +2,7 @@ import React, {useEffect, useRef, useState} from "react";
import { Card, Grid } from "@material-ui/core";
import { useTranslation } from "react-i18next";
import { useStyles } from "../../styles";
import {select, scaleBand, axisBottom, axisLeft, scaleLinear, max, min, ascending} from "d3";
import {select, scaleBand, axisBottom, axisLeft, scaleLinear, max, min, ascending, descending} from "d3";
import {getTimeRangeOfTimelineData, newGroupByPeriods} from "../../utils";
export const Timeline = (props) => {
......@@ -22,22 +22,18 @@ export const Timeline = (props) => {
//console.log(props.timelineData);
const svgRef = useRef();
//const [data, setData] = useState(binnedData);
//const [scale, setScale] = useState();
const [data, setData] = useState();
const svg = select(svgRef.current);
const sortPeriods = () =>
setData(newGroupByPeriods(filteredTimelineData.sort( (a, b) => a.periodSpans[0] - b.periodSpans[0] )));
const margin = {top: 5, right: 20, left: 20, bottom: 30};
useEffect( () => {
if (timelineObjectsData||filteredTimelineData) {
setData(newGroupByPeriods(filteredTimelineData));
data&&data.size>0&&console.log([...data.values()].sort( (a,b) => a.periodSpan?.[0]-b.periodSpan?.[0] ));
//data&&data.size>0&&console.log([...data.values()].sort( (a,b) => a.periodSpan?.[0]-b.periodSpan?.[0] ));
}
//const byPeriodData = newGroupByPeriods(filteredTimelineData)
......@@ -45,7 +41,6 @@ export const Timeline = (props) => {
)
useEffect(() => {
//setData(byPeriodData);
//svg dimensions
const containerHeight = parseInt(select("#timelineContainer").style("height")),
......@@ -57,10 +52,9 @@ export const Timeline = (props) => {
svg.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom);
//remove previously rendered timeline bars in the case there is no current data from the current search
//remove previously rendered timeline bars in the case there is no data from the current search
//if (!timelineObjectsData||!byPeriodData||byPeriodData.size===0) {
if (!data||data.size===0) {
console.log("data", data);
svg.select(".bars")
.selectAll(".bar").remove()
svg.select(".bars")
......@@ -69,10 +63,12 @@ export const Timeline = (props) => {
} else {
const periodIds = [...data.keys()];
//scale for the x axis
const xScale = scaleLinear()
.domain(xDomain)
.range([0,width])
//scale for the y axis
const yScale = scaleBand()
.domain(periodIds)
.range([height,0])
......@@ -90,11 +86,12 @@ export const Timeline = (props) => {
const timelineCanvas = svg.select(".bars")
.attr("transform",`translate(${margin.left}, ${margin.top})`)
//sync svg groups for bars and labels to the values of the data (map grouped by periods)
//bind svg groups for bars and labels to the values of the data (map grouped by periods)
const barGroups = timelineCanvas
.selectAll(".barGroup")
.data([...data.values()], (data,index) => periodIds[index]);
console.log(barGroups);
.data([...data.values()], (data,index) => data.periodName+data.periodSpan[0]);
//todo: evaluate if generating the key form period name + period beginning sufficiently unique?
//console.log("bar groups: ", barGroups);
//instructions for joining the synced data and group elements: add svg g, rect and text elements on enter
//returns a selection of new and updating groups
......@@ -107,6 +104,8 @@ export const Timeline = (props) => {
group
.append("rect")
.attr("class", "bar")
.attr("height", yScale.bandwidth())
.attr("fill", "#69b3a2");
group
.append("text")
.attr("class","label");
......@@ -118,29 +117,27 @@ export const Timeline = (props) => {
newAndUpdatedGroups
.attr("transform", (value, index) => `translate(${xScale(value.periodSpan?.[0])},${yScale(periodIds[index])})`)
//extend the svg rect elements as chart bars according to the data
//extend the svg rect elements as chart bars according to the data and return as "bar"
const bar = newAndUpdatedGroups.selectAll(".bar")
.attr("height", yScale.bandwidth())
.attr("fill", "#69b3a2")
.transition()
.attr("width", value => Math.abs(xScale(value.periodSpan?.[0])-xScale(value.periodSpan?.[1]))||0);
//add period names as text labels to the groups
//add period names as text labels to the groups and return as "labels"
const labels = newAndUpdatedGroups.selectAll(".label")
.text(value => value.periodName);
console.log(newAndUpdatedGroups);
console.log("new and updated after labels: ", newAndUpdatedGroups);
//attach click event and sort function to sort button;
select(".sortButton").on("click", () =>
svg.selectAll(".barGroup").sort( (a,b) => ascending(parseInt(a.periodSpan?.[0]),parseInt(b.periodSpan?.[0])) )
.attr("transform", (value, index) => `translate(${xScale(value.periodSpan?.[0])},${yScale(periodIds[index])})`)
);
//on click show detailed view of items for a period
//on click show detailed view of dated objects for a period
newAndUpdatedGroups.on("click", (event, value) => {
//console.log(value)
const element = svg.selectAll(".bar").nodes(),
index = element.indexOf(event.currentTarget);
/*const element = svg.selectAll(".bar").nodes(),
index = element.indexOf(event.currentTarget);*/
const itemDatingMin = min(value.items, item => item.spanDated?.[0]),
itemDatingMax = max(value.items, item => item.spanDated?.[1]);
......@@ -164,7 +161,7 @@ export const Timeline = (props) => {
.attr("transform", `translate(0,${height})`)
.call(axisBottom(xScaleDetail))
//join svg rect elements with array of item datings
//join svg rect elements with array of item dating
svg.select(".bars")
.selectAll("rect").data(value.items).join(
enter => enter.append("rect")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment