Skip to content

Commit

Permalink
Merge pull request #2 from chartshq/migrate
Browse files Browse the repository at this point in the history
Add chart demos
  • Loading branch information
UD-UD authored Oct 8, 2020
2 parents 44024a1 + 13e0247 commit 2cb5684
Show file tree
Hide file tree
Showing 28 changed files with 6,191 additions and 0 deletions.
4,886 changes: 4,886 additions & 0 deletions examples/public/data/cars-with-null.json

Large diffs are not rendered by default.

41 changes: 41 additions & 0 deletions examples/src/Examples/CrossInteractive/Canvas.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import * as React from "react";
import Muze, { Canvas } from "@chartshq/react-muze/components";

async function createDataModel() {
const data = await fetch("/data/cars.json")
.then((d) => d.json());
const schema = await fetch("/data/cars-schema.json")
.then((d) => d.json());
const DataModelClass = await Muze.DataModel.onReady();
const formattedData = await DataModelClass.loadData(data, schema);
return new DataModelClass(formattedData);
}

class CanvasInteractive extends React.Component {
constructor(props) {
super(props);
this.state = {
dm: null,
};
}

componentDidMount() {
createDataModel().then((dm) => {
this.setState({ dm });
});
}

render() {
const { dm } = this.state;

return (
<Muze data={dm}>
<Canvas rows={['Miles_per_Gallon']} columns={['Cylinders']} crossInteractive />
<Canvas rows={['Miles_per_Gallon']} columns={['Origin']} />
<Canvas rows={['Acceleration']} columns={['Cylinders']} crossInteractive />
</Muze>
);
}
}

export default CanvasInteractive;
41 changes: 41 additions & 0 deletions examples/src/Examples/CrossInteractive/Global.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import * as React from "react";
import Muze, { Canvas } from "@chartshq/react-muze/components";

async function createDataModel() {
const data = await fetch("/data/cars.json")
.then((d) => d.json());
const schema = await fetch("/data/cars-schema.json")
.then((d) => d.json());
const DataModelClass = await Muze.DataModel.onReady();
const formattedData = await DataModelClass.loadData(data, schema);
return new DataModelClass(formattedData);
}

class MuzeInteractive extends React.Component {
constructor(props) {
super(props);
this.state = {
dm: null,
};
}

componentDidMount() {
createDataModel().then((dm) => {
this.setState({ dm });
});
}

render() {
const { dm } = this.state;

return (
<Muze data={dm} crossInteractive>
<Canvas rows={['Miles_per_Gallon']} columns={['Cylinders']} />
<Canvas rows={['Horsepower']} columns={['Cylinders']} />
<Canvas rows={['Acceleration']} columns={['Cylinders']} />
</Muze>
);
}
}

export default MuzeInteractive;
42 changes: 42 additions & 0 deletions examples/src/Examples/General/AxisPadding.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import * as React from "react";
import Muze, { Canvas } from "@chartshq/react-muze/components";
import { Axes } from "@chartshq/react-muze/configurations";

async function createDataModel() {
const data = await fetch("/data/cars.json")
.then((d) => d.json());
const schema = await fetch("/data/cars-schema.json")
.then((d) => d.json());
const DataModelClass = await Muze.DataModel.onReady();
const formattedData = await DataModelClass.loadData(data, schema);
return new DataModelClass(formattedData);
}

const axesConfig = Axes.LinearAxis.config().padding(0.2).create();

class AxisPadding extends React.Component {
constructor(props) {
super(props);
this.state = {
dm: null,
};
}

componentDidMount() {
createDataModel().then((dm) => {
this.setState({ dm });
});
}

render() {
const { dm } = this.state;

return (
<Muze data={dm}>
<Canvas rows={['Acceleration']} columns={['Cylinders']} xAxis={axesConfig} />
</Muze>
);
}
}

export default AxisPadding;
39 changes: 39 additions & 0 deletions examples/src/Examples/General/AxisPosition.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import * as React from "react";
import Muze, { Canvas } from "@chartshq/react-muze/components";

async function createDataModel() {
const data = await fetch("/data/cars.json")
.then((d) => d.json());
const schema = await fetch("/data/cars-schema.json")
.then((d) => d.json());
const DataModelClass = await Muze.DataModel.onReady();
const formattedData = await DataModelClass.loadData(data, schema);
return new DataModelClass(formattedData);
}

class AxisPosition extends React.Component {
constructor(props) {
super(props);
this.state = {
dm: null,
};
}

componentDidMount() {
createDataModel().then((dm) => {
this.setState({ dm });
});
}

render() {
const { dm } = this.state;

return (
<Muze data={dm}>
<Canvas rows={[[], ['Acceleration']]} columns={['Year']} />
</Muze>
);
}
}

