Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 259: nodesize by words #293

Open
wants to merge 31 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
5778f02
Issue 259: node size by number of spoken words
densandra Apr 19, 2024
b554423
259: implemented node size interpolation for relations graph
densandra May 21, 2024
34c9480
259: unified implementation of RelationsGraph and NetworkGraph
densandra May 21, 2024
576a65f
Bump the github-actions group with 3 updates
dependabot[bot] Apr 1, 2024
896afc1
Add link to DraCor mailing list
cmil Apr 5, 2024
cb2e994
add publications
lehkost Apr 11, 2024
76131f6
add publications
lehkost Apr 26, 2024
89319d3
improve bibl. record
lehkost Apr 26, 2024
3972f1b
Adjust alignment and direction of full text view for rtl scripts
cmil Apr 27, 2024
31374ed
2.2.0
cmil Apr 27, 2024
afb5e5c
adjust dashes
lehkost Apr 29, 2024
dc46da3
add 2 research papers
lehkost Apr 30, 2024
60e54bd
Bump ejs from 3.1.7 to 3.1.10
dependabot[bot] May 2, 2024
b51b796
Bump node from 21 to 22
dependabot[bot] May 3, 2024
83fccba
Bump axios from 1.6.0 to 1.6.1
dependabot[bot] May 3, 2024
a3cd960
Bump actions/checkout from 4.1.2 to 4.1.4 in the github-actions group
dependabot[bot] May 3, 2024
c524063
Update Docker section in README
cmil May 3, 2024
c9e9731
add paper
lehkost May 8, 2024
1c2ded3
add research papers and a monograph
lehkost May 25, 2024
54f91ce
update one record
lehkost May 28, 2024
3cec78a
add research articles
lehkost May 31, 2024
1e7d792
Use `git describe` to determine the frontend version to display
cmil May 31, 2024
9bc7ac2
Merge branch 'dracor-org:main' into 259-nodesize-by-words
densandra Jun 1, 2024
8876ea0
Merge remote-tracking branch 'upstream/main' into 259-nodesize-by-words
densandra Jun 1, 2024
34d7e9d
Merge branch '259-nodesize-by-words' of https://github.com/densandra/…
densandra Jun 1, 2024
2e12e03
Issue 259: node size by number of spoken words
densandra Apr 19, 2024
87163ca
259: implemented node size interpolation for relations graph
densandra May 21, 2024
4f681be
259: unified implementation of RelationsGraph and NetworkGraph
densandra May 21, 2024
c374963
add 2 research papers
lehkost Apr 30, 2024
fcc0428
update one record
lehkost May 28, 2024
9340ee5
Merge branch '259-nodesize-by-words' of https://github.com/densandra/…
densandra Jun 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions src/components/Graph/Graph.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import React from 'react';
import PropTypes from 'prop-types';
// we need to require from react-sigma/lib/ to make build work
import {
Sigma,
EdgeShapes,
NodeShapes,
ForceAtlas2,
RandomizeNodePositions,
} from 'react-sigma/lib/';

const Graph = ({graph, settings, edgeShape}) => {
const layoutOptions = {
iterationsPerRender: 40,
edgeWeightInfluence: 0,
timeout: 2000,
adjustSizes: false,
gravity: 3,
slowDown: 5,
linLogMode: true,
outboundAttractionDistribution: false,
strongGravityMode: false,
};

const layout = <ForceAtlas2 {...layoutOptions} />;

let sigma = null;
if (graph && graph.nodes.length > 0) {
sigma = (
<Sigma
renderer="canvas"
graph={graph}
settings={settings}
style={{display: 'flex', flexGrow: 1}}
>
<EdgeShapes default={edgeShape} />
<NodeShapes default="circle" />
<RandomizeNodePositions>{layout}</RandomizeNodePositions>
</Sigma>
);
}

return sigma;
};

Graph.propTypes = {
graph: PropTypes.shape({
nodes: PropTypes.array.isRequired,
edges: PropTypes.array.isRequired,
}).isRequired,
settings: PropTypes.object.isRequired,
edgeShape: PropTypes.string.isRequired,
};

export default Graph;
33 changes: 33 additions & 0 deletions src/components/Graph/NetworkGraph.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from 'react';
import PropTypes from 'prop-types';
import {makeGraph} from '../../network';

import Graph from './Graph';

const NetworkGraph = ({characters, play}) => {
const graph = makeGraph(characters, play, 'cooccurence');

const settings = {
maxEdgeSize: 5,
defaultLabelSize: 15,
defaultEdgeColor: '#61affe65', // FIXME: this does not seem to work
defaultNodeColor: '#61affe',
labelThreshold: 5,
labelSize: 'fixed',
drawLabels: true,
mouseWheelEnabled: false,
drawEdges: true,
};

return <Graph graph={graph} settings={settings} edgeShape="line" />;
};

NetworkGraph.propTypes = {
characters: PropTypes.array.isRequired,
play: PropTypes.shape({
relations: PropTypes.array.isRequired,
segments: PropTypes.array.isRequired,
}).isRequired,
};

export default NetworkGraph;
35 changes: 35 additions & 0 deletions src/components/Graph/RelationsGraph.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React from 'react';
import PropTypes from 'prop-types';
import {makeGraph} from '../../network';
import Graph from './Graph';

const RelationsGraph = ({characters, play}) => {
const graph = makeGraph(characters, play, 'relation');

const settings = {
maxEdgeSize: 5,
defaultLabelSize: 14,
defaultEdgeColor: '#61affe65', // FIXME: this does not seem to work
defaultNodeColor: '#61affe',
edgeLabelColor: 'edge',
labelThreshold: 3,
labelSize: 'fixed',
drawLabels: true,
drawEdges: true,
drawEdgeLabels: true,
edgeLabelSize: 'proportional',
minArrowSize: 10,
};

return <Graph graph={graph} settings={settings} edgeShape="curvedArrow" />;
};

RelationsGraph.propTypes = {
characters: PropTypes.array.isRequired,
play: PropTypes.shape({
relations: PropTypes.array.isRequired,
segments: PropTypes.array.isRequired,
}).isRequired,
};

export default RelationsGraph;
75 changes: 0 additions & 75 deletions src/components/NetworkGraph.js

This file was deleted.

60 changes: 31 additions & 29 deletions src/components/Play.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ import PropTypes from 'prop-types';
import {Container} from 'reactstrap';
import {Helmet} from 'react-helmet';
import api from '../api';
import {makeGraph} from '../network';
import PlayDetailsHeader from './PlayDetailsHeader';
import PlayDetailsNav from './PlayDetailsNav';
import PlayDetailsTab from './PlayDetailsTab';
import CastList from './CastList';
import SourceInfo from './SourceInfo';
import DownloadLinks from './DownloadLinks';
import NetworkGraph from './NetworkGraph';
import RelationsGraph from './RelationsGraph';
import NetworkGraph from './Graph/NetworkGraph';
import RelationsGraph from './Graph/RelationsGraph';
import SpeechDistribution, {SpeechDistributionNav} from './SpeechDistribution';
import TEIPanel from './TEIPanel';
import PlayMetrics from './PlayMetrics';
Expand All @@ -21,16 +20,6 @@ import './Play.scss';

const apiUrl = api.getBaseURL();

const edgeColor = '#61affe65';
const nodeColor = '#61affe';

const nodeProps = (node) => {
const {sex} = node;
const color = sex === 'MALE' || sex === 'FEMALE' ? '#1f2448' : '#61affe';
const type = sex === 'MALE' ? 'square' : 'circle';
return {color, type};
};

const navItems = [
{name: 'network', label: 'Network'},
{name: 'relations', label: 'Relations'},
Expand All @@ -43,7 +32,7 @@ const tabNames = new Set(navItems.map((item) => item.name));

const PlayInfo = ({corpusId, playId}) => {
const [play, setPlay] = useState(null);
const [graph, setGraph] = useState(null);
const [characters, setCharacters] = useState(null);
const [error, setError] = useState(null);
const [chartType, setChartType] = useState('sapogov');

Expand All @@ -55,10 +44,7 @@ const PlayInfo = ({corpusId, playId}) => {
try {
const response = await api.get(url);
if (response.ok) {
const {characters, segments} = response.data;
const graph = makeGraph(characters, segments, nodeProps, edgeColor);
setPlay(response.data);
setGraph(graph);
} else if (response.status === 404) {
setError(new Error('not found'));
} else {
Expand All @@ -72,6 +58,27 @@ const PlayInfo = ({corpusId, playId}) => {
fetchPlay();
}, [corpusId, playId]);

useEffect(() => {
async function fetchCharacters() {
setError(null);
const url = `/corpora/${corpusId}/plays/${playId}/characters`;
try {
const response = await api.get(url);
if (response.ok) {
setCharacters(response.data);
} else if (response.status === 404) {
setError(new Error('not found'));
} else {
setError(response.originalError);
}
} catch (error) {
console.error(error);
}
}

fetchCharacters();
}, [corpusId, playId]);

if (error && error.message === 'not found') {
return <p>No such play!</p>;
}
Expand All @@ -81,16 +88,11 @@ const PlayInfo = ({corpusId, playId}) => {
return <p>Error!</p>;
}

if (!play) {
if (!play || !characters) {
return <p className="loading">Loading...</p>;
}

if (!graph) {
return <p>No Graph!</p>;
}

console.log('PLAY', play);
console.log('GRAPH', graph);

const groups = play.characters
.filter((m) => Boolean(m.isGroup))
Expand All @@ -109,7 +111,7 @@ const PlayInfo = ({corpusId, playId}) => {

let tabContent = null;
let description = null;
let characters = null;
let cast = null;
let metrics = null;
let segments = null;

Expand Down Expand Up @@ -143,8 +145,8 @@ const PlayInfo = ({corpusId, playId}) => {
);
segments = <Segments play={play} />;
} else if (tab === 'relations') {
tabContent = <RelationsGraph {...{play, nodeColor, edgeColor}} />;
characters = castList;
tabContent = <RelationsGraph {...{characters, play}} />;
cast = castList;
description = (
<p>
This tab visualises kinship and other relationship data, following the
Expand All @@ -156,8 +158,8 @@ const PlayInfo = ({corpusId, playId}) => {
</p>
);
} else {
tabContent = <NetworkGraph {...{graph, nodeColor, edgeColor, play}} />;
characters = castList;
tabContent = <NetworkGraph {...{characters, play}} />;
cast = castList;
metrics = playMetrics;
description = (
<p>
Expand All @@ -184,7 +186,7 @@ const PlayInfo = ({corpusId, playId}) => {
</PlayDetailsHeader>
<Container fluid>
<PlayDetailsTab
characters={characters}
characters={cast}
description={description}
metrics={metrics}
segments={segments}
Expand Down
Loading