Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into update-mocha
- Loading branch information
Showing
9 changed files
with
226 additions
and
158 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
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,26 @@ | ||
import { LivePlotData, LivePlotsColors } from 'dvc/src/plots/webview/contract' | ||
import React from 'react' | ||
import { EmptyState } from './EmptyState' | ||
import { Plot } from './Plot' | ||
import styles from './styles.module.scss' | ||
|
||
interface LivePlotsProps { | ||
plots: LivePlotData[] | ||
colors: LivePlotsColors | ||
} | ||
|
||
export const LivePlots: React.FC<LivePlotsProps> = ({ plots, colors }) => | ||
plots.length ? ( | ||
<div className={styles.singleViewPlotsGrid}> | ||
{plots.map(plotData => ( | ||
<Plot | ||
values={plotData.values} | ||
title={plotData.title} | ||
scale={colors} | ||
key={`plot-${plotData.title}`} | ||
/> | ||
))} | ||
</div> | ||
) : ( | ||
EmptyState('No metrics selected') | ||
) |
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,32 @@ | ||
import { LivePlotsColors, LivePlotValues } from 'dvc/src/plots/webview/contract' | ||
import React from 'react' | ||
import { VegaLite } from 'react-vega' | ||
import { config, createSpec } from './constants' | ||
import styles from './styles.module.scss' | ||
import { withScale } from '../../util/styles' | ||
|
||
interface PlotProps { | ||
values: LivePlotValues | ||
title: string | ||
scale?: LivePlotsColors | ||
} | ||
|
||
export const Plot: React.FC<PlotProps> = ({ values, title, scale }) => { | ||
const spec = createSpec(title, scale) | ||
|
||
return ( | ||
<div | ||
className={styles.plot} | ||
style={withScale(1)} | ||
data-testid={`plot-${title}`} | ||
> | ||
<VegaLite | ||
actions={false} | ||
config={config} | ||
spec={spec} | ||
data={{ values }} | ||
renderer="svg" | ||
/> | ||
</div> | ||
) | ||
} |
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,35 @@ | ||
import { VegaPlot } from 'dvc/src/plots/webview/contract' | ||
import React from 'react' | ||
import cx from 'classnames' | ||
import { VegaLite, VisualizationSpec } from 'react-vega' | ||
import { config } from './constants' | ||
import styles from './styles.module.scss' | ||
import { withScale } from '../../util/styles' | ||
|
||
interface StaticPlotProps { | ||
plot: VegaPlot | ||
} | ||
|
||
export const StaticPlot: React.FC<StaticPlotProps> = ({ plot }) => { | ||
const nbRevisions = (plot.multiView && plot.revisions?.length) || 1 | ||
const className = cx(styles.plot, { | ||
[styles.multiViewPlot]: plot.multiView | ||
}) | ||
|
||
return ( | ||
<div className={className} style={withScale(nbRevisions)}> | ||
<VegaLite | ||
actions={false} | ||
config={config} | ||
spec={ | ||
{ | ||
...plot.content, | ||
height: 'container', | ||
width: 'container' | ||
} as VisualizationSpec | ||
} | ||
renderer="svg" | ||
/> | ||
</div> | ||
) | ||
} |
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,57 @@ | ||
import { VegaPlot, VegaPlots } from 'dvc/src/plots/webview/contract' | ||
import React from 'react' | ||
import styles from './styles.module.scss' | ||
import { StaticPlot } from './StaticPlot' | ||
|
||
interface StaticPlotsProps { | ||
plots: VegaPlots | ||
} | ||
|
||
type StaticPlotAccumulator = { | ||
singleViewPlots: VegaPlots | ||
multiViewPlots: VegaPlots | ||
} | ||
|
||
export const StaticPlots: React.FC<StaticPlotsProps> = ({ plots }) => { | ||
const fillInPlotsType = ( | ||
plotsType: VegaPlots, | ||
path: string, | ||
plot: VegaPlot | ||
) => { | ||
plotsType[path] = plotsType[path] ? [...plotsType[path], plot] : [plot] | ||
} | ||
|
||
const { singleViewPlots, multiViewPlots } = Object.entries(plots).reduce( | ||
(acc: StaticPlotAccumulator, [path, plots]) => { | ||
plots.forEach(plot => { | ||
if (plot.multiView) { | ||
fillInPlotsType(acc.multiViewPlots, path, plot) | ||
return | ||
} | ||
fillInPlotsType(acc.singleViewPlots, path, plot) | ||
}) | ||
return acc | ||
}, | ||
{ multiViewPlots: {}, singleViewPlots: {} } | ||
) | ||
|
||
const makeKey = (path: string, i: number) => `plot-${path}-${i}` | ||
|
||
const renderPlots = (entries: VegaPlots) => | ||
Object.entries(entries).map(([path, plots]) => | ||
plots.map((plot: VegaPlot, i) => ( | ||
<StaticPlot key={makeKey(path, i)} plot={plot} /> | ||
)) | ||
) | ||
|
||
return ( | ||
<> | ||
<div className={styles.singleViewPlotsGrid}> | ||
{renderPlots(singleViewPlots)} | ||
</div> | ||
<div className={styles.multiViewPlotsGrid}> | ||
{renderPlots(multiViewPlots)} | ||
</div> | ||
</> | ||
) | ||
} |
Oops, something went wrong.