Skip to content

Commit a6c47fd

Browse files
committed
refactor: replace is_streamgraph with visualization_type
1 parent c5bf181 commit a6c47fd

File tree

14 files changed

+308
-275
lines changed

14 files changed

+308
-275
lines changed

vis/js/HeadstartRunner.tsx

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,29 @@
11
// @ts-nocheck
2-
import ReactDOM from "react-dom";
2+
import Bowser from "bowser";
33
import React from "react";
4-
import { createStore } from "redux";
5-
import { Provider } from "react-redux";
4+
import ReactDOM from "react-dom";
65
import { createRoot } from "react-dom/client";
6+
import { Provider } from "react-redux";
7+
import { createStore } from "redux";
78

8-
import rootReducer, { getInitialState } from "./reducers";
99
import {
10-
initializeStore,
11-
updateDimensions,
1210
applyForceAreas,
1311
applyForcePapers,
12+
initializeStore,
13+
updateDimensions,
1414
} from "./actions";
15-
16-
import applyHeadstartMiddleware from "./middleware";
17-
18-
import { applyForce } from "./utils/force";
19-
20-
import { getChartSize, getListSize } from "./utils/dimensions";
2115
import Headstart from "./components/Headstart";
22-
import { removeQueryParams } from "./utils/url";
23-
import debounce from "./utils/debounce";
24-
import DataManager from "./dataprocessing/managers/DataManager";
2516
import FetcherFactory from "./dataprocessing/fetchers/FetcherFactory";
26-
import handleZoomSelectQuery from "./utils/backButton";
27-
28-
import Bowser from "bowser";
17+
import DataManager from "./dataprocessing/managers/DataManager";
18+
import applyHeadstartMiddleware from "./middleware";
19+
import rootReducer, { getInitialState } from "./reducers";
20+
import { STREAMGRAPH_MODE } from "./reducers/chartType";
2921
import { Config } from "./types/config";
22+
import handleZoomSelectQuery from "./utils/backButton";
23+
import debounce from "./utils/debounce";
24+
import { getChartSize, getListSize } from "./utils/dimensions";
25+
import { applyForce } from "./utils/force";
26+
import { removeQueryParams } from "./utils/url";
3027

3128
class HeadstartRunner {
3229
public config: Config;
@@ -79,7 +76,7 @@ class HeadstartRunner {
7976
const browserName = browser.getBrowserName(true);
8077

8178
const isSupportedBrowser = SUPPORTED.map((browserName) =>
82-
browserName.toLowerCase()
79+
browserName.toLowerCase(),
8380
).includes(browserName);
8481

8582
if (!isSupportedBrowser || !browserName) {
@@ -88,7 +85,7 @@ class HeadstartRunner {
8885
"This visualization was successfully tested " +
8986
"with the latest versions of " +
9087
"Chrome, Firefox, Safari, Edge and Opera. " +
91-
"We strongly recommend using one of these browsers."
88+
"We strongly recommend using one of these browsers.",
9289
);
9390
}
9491
}
@@ -98,7 +95,7 @@ class HeadstartRunner {
9895
rootNode.render(
9996
<Provider store={this.store}>
10097
<Headstart />
101-
</Provider>
98+
</Provider>,
10299
);
103100
}
104101

@@ -116,7 +113,7 @@ class HeadstartRunner {
116113
const dataFetcher = FetcherFactory.getInstance(config.mode, {
117114
serverUrl: config.server_url,
118115
files: config.files,
119-
isStreamgraph: config.is_streamgraph,
116+
isStreamgraph: config.visualization_type === STREAMGRAPH_MODE,
120117
});
121118

122119
return await dataFetcher.getData();
@@ -145,11 +142,14 @@ class HeadstartRunner {
145142
height,
146143
list.height,
147144
this.dataManager.scalingFactors,
148-
this.dataManager.author
149-
)
145+
this.dataManager.author,
146+
),
150147
);
151148

152-
if (!this.config.is_streamgraph) {
149+
const { visualization_type: visualizationType } = this.config;
150+
const isNotStreamgraph = visualizationType !== STREAMGRAPH_MODE;
151+
152+
if (isNotStreamgraph) {
153153
this.applyForceLayout();
154154
}
155155
}
@@ -190,7 +190,7 @@ class HeadstartRunner {
190190
this.store.dispatch(applyForceAreas(newAreas, state.chart.height)),
191191
(newPapers: any) =>
192192
this.store.dispatch(applyForcePapers(newPapers, state.chart.height)),
193-
this.config
193+
this.config,
194194
);
195195
}
196196

@@ -210,7 +210,7 @@ class HeadstartRunner {
210210
scaleBy: string,
211211
baseUnit: string,
212212
isContentBased: boolean,
213-
initialSort: string
213+
initialSort: string,
214214
) {
215215
this.config.scale_by = scaleBy;
216216
this.config.base_unit = baseUnit;

vis/js/dataprocessing/managers/DataManager.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
// @ts-nocheck
2+
import { AllPossiblePapersType, Config, Paper } from "@js/types";
23
import d3 from "d3";
34
import $ from "jquery";
4-
import { Config, Paper, AllPossiblePapersType } from "@js/types";
5+
6+
import { GEOMAP_MODE, STREAMGRAPH_MODE } from "@/js/reducers/chartType";
7+
import { AquanaviPaper } from "@/js/types/models/paper";
8+
59
import {
610
checkIsAquanaviData,
711
extractAuthors,
@@ -25,8 +29,6 @@ import {
2529
} from "../../utils/scale";
2630
import { transformData } from "../../utils/streamgraph";
2731
import DEFAULT_SCHEME, { SchemeObject } from "../schemes/defaultScheme";
28-
import { GEOMAP_MODE } from "@/js/reducers/chartType";
29-
import { AquanaviPaper } from "@/js/types/models/paper";
3032

3133
const GOLDEN_RATIO = 2.6;
3234

@@ -65,7 +67,9 @@ class DataManager {
6567
// initialize this.scalingFactors
6668
this.__computeScalingFactors(this.papers.length);
6769

68-
if (!this.config.is_streamgraph) {
70+
const { visualization_type: visualizationType } = this.config;
71+
const isNotStreamgraph = visualizationType !== STREAMGRAPH_MODE;
72+
if (isNotStreamgraph) {
6973
// scale this.papers based on the chart size
7074
this.__scalePapers(chartSize);
7175
// initialize this.areas

vis/js/default-config.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ var config: Config = {
1313
is_authorview: false,
1414
//when set to true, scale map using metrics
1515
content_based: false,
16-
//show streamgraph instead of map
17-
is_streamgraph: false,
16+
1817
//tag that headstart is appended to
1918
tag: "visualization",
2019

vis/js/reducers/chartType.ts

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,41 @@
1-
import { VisualizationTypes } from "../types";
1+
import { Action, VisualizationTypes } from "../types";
22

33
export const STREAMGRAPH_MODE = "timeline";
44
export const KNOWLEDGEMAP_MODE = "overview";
55
export const GEOMAP_MODE = "geomap";
6+
const WARNINGS = {
7+
undefined:
8+
"Chart type is not defined in the configuration. The overview one will be used as a fallback.",
9+
notAllowed:
10+
"Configured chart type is not allowed. The overview one will be used as a fallback.",
11+
};
612

7-
const chartType = (
8-
state: VisualizationTypes = KNOWLEDGEMAP_MODE,
9-
action: any,
10-
) => {
11-
if (action.canceled) {
12-
return state;
13-
}
13+
type ChartTypeReducer = (
14+
prevState: VisualizationTypes | undefined,
15+
action: Action,
16+
) => VisualizationTypes;
17+
18+
export const chartType: ChartTypeReducer = (prevState, action) => {
19+
const state = prevState ?? KNOWLEDGEMAP_MODE;
1420

1521
switch (action.type) {
16-
case "INITIALIZE":
17-
const isStreamgraph: boolean = action.configObject.is_streamgraph;
18-
const type: VisualizationTypes = action.configObject.visualization_type;
22+
case "INITIALIZE": {
23+
const type = action.configObject?.visualization_type;
1924

20-
if (isStreamgraph) {
21-
return STREAMGRAPH_MODE;
25+
if (!type) {
26+
console.warn(WARNINGS.undefined);
27+
return KNOWLEDGEMAP_MODE;
2228
}
2329

24-
switch (type) {
25-
case KNOWLEDGEMAP_MODE:
26-
return KNOWLEDGEMAP_MODE;
27-
case STREAMGRAPH_MODE:
28-
return STREAMGRAPH_MODE;
29-
case GEOMAP_MODE:
30-
return GEOMAP_MODE;
31-
default:
32-
KNOWLEDGEMAP_MODE;
30+
if (![STREAMGRAPH_MODE, KNOWLEDGEMAP_MODE, GEOMAP_MODE].includes(type)) {
31+
console.warn(WARNINGS.notAllowed);
32+
return KNOWLEDGEMAP_MODE;
3333
}
34-
default:
34+
35+
return type;
36+
}
37+
default: {
3538
return state;
39+
}
3640
}
3741
};
38-
39-
export default chartType;

vis/js/reducers/data.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import d3 from "d3";
22

33
import { getValueOrZero } from "../utils/data";
44
import { getDiameterScale, getResizedScale } from "../utils/scale";
5+
import { STREAMGRAPH_MODE } from "./chartType";
56

67
const data = (
78
state = { list: [], options: {}, size: null } as any,
@@ -21,7 +22,8 @@ const data = (
2122
paperMaxScale: action.scalingFactors.paperMaxScale,
2223
paperWidthFactor: action.configObject.paper_width_factor,
2324
paperHeightFactor: action.configObject.paper_height_factor,
24-
isStreamgraph: action.configObject.is_streamgraph,
25+
isStreamgraph:
26+
action.configObject.visualization_type === STREAMGRAPH_MODE,
2527
visualizationId: action.contextObject.id,
2628
hoveredItemId: null,
2729
};

vis/js/reducers/heading.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Config } from "../types";
2-
import { GEOMAP_MODE } from "./chartType";
2+
import { GEOMAP_MODE, STREAMGRAPH_MODE } from "./chartType";
33

44
const context = (state = {}, action: any) => {
55
if (action.canceled) {
@@ -45,19 +45,22 @@ const getTitleStyle = (config: Config) => {
4545
};
4646

4747
const getTitleLabelType = (config: Config) => {
48-
if (config.is_authorview && config.is_streamgraph) {
48+
const isStreamgraph = config.visualization_type === STREAMGRAPH_MODE;
49+
const isGeomap = config.visualization_type === GEOMAP_MODE;
50+
51+
if (config.is_authorview && isStreamgraph) {
4952
return "authorview-streamgraph";
5053
}
5154

52-
if (config.is_authorview && !config.is_streamgraph) {
55+
if (config.is_authorview && !isStreamgraph) {
5356
return "authorview-knowledgemap";
5457
}
5558

56-
if (config.is_streamgraph) {
59+
if (isStreamgraph) {
5760
return "keywordview-streamgraph";
5861
}
5962

60-
if (config.visualization_type === GEOMAP_MODE) {
63+
if (isGeomap) {
6164
return "geomap";
6265
}
6366

vis/js/reducers/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import areas from "./areas";
99
import author from "./author";
1010
import bubbleOrder from "./bubbleOrder";
1111
import chart from "./chart";
12-
import chartType from "./chartType";
12+
import { chartType } from "./chartType";
1313
import contextLine from "./contextLine";
1414
import data from "./data";
1515
import { geomapSettings } from "./geomapSettings";

vis/js/reducers/timespan.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// @ts-nocheck
22

33
import dateFormat from "dateformat";
4+
5+
import { STREAMGRAPH_MODE } from "./chartType";
46
import { getModifier } from "./contextLine";
57

68
const timespan = (state = null, action: any) => {
@@ -54,19 +56,22 @@ const getTimespan = (config, context) => {
5456
const modifier = getModifier(config, context);
5557
// most recent streamgraphs straight away display "Until xyz",
5658
// other maps have a more complicated logic
57-
if (!config.is_streamgraph || modifier !== "most-recent") {
59+
60+
const { visualization_type: visualizationType } = config;
61+
const isNotStreamgraph = visualizationType !== STREAMGRAPH_MODE;
62+
if (isNotStreamgraph || modifier !== "most-recent") {
5863
const defaultFromHyphenated =
5964
SERVICE_START[config.service] || SERVICE_START.default;
6065

6166
const fromHyphenated = dateFormat(from, hyphenFormat);
6267
const fromFormatted = dateFormat(from, displayFormat);
6368

6469
if (fromHyphenated !== defaultFromHyphenated) {
65-
return fromFormatted + " - " + toFormatted;
70+
return `${fromFormatted} - ${toFormatted}`;
6671
}
6772
}
6873

69-
return "Until " + toFormatted;
74+
return `Until ${toFormatted}`;
7075
};
7176

7277
const getTodayDate = () => {

vis/js/types/configs/config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ export type Config = {
2020
scale_toolbar: boolean;
2121
is_authorview: boolean;
2222
content_based: boolean;
23-
is_streamgraph: boolean;
2423
tag: string;
2524

2625
metric_list?: boolean;

0 commit comments

Comments
 (0)