Skip to content

Commit

Permalink
Improved table layout and responsiveness
Browse files Browse the repository at this point in the history
  • Loading branch information
graphieros committed Jan 30, 2024
1 parent 6780fb4 commit 0e6998c
Show file tree
Hide file tree
Showing 15 changed files with 269 additions and 60 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vue-data-ui",
"private": false,
"version": "1.9.70",
"version": "1.9.71",
"type": "module",
"description": "A user-empowering data visualization Vue components library",
"keywords": [
Expand Down
159 changes: 113 additions & 46 deletions src/atoms/DataTable.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
<script setup>
import { computed, onMounted, ref } from "vue";
import Shape from "./Shape.vue";
const props = defineProps({
colNames: {
type: Array,
default() {
return []
}
},
head: Array,
body: Array,
title: String,
Expand All @@ -11,61 +18,121 @@ const props = defineProps({
const { backgroundColor:thbg, color:thc, outline:tho } = props.config.th;
const { backgroundColor:tdbg, color:tdc, outline:tdo } = props.config.td;
const breakpoint = computed(() => {
return props.config.breakpoint
})
const tableContainer = ref(null)
const isResponsive = ref(false)
onMounted(() => {
const observer = new ResizeObserver((entries) => {
entries.forEach(entry => {
isResponsive.value = entry.contentRect.width < breakpoint.value;
})
})
if(tableContainer.value) {
observer.observe(tableContainer.value)
}
})
</script>

<template>
<table data-cy="vue-data-ui-table-data" class="vue-ui-data-table">
<thead>
<tr>
<th :style="{backgroundColor: thbg, color: thc, outline: tho}" :colspan="head.length">
{{ title }}
</th>
</tr>
<tr>
<th :style="{backgroundColor: thbg, color: thc, outline: tho}" v-for="(th, i) in head" :key="`th_${i}`">
<div style="display: flex; align-items:center; justify-content:center; justify-content:flex-end;padding-right: 3px; gap:3px">
<svg height="12" width="12" v-if="th.color" viewBox="0 0 20 20" style="background: none;">
<circle cx="10" cy="10" r="10" :fill="th.color"/>
</svg>
<slot name="th" :th="th"/>
</div>
</th>
</tr>
</thead>

<tbody>
<tr v-for="(tr, i) in body">
<td v-for="(td, j) in tr" :style="{backgroundColor: tdbg, color: tdc, outline: tdo}">
<div style="display: flex; align-items:center; gap: 5px; justify-content:flex-end; width:100%; padding-right:3px;">
<svg height="12" width="12" v-if="td.color" viewBox="0 0 20 20" style="background: none;overflow: visible">
<Shape
:plot="{ x: 10, y: 10 }"
:color="td.color"
:radius="9"
:shape="config.shape || 'circle'"
/>
</svg>
<slot name="td" :td="td"></slot>
</div>
</td>
</tr>
</tbody>
</table>
<div ref="tableContainer" style="width: 100%; container-type: inline-size;" :class="{'vue-ui-responsive': isResponsive}">
<table data-cy="vue-data-ui-table-data" class="vue-ui-data-table">
<caption :style="{backgroundColor: thbg, color: thc, outline: tho}">
{{ title }}
</caption>
<thead>
<tr>
<th :style="{backgroundColor: thbg, color: thc, outline: tho}" v-for="(th, i) in head" :key="`th_${i}`">
<div style="display: flex; align-items:center; justify-content:center; justify-content:flex-end;padding-right: 3px; gap:3px">
<svg height="12" width="12" v-if="th.color" viewBox="0 0 20 20" style="background: none;">
<circle cx="10" cy="10" r="10" :fill="th.color"/>
</svg>
<slot name="th" :th="th"/>
</div>
</th>
</tr>
</thead>

<tbody>
<tr v-for="(tr, i) in body">
<td role="" v-for="(td, j) in tr" :data-cell="colNames[j]" :style="{backgroundColor: tdbg, color: tdc, outline: tdo}">
<div style="display: flex; align-items:center; gap: 5px; justify-content:flex-end; width:100%; padding-right:3px;">
<svg height="12" width="12" v-if="td.color" viewBox="0 0 20 20" style="background: none;overflow: visible">
<Shape
:plot="{ x: 10, y: 10 }"
:color="td.color"
:radius="9"
:shape="config.shape || 'circle'"
/>
</svg>
<slot name="td" :td="td"></slot>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</template>

<style scoped>
table.vue-ui-data-table {
width: 100%;
border-collapse:collapse;
}
.vue-ui-data-table td {
padding-right: 6px;
font-variant-numeric: tabular-nums;
}
<style scoped lang="scss">
.vue-ui-data-table th {
position: sticky;
top:0;
font-weight: 400;
user-select: none;
}
table {
width: 100%;
padding: 1rem;
border-collapse:collapse;
}
caption,
th,
td {
padding: 0.5rem;
font-variant-numeric: tabular-nums;
}
caption {
font-size: 1.3rem;
font-weight: 700;
}
.vue-ui-responsive {
th {
display: none;
}
td {
display: grid;
gap: 0.5rem;
grid-template-columns: repeat(2, 1fr);
padding: 0.5rem 1rem;
outline: none !important;
text-align: left;
}
tr {
outline: 1px solid #CCCCCC;
}
td:first-child {
padding-top: 1rem;
}
td:last-child {
padding-bottom: 1rem;
}
td::before {
content: attr(data-cell) ": ";
font-weight: 700;
text-transform: capitalize;
}
}
</style>
9 changes: 9 additions & 0 deletions src/components/vue-ui-donut-evolution.cy.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import VueUiDonutEvolution from './vue-ui-donut-evolution.vue'



describe('<VueUiDonutEvolution />', () => {
beforeEach(function () {
const stub = cy.stub()
Cypress.on('uncaught:exception', (err, runnable) => {
if (err.message.includes('ResizeObserver')) {
stub()
return false
}
})
cy.fixture('donut-evolution.json').as('fixture');
cy.viewport(400, 400);
cy.get('@fixture').then((fixture) => {
Expand Down
10 changes: 8 additions & 2 deletions src/components/vue-ui-donut-evolution.vue
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,15 @@ const table = computed(() => {
backgroundColor: donutEvolutionConfig.value.table.td.backgroundColor,
color: donutEvolutionConfig.value.table.td.color,
outline: donutEvolutionConfig.value.table.td.outline
}
},
breakpoint: donutEvolutionConfig.value.table.responsiveBreakpoint
}
return { head, body, config };
const colNames = [
donutEvolutionConfig.value.table.columnNames.period
].concat(convertedDataset.value.filter(ds => !segregated.value.includes(ds.uid)).map(ds => ds.name)).concat(donutEvolutionConfig.value.table.columnNames.total)
return { head, body, config, colNames };
});
function getData() {
Expand Down Expand Up @@ -773,6 +778,7 @@ defineExpose({
<DataTable
v-if="mutableConfig.showTable"
:colNames="table.colNames"
:head="table.head"
:body="table.body"
:config="table.config"
Expand Down
7 changes: 7 additions & 0 deletions src/components/vue-ui-donut.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ import VueUiDonut from './vue-ui-donut.vue';

describe('<VueUiDonut />', () => {
beforeEach(function () {
const stub = cy.stub()
Cypress.on('uncaught:exception', (err, runnable) => {
if (err.message.includes('ResizeObserver')) {
stub()
return false
}
})
cy.fixture('donut.json').as('fixture');
cy.viewport(1000, 1100);
});
Expand Down
11 changes: 10 additions & 1 deletion src/components/vue-ui-donut.vue
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,18 @@ const dataTable = computed(() => {
backgroundColor: donutConfig.value.table.td.backgroundColor,
color: donutConfig.value.table.td.color,
outline: donutConfig.value.table.td.outline
}
},
breakpoint: donutConfig.value.table.responsiveBreakpoint
}
const colNames = [
donutConfig.value.table.columnNames.series,
donutConfig.value.table.columnNames.value,
donutConfig.value.table.columnNames.percentage
]
return {
colNames,
head,
body,
config
Expand Down Expand Up @@ -608,6 +616,7 @@ defineExpose({
<!-- DATA TABLE -->
<DataTable
v-if="mutableConfig.showTable"
:colNames="dataTable.colNames"
:head="dataTable.head"
:body="dataTable.body"
:config="dataTable.config"
Expand Down
13 changes: 11 additions & 2 deletions src/components/vue-ui-molecule.vue
Original file line number Diff line number Diff line change
Expand Up @@ -384,13 +384,21 @@ const dataTable = computed(() => {
backgroundColor: moleculeConfig.value.table.td.backgroundColor,
color: moleculeConfig.value.table.td.color,
outline: moleculeConfig.value.table.td.outline
}
},
breakpoint: moleculeConfig.value.table.responsiveBreakpoint
}
const colNames = [
moleculeConfig.value.table.translations.nodeName,
moleculeConfig.value.table.translations.details,
moleculeConfig.value.table.translations.parentNode
]
return {
head,
body,
config
config,
colNames
}
});
Expand Down Expand Up @@ -535,6 +543,7 @@ defineExpose({

<DataTable
v-if="mutableConfig.showTable"
:colNames="dataTable.colNames"
:head="dataTable.head"
:body="dataTable.body"
:config="dataTable.config"
Expand Down
13 changes: 11 additions & 2 deletions src/components/vue-ui-mood-radar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,21 @@ const dataTable = computed(() => {
backgroundColor: radarConfig.value.table.td.backgroundColor,
color: radarConfig.value.table.td.color,
outline: radarConfig.value.table.td.outline
}
},
breakpoint: radarConfig.value.table.responsiveBreakpoint
}
const colNames = [
radarConfig.value.table.columnNames.series,
radarConfig.value.table.columnNames.value,
radarConfig.value.table.columnNames.percentage
]
return {
head,
body,
config
config,
colNames
}
});
Expand Down Expand Up @@ -436,6 +444,7 @@ defineExpose({
<!-- DATA TABLE -->
<DataTable
v-if="mutableConfig.showTable"
:colNames="dataTable.colNames"
:head="dataTable.head"
:body="dataTable.body"
:config="dataTable.config"
Expand Down
7 changes: 7 additions & 0 deletions src/components/vue-ui-rings.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ import VueUiRings from './vue-ui-rings.vue'
describe('<VueUiRings />', () => {

beforeEach(function() {
const stub = cy.stub()
Cypress.on('uncaught:exception', (err, runnable) => {
if (err.message.includes('ResizeObserver')) {
stub()
return false
}
})
cy.fixture('rings.json').as('fixture');
cy.viewport(600, 800);
});
Expand Down
Loading

0 comments on commit 0e6998c

Please sign in to comment.