export default AxisPosition;
76 changes: 76 additions & 0 deletions examples/src/Examples/General/Border.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import * as React from "react";
import Muze, { Canvas } from "@chartshq/react-muze/components";
import { Border } from "@chartshq/react-muze/configurations";
import { MuzeConstants } from "@chartshq/react-muze/constants";

async function createDataModel() {
const data = await fetch("/data/coffee.csv")
.then((d) => d.text());
const schema = [
{
"name": "Market",
"type": "dimension"
},
{
"name": "Product Type",
"type": "dimension"
},
{
"name": "Revenue",
"type": "measure",
"format": val => `$${val.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")}`
},
{
"name": "Expense",
"type": "measure",
"format": val => `$${val.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")}`
},
{
"name": "Profit",
"type": "measure"
}
];
const DataModelClass = await Muze.DataModel.onReady();
const formattedData = await DataModelClass.loadData(data, schema);
return new DataModelClass(formattedData);
}

const border = Border.config()
.showRowBorders({ top: true, bottom: true, left: true, right: true })
.showColBorders({ top: true, bottom: true, left: true, right: true })
.showValueBorders({ top: false, bottom: false, left: false, right: false })
.width(1)
.style(MuzeConstants.BORDER_STYLE.DASHED)
.color("#a2a2a2")
.create();

class BorderConfig extends React.Component {
constructor(props) {
super(props);
this.state = {
dm: null,
};
}

componentDidMount() {
createDataModel().then((dm) => {
this.setState({ dm });
});
}

render() {
const { dm } = this.state;

return (
<Muze data={dm}>
<Canvas
rows={['Market', 'Product Type']}
columns={[['Revenue', 'Expense'], ['Revenue', 'Expense']]}
border={border}
/>
</Muze>
);
}
}

export default BorderConfig;
40 changes: 40 additions & 0 deletions examples/src/Examples/General/ColorScheme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import * as React from "react";
import Muze, { Canvas } from "@chartshq/react-muze/components";

async function createDataModel() {
const data = await fetch("/data/cars.json")
.then((d) => d.json());
const schema = await fetch("/data/cars-schema.json")
.then((d) => d.json());
const DataModelClass = await Muze.DataModel.onReady();
const formattedData = await DataModelClass.loadData(data, schema);
return new DataModelClass(formattedData);
}

class ColorScheme extends React.Component {
constructor(props) {
super(props);
this.state = {
dm: null,
};
}

componentDidMount() {
createDataModel().then((dm) => {
this.setState({ dm });
});
}

render() {
const { dm } = this.state;

return (
<Muze data={dm} colorScheme={['#00876C', '#E88E63', 'magenta']}>
<Canvas rows={['Acceleration']} columns={['Cylinders']} color="Origin" />
<Canvas rows={['Acceleration']} columns={['Year']} color="Origin" />
</Muze>
);
}
}

export default ColorScheme;
44 changes: 44 additions & 0 deletions examples/src/Examples/General/ConnectNullData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import * as React from "react";
import Muze, { Canvas, Layer } from "@chartshq/react-muze/components";

async function createDataModel() {
const data = await fetch("/data/cars-with-null.json")
.then((d) => d.json());
const schema = await fetch("/data/cars-schema.json")
.then((d) => d.json());
const DataModelClass = await Muze.DataModel.onReady();
const formattedData = await DataModelClass.loadData(data, schema);
return new DataModelClass(formattedData);
}

class ConnectNullDataChart extends React.Component {
constructor(props) {
super(props);
this.state = {
dm: null,
};
}

componentDidMount() {
createDataModel().then((dm) => {
this.setState({ dm });
});
}

render() {
const { dm } = this.state;

return (
<Muze data={dm}>
<Canvas rows={['Acceleration']} columns={['Year']} color="Origin">
<Layer mark='line' />
</Canvas>
<Canvas rows={['Acceleration']} columns={['Year']} color="Origin">
<Layer mark='line' connectNullData />
</Canvas>
</Muze>
);
}
}

export default ConnectNullDataChart;
40 changes: 40 additions & 0 deletions examples/src/Examples/General/Creation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import * as React from "react";
import Muze, { Canvas } from "@chartshq/react-muze/components";

async function createDataModel() {
const data = await fetch("/data/cars.json")
.then((d) => d.json());
const schema = await fetch("/data/cars-schema.json")
.then((d) => d.json());
const DataModelClass = await Muze.DataModel.onReady();
const formattedData = await DataModelClass.loadData(data, schema);
return new DataModelClass(formattedData);
}

class BasicChart extends React.Component {
constructor(props) {
super(props);
this.state = {
dm: null,
};
}

componentDidMount() {
createDataModel().then((dm) => {
this.setState({ dm });
});
}

render() {
const { dm } = this.state;

return (
<Muze data={dm}>
<Canvas rows={['Acceleration']} columns={['Origin']} />
<Canvas rows={['Acceleration']} columns={['Year']} />
</Muze>
);
}
}

export default BasicChart;
Loading

0 comments on commit 2cb5684

Please sign in to comment.