Published
Edited
Mar 8, 2021
1 fork
Importers
1 star
Insert cell
md`# Churn Rate`
Insert cell
churnRate(ipfsTransitions, ipfsStates, 'IPFS Churn Rate')
Insert cell
churnRate(filecoinTransitions, filecoinStates, 'Filecoin Churn Rate')
Insert cell
churnRate = (transitions, states, title) => {
const container = html`<canvas></canvas>`;
const myChart = new Chart(container, {
type: 'line',
data: {
labels: transitions.map((t) => dateDiffToHuman(t.date)),
datasets: [{
data: transitions.map(({ transitions }) => Math.floor(transitions['Lapsed High-Value'] / (transitions['Lapsed High-Value'] + transitions['High-Value'] + transitions['High to Low-Value']) * 100)),
fill: false,
label: 'Lapsed High-Value',
borderColor: color.red,
lineTension: 0,
borderWidth: 3,
yAxisID: 'A',
}, {
data: transitions.map(({ transitions }) => Math.floor(transitions['High to Low-Value'] / (transitions['High to Low-Value'] + transitions['High-Value'] + transitions['Lapsed High-Value']) * 100)),
fill: false,
label: 'High to Low-Value',
borderColor: color.orange,
lineTension: 0,
borderWidth: 3,
yAxisID: 'A',
}, {
type: 'bar',
data: states.map(({ states }) => states.high),
label: 'High-Value Users',
backgroundColor: colorMap['High-Value'],
borderWidth: 3,
yAxisID: 'B',
}]
},
options: {
title: {
display: true,
text: title
},
scales: {
yAxes: [{
id: 'B',
ticks: {
min: 0
},
scaleLabel: {
display: true,
labelString: 'High-Value User Volume',
},
gridLines: {
display: false
},
}, {
id: 'A',
ticks: {
callback: (value) => `${value}%`,
},
position: 'right',
gridLines: {
zeroLineColor: 'black'
},
scaleLabel: {
display: true,
labelString: 'Churn Rate',
},
}],
}
},
});
return container;
}
Insert cell
colorMap = ({
'First Time': color.blue,
'Bounced' : color.red,
'Lapsed High-Value': d3.color(color.red).darker().hex(),
'Lapsed Low-Value': d3.color(color.red).brighter().hex(),
'High to Low-Value': d3.color(color.yellow).brighter(0.5).hex(),
'Low-Value': d3.color(color.yellow).darker(0.25).hex(),
'New Low-Value': color.yellow,
'Reactivated Low-Value': d3.color(color.yellow).brighter(0.25).hex(),
'High-Value': d3.color(color.green).darker(0.25).hex(),
'Low to High-Value': d3.color(color.green).brighter(0.75).hex(),
'New High-Value': d3.color(color.green).brighter(0.12).hex(),
'Reactivated High-Value': d3.color(color.green).brighter(1.7).hex()
})
Insert cell
color = ({
red: d3.schemeTableau10[2],
orange: d3.schemeTableau10[1],
green: d3.schemeTableau10[4],
teal: d3.schemeTableau10[3],
blue: d3.schemeTableau10[0],
grey: d3.schemeTableau10[9],
yellow: d3.schemeTableau10[5]
})
Insert cell
Insert cell
ipfsTransitions = (await fetch(`${ipfsGetTransitionsUrl}?start_date=${startDate}`)).json()
Insert cell
filecoinTransitions = (await fetch(`${filecoinGetTransitionsUrl}?start_date=${startDate}`)).json()
Insert cell
ipfsStates = (await fetch(`${ipfsGetStatesUrl}?start_date=${startDate}`)).json()
Insert cell
filecoinStates = (await fetch(`${filecoinGetStatesUrl}?start_date=${startDate}`)).json()
Insert cell
Chart = require('https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.bundle.min.js')
Insert cell
moment = require('moment')
Insert cell
d3 = require('d3')
Insert cell
import { dateDiffToHuman } from '@protocol/utils'
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more