Skip to content

Commit

Permalink
Conditional Render OpenGov doc (w3f#4826)
Browse files Browse the repository at this point in the history
* Conditional Render OpenGov doc

* Update maintain-guides-opengov.md

* added multi network support for charts

* removed unused constants

* slight cleanup

* update readme

* Add OpenGov to Kusama Guide

* note on Kusama tracks

---------

Co-authored-by: Bader Youssef <[email protected]>
  • Loading branch information
DrW3RK and CrackTheCode016 authored May 23, 2023
1 parent 2ab9d37 commit da78b55
Show file tree
Hide file tree
Showing 35 changed files with 35,554 additions and 71 deletions.
26 changes: 16 additions & 10 deletions components/Chart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import openGovVariables from "./utilities/openGovVariables";

// Maps a type and props to a JSX charts.js component
function mapTypeToComponent(type, key) {
function mapTypeToComponent(type, key, network, maxY, maxX) {
ChartJS.register(
CategoryScale,
LinearScale,
Expand All @@ -25,7 +25,7 @@ function mapTypeToComponent(type, key) {
Legend
);
// Configure props using data
let props = configureProps(key);
let props = configureProps(key, network, maxY, maxX);
ChartJS.defaults.font.size = 18;
switch (type) {
case 'line':
Expand All @@ -35,8 +35,9 @@ function mapTypeToComponent(type, key) {
}
}

function configureProps(key) {
let govData = openGovVariables[key];
function configureProps(key, network, maxY, maxX) {
console.log(`${network}${key}`);
let govData = openGovVariables[`${network}${key}`];

const approvals = govData.map((_) => { return { x: _.time_hours, y: _.approval } });
const support = govData.map((_) => { return { x: _.time_hours, y: _.support } });
Expand Down Expand Up @@ -64,21 +65,26 @@ function configureProps(key) {
y: {
type: 'linear',
min: 0,
max: 100,
max: maxY,
ticks: {
callback: function(value, index, ticks) {
return `${value}%`;
callback: function (value) {
return `${value}%`;
}
}
},
x: {
type: 'linear',
min: 0,
max: 672,
max: maxX,
title: {
display: true,
text: "Hours",
},
ticks: {
callback: function (value) {
return `${value}`;
}
}
}
},
plugins: {
Expand All @@ -100,8 +106,8 @@ function configureProps(key) {
return props;
}

function Chart({ title, type, dataId }) {
let chart = mapTypeToComponent(type, dataId);
function Chart({ title, type, dataId, network, maxY, maxX}) {
let chart = mapTypeToComponent(type, dataId, network, maxY, maxX);
return (
<div className="App">
<header className="App-header">
Expand Down
2 changes: 1 addition & 1 deletion components/utilities/charts_data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Chart from "./../../components/Chart";
// The title can be left empty, type refers to the type of chart or graph, and dataId should refer to
// a dataset within openGovVariables.js

<Chart title="" type="line" dataId="Whitelist" />;
<Chart title="" type="line" dataId="Whitelist" maxX="" maxY="" network="Polkadot" />;
```

## Adding new datasets
Expand Down
Loading

0 comments on commit da78b55

Please sign in to comment.