Skip to content

Commit

Permalink
Merge pull request simwrapper#121 from simwrapper/106-topsheets
Browse files Browse the repository at this point in the history
106-topsheets
  • Loading branch information
billyc committed Mar 30, 2022
2 parents f7ba932 + 2c79733 commit 6c430f4
Show file tree
Hide file tree
Showing 9 changed files with 298 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/charts/allCharts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// the name of the import will be the chart "type" in YAML.

// resizable charts:
import aggregate from './aggregate.vue'
import area from './area.vue'
import bar from './bar.vue'
import bubble from './bubble.vue'
Expand All @@ -18,7 +19,6 @@ import vega from './vega.vue'
import video from './video.vue'

// full-screen map visualizations:
import aggregate from './aggregate.vue'
import carriers from './carriers.vue'
import flowmap from './flowmap.vue'
import links from './links.vue'
Expand Down
2 changes: 1 addition & 1 deletion src/js/HTTPFileSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ class SVNFileSystem {
// find all dashboards, topsheets, and viz-* yamls in each configuration folder.
// Overwrite keys as we go; identically-named configs from parent folders get superceded as we go.
const dashboard = 'dashboard*.y?(a)ml'
const topsheet = 'topsheet*.y?(a)ml'
const topsheet = '{topsheet,table}*.y?(a)ml'
const viz = 'viz*.y?(a)ml'
const config = 'simwrapper-config.y?(a)ml'

Expand Down
16 changes: 2 additions & 14 deletions src/plugins/aggregate-od/AggregateOd.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
.info-description(style="padding: 0 0.5rem;" v-if="this.vizDetails.description")
p.description {{ this.vizDetails.description }}

.widgets(v-if="!thumbnail" style="{'padding': config ? '0 0'}")
.widget-column()
.widgets(v-if="!thumbnail" :style="{'padding': yamlConfig ? '0 0.5rem 0.5rem 0.5rem' : '0 0'}")
.widget-column
h4.heading {{ $t('time')}}
label.checkbox(style="margin: 0 0.5rem 0 auto;")
input(type="checkbox" v-model="showTimeRange")
Expand Down Expand Up @@ -1359,7 +1359,6 @@ h4 {
display: flex;
flex-direction: row;
user-select: none;
padding: 0.5rem 0.5rem;
}
.widget-column {
Expand Down Expand Up @@ -1409,10 +1408,6 @@ h4 {
width: 12rem;
}
.scale-slider {
// margin: 0rem 0px auto 0px;
}
.heading {
font-weight: bold;
text-align: left;
Expand All @@ -1424,13 +1419,6 @@ h4 {
margin: 0 0 0rem 0.5rem;
}
.checkbox {
// font-size: 0.8rem;
// margin-top: 0.25rem;
// margin-right: 0.5rem;
// margin-left: 1rem;
}
.description {
margin-top: 0rem;
padding: 0rem 0.25rem;
Expand Down
152 changes: 152 additions & 0 deletions src/plugins/calculation-table/CalculationTable.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
<template lang="pug">
.my-component(:class="{'hide-thumbnail': !thumbnail}" oncontextmenu="return false")

img.thumb(v-if="thumbnail" src="./assets/table.png" :width="128")


.topsheet(v-if="!thumbnail && isLoaded")
p.header {{ subfolder }}

h2 {{ vizDetails.title }}
p {{ vizDetails.description}}

hr

component.dash-card(
is="TopSheet"
:fileSystemConfig="fileSystem"
:subfolder="subfolder"
:config="vizDetails"
:yaml="yamlConfig"
:files="files"
:cardTitle="vizDetails.title"
:cardId="'table1'"
:allConfigFiles="allConfigFiles"
)

//- @isLoaded="handleCardIsLoaded(card)"
//- @dimension-resizer="setDimensionResizer"
//- @titles="setCardTitles(card, $event)"
</template>

<script lang="ts">
import { Vue, Component, Prop, Watch } from 'vue-property-decorator'
import YAML from 'yaml'
import util from '@/js/util'
import globalStore from '@/store'
import { ColorScheme, FileSystemConfig, VisualizationPlugin, Status, YamlConfigs } from '@/Globals'
import HTTPFileSystem from '@/js/HTTPFileSystem'
import TopSheet from '@/components/TopSheet/TopSheet.vue'
@Component({
components: { TopSheet },
})
class MyComponent extends Vue {
@Prop({ required: true }) private root!: string
@Prop({ required: true }) private subfolder!: string
@Prop({ required: false }) private yamlConfig!: string
@Prop({ required: false }) private thumbnail!: boolean
private globalState = globalStore.state
private fileApi!: HTTPFileSystem
private fileSystem!: FileSystemConfig
private vizDetails = {
title: '',
description: '',
thumbnail: '',
}
private isLoaded = false
private allConfigFiles: YamlConfigs = { dashboards: {}, topsheets: {}, vizes: {}, configs: {} }
private files: string[] = []
private async mounted() {
this.buildFileApi()
await this.getVizDetails()
this.allConfigFiles = await this.fileApi.findAllYamlConfigs(this.subfolder)
const { files } = await this.fileApi.getDirectory(this.subfolder)
this.files = files
this.isLoaded = true
if (this.thumbnail) return
}
public buildFileApi() {
const filesystem = this.getFileSystem(this.root)
this.fileApi = new HTTPFileSystem(filesystem)
this.fileSystem = filesystem
}
private thumbnailUrl = "url('assets/thumbnail.jpg') no-repeat;"
private get urlThumbnail() {
return this.thumbnailUrl
}
private getFileSystem(name: string) {
const svnProject: FileSystemConfig[] = this.$store.state.svnProjects.filter(
(a: FileSystemConfig) => a.slug === name
)
if (svnProject.length === 0) {
console.log('no such project')
throw Error
}
return svnProject[0]
}
private async getVizDetails() {
if (!this.fileApi) return
console.log(this.yamlConfig)
// first get config
try {
const text = await this.fileApi.getFileText(this.subfolder + '/' + this.yamlConfig)
this.vizDetails = YAML.parse(text)
} catch (e) {
console.error('failed')
}
const t = this.vizDetails.title ? this.vizDetails.title : 'Table'
this.$emit('title', t)
}
}
// !register plugin!
globalStore.commit('registerPlugin', {
kebabName: 'calculation-table',
prettyName: 'Table',
description: 'Calculation table',
filePatterns: ['(topsheet|table)*.y?(a)ml'],
component: MyComponent,
} as VisualizationPlugin)
export default MyComponent
</script>

<style scoped lang="scss">
@import '@/styles.scss';
.my-component {
margin: 0 0;
padding: 0 2rem;
}
.header {
margin-top: 0.5rem;
margin-bottom: 2rem;
color: var(--text);
}
.topsheet {
max-width: 55rem;
margin: 0rem auto;
}
@media only screen and (max-width: 640px) {
}
</style>
Binary file added src/plugins/calculation-table/assets/table.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 8 additions & 10 deletions src/plugins/pluginRegistry.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// import plugins in the order you want them to appear on project pages
import CarrierViewer from '@/plugins/carrier-viewer/CarrierViewer.vue'
import VehicleAnimation from '@/plugins/vehicle-animation/VehicleAnimation.vue'
import CalculationTable from '@/plugins/calculation-table/CalculationTable.vue'
import XyHexagons from '@/plugins/xy-hexagons/XyHexagons.vue'
// import AgentAnimation from '@/plugins/agent-animation/AgentAnimation.vue'
import LinksGl from '@/plugins/links-gl/LinkVolumes.vue'
// import LinkVolumes from '@/plugins/link-vols/LinkVolumes.vue'
import TransitDemand from '@/plugins/transit-demand/TransitDemand.vue'
import ShapeFile from '@/plugins/shape-file/ShapeFile.vue'
import AggregateOd from '@/plugins/aggregate-od/AggregateOd.vue'
Expand All @@ -15,19 +14,18 @@ import ImageView from '@/plugins/image/ImageView.vue'

// // EVERY plugin must also be exported here:
const plugins = {
AggregateOd,
CalculationTable,
CarrierViewer,
VehicleAnimation,
XyHexagons,
// AgentAnimation,
ImageView,
LinksGl,
// LinkVolumes,
ShapeFile,
SankeyDiagram,
VegaLite,
AggregateOd,
ShapeFile,
TransitDemand,
VegaLite,
VehicleAnimation,
VideoPlayer,
ImageView,
XyHexagons,
}

export default plugins
128 changes: 128 additions & 0 deletions src/templates/BlankPlugin.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<template lang="pug">
.my-component(:class="{'hide-thumbnail': !thumbnail}" oncontextmenu="return false")

img.thumb(v-if="thumbnail" src="./assets/table.png" :width="128")


</template>

<script lang="ts">
import { Vue, Component, Prop, Watch } from 'vue-property-decorator'
import YAML from 'yaml'
import util from '@/js/util'
import globalStore from '@/store'
import { ColorScheme, FileSystemConfig, VisualizationPlugin, Status } from '@/Globals'
import HTTPFileSystem from '@/js/HTTPFileSystem'
@Component({
components: {},
})
class MyComponent extends Vue {
@Prop({ required: true }) private root!: string
@Prop({ required: true }) private subfolder!: string
@Prop({ required: false }) private yamlConfig!: string
@Prop({ required: false }) private thumbnail!: boolean
private globalState = globalStore.state
private fileApi!: HTTPFileSystem
private fileSystem!: FileSystemConfig
private vizDetails = {
title: '',
description: '',
thumbnail: '',
}
private async mounted() {
this.buildFileApi()
await this.getVizDetails()
if (this.thumbnail) return
// this.statusMessage = `${this.$i18n.t('loading')}`
this.buildThumbnail()
}
private beforeDestroy() {}
public buildFileApi() {
const filesystem = this.getFileSystem(this.root)
this.fileApi = new HTTPFileSystem(filesystem)
this.fileSystem = filesystem
}
private thumbnailUrl = "url('assets/thumbnail.jpg') no-repeat;"
private get urlThumbnail() {
return this.thumbnailUrl
}
private getFileSystem(name: string) {
const svnProject: FileSystemConfig[] = this.$store.state.svnProjects.filter(
(a: FileSystemConfig) => a.slug === name
)
if (svnProject.length === 0) {
console.log('no such project')
throw Error
}
return svnProject[0]
}
private async getVizDetails() {
if (!this.fileApi) return
console.log(this.yamlConfig)
// first get config
try {
const text = await this.fileApi.getFileText(this.subfolder + '/' + this.yamlConfig)
this.vizDetails = YAML.parse(text)
} catch (e) {
console.error('failed')
}
const t = this.vizDetails.title ? this.vizDetails.title : 'Table'
this.$emit('title', t)
}
private async buildThumbnail() {
if (!this.fileApi) return
if (this.thumbnail && this.vizDetails.thumbnail) {
try {
const blob = await this.fileApi.getFileBlob(
this.subfolder + '/' + this.vizDetails.thumbnail
)
const buffer = await blob.arrayBuffer()
const base64 = util.arrayBufferToBase64(buffer)
if (base64)
this.thumbnailUrl = `center / cover no-repeat url(data:image/png;base64,${base64})`
} catch (e) {
console.error(e)
}
}
}
}
// !register plugin!
globalStore.commit('registerPlugin', {
kebabName: 'calculation-table',
prettyName: 'Table',
description: 'Calculation table',
filePatterns: ['(topsheet|table)*.y?(a)ml'],
component: MyComponent,
} as VisualizationPlugin)
export default MyComponent
</script>

<style scoped lang="scss">
@import '@/styles.scss';
.my-component {
}
@media only screen and (max-width: 640px) {
}
</style>
2 changes: 1 addition & 1 deletion src/views/DashBoard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export default class VueComponent extends Vue {
}
private getCardComponent(card: any) {
if (card.type === 'topsheet') return 'TopSheet'
if (card.type === 'table' || card.type === 'topsheet') return 'TopSheet'
// might be a chart
if (chartTypes.indexOf(card.type) > -1) return 'card-' + card.type
Expand Down

0 comments on commit 6c430f4

Please sign in to comment.