Skip to content

Commit

Permalink
fix: deal more gracefully with data sources that have a common base f…
Browse files Browse the repository at this point in the history
…ile name
  • Loading branch information
FUDCo committed May 19, 2020
1 parent d4f5f0f commit f05f3ba
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
16 changes: 8 additions & 8 deletions packages/stat-logger/src/statGraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import path from 'path';
import * as vega from 'vega';

export function initGraphSpec(statsPath, xField, xLabel, yField, yLabel) {
const tag = path.basename(statsPath);
const spec = {
$schema: 'https://vega.github.io/schema/vega/v5.json',
width: 1500,
Expand All @@ -24,15 +23,15 @@ export function initGraphSpec(statsPath, xField, xLabel, yField, yLabel) {
type: 'linear',
range: 'width',
nice: true,
domain: { data: tag, field: xField },
domain: { data: statsPath, field: xField },
},
{
name: 'y',
type: 'linear',
range: 'height',
nice: true,
zero: true,
domain: { data: tag, field: yField },
domain: { data: statsPath, field: yField },
},
{
name: 'legend',
Expand Down Expand Up @@ -69,25 +68,26 @@ export function initGraphSpec(statsPath, xField, xLabel, yField, yLabel) {
}

export function addDataToGraphSpec(spec, statsPath) {
const tag = path.basename(statsPath);
const dataElement = {
name: tag,
name: statsPath,
format: { type: 'tsv' },
url: `file://${statsPath}`,
};
spec.data.push(dataElement);
}

export function addGraphToGraphSpec(spec, statsPath, yField, color) {
const tag = path.basename(statsPath);
export function addGraphToGraphSpec(spec, tag, statsPath, yField, color) {
if (!tag) {
tag = path.basename(statsPath);
}
const legendElement = {
text: `${tag} - ${yField}`,
color,
};
spec.data[0].values.push(legendElement);
const lineElement = {
type: 'line',
from: { data: tag },
from: { data: statsPath },
encode: {
enter: {
x: { scale: 'x', field: spec.scales[0].domain.field },
Expand Down
9 changes: 9 additions & 0 deletions packages/swingset-runner/src/dataGraphApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export async function dataGraphApp(xField, xLabel, yField, yLabel, lineFields) {

let outfile = null;
const datafiles = [];
const tags = [];
let type = 'png';

while (argv[0]) {
Expand All @@ -35,11 +36,18 @@ export async function dataGraphApp(xField, xLabel, yField, yLabel, lineFields) {
case '--pdf':
type = 'pdf';
break;
case '--label':
case '-l':
tags.push(argv.shift());
break;
default:
throw new Error(`invalid flag ${arg}`);
}
} else {
datafiles.push(arg);
if (datafiles.length < tags.length) {
tags.push(undefined);
}
}
}
if (datafiles.length < 1) {
Expand All @@ -53,6 +61,7 @@ export async function dataGraphApp(xField, xLabel, yField, yLabel, lineFields) {
for (let lineIdx = 0; lineIdx < lineFields.length; lineIdx += 1) {
addGraphToGraphSpec(
spec,
tags[dataIdx],
datafiles[dataIdx],
lineFields[lineIdx],
groupColors[lineIdx % groupColors.length],
Expand Down

0 comments on commit f05f3ba

Please sign in to comment.