Skip to content

Commit

Permalink
Added sample files
Browse files Browse the repository at this point in the history
  • Loading branch information
ashitaaB committed Nov 15, 2024
1 parent 142b20e commit eea9804
Show file tree
Hide file tree
Showing 6 changed files with 4,616 additions and 2 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
# Dependency directories
node_modules/

examples/*
22 changes: 22 additions & 0 deletions examples/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Muze</title>
</head>

<body>
<div id="chart"></div>
<p>Hello</p>
<!-- <script src="./js/legend-samples/line-dashed.js"></script> -->
<!-- <script src="./js/axis/sample4.js"></script> -->
<!-- <script src="./js/test.js"></script> -->
<!-- <script src="./js/word.js"></script> -->
<!-- For testing examples exported from Mode use the script below -->
<!-- <script src="./js/axis/import-from-mode.js"></script> -->
<!-- <script type="module" src="./js/index.js"></script> -->
<script type="module" src="./index.js"></script>
</body>
</html>
73 changes: 73 additions & 0 deletions examples/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import muze from "@viz/muze";
import "@viz/muze/muze.css";

const loadData = async function ({
dataSetLink = "/data/cars.json",
schemaLink = "/data/cars-schema.json",
}) {
let data = await fetch(dataSetLink).then((d) =>
dataSetLink.split(".").pop() === "csv" ? d.text() : d.json()
);
let schema = await fetch(schemaLink).then((d) => d.json());

return { schema, data };
};

let { schema, data } = await loadData({
dataSetLink: "/data/mn_mv/new_data.csv",
schemaLink: "/data/mn_mv/schema.json",
});

const { DataModel } = muze;
const env = muze();
console.log("Hi");

const formattedData = DataModel.loadDataSync(data, schema);
let rootData = new DataModel(formattedData);

rootData = rootData.select({
operator: "and",
conditions: [
{
field: "region",
value: ["Central", "East"],
operator: "in",
},
// {
// field: "Measure Names",
// value: ["quantity", "profit"],
// operator: "in",
// },
{
field: "ship_mode",
value: ["First Class", "Second Class"],
operator: "in",
},
{
field: "segment",
value: ["Consumer", "Corporate"],
operator: "in",
},
],
});

window.canvas = env
.canvas()
.data(rootData)
.width(900)
.height(600)
.rows([["Measure Names", "region", "ship_mode"]])
.columns([["region", "category"]])
// .detail(["category"])
.layers([
{
mark: "text",
encoding: {
text: "Measure Values",
color: "sales",
},
},
])
.mount("#chart");

// console.log(window.canvas);
Loading

0 comments on commit eea9804

Please sign in to comment.