);
diff --git a/client-report/src/components/beeswarm/beeswarm.js b/client-report/src/components/beeswarm/beeswarm.js
index a8427ad09..455be374e 100644
--- a/client-report/src/components/beeswarm/beeswarm.js
+++ b/client-report/src/components/beeswarm/beeswarm.js
@@ -1,6 +1,6 @@
// Copyright (C) 2012-present, The Authors. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License, version 3, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see .
-import React from "react";
+import React, { useState, useEffect } from "react";
import CommentList from "../lists/commentList";
import * as globals from "../globals";
import _ from "lodash";
@@ -44,11 +44,11 @@ import _ from "lodash";
// }
-class VoronoiCells extends React.Component {
+const VoronoiCells = ({ currentBeeswarmComment, voronoi, onHoverCallback }) => {
/* https://bl.ocks.org/mbostock/6526445e2b44303eebf21da3b6627320 */
- getFill(cell) {
+ const getFill = (cell) => {
/* find the index of cell.data.tid in probabilitiesTids and use the index of it as the accessor */
@@ -58,7 +58,7 @@ class VoronoiCells extends React.Component {
// // !this.props.probabilitiesTids
// ) {
// return
- if (this.props.currentBeeswarmComment && this.props.currentBeeswarmComment.tid === cell.data.tid) {
+ if (currentBeeswarmComment?.tid === cell.data.tid) {
return "rgb(255,0,0)";
} else {
return "black"
@@ -78,19 +78,18 @@ class VoronoiCells extends React.Component {
// }
}
- render() {
return (
{
- this.props.voronoi.map((cell, i) => {
+ voronoi.map((cell, i) => {
return (
-
+
@@ -100,87 +99,83 @@ class VoronoiCells extends React.Component {
}
)
- }
}
-class Beeswarm extends React.Component {
- constructor(props) {
- super(props);
-
- this.svgWidth = 960;
- this.svgHeight = 200;
- this.margin = {top: 10, right: 10, bottom: 10, left: 10};
- this.widthMinusMargins = 960 - this.margin.left - this.margin.right;
- this.heightMinusMargins = 200 - this.margin.top - this.margin.bottom;
-
- this.state = {
- currentBeeswarmComment: null,
- commentsWithExtremity: null,
- axesRendered: false,
- };
- }
- onHoverCallback(d) {
+const Beeswarm = ({ comments, extremity, probabilitiesTids, probabilities, conversation, ptptCount, math, formatTid, voteColors }) => {
+
+ const svgWidth = 960;
+ const svgHeight = 200;
+ const margin = {top: 10, right: 10, bottom: 10, left: 10};
+ const widthMinusMargins = 960 - margin.left - margin.right;
+ const heightMinusMargins = 200 - margin.top - margin.bottom;
+
+ const [currentBeeswarmComment, setCurrentBeeswarmComment] = useState(null);
+ const [commentsWithExtremity, setCommentsWithExtremity] = useState(null);
+ const [x, setX] = useState(null);
+ const [axesRendered, setAxesRendered] = useState(false);
+ const[vor, setVoronoi] = useState(null);
+
+ const onHoverCallback = (d) => {
return () => {
- this.setState({currentBeeswarmComment: d.data});
+ setCurrentBeeswarmComment(d.data);
}
}
- componentDidMount() {
+ const setup = () => {
+ const commentsWithExtremityPlaceHolder = [];
+ _.each(comments, (comment) => {
+ if (extremity[comment.tid] > 0) {
+ const cwe = Object.assign({}, comment, {extremity: extremity[comment.tid]});
+ commentsWithExtremityPlaceHolder.push(cwe)
+ }
+ })
+
+ var x = d3.scaleLinear()
+ .rangeRound([0, widthMinusMargins]);
+
+ x.domain(d3.extent(commentsWithExtremityPlaceHolder, function(d) { return d.extremity; }));
+
+ var simulation = d3.forceSimulation(commentsWithExtremityPlaceHolder)
+ .force("x", d3.forceX(function(d) {
+ return x(d.extremity);
+ }).strength(1))
+ .force("y", d3.forceY(heightMinusMargins / 2))
+ .force("collide", d3.forceCollide(4))
+ .stop();
+
+ for (var i = 0; i < 120; ++i) simulation.tick();
+
+ const voronoi = d3.voronoi()
+ .extent([[-margin.left, -margin.top], [widthMinusMargins + margin.right, heightMinusMargins + margin.top]])
+ .x(function(d) { return d.x; })
+ .y(function(d) { return d.y; })
+ .polygons(commentsWithExtremityPlaceHolder)
+
+ // if (!this.state.axesRendered) {
+ // d3.select("#beeswarmAxisAttachPointD3").append("g")
+ // .attr("class", "axis axis--x")
+ // .attr("transform", "translate(0," + this.heightMinusMargins + ")")
+ // .call(d3.axisBottom(x).ticks(3));
+ // }
+
+ setX(x);
+ setVoronoi(voronoi);
+ setCommentsWithExtremity(commentsWithExtremityPlaceHolder);
+ setAxesRendered(true);
+}
+
+ useEffect(() => {
if (
- this.props.comments &&
- this.props.extremity &&
- !this.state.commentsWithExtremity /* if we poll, change this so it is auto updating */
+ comments &&
+ extremity &&
+ commentsWithExtremity /* if we poll, change this so it is auto updating */
) {
- this.setup();
+ setup();
}
- }
- setup () {
- const commentsWithExtremity = [];
- _.each(this.props.comments, (comment) => {
- if (this.props.extremity[comment.tid] > 0) {
- const cwe = Object.assign({}, comment, {extremity: this.props.extremity[comment.tid]});
- commentsWithExtremity.push(cwe)
- }
- })
-
- var x = d3.scaleLinear()
- .rangeRound([0, this.widthMinusMargins]);
-
- x.domain(d3.extent(commentsWithExtremity, function(d) { return d.extremity; }));
-
- var simulation = d3.forceSimulation(commentsWithExtremity)
- .force("x", d3.forceX(function(d) {
- return x(d.extremity);
- }).strength(1))
- .force("y", d3.forceY(this.heightMinusMargins / 2))
- .force("collide", d3.forceCollide(4))
- .stop();
-
- for (var i = 0; i < 120; ++i) simulation.tick();
-
- const voronoi = d3.voronoi()
- .extent([[-this.margin.left, -this.margin.top], [this.widthMinusMargins + this.margin.right, this.heightMinusMargins + this.margin.top]])
- .x(function(d) { return d.x; })
- .y(function(d) { return d.y; })
- .polygons(commentsWithExtremity)
-
- // if (!this.state.axesRendered) {
- // d3.select("#beeswarmAxisAttachPointD3").append("g")
- // .attr("class", "axis axis--x")
- // .attr("transform", "translate(0," + this.heightMinusMargins + ")")
- // .call(d3.axisBottom(x).ticks(3));
- // }
-
- this.setState({
- x,
- voronoi,
- commentsWithExtremity,
- axesRendered: true
- })
- }
- render() {
+ }, []);
+
return (
-
+
How divisive was the conversation?
Statements (here as little circles) to the left were voted on the same way—either everyone agreed or everyone disagreed. Statements to the right were divisive—participants were split between agreement and disagreement.
@@ -188,19 +183,19 @@ class Beeswarm extends React.Component {
How to use this: Hover to see the statement text. Start on the far right to find out what the most divisive statement was.