Skip to content
This repository has been archived by the owner on Feb 19, 2022. It is now read-only.

[WIP] Resurrect victory-cli #7

Closed
wants to merge 5 commits into from
Closed
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
13 changes: 2 additions & 11 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
{
"presets": [
"babel-preset-es2015",
"babel-preset-stage-0",
"babel-preset-react",
],
"env": {
"coverage": {
"plugins": [ [ "istanbul", { "ignore": "test" } ] ]
}
}
}
"presets": [["@babel/preset-env", { "modules": false }]]
}
3 changes: 3 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"extends":
- "formidable/configurations/es6-node"
- "formidable/configurations/es6-react"
"settings":
"react":
"version": "detect"
"env":
"browser": true
"node": true
Expand Down
93 changes: 15 additions & 78 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,62 +16,22 @@
</p>

<h4 align="center">
A tool for generating <a href="https://github.com/FormidableLabs/victory/">Victory</a> component image charts on the command line.
A tool for generating <a href="https://github.com/FormidableLabs/victory/">Victory</a> chart svgs from the command line.
</h4>

---

## Installation

First, install `librsvg`, which is a dependency for this library to work. **THIS IS IMPORTANT**:

If you do not install `librsvg` first, the global install _will blow up_.

#### Ubuntu:

```bash
sudo apt-get install librsvg2-dev
```

#### RedHat / OpenSUSE:

```bash
sudo yum install librsvg2-devel
```

#### Mac OS X:

```bash
brew install librsvg
```

If, after installing LibRSVG through homebrew you are experiencing issues installing this module,
try manually exporting the package config with this command:

```bash
export PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig
```

Then, install this module.

```sh
npm install -g victory-cli
$ npm install -g victory-cli
# or, using yarn
$ yarn global add victory-cli
```

For further information, [see this thread](https://github.com/Homebrew/homebrew/issues/14123).

#### Windows:

You will need cairo and librsvg-2 libraries which is bundled in GTK. Go to http://www.gtk.org/download/win64.php
(or http://www.gtk.org/download/win32.php for 32-bit node) and download the all-in-one bundle (these instructions
used the following zip http://win32builder.gnome.org/gtk+-bundle_3.6.4-20131201_win64.zip). Unzip the contents
in C:\GTK (if you want to change this you must define `-GTK_Root=c:\another\path` shell variable to npm or node-gyp
to reflect your changes), and add `"C:\GTK\bin;"` to the PATH environment variable in Windows, it's necessary for
node-rsvg runtime to load those libs.

## Usage

Once installed, you can now run `victory-cli` from the command line. Check out the usage info below to
Once installed, you can run `victory-cli` from the command line. Check out the usage info below to
see some of the cool things you can do:

```sh
Expand All @@ -82,8 +42,6 @@ Usage: victory-cli [data] [script] [options]
-h, --help output usage information
-V, --version output the version number
-c, --charttype [charttype] 'area', 'bar', 'line', 'scatter' or 'pie' (default: line)
-f, --format [format] 'png' or 'svg' (default: png)
-p, --print Prints chart to console (iTerm3 & .png format only!) (default: false)
-h, --h [h] Chart height (default: 500)
-w, --w [w] Chart width (default: 500)
-x, --x [x] Data x value (default: null)
Expand All @@ -93,43 +51,24 @@ Usage: victory-cli [data] [script] [options]

### Basic Example

So, like [Victory](https://github.com/FormidableLabs/victory/), `victory-cli` comes with some sensible defaults.
To render a default line chart to a png, you would run:

```sh
victory-cli -c line > test.png
```
So, like [Victory](https://github.com/FormidableLabs/victory/), `victory-cli` comes with some sensible defaults,
which includes a default data set.

If you instead wanted an svg file, you could run:
If you wanted to print a line chart using the default data set to `test.svg`, you could run:

```sh
victory-cli -c line -f svg > test.svg
$ victory-cli -c line > test.svg
```

You can also use the `-c` flag to select any of our preset charts, detailed in the usage doc above.

### Images in the Term

Generating images is cool, but displaying charts in the terminal is even cooler! By default `victory-cli` writes
to `stdout`, so you can do things like piping and file output, but you can override this with the `-p` or `--print` flag.

> Note: This only works on iTerm 3. It should work in HyperChart soon.

```sh
victory-cli -c line --print
```

💥 Boom:

![http://i.imgur.com/ZF3e5lh.png](http://i.imgur.com/ZF3e5lh.png)

### Theming

Out of the box we support a light, dark and hacker (green) theme for your charts. Simply set the `-t` flag
to have the theme applied:

```sh
victory-cli -c area -t light --print
$ victory-cli -c area -t light
```

### Custom Data
Expand All @@ -138,7 +77,7 @@ So you brought your own data did ya? Thats cool, its the first argument of this
own data in like this:

```sh
victory-cli data/data.json --print
$ victory-cli data/data.json
```

We expect the data to be in a regular chart data format like:
Expand All @@ -161,7 +100,7 @@ field names. So if your data looks like this:
It can still work by running:

```sh
victory-cli data/data.json -x foo -y bar --print
$ victory-cli data/data.json -x foo -y bar
```

If your data is too different from what we accept, check out how to do a custom component script below.
Expand Down Expand Up @@ -220,17 +159,15 @@ module.exports = function wrapperComponent(data, options) {
After you've created this file, simply run it like this:

```sh
victory-cli data.json script.js --print
$ victory-cli data.json script.js
```

💥 And it's custom chart city:

![http://i.imgur.com/VyB4eqa.png](http://i.imgur.com/VyB4eqa.png)

## Credits

This project was HEAVILY inspired by Matthew Conlens work on [https://github.com/mathisonian/hyperchart](https://github.com/mathisonian/hyperchart)

## _IMPORTANT_

<img alt="Maintenance Status" src="https://img.shields.io/badge/maintenance-experimental-purple.svg" />

This project is in a pre-release state. We're hard at work fixing bugs and improving the API. Be prepared for breaking changes!
41 changes: 12 additions & 29 deletions bin/victory-cli.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env node

"use strict";

require("babel-register")({
Expand All @@ -7,9 +8,7 @@ require("babel-register")({

const path = require("path");
const commander = require("commander");
const termIMG = require("term-img");

const generatePng = require("../lib/generate-png.js");
const generateSvg = require("../lib/generate-svg.js");
const wrapperComponent = require("../lib/wrapper-component.js");

Expand All @@ -24,8 +23,6 @@ program.option(
"'area', 'bar', 'line', 'scatter' or 'pie'",
"line"
);
program.option("-f, --format [format]", "'png' or 'svg'", "png");
program.option("-p, --print", "Prints chart to console (iTerm3 & .png format only!)");
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this feature was dependent on a generated png, we no longer support printed imgs to iTerm either

program.option("-h, --h [h]", "Chart height", DEFAULT_DIMENSIONS);
program.option("-w, --w [w]", "Chart width", DEFAULT_DIMENSIONS);
program.option("-x, --x [x]", "Data x value");
Expand All @@ -44,8 +41,6 @@ if (program.rawArgs.length < MIN_ARGS) {

const cliOptions = {
charttype: program.charttype,
format: program.format,
print: program.print,
height: program.h,
width: program.w,
x: program.x,
Expand All @@ -64,11 +59,16 @@ if (program.args[DATA_ARG]) {
} else {
data = {
data: [
{ x: 0, y: 10 },
{ x: 5, y: 20 },
{ x: 10, y: 30 },
{ x: 15, y: 40 },
{ x: 20, y: 50 }
{ x: 0,
y: 10 },
{ x: 5,
y: 20 },
{ x: 10,
y: 30 },
{ x: 15,
y: 40 },
{ x: 20,
y: 50 }
]
};
}
Expand All @@ -85,21 +85,4 @@ if (program.args[SCRIPT_ARG] !== undefined) {
}

const SVG = generateSvg(component);

if (cliOptions.format === "svg") {
process.stdout.write(SVG);
} else {
generatePng(SVG, cliOptions)
.then((output) => {
if (cliOptions.print) {
termIMG(output, {
fallback: () => console.log("Printing images is only supported in the latest iTerm!")
});
} else {
process.stdout.write(output);
}
})
.catch((err) => {
throw new Error(err);
});
}
process.stdout.write(SVG);
28 changes: 0 additions & 28 deletions lib/generate-png.js

This file was deleted.

7 changes: 4 additions & 3 deletions lib/generate-svg.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const React = require("react");
const ReactDOM = require("react-dom/server");

module.exports = function generateSVG(comp) {
return ReactDOM.renderToString(React.createElement(comp));
};
const generateSVG = (comp) =>
ReactDOM.renderToString(React.createElement(comp));

module.exports = generateSVG;
22 changes: 0 additions & 22 deletions lib/rasterizer.js

This file was deleted.

Loading