-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable choosing scatterplot in menu
- Loading branch information
Showing
11 changed files
with
181 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright 2017-2022 Allegro.pl | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
.scatterplot { | ||
.scatterplot-container { | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: flex-start; | ||
align-items: center; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2017-2022 Allegro.pl | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import * as React from "react"; | ||
|
||
import { ChartProps } from "../../../common/models/chart-props/chart-props"; | ||
import makeQuery from "../../../common/utils/query/visualization-query"; | ||
import { | ||
ChartPanel, | ||
DefaultVisualizationControls, | ||
VisualizationProps | ||
} from "../../views/cube-view/center-panel/center-panel"; | ||
|
||
import "./scatterplot.scss"; | ||
|
||
const Scatterplot: React.SFC<ChartProps> = () => { | ||
return <div className="scatterplot-container"> | ||
<h2>Scatterplot will be here</h2> | ||
</div>; | ||
}; | ||
|
||
export function ScatterplotVisualization(props: VisualizationProps) { | ||
return <React.Fragment> | ||
<DefaultVisualizationControls {...props} /> | ||
<ChartPanel {...props} queryFactory={makeQuery} chartComponent={Scatterplot}/> | ||
</React.Fragment>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
src/common/visualization-manifests/scatterplot/scatterplot.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* Copyright 2017-2022 Allegro.pl | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import { allDimensions } from "../../models/dimension/dimensions"; | ||
import { allMeasures } from "../../models/measure/measures"; | ||
import { MeasureSeries } from "../../models/series/measure-series"; | ||
import { Split } from "../../models/split/split"; | ||
import { Resolve, VisualizationManifest } from "../../models/visualization-manifest/visualization-manifest"; | ||
import { emptySettingsConfig } from "../../models/visualization-settings/empty-settings-config"; | ||
import { Predicates } from "../../utils/rules/predicates"; | ||
import { | ||
ActionVariables, | ||
visualizationDependentEvaluatorBuilder | ||
} from "../../utils/rules/visualization-dependent-evaluator"; | ||
|
||
// FIXME: Update conditions and tests in EssenceProps src/common/models/essence/essence.mocha.ts | ||
const rulesEvaluator = visualizationDependentEvaluatorBuilder | ||
.when(Predicates.numberOfSplitsIsNot(1)) | ||
.then(variables => Resolve.manual( | ||
3, | ||
"Scatterplot needs exactly 1 split", | ||
variables.splits.length() > 1 ? suggestRemovingSplits(variables) : suggestAddingSplits(variables) | ||
)) | ||
.when(Predicates.numberOfSeriesIsNot(2)) | ||
.then(variables => Resolve.manual( | ||
3, | ||
"Scatterplot needs exactly 2 measures", | ||
variables.series.series.size < 2 ? suggestAddingMeasure(variables) : suggestRemovingMeasures(variables) | ||
)) | ||
.otherwise(({ isSelectedVisualization }) => | ||
Resolve.ready(isSelectedVisualization ? 10 : 3) | ||
) | ||
.build(); | ||
|
||
const suggestRemovingSplits = ({ splits }: ActionVariables) => [{ | ||
description: splits.length() === 2 ? "Remove last split" : `Remove last ${splits.length() - 1} splits`, | ||
adjustment: { splits: splits.slice(0, 1) } | ||
}]; | ||
|
||
const suggestAddingSplits = ({ dataCube, splits }: ActionVariables) => | ||
allDimensions(dataCube.dimensions) | ||
.filter(dimension => !splits.hasSplitOn(dimension)) | ||
.slice(0, 2) | ||
.map(dimension => ({ | ||
description: `Add ${dimension.title} split`, | ||
adjustment: { | ||
splits: splits.addSplit(Split.fromDimension(dimension)) | ||
} | ||
})); | ||
|
||
const suggestAddingMeasure = ({ dataCube, series }: ActionVariables) => { | ||
const firstSeriesKey = series.getSeriesKeys().first(); | ||
const notUsedMeasures = allMeasures(dataCube.measures).filter(measure => measure.name !== firstSeriesKey); | ||
|
||
if (notUsedMeasures.length > 0) { | ||
const firstMeasure = notUsedMeasures[0]; | ||
return [{ | ||
description: `Add measure ${firstMeasure.title}`, | ||
adjustment: { | ||
series: series.addSeries(MeasureSeries.fromMeasure(firstMeasure)) | ||
} | ||
}]; | ||
} | ||
|
||
return [{ | ||
description: "Second measure needed", | ||
adjustment: null | ||
}]; | ||
}; | ||
|
||
const suggestRemovingMeasures = ({ series }: ActionVariables) => [{ | ||
description: series.count() === 3 ? "Remove last measure" : "Use first two measures", | ||
adjustment: { | ||
series: series.takeNFirst(2) | ||
} | ||
}]; | ||
|
||
export const SCATTERPLOT_MANIFEST = new VisualizationManifest( | ||
"scatterplot", | ||
"Scatterplot", | ||
rulesEvaluator, | ||
emptySettingsConfig | ||
); |