Skip to content

Commit

Permalink
Merge pull request #2242 from concord-consortium/187147065-view-as-gr…
Browse files Browse the repository at this point in the history
…aph-multiple

"View as graph" adds a layer when possible
  • Loading branch information
bgoldowsky authored Mar 26, 2024
2 parents a8bc36e + 30c10dd commit a96e7f5
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 13 deletions.
12 changes: 6 additions & 6 deletions docs/unit-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,13 @@ Not updated to common toolbar framework and does not support toolbar configurati

#### Graph

- `autoAssignAttributes`: boolean, default true
- `connectPointsByDefault`: boolean, default true
- `defaultSeriesLegend`: boolean, default true
- `autoAssignAttributes`: boolean, default true. When true, when a dataset is connected to the graph, its first two columns will be immediately assigned to the "x" and "y" axes of the graph.
- `connectPointsByDefault`: boolean, default true. When true connecting lines between data points are drawn.
- `defaultAxisLabels`: { "bottom": "x", "left": "y" }, default none
- `disableAttributeDnD`: boolean, default true
- `emptyPlotIsNumeric`: boolean, default true
- `scalePlotOnValueChange`: boolean, default true
- `defaultSeriesLegend`: boolean, default true. When true, the graph can connect to and display multiple datasets, and includes a legend area which allows adding, modifying, and removing these layers.
- `disableAttributeDnD`: boolean, default true. When true, you cannot drop attributes onto the axes to change the graph. "false" setting not currently tested.
- `emptyPlotIsNumeric`: boolean, default true. When true graph defaults to numeric axes. "false" setting not currently tested.
- `scalePlotOnValueChange`: boolean, default true. When true, adding/deleting/modifying value of any data causes the graph to be rescaled to fit the data.

Uses the common toolbar framework. Default toolbar buttons:

Expand Down
7 changes: 5 additions & 2 deletions src/hooks/use-consumer-tile-linking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { SharedModelUnion } from "../models/shared/shared-model-manager";
import { SharedModelType } from "../models/shared/shared-model";
import { logSharedModelDocEvent } from "../models/document/log-shared-model-document-event";
import { LogEventName } from "../lib/logger-types";
import { useAppConfig } from "./use-stores";

interface IProps {
// TODO: This should be replaced with a generic disabled
Expand Down Expand Up @@ -56,6 +57,7 @@ interface IProps {
export const useConsumerTileLinking = ({
model, shareType, hasLinkableRows, readOnly, tileType, onLinkTile, onUnlinkTile, onCreateTile
}: IProps) => {
const appConfig = useAppConfig();
// In the future we might need to limit this search to only tiles that are consumers for 'shareType'.
// At the moment we have no cases where it matters.
const { consumers: linkableTilesAllTypes } = useLinkableTiles({ model });
Expand Down Expand Up @@ -89,7 +91,8 @@ export const useConsumerTileLinking = ({
// Don't remove old links before adding the new one, since some models (eg, table) take action
// if they see they have no linked data.
let dataSetsToRemove = [] as SharedModelType[];
if (shareType === SharedDataSet && !getTileContentInfo(consumerTile.type)?.consumesMultipleDataSets) {
const allowsMultiple = getTileContentInfo(consumerTile.type)?.consumesMultipleDataSets?.(appConfig);
if (shareType === SharedDataSet && !allowsMultiple) {
dataSetsToRemove = sharedModelManager.getTileSharedModelsByType(consumerTile, SharedDataSet);
}
if (modelToShare){
Expand All @@ -105,7 +108,7 @@ export const useConsumerTileLinking = ({
});
}
}
}, [model.content, modelToShare, readOnly, shareType, sharedModelManager]);
}, [appConfig, model.content, modelToShare, readOnly, shareType, sharedModelManager]);

const unlinkTile = useCallback((tileInfo: ITileLinkMetadata) => {
const linkedTile = getTileContentById(model.content, tileInfo.id);
Expand Down
2 changes: 1 addition & 1 deletion src/models/tiles/geometry/geometry-registration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ registerTileContentInfo({
defaultHeight: kGeometryDefaultHeight,
exportNonDefaultHeight: true,
isDataConsumer: true,
consumesMultipleDataSets: true,
consumesMultipleDataSets: () => true,
defaultContent: defaultGeometryContent,
tileSnapshotPreProcessor
});
Expand Down
2 changes: 1 addition & 1 deletion src/models/tiles/tile-content-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export interface ITileContentInfo {
isDataConsumer?: boolean;
isDataProvider?: boolean;
isVariableProvider?: boolean;
consumesMultipleDataSets?: boolean;
consumesMultipleDataSets?: (appConfig: AppConfigModelType) => boolean;
tileSnapshotPreProcessor?: TileModelSnapshotPreProcessor;
contentSnapshotPostProcessor?: TileContentSnapshotPostProcessor;
updateContentWithNewSharedModelIds?: TileContentNewSharedModelIdUpdater;
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/graph/graph-registration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import { updateGraphContentWithNewSharedModelIds, updateGraphObjectWithNewShared

import Icon from "./assets/graph-icon.svg";
import HeaderIcon from "./assets/graph-tile-id.svg";
import { AppConfigModelType } from "../../models/stores/app-config-model";

function graphAllowsMultipleDataSets(appConfig: AppConfigModelType) {
return !!appConfig.getSetting("defaultSeriesLegend", "graph");
}

registerTileContentInfo({
defaultContent: (options) => createGraphModel(undefined, options?.appConfig),
Expand All @@ -16,6 +21,7 @@ registerTileContentInfo({
displayName: "Graph",
type: kGraphTileType,
isDataConsumer: true,
consumesMultipleDataSets: graphAllowsMultipleDataSets,
updateContentWithNewSharedModelIds: updateGraphContentWithNewSharedModelIds,
updateObjectReferenceWithNewSharedModelIds: updateGraphObjectWithNewSharedModelIds
});
Expand Down
4 changes: 1 addition & 3 deletions src/plugins/graph/models/graph-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -790,9 +790,7 @@ export function createGraphModel(snap?: IGraphModelSnapshot, appConfig?: AppConf
yAttributeLabel: axisLabels && axisLabels.left,
...snap
});
// TODO: make a dedicated setting for this rather than using defaultSeriesLegend as a proxy:
// const connectLinesByDefault = appConfig?.getSetting("defaultConnectedLines", "graph");
const connectByDefault = appConfig?.getSetting("defaultSeriesLegend", "graph");
const connectByDefault = appConfig?.getSetting("connectPointsByDefault", "graph");
if (connectByDefault) {
const cLines = ConnectingLinesModel.create();
createdGraphModel.addAdornment(cLines);
Expand Down

0 comments on commit a96e7f5

Please sign in to comment.