Skip to content

Commit

Permalink
feat(charts): add charts component with mock dataadd charts component…
Browse files Browse the repository at this point in the history
… and use it on Stage.vue as a simple demo
  • Loading branch information
AsahiLuna authored and GalvinGao committed Aug 13, 2019
1 parent b6384c8 commit 24c763b
Show file tree
Hide file tree
Showing 2 changed files with 154 additions and 3 deletions.
138 changes: 138 additions & 0 deletions src/components/Charts.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
<template>
<v-dialog
v-model="value"
fullscreen
hide-overlay
transition="dialog-bottom-transition"
>
<template v-slot:activator="{ on }">
<slot />
<div
class="skyline"
v-on="on"
>
<v-sparkline
:value="sparkline.value"
:gradient="sparkline.gradient"
:smooth="sparkline.radius || false"
:padding="sparkline.padding"
:line-width="sparkline.width"
:stroke-linecap="sparkline.lineCap"
:gradient-direction="sparkline.gradientDirection"
auto-draw
/>
</div>
</template>
<div class="charts-wrapper">
<v-toolbar>
<v-toolbar-title>Charts</v-toolbar-title>

<v-spacer />

<v-btn
icon
@click="value = !value"
>
<v-icon>mdi-close</v-icon>
</v-btn>
</v-toolbar>
<div
:id="computedChartsId"
class="charts"
/>
</div>
</v-dialog>
</template>

<script>
import Plotly from "plotly.js-dist";
export default {
name: "Charts",
props: {
value: {
type: Boolean,
default: false
},
chartsId: {
type: String,
required: true
},
height: {
type: Number,
default: window.innerHeight - 64 // minus toolbar height
},
width: {
type: Number,
default: window.innerWidth
},
gradient: {
type: Array,
default: () => {
return ["white"];
}
}
},
data() {
return {
initDate: new Date()
};
},
computed: {
sparkline() {
return {
width: 10,
radius: 10,
padding: 8,
lineCap: "round",
gradient: this.gradient,
value: [0, 2, 5, 9, 5, 10, 3, 5, 0, 0, 1, 8, 2, 9, 0],
gradientDirection: "top"
};
},
computedChartsId() {
return `${this.initDate.getTime().toString()}_${this.chartsId}`;
}
},
watch: {},
mounted() {
var trace1 = {
x: [1, 2, 3, 4],
y: [10, 15, 13, 17],
type: "scatter"
};
var trace2 = {
x: [1, 2, 3, 4],
y: [16, 5, 11, 9],
type: "scatter"
};
var layout = {
width: this.width,
height: this.height,
showlegend: false
};
var data = [trace1, trace2];
Plotly.newPlot(this.computedChartsId, data, layout);
},
methods: {}
};
</script>

<style scoped>
.charts-wrapper {
width: 100%;
height: -webkit-fill-available;
display: flex;
justify-content: center;
align-items: center;
background: #fff;
flex-direction: column;
}
.skyline {
width: 40px;
margin-left: 5px;
}
</style>
19 changes: 16 additions & 3 deletions src/views/Stats/Stage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,13 @@
<td class="text-xs-right">
{{ props.item.quantity }}
</td>
<td class="text-xs-right">
{{ props.item.percentageText }}
<td class="text-xs-right charts-data-wrapper">
<Charts
v-model="expanded[props.item.item.itemId]"
:charts-id="props.item.item.itemId"
>
{{ props.item.percentageText }}
</Charts>
</td>
<td class="text-xs-right">
{{ props.item.apPPR }}
Expand All @@ -316,11 +321,13 @@
<script>
import get from '@/utils/getters'
import Item from "@/components/Item";
import Charts from "@/components/Charts";
export default {
name: "StatsByStage",
components: {Item},
components: {Item, Charts},
data: () => ({
expanded: {},
step: 1,
selected: {
zone: null,
Expand Down Expand Up @@ -474,4 +481,10 @@
.v-table {
background: transparent !important;
}
.charts-data-wrapper {
display: flex;
justify-content: flex-end;
align-items: center;
}
</style>

0 comments on commit 24c763b

Please sign in to comment.