diff --git a/src/Layout/Routes.js b/src/Layout/Routes.js index 4f645908..8ad2bb3a 100644 --- a/src/Layout/Routes.js +++ b/src/Layout/Routes.js @@ -4,14 +4,14 @@ import { Route, Routes } from "react-router-dom"; // eslint-disable-next-line import/no-unresolved import config from "config"; import AuthorsRoute from "pages/AuthorsRoute"; +import ComplexDistance from "pages/ComplexDistance"; +import CorpImport from "pages/CorpImport"; import { CreateCorpus, CreateDictionary } from "pages/CreateDictionary"; import { CorpusDashboard, DictionaryDashboard, ParallelCorporaDashboard } from "pages/Dashboard"; import DashboardRoute from "pages/DashboardRoute"; import Desktop from "pages/Desktop"; import DialeqtImport from "pages/DialeqtImport"; import DictImport from "pages/DictImport"; -import ComplexDistance from "pages/ComplexDistance"; -import CorpImport from "pages/CorpImport"; import DictionariesAll from "pages/DictionariesAll"; import DistanceMap from "pages/DistanceMap"; import MapSelectedLanguages from "pages/DistanceMap/map"; diff --git a/src/components/CognateAnalysisModal/index.js b/src/components/CognateAnalysisModal/index.js index fc8d5917..37f19ec9 100644 --- a/src/components/CognateAnalysisModal/index.js +++ b/src/components/CognateAnalysisModal/index.js @@ -247,6 +247,26 @@ const computeMorphCognateAnalysisMutation = gql` } `; +const computeComplexDistanceMutation = gql` + mutation complexDistance ( + $resultPool: [ObjectVal]! + $debugFlag: Boolean + ) { + complex_distance( + result_pool: $resultPool + debug_flag: $debugFlag + ) { + result + minimum_spanning_tree + embedding_2d + embedding_3d + language_name_list + message + triumph + } + } +`; + const SUGGESTIONS_PER_PAGE = 50; function equalIds(id_a, id_b) { @@ -1265,6 +1285,7 @@ class CognateAnalysisModal extends React.Component { xlsx_url: "", json_url: "", figure_url: "", + fileSuite: null, minimum_spanning_tree: [], embedding_2d: [], @@ -1340,6 +1361,7 @@ class CognateAnalysisModal extends React.Component { this.admin_section_render = this.admin_section_render.bind(this); this.suggestions_render = this.suggestions_render.bind(this); + this.brose_files_render = this.brose_files_render.bind(this); this.sg_connect = this.sg_connect.bind(this); } @@ -1985,6 +2007,16 @@ class CognateAnalysisModal extends React.Component { } } + handleComplexDistanceResult({ data: { complex_distance }}) + { + this.setState({ + ...complex_distance, + /* Calculate plotly data */ + ...this.handleResult(complex_distance), + computing: false + }); + } + handleSwadeshResult({ data: { swadesh_analysis }}) { this.setState({ @@ -2103,7 +2135,13 @@ class CognateAnalysisModal extends React.Component { } handleCreate() { - const { perspectiveId, computeCognateAnalysis, computeSwadeshAnalysis, computeMorphCognateAnalysis } = this.props; + const { + perspectiveId, + computeCognateAnalysis, + computeSwadeshAnalysis, + computeMorphCognateAnalysis, + computeComplexDistance + } = this.props; const groupField = this.fieldDict[this.state.groupFieldIdStr]; @@ -2214,6 +2252,30 @@ class CognateAnalysisModal extends React.Component { data => this.handleMorphologyResult(data), error_data => this.handleError(error_data) ); + } else if (this.props.mode === "complex_distance") { + this.setState({ computing: true }); + + const { fileSuite, debugFlag } = this.state; + const resultPool = new Array(fileSuite.length); + + for (const [index, file] of fileSuite.entries()) { + const reader = new FileReader(); + reader.onload = () => { + resultPool[index] = JSON.parse(reader.result); + if ((index + 1) == fileSuite.length) { + computeComplexDistance({ + variables: { + resultPool, + debugFlag + } + }).then( + data => this.handleComplexDistanceResult(data), + error_data => this.handleError(error_data) + ); + } + }; + reader.readAsText(file); + } } else { /* Otherwise we will launch it as usual and then will wait for results to display them. */ this.setState({ @@ -2784,6 +2846,40 @@ class CognateAnalysisModal extends React.Component { ); } + brose_files_render() { + + const { fileSuite } = this.state; + + return ( +
{this.state.result}