Skip to content

Commit

Permalink
refactor: cleaned up logic and update data method
Browse files Browse the repository at this point in the history
  • Loading branch information
Swiftwork committed Jun 10, 2021
1 parent e7fd92d commit a7fc020
Show file tree
Hide file tree
Showing 6 changed files with 425 additions and 468 deletions.
95 changes: 0 additions & 95 deletions examples/example-multiple.html

This file was deleted.

189 changes: 97 additions & 92 deletions examples/example.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

body {
margin: 0;
background: #f7f4f0;
background: #f5f3f1;
}

.funnel {
Expand Down Expand Up @@ -64,98 +64,103 @@
</div>

<script src="../dist/index.umd.js"></script>
<script type="text/javascript">
if (typeof fg == 'undefined') {
document.write('<script src="https://unpkg.com/@trutoo/funnel-graph">\x3C/script>');
}
</script>
<script>

var dataExample1 = {
values: [11000, 3000, 240]
};

var dataExample2 = {
labels: ['Impressions 2', 'Add To Cart 2', 'Buy 2'],
values: [12000, 5700, 360]
};

var dataExample3 = {
labels: ['Impressions', 'Add To Cart', 'Buy'],
subLabels: ['Direct', 'Social Media', 'Ads'],
values: [
[3500, 2500, 6500],
[3300, 1400, 1000],
[600, 200, 130]
],
};

var dataExample4 = {
labels: ['Impressions', 'Add To Cart', 'Buy', 'Refund'],
subLabels: ['Organic', 'Direct', 'Social Media', 'Ads', 'Something 1', 'Something 2', 'Something 3', 'Something 4'],
values: [
[3000, 3000, 3000, 3000, 3000, 3500, 2500, 6500],
[2000, 2000, 2000, 2000, 2000, 3300, 1400, 1000],
[1500, 1500, 1500, 1500, 1500, 2000, 600, 130],
[1000, 1000, 1000, 1000, 1000, 300, 100, 70],
],
};

var graph = new fg.FunnelGraph({
container: '.funnel',
gradientDirection: 'horizontal',
data: dataExample3,
displayPercent: true,
direction: 'horizontal',
width: 800,
height: 300,
subLabelValue: 'raw'
});

graph.draw();

// direction methods
document.querySelector('#makeVertical').addEventListener('click', function () {
graph.setWidth(300);
graph.setHeight(400);
graph.makeVertical();
});

document.querySelector('#makeHorizontal').addEventListener('click', function () {
graph.setWidth(800);
graph.setHeight(300);
graph.makeHorizontal();
});

document.querySelector('#toggleDirection').addEventListener('click', function () {
graph.direction === 'horizontal' ? document.querySelector('#makeVertical').click() :
document.querySelector('#makeHorizontal').click();
});

// gradient methods
document.querySelector('#gradientMakeVertical').addEventListener('click', function () {
graph.gradientMakeVertical();
});

document.querySelector('#gradientMakeHorizontal').addEventListener('click', function () {
graph.gradientMakeHorizontal();
});

document.querySelector('#gradientToggleDirection').addEventListener('click', function () {
graph.gradientToggleDirection();
});

document.querySelector('#useData1').addEventListener('click', function () {
graph.updateData(dataExample1);
});

document.querySelector('#useData2').addEventListener('click', function () {
graph.updateData(dataExample2);
});

document.querySelector('#useData3').addEventListener('click', function () {
graph.updateData(dataExample3);
});

document.querySelector('#useData4').addEventListener('click', function () {
graph.updateData(dataExample4);
});

(function () {
var dataExample1 = {
values: [11000, 3000, 240]
};

var dataExample2 = {
labels: ['Impressions 2', 'Add To Cart 2', 'Buy 2'],
values: [12000, 5700, 360],
};

var dataExample3 = {
labels: ['Impressions', 'Add To Cart', 'Buy'],
subLabels: ['Direct', 'Social Media', 'Ads'],
values: [
[3500, 2500, 6500],
[3300, 1400, 1000],
[600, 200, 130]
],
};

var dataExample4 = {
labels: ['Impressions', 'Add To Cart', 'Buy', 'Refund'],
subLabels: ['Organic', 'Direct', 'Social Media', 'Ads', 'Something 1', 'Something 2', 'Something 3', 'Something 4'],
values: [
[3000, 3000, 3000, 3000, 3000, 3500, 2500, 6500],
[2000, 2000, 2000, 2000, 2000, 3300, 1400, 1000],
[1500, 1500, 1500, 1500, 1500, 2000, 600, 130],
[1000, 1000, 1000, 1000, 1000, 300, 100, 70],
],
};

var graph = new fg.FunnelGraph({
container: '.funnel',
gradientDirection: 'horizontal',
data: dataExample3,
displayPercent: true,
direction: 'horizontal',
width: 800,
height: 300,
subLabelValue: 'raw'
});

graph.draw();

// direction methods
document.querySelector('#makeVertical').addEventListener('click', function () {
graph.setWidth(300);
graph.setHeight(400);
graph.makeVertical();
});

document.querySelector('#makeHorizontal').addEventListener('click', function () {
graph.setWidth(800);
graph.setHeight(300);
graph.makeHorizontal();
});

document.querySelector('#toggleDirection').addEventListener('click', function () {
graph.direction === 'horizontal' ? document.querySelector('#makeVertical').click() :
document.querySelector('#makeHorizontal').click();
});

// gradient methods
document.querySelector('#gradientMakeVertical').addEventListener('click', function () {
graph.gradientMakeVertical();
});

document.querySelector('#gradientMakeHorizontal').addEventListener('click', function () {
graph.gradientMakeHorizontal();
});

document.querySelector('#gradientToggleDirection').addEventListener('click', function () {
graph.gradientToggleDirection();
});

document.querySelector('#useData1').addEventListener('click', function () {
graph.updateData(dataExample1);
});

document.querySelector('#useData2').addEventListener('click', function () {
graph.updateData(dataExample2);
});

document.querySelector('#useData3').addEventListener('click', function () {
graph.updateData(dataExample3);
});

document.querySelector('#useData4').addEventListener('click', function () {
graph.updateData(dataExample4);
});
})();
</script>
</body>

Expand Down
6 changes: 3 additions & 3 deletions src/index.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
:root {
--text: #003f5c;
--primary: #a05195;
--accent: #f95d6a;
--text: MidnightBlue;
--primary: MidnightBlue;
--accent: Crimson;
--backdrop: rgba(0, 0, 0, 0.75);
--backdrop-text: #ffffff;
}
Expand Down
Loading

0 comments on commit a7fc020

Please sign in to comment.