-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Historical Graph to Building Details Over Any Tracked Column #107
Merged
Merged
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b5c612b
Add D3 with bar graph with fake data
vkoves d2f6d1d
Add Total GHG emissions graph to all buildings
vkoves 7f13ddb
Add ability to switch graph column
vkoves e2f8de6
Run linting
vkoves 1302652
Increase graph margin to fix Merch Mart gas use
vkoves d3c4022
Remove excess <g> tag
vkoves 9a7758d
fixing weird pandas and numpy version issue
alexkcode 0546186
attempt at fixing netlify issue
alexkcode dac8087
Move requirements.txt
vkoves File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,9 @@ | |
"main": "index.js", | ||
"repository": "[email protected]:vkoves/electrify-chicago.git", | ||
"author": "Viktor Köves <[email protected]>", | ||
"engines" : { "node" : ">=16.00 < 17.0.0" }, | ||
"engines": { | ||
"node": ">=16.00 < 17.0.0" | ||
}, | ||
"license": "MIT", | ||
"scripts": { | ||
"build": "gridsome build", | ||
|
@@ -16,6 +18,7 @@ | |
}, | ||
"dependencies": { | ||
"csv-parse": "^5.3.6", | ||
"d3": "^7.9.0", | ||
"gridsome": "^0.7.0", | ||
"leaflet": "~1.7.0", | ||
"leaflet.gridlayer.googlemutant": "^0.14.0", | ||
|
@@ -25,6 +28,7 @@ | |
}, | ||
"devDependencies": { | ||
"@microsoft/eslint-formatter-sarif": "^3.0.0", | ||
"@types/d3": "^7.4.3", | ||
"@types/leaflet": "^1.9.3", | ||
"@types/sindresorhus__slugify": "^0.9.3", | ||
"@typescript-eslint/eslint-plugin": "^5.56.0", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
<template> | ||
<div class="bar-graph-cont"> | ||
<div | ||
class="label" | ||
v-html="graphTitle" | ||
/> | ||
|
||
<svg><!-- D3 inserts here --></svg> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { Component, Prop, Vue, Watch } from 'vue-property-decorator'; | ||
import * as d3 from 'd3'; | ||
|
||
export interface IGraphPoint { | ||
x: number | string; | ||
y: number; | ||
} | ||
|
||
/** | ||
* A component that can graph an arbitrary array of numeric data | ||
*/ | ||
@Component({ | ||
components: { | ||
}, | ||
}) | ||
export default class BarGraph extends Vue { | ||
@Prop({required: true}) graphTitle!: string; | ||
|
||
@Prop({required: true}) graphData!: Array<IGraphPoint>; | ||
|
||
@Watch('graphData') | ||
onDataChanged(): void { | ||
this.renderGraph(); | ||
} | ||
|
||
readonly width = 800; | ||
readonly height = 400; | ||
|
||
readonly graphMargins = { top: 30, right: 30, bottom: 50, left: 50 }; | ||
readonly barMargin = 0.2; | ||
|
||
svg!: d3.Selection<SVGGElement, unknown, HTMLElement, any>; | ||
|
||
|
||
mounted(): void { | ||
const outerWidth = this.width + this.graphMargins.left + this.graphMargins.right; | ||
const outerHeight = this.height + this.graphMargins.top + this.graphMargins.bottom; | ||
|
||
this.svg = d3 | ||
.select("svg") | ||
.attr("width", outerWidth) | ||
.attr("height", outerHeight) | ||
.attr("viewBox", `0 0 ${outerWidth} ${outerHeight}`) | ||
.attr("preserveAspectRatio", "xMidYMid meet") | ||
.append("g") | ||
.attr("transform", `translate(${this.graphMargins.left},${this.graphMargins.top})`); | ||
|
||
this.renderGraph(); | ||
} | ||
|
||
renderGraph(): void { | ||
// Empty the SVG | ||
this.svg.html(null); | ||
|
||
const g = this.svg.append("g"); | ||
|
||
|
||
const xVals: Array<string> = this.graphData.map((d) => d.x.toString()); | ||
const yVals: Array<number> = this.graphData.map((d) => d.y); | ||
|
||
const x = d3 | ||
.scaleBand() | ||
.range([0, this.width]) | ||
.domain(xVals) | ||
.padding(this.barMargin); | ||
|
||
const y = d3 | ||
.scaleLinear() | ||
.domain([ 0, d3.max(yVals) as number]) | ||
.rangeRound([this.height, 0]); | ||
|
||
// Render X axis | ||
this.svg.append("g") | ||
.attr("transform", `translate(0, ${this.height})`) | ||
.call(d3.axisBottom(x)) | ||
.selectAll("text") | ||
.attr("transform", "translate(-10,0)rotate(-45)") | ||
.style("text-anchor", "end"); | ||
|
||
// Render Y axis | ||
this.svg.append("g") | ||
.call(d3.axisLeft(y)); | ||
|
||
this.svg.selectAll("mybar") | ||
.data(this.graphData) | ||
.enter() | ||
.append("rect") | ||
.attr("x", (d) => { | ||
return x(d.x.toString() as string) as number; | ||
}) | ||
.attr("y", (d) => y(d.y)) | ||
.attr("width", x.bandwidth()) | ||
.attr("height", (d) => this.height - y(d.y)) | ||
.attr("fill", "#69b3a2"); | ||
} | ||
} | ||
</script> | ||
|
||
<style lang="scss"> | ||
.bar-graph-cont { | ||
margin: 1rem 0; | ||
|
||
.label { | ||
font-weight: bold; | ||
font-size: 1.25rem; | ||
margin-bottom: 0.5rem; | ||
} | ||
|
||
svg { | ||
width: 100%; | ||
border: solid $border-thin $grey-light; | ||
aspect-ratio: 2; | ||
height: auto; | ||
max-width: 50rem; | ||
} | ||
|
||
.tick { | ||
font-weight: bold; | ||
font-size: 1rem; | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check warning
Code scanning / ESLint
disallow use of v-html to prevent XSS attack Warning