Skip to content

Commit

Permalink
feat: Add legends to the graphs produced by the stat-logger graphing …
Browse files Browse the repository at this point in the history
…utility
  • Loading branch information
FUDCo committed Mar 16, 2020
1 parent 142b5c9 commit 65340d9
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion packages/stat-logger/src/statGraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ export function initGraphSpec(statsPath, xField, xLabel, yField, yLabel) {
padding: 5,
background: 'white',

data: [],
data: [
{
name: 'legend',
values: [],
},
],

scales: [
{
Expand All @@ -29,6 +34,12 @@ export function initGraphSpec(statsPath, xField, xLabel, yField, yLabel) {
zero: true,
domain: { data: tag, field: yField },
},
{
name: 'legend',
type: 'ordinal',
domain: { data: 'legend', field: 'text' },
range: { data: 'legend', field: 'color' },
},
],

axes: [
Expand All @@ -37,6 +48,22 @@ export function initGraphSpec(statsPath, xField, xLabel, yField, yLabel) {
],

marks: [],

legends: [
{
type: 'symbol',
symbolType: 'stroke',
fill: 'legend',
direction: 'vertical',
orient: 'top-left',
rowPadding: 0,
clipHeight: 0,
titleOrient: 'top',
symbolStrokeWidth: 2,
symbolSize: 1000,
stroke: 'legend',
},
],
};
return spec;
}
Expand All @@ -53,6 +80,11 @@ export function addDataToGraphSpec(spec, statsPath) {

export function addGraphToGraphSpec(spec, statsPath, yField, color) {
const tag = path.basename(statsPath);
const legendElement = {
text: `${tag} - ${yField}`,
color,
};
spec.data[0].values.push(legendElement);
const lineElement = {
type: 'line',
from: { data: tag },
Expand Down

0 comments on commit 65340d9

Please sign in to comment.