Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multiple formats support when downloading raw data #894

Merged
merged 4 commits into from
Dec 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ repos:
hooks:
- id: fe
name: lint-staged
entry: cd frontend && lint-staged
entry: ./frontend/scripts/lint-staged.sh
language: node
files: ^frontend/
pass_filenames: false
description: lint frontend code by lint-staged
- repo: meta
hooks:
Expand Down
2 changes: 1 addition & 1 deletion frontend/lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"packages": [
"packages/*"
],
"version": "2.1.0-1",
"version": "2.1.1",
"npmClient": "yarn",
"useWorkspaces": true,
"command": {
Expand Down
4 changes: 2 additions & 2 deletions frontend/packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@visualdl/cli",
"version": "2.1.0-1",
"version": "2.1.1",
"description": "A platform to visualize the deep learning process and result.",
"keywords": [
"visualdl",
Expand Down Expand Up @@ -34,7 +34,7 @@
"dist"
],
"dependencies": {
"@visualdl/server": "2.1.0-1",
"@visualdl/server": "2.1.1",
"open": "7.3.0",
"ora": "5.1.0",
"pm2": "4.5.1",
Expand Down
8 changes: 4 additions & 4 deletions frontend/packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@visualdl/core",
"version": "2.1.0-1",
"version": "2.1.1",
"description": "A platform to visualize the deep learning process and result.",
"keywords": [
"visualdl",
Expand Down Expand Up @@ -35,8 +35,8 @@
],
"dependencies": {
"@tippyjs/react": "4.2.0",
"@visualdl/netron": "2.1.0-1",
"@visualdl/wasm": "2.1.0-1",
"@visualdl/netron": "2.1.1",
"@visualdl/wasm": "2.1.1",
"bignumber.js": "9.0.1",
"d3": "6.3.1",
"d3-format": "2.0.0",
Expand Down Expand Up @@ -105,7 +105,7 @@
"@types/react-router-dom": "5.1.6",
"@types/snowpack-env": "2.3.3",
"@types/styled-components": "5.1.7",
"@visualdl/mock": "2.1.0-1",
"@visualdl/mock": "2.1.1",
"babel-plugin-styled-components": "1.12.0",
"dotenv": "8.2.0",
"enhanced-resolve": "5.4.1",
Expand Down
3 changes: 3 additions & 0 deletions frontend/packages/core/public/icons/chevron-left.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions frontend/packages/core/public/icons/chevron-right.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions frontend/packages/core/public/locales/en/scalar.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"download-data": "Download data",
"download-data-format": "In {{format}}",
"download-image": "Download image",
"ignore-outliers": "Ignore outliers in chart scaling",
"max": "Max.",
Expand Down
1 change: 1 addition & 0 deletions frontend/packages/core/public/locales/zh/scalar.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"download-data": "下载数据",
"download-data-format": "{{format}} 格式",
"download-image": "下载图片",
"ignore-outliers": "图表缩放时忽略极端值",
"max": "最大值",
Expand Down
47 changes: 41 additions & 6 deletions frontend/packages/core/src/components/ChartToolbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const ToolboxItem = styled.a<{active?: boolean}>`
}
`;

const ChartToolboxMenu = styled.div`
const ChartToolboxMenuWrapper = styled.div`
background-color: var(--background-color);
${transitionProps('background-color')};

Expand All @@ -65,9 +65,16 @@ const ChartToolboxMenu = styled.div`
}
`;

const ChartToolboxMenuIcon = styled(Icon)`
vertical-align: middle;
font-size: 78%;
margin-left: 0.6em;
`;

interface ChartToolboxItemChild {
label: string;
onClick?: () => unknown;
children?: ChartToolboxItemChild[];
}

type BaseChartToolboxItem = {
Expand Down Expand Up @@ -169,17 +176,45 @@ const ToggleChartToolbox: FunctionComponent<ToggleChartToolboxItem> = ({
);
};

const ChartToolboxMenu: FunctionComponent<ChartToolboxItemChild> = ({label, onClick, children}) => {
return children ? (
<Tippy
content={
<ChartToolboxMenuWrapper>
{children.map((item, index) => (
<ChartToolboxMenu {...item} key={index} />
))}
</ChartToolboxMenuWrapper>
}
placement="right-start"
animation="shift-away-subtle"
interactive
hideOnClick={false}
arrow={false}
role="menu"
theme="menu"
offset={[0, 0]}
>
<a>
{label} <ChartToolboxMenuIcon type="chevron-right" />
</a>
</Tippy>
) : (
<ChartToolboxMenuWrapper>
<a onClick={() => onClick?.()}>{label}</a>
</ChartToolboxMenuWrapper>
);
};

const MenuChartToolbox: FunctionComponent<MenuChartToolboxItem> = ({icon, menuList}) => {
return (
<Tippy
content={
<ChartToolboxMenu>
<ChartToolboxMenuWrapper>
{menuList.map((item, index) => (
<a key={index} onClick={() => item.onClick?.()}>
{item.label}
</a>
<ChartToolboxMenu {...item} key={index} />
))}
</ChartToolboxMenu>
</ChartToolboxMenuWrapper>
}
placement="right-start"
animation="shift-away-subtle"
Expand Down
38 changes: 31 additions & 7 deletions frontend/packages/core/src/components/ScalarPage/ScalarChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ import {useRunningRequest} from '~/hooks/useRequest';
import {useTranslation} from 'react-i18next';
import useWebAssembly from '~/hooks/useWebAssembly';

const DownloadDataTypes = {
csv: 'csv',
tsv: 'tsv'
// excel: 'xlsx'
} as const;

const labelFormatter = format('.8');

const Wrapper = styled.div`
Expand Down Expand Up @@ -211,6 +217,24 @@ const ScalarChart: FunctionComponent<ScalarChartProps> = ({
[formatter, ranges, xAxisType, yAxisType]
);

const downloadData = useCallback(
(type: keyof typeof DownloadDataTypes) => {
saveFile(
runs.map(
run =>
`/scalar/data?${queryString.stringify({
run: run.label,
tag,
type
})}`
),
runs.map(run => `visualdl-scalar-${run.label}-${tag}.${DownloadDataTypes[type]}`),
`visualdl-scalar-${tag}.zip`
);
},
[runs, tag]
);

const toolbox = useMemo(
() => [
{
Expand Down Expand Up @@ -241,17 +265,17 @@ const ScalarChart: FunctionComponent<ScalarChartProps> = ({
},
{
label: t('scalar:download-data'),
onClick: () =>
saveFile(
runs.map(run => `/scalar/data?${queryString.stringify({run: run.label, tag})}`),
runs.map(run => `visualdl-scalar-${run.label}-${tag}.tsv`),
`visualdl-scalar-${tag}.zip`
)
children: Object.keys(DownloadDataTypes)
.sort((a, b) => a.localeCompare(b))
.map(format => ({
label: t('scalar:download-data-format', {format}),
onClick: () => downloadData(format as keyof typeof DownloadDataTypes)
}))
}
]
}
],
[runs, t, tag, toggleMaximized, toggleYAxisType]
[downloadData, t, toggleMaximized, toggleYAxisType]
);

// display error only on first fetch
Expand Down
2 changes: 1 addition & 1 deletion frontend/packages/demo/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@visualdl/demo",
"version": "2.1.0-1",
"version": "2.1.1",
"description": "A platform to visualize the deep learning process and result.",
"keywords": [
"visualdl",
Expand Down
13 changes: 10 additions & 3 deletions frontend/packages/mock/data/scalar/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@
import {Request, Response} from 'express';

export default (req: Request, res: Response) => {
const {run, tag} = req.query;
res.setHeader('Content-Type', 'text/tab-separated-values');
return `scalar\n${run}\n${tag}`;
const {run, tag, type} = req.query;
switch (type) {
case 'tsv':
res.setHeader('Content-Type', 'text/tab-separated-values');
break;
case 'csv':
res.setHeader('Content-Type', 'text/comma-separated-values');
break;
}
return `scalar\n${run}\n${tag}\n${type}`;
};
2 changes: 1 addition & 1 deletion frontend/packages/mock/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@visualdl/mock",
"version": "2.1.0-1",
"version": "2.1.1",
"description": "A platform to visualize the deep learning process and result.",
"keywords": [
"visualdl",
Expand Down
2 changes: 1 addition & 1 deletion frontend/packages/netron/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@visualdl/netron",
"version": "2.1.0-1",
"version": "2.1.1",
"description": "A platform to visualize the deep learning process and result.",
"keywords": [
"visualdl",
Expand Down
8 changes: 4 additions & 4 deletions frontend/packages/server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@visualdl/server",
"version": "2.1.0-1",
"version": "2.1.1",
"description": "A platform to visualize the deep learning process and result.",
"keywords": [
"visualdl",
Expand Down Expand Up @@ -36,7 +36,7 @@
"ecosystem.config.d.ts"
],
"dependencies": {
"@visualdl/core": "2.1.0-1",
"@visualdl/core": "2.1.1",
"dotenv": "8.2.0",
"enhanced-resolve": "5.4.1",
"express": "4.17.1",
Expand All @@ -47,14 +47,14 @@
"@types/enhanced-resolve": "3.0.6",
"@types/express": "4.17.9",
"@types/node": "14.14.16",
"@visualdl/mock": "2.1.0-1",
"@visualdl/mock": "2.1.1",
"cross-env": "7.0.3",
"nodemon": "2.0.6",
"ts-node": "9.1.1",
"typescript": "4.0.5"
},
"optionalDependencies": {
"@visualdl/demo": "2.1.0-1"
"@visualdl/demo": "2.1.1"
},
"engines": {
"node": ">=12",
Expand Down
2 changes: 1 addition & 1 deletion frontend/packages/wasm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@visualdl/wasm",
"version": "2.1.0-1",
"version": "2.1.1",
"title": "VisualDL",
"description": "A platform to visualize the deep learning process and result.",
"keywords": [
Expand Down
11 changes: 11 additions & 0 deletions frontend/scripts/lint-staged.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

set -e

echo $0

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

cd $SCRIPT_DIR/..

./node_modules/.bin/lint-staged --no-stash