mirror of
https://github.com/PeWu/topola-viewer.git
synced 2026-05-27 07:36:18 +00:00
Toggle showing IDs (#131)
This commit is contained in:
16
src/app.tsx
16
src/app.tsx
@@ -16,6 +16,7 @@ import {TopBar} from './menu/top_bar';
|
|||||||
import {TopolaData} from './util/gedcom_util';
|
import {TopolaData} from './util/gedcom_util';
|
||||||
import {useEffect, useState} from 'react';
|
import {useEffect, useState} from 'react';
|
||||||
import {useHistory, useLocation} from 'react-router';
|
import {useHistory, useLocation} from 'react-router';
|
||||||
|
import {idToIndiMap} from './util/gedcom_util';
|
||||||
import {
|
import {
|
||||||
Chart,
|
Chart,
|
||||||
ChartType,
|
ChartType,
|
||||||
@@ -30,6 +31,7 @@ import {
|
|||||||
ConfigPanel,
|
ConfigPanel,
|
||||||
configToArgs,
|
configToArgs,
|
||||||
DEFALUT_CONFIG,
|
DEFALUT_CONFIG,
|
||||||
|
Ids,
|
||||||
} from './config';
|
} from './config';
|
||||||
import {
|
import {
|
||||||
getSelection,
|
getSelection,
|
||||||
@@ -217,6 +219,17 @@ export function App() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function toggleIds(config: Config, data: TopolaData | undefined) {
|
||||||
|
if (data === undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let shouldHideIds = config.id === Ids.HIDE;
|
||||||
|
let indiMap = idToIndiMap(data.chartData);
|
||||||
|
indiMap.forEach((indi) => {
|
||||||
|
indi.hideId = shouldHideIds;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/** Sets error message after data load failure. */
|
/** Sets error message after data load failure. */
|
||||||
function setErrorMessage(message: string) {
|
function setErrorMessage(message: string) {
|
||||||
setError(message);
|
setError(message);
|
||||||
@@ -325,6 +338,7 @@ export function App() {
|
|||||||
const data = await loadData(args.sourceSpec, args.selection);
|
const data = await loadData(args.sourceSpec, args.selection);
|
||||||
// Set state with data.
|
// Set state with data.
|
||||||
setData(data);
|
setData(data);
|
||||||
|
toggleIds(args.config, data);
|
||||||
setShowSidePanel(args.showSidePanel);
|
setShowSidePanel(args.showSidePanel);
|
||||||
setState(AppState.SHOWING_CHART);
|
setState(AppState.SHOWING_CHART);
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
@@ -468,6 +482,7 @@ export function App() {
|
|||||||
config={config}
|
config={config}
|
||||||
onChange={(config) => {
|
onChange={(config) => {
|
||||||
setConfig(config);
|
setConfig(config);
|
||||||
|
toggleIds(config, data);
|
||||||
updateUrl(configToArgs(config));
|
updateUrl(configToArgs(config));
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
@@ -491,6 +506,7 @@ export function App() {
|
|||||||
onSelection={onSelection}
|
onSelection={onSelection}
|
||||||
freezeAnimation={freezeAnimation}
|
freezeAnimation={freezeAnimation}
|
||||||
colors={config.color}
|
colors={config.color}
|
||||||
|
hideIds={config.id}
|
||||||
/>
|
/>
|
||||||
{showSidePanel ? (
|
{showSidePanel ? (
|
||||||
<Media greaterThanOrEqual="large" className="sidePanel">
|
<Media greaterThanOrEqual="large" className="sidePanel">
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import {ChartColors} from './config';
|
import {ChartColors, Ids} from './config';
|
||||||
import {interpolateNumber} from 'd3-interpolate';
|
import {interpolateNumber} from 'd3-interpolate';
|
||||||
import {IntlShape, useIntl} from 'react-intl';
|
import {IntlShape, useIntl} from 'react-intl';
|
||||||
import {max, min} from 'd3-array';
|
import {max, min} from 'd3-array';
|
||||||
@@ -257,6 +257,7 @@ export interface ChartProps {
|
|||||||
onSelection: (indiInfo: IndiInfo) => void;
|
onSelection: (indiInfo: IndiInfo) => void;
|
||||||
freezeAnimation?: boolean;
|
freezeAnimation?: boolean;
|
||||||
colors?: ChartColors;
|
colors?: ChartColors;
|
||||||
|
hideIds?: Ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
class ChartWrapper {
|
class ChartWrapper {
|
||||||
@@ -418,7 +419,8 @@ export function Chart(props: ChartProps) {
|
|||||||
if (prevProps) {
|
if (prevProps) {
|
||||||
const initialRender =
|
const initialRender =
|
||||||
props.chartType !== prevProps?.chartType ||
|
props.chartType !== prevProps?.chartType ||
|
||||||
props.colors !== prevProps?.colors;
|
props.colors !== prevProps?.colors ||
|
||||||
|
props.hideIds !== prevProps?.hideIds;
|
||||||
const resetPosition =
|
const resetPosition =
|
||||||
props.chartType !== prevProps?.chartType ||
|
props.chartType !== prevProps?.chartType ||
|
||||||
props.data !== prevProps.data ||
|
props.data !== prevProps.data ||
|
||||||
|
|||||||
@@ -8,12 +8,19 @@ export enum ChartColors {
|
|||||||
COLOR_BY_GENERATION,
|
COLOR_BY_GENERATION,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum Ids {
|
||||||
|
HIDE,
|
||||||
|
SHOW,
|
||||||
|
}
|
||||||
|
|
||||||
export interface Config {
|
export interface Config {
|
||||||
color: ChartColors;
|
color: ChartColors;
|
||||||
|
id: Ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DEFALUT_CONFIG: Config = {
|
export const DEFALUT_CONFIG: Config = {
|
||||||
color: ChartColors.COLOR_BY_GENERATION,
|
color: ChartColors.COLOR_BY_GENERATION,
|
||||||
|
id: Ids.SHOW,
|
||||||
};
|
};
|
||||||
|
|
||||||
const COLOR_ARG = new Map<string, ChartColors>([
|
const COLOR_ARG = new Map<string, ChartColors>([
|
||||||
@@ -24,6 +31,13 @@ const COLOR_ARG = new Map<string, ChartColors>([
|
|||||||
const COLOR_ARG_INVERSE = new Map<ChartColors, string>();
|
const COLOR_ARG_INVERSE = new Map<ChartColors, string>();
|
||||||
COLOR_ARG.forEach((v, k) => COLOR_ARG_INVERSE.set(v, k));
|
COLOR_ARG.forEach((v, k) => COLOR_ARG_INVERSE.set(v, k));
|
||||||
|
|
||||||
|
const ID_ARG = new Map<string, Ids>([
|
||||||
|
['h', Ids.HIDE],
|
||||||
|
['s', Ids.SHOW],
|
||||||
|
]);
|
||||||
|
const ID_ARG_INVERSE = new Map<Ids, string>();
|
||||||
|
ID_ARG.forEach((v, k) => ID_ARG_INVERSE.set(v, k));
|
||||||
|
|
||||||
export function argsToConfig(args: ParsedQuery<any>): Config {
|
export function argsToConfig(args: ParsedQuery<any>): Config {
|
||||||
const getParam = (name: string) => {
|
const getParam = (name: string) => {
|
||||||
const value = args[name];
|
const value = args[name];
|
||||||
@@ -32,11 +46,15 @@ export function argsToConfig(args: ParsedQuery<any>): Config {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
color: COLOR_ARG.get(getParam('c') ?? '') ?? DEFALUT_CONFIG.color,
|
color: COLOR_ARG.get(getParam('c') ?? '') ?? DEFALUT_CONFIG.color,
|
||||||
|
id: ID_ARG.get(getParam('i') ?? '') ?? DEFALUT_CONFIG.id,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function configToArgs(config: Config): ParsedQuery<any> {
|
export function configToArgs(config: Config): ParsedQuery<any> {
|
||||||
return {c: COLOR_ARG_INVERSE.get(config.color)};
|
return {
|
||||||
|
c: COLOR_ARG_INVERSE.get(config.color),
|
||||||
|
i: ID_ARG_INVERSE.get(config.id),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ConfigPanel(props: {
|
export function ConfigPanel(props: {
|
||||||
@@ -64,7 +82,9 @@ export function ConfigPanel(props: {
|
|||||||
name="checkboxRadioGroup"
|
name="checkboxRadioGroup"
|
||||||
value="none"
|
value="none"
|
||||||
checked={props.config.color === ChartColors.NO_COLOR}
|
checked={props.config.color === ChartColors.NO_COLOR}
|
||||||
onClick={() => props.onChange({color: ChartColors.NO_COLOR})}
|
onClick={() =>
|
||||||
|
props.onChange({...props.config, color: ChartColors.NO_COLOR})
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</Form.Field>
|
</Form.Field>
|
||||||
<Form.Field className="no-margin">
|
<Form.Field className="no-margin">
|
||||||
@@ -81,7 +101,7 @@ export function ConfigPanel(props: {
|
|||||||
value="generation"
|
value="generation"
|
||||||
checked={props.config.color === ChartColors.COLOR_BY_GENERATION}
|
checked={props.config.color === ChartColors.COLOR_BY_GENERATION}
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
props.onChange({color: ChartColors.COLOR_BY_GENERATION})
|
props.onChange({...props.config, color: ChartColors.COLOR_BY_GENERATION})
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</Form.Field>
|
</Form.Field>
|
||||||
@@ -99,7 +119,50 @@ export function ConfigPanel(props: {
|
|||||||
value="gender"
|
value="gender"
|
||||||
checked={props.config.color === ChartColors.COLOR_BY_SEX}
|
checked={props.config.color === ChartColors.COLOR_BY_SEX}
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
props.onChange({color: ChartColors.COLOR_BY_SEX})
|
props.onChange({...props.config, color: ChartColors.COLOR_BY_SEX})
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</Form.Field>
|
||||||
|
</Item.Content>
|
||||||
|
</Item>
|
||||||
|
<Item>
|
||||||
|
<Item.Content>
|
||||||
|
<Header sub>
|
||||||
|
<FormattedMessage id="config.ids" defaultMessage="IDs" />
|
||||||
|
</Header>
|
||||||
|
<Form.Field className="no-margin">
|
||||||
|
<Checkbox
|
||||||
|
radio
|
||||||
|
label={
|
||||||
|
<FormattedMessage
|
||||||
|
tagName="label"
|
||||||
|
id="config.ids.HIDE"
|
||||||
|
defaultMessage="hide"
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
name="checkboxRadioGroup"
|
||||||
|
value="hide"
|
||||||
|
checked={props.config.id === Ids.HIDE}
|
||||||
|
onClick={() =>
|
||||||
|
props.onChange({...props.config, id: Ids.HIDE})
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</Form.Field>
|
||||||
|
<Form.Field className="no-margin">
|
||||||
|
<Checkbox
|
||||||
|
radio
|
||||||
|
label={
|
||||||
|
<FormattedMessage
|
||||||
|
tagName="label"
|
||||||
|
id="config.ids.SHOW"
|
||||||
|
defaultMessage="show"
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
name="checkboxRadioGroup"
|
||||||
|
value="show"
|
||||||
|
checked={props.config.id === Ids.SHOW}
|
||||||
|
onClick={() =>
|
||||||
|
props.onChange({...props.config, id: Ids.SHOW})
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</Form.Field>
|
</Form.Field>
|
||||||
|
|||||||
Reference in New Issue
Block a user