Added stable sorting to graph

This commit is contained in:
2020-02-28 00:05:16 +01:00
parent 96178cafa7
commit 71c77975f8
3 changed files with 27 additions and 21 deletions
-1
View File
@@ -9,7 +9,6 @@
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" /> <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous" /> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous" />
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" /> <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" />
<link href="https://unpkg.com/react-vis@1.6.7/dist/dist.min.js" />
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" /> <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<title>Demo App - Jeroen Vijgen</title> <title>Demo App - Jeroen Vijgen</title>
</head> </head>
+25 -13
View File
@@ -12,7 +12,26 @@ interface IData {
export default class GraphView extends React.Component<{ export default class GraphView extends React.Component<{
data: any data: any
}> { }> {
// Remove "year-" from the label, not required.
prepDate(date: string): string {
return date.substring(5, date.length);
}
parseData(): Array<IData>{ parseData(): Array<IData>{
// Sort data to coherently display in the Graph.
// eslint-disable-next-line
this.props.data.sort((a: any, b: any) => {
let dateA = new Date(a.date);
let dateB = new Date(b.date);
let same = dateA.getTime() === dateB.getTime();
// Date is eql, ignore sorting to stablize sorting.
if (same) return 0;
// Date A is greater than Date B.
if (dateA > dateB) return 1;
// Date A is lesser than Date B.
if (dateA < dateB) return -1;
});
// Object needing to be returned: // Object needing to be returned:
// { id: "missed_chat_count", data: [{x: int (DATE), y: int (Count)}] } // { id: "missed_chat_count", data: [{x: int (DATE), y: int (Count)}] }
// { id: "conversation_count", data: [{x: int (DATE), y: int (Count)}] } // { id: "conversation_count", data: [{x: int (DATE), y: int (Count)}] }
@@ -22,9 +41,9 @@ export default class GraphView extends React.Component<{
array.push({ id: "conversation_count", data: [] }); array.push({ id: "conversation_count", data: [] });
array.push({ id: "visitors_with_conversation_count", data: [] }); array.push({ id: "visitors_with_conversation_count", data: [] });
this.props.data.forEach((_item: any) => { this.props.data.forEach((_item: any) => {
array[0].data.push({ x: _item.date, y: _item.missed_chat_count }); array[0].data.push({ x: this.prepDate(_item.date), y: _item.missed_chat_count });
array[1].data.push({ x: _item.date, y: _item.conversation_count }); array[1].data.push({ x: this.prepDate(_item.date), y: _item.conversation_count });
array[2].data.push({ x: _item.date, y: _item.visitors_with_conversation_count }); array[2].data.push({ x: this.prepDate(_item.date), y: _item.visitors_with_conversation_count });
}); });
return array; return array;
} }
@@ -35,11 +54,11 @@ export default class GraphView extends React.Component<{
<div className="GraphView"> <div className="GraphView">
<ResponsiveAreaBump <ResponsiveAreaBump
data={this.parseData()} data={this.parseData()}
margin={{ top: 40, right: 100, bottom: 40, left: 100 }} margin={{ top: 40, right: 60, bottom: 40, left: 60 }}
spacing={4} spacing={4}
colors={{ scheme: 'nivo' }} colors={{ scheme: 'nivo' }}
blendMode="multiply" blendMode="multiply"
startLabel="id" endLabel={false}
axisTop={{ axisTop={{
tickSize: 5, tickSize: 5,
tickPadding: 5, tickPadding: 5,
@@ -48,14 +67,7 @@ export default class GraphView extends React.Component<{
legendPosition: 'middle', legendPosition: 'middle',
legendOffset: -36 legendOffset: -36
}} }}
axisBottom={{ axisBottom={null}
tickSize: 5,
tickPadding: 5,
tickRotation: 0,
legend: '',
legendPosition: 'middle',
legendOffset: 32
}}
/> />
</div> </div>
) )
+2 -7
View File
@@ -5,14 +5,10 @@ body {
sans-serif; sans-serif;
-webkit-font-smoothing: antialiased; -webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale; -moz-osx-font-smoothing: grayscale;
background: url(./Background/bg.jfif) no-repeat center center; background: url(./Background/bg.jfif);
/* background-color: #282c34; */
height: 100%;
margin: 0;
} }
#App { #App {
height: 100%;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
@@ -23,7 +19,6 @@ body {
.DashboardComponent { .DashboardComponent {
background-color: white; background-color: white;
border-style: solid; border-style: solid;
border-width: solid;
border-color: #FD4114; border-color: #FD4114;
border-radius: 7px; border-radius: 7px;
} }
@@ -33,5 +28,5 @@ body {
} }
.GraphView { .GraphView {
height: 250px; height: 300px;
} }