Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stelgkio committed Oct 22, 2021
0 parents commit 4661efa
Show file tree
Hide file tree
Showing 40 changed files with 3,186 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# d3js-angular-9696zw

[Edit on StackBlitz ⚡️](https://stackblitz.com/edit/d3js-angular-9696zw)
100 changes: 100 additions & 0 deletions angular.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"demo": {
"root": "",
"sourceRoot": "src",
"projectType": "application",
"prefix": "app",
"schematics": {},
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/demo",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.app.json",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.css"
],
"scripts": []
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true
}
}
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "demo:build"
},
"configurations": {
"production": {
"browserTarget": "demo:build:production"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "demo:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.spec.json",
"karmaConfig": "src/karma.conf.js",
"styles": [
"styles.css"
],
"scripts": [],
"assets": [
"src/favicon.ico",
"src/assets"
]
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"src/tsconfig.app.json",
"src/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
]
}
}
}
}
},
"defaultProject": "demo"
}
70 changes: 70 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"name": "d3js-angular-example",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "6.0.3",
"@angular/cdk": "6.2.1",
"@angular/common": "6.0.3",
"@angular/compiler": "6.0.3",
"@angular/core": "6.0.3",
"@angular/forms": "6.0.3",
"@angular/http": "6.0.3",
"@angular/material": "6.2.1",
"@angular/platform-browser": "6.0.3",
"@angular/platform-browser-dynamic": "6.0.3",
"@angular/router": "6.0.3",
"core-js": "2.5.4",
"d3": "5.4.0",
"d3-array": "^2.0.3",
"d3-axis": "^1.0.12",
"d3-brush": "^1.0.6",
"d3-scale": "^3.0.0",
"d3-scale-chromatic": "^1.3.3",
"d3-selection": "^1.4.0",
"d3-shape": "^1.3.5",
"d3-time-format": "^2.1.3",
"d3-zoom": "^1.7.3",
"rxjs": "6.0.0",
"zone.js": "0.8.26"
},
"devDependencies": {
"@angular-devkit/build-angular": "0.6.8",
"@angular/cli": "6.0.8",
"@angular/compiler-cli": "6.0.3",
"@angular/language-service": "6.0.3",
"@types/d3-array": "1.2.1",
"@types/d3-axis": "1.0.10",
"@types/d3-brush": "1.0.8",
"@types/d3-color": "1.2.1",
"@types/d3-scale": "2.0.1",
"@types/d3-scale-chromatic": "1.2.0",
"@types/d3-selection": "1.3.1",
"@types/d3-shape": "1.2.3",
"@types/d3-time-format": "2.1.0",
"@types/d3-zoom": "1.7.1",
"@types/jasmine": "2.8.6",
"@types/jasminewd2": "2.0.3",
"@types/node": "8.9.4",
"codelyzer": "4.2.1",
"jasmine-core": "2.99.1",
"jasmine-spec-reporter": "4.2.1",
"karma": "1.7.1",
"karma-chrome-launcher": "2.2.0",
"karma-coverage-istanbul-reporter": "2.0.0",
"karma-jasmine": "1.1.1",
"karma-jasmine-html-reporter": "0.2.2",
"protractor": "5.3.0",
"ts-node": "5.0.1",
"tslint": "5.9.1",
"typescript": "2.7.2"
}
}
27 changes: 27 additions & 0 deletions src/app/01_line_chart/line-chart.component.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.axis {
font: 10px sans-serif;
}

.axis path,
.axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}

.axis-title {
fill: none;
stroke: black;
stroke-width: 0.5px;
}


.axis--x path {
/*display: none;*/
}

.line {
fill: none;
stroke: steelblue;
stroke-width: 1.5px;
}
2 changes: 2 additions & 0 deletions src/app/01_line_chart/line-chart.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h2>{{ title }}</h2>
<svg width="900" height="500"></svg>
84 changes: 84 additions & 0 deletions src/app/01_line_chart/line-chart.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { Component, ViewEncapsulation, OnInit } from '@angular/core';

import * as d3 from 'd3-selection';
import * as d3Scale from 'd3-scale';
import * as d3Shape from 'd3-shape';
import * as d3Array from 'd3-array';
import * as d3Axis from 'd3-axis';

import { STOCKS } from '../shared';

@Component({
selector: 'app-line-chart',
encapsulation: ViewEncapsulation.None,
templateUrl: './line-chart.component.html',
styleUrls: ['./line-chart.component.css']
})
export class LineChartComponent implements OnInit {

title = 'Line Chart';

private margin = {top: 20, right: 20, bottom: 30, left: 50};
private width: number;
private height: number;
private x: any;
private y: any;
private svg: any;
private line: d3Shape.Line<[number, number]>;

constructor() {
this.width = 900 - this.margin.left - this.margin.right;
this.height = 500 - this.margin.top - this.margin.bottom;
}

ngOnInit() {
this.initSvg();
this.initAxis();
this.drawAxis();
this.drawLine();
}

private initSvg() {
this.svg = d3.select('svg')
.append('g')
.attr('transform', 'translate(' + this.margin.left + ',' + this.margin.top + ')');
}

private initAxis() {
this.x = d3Scale.scaleTime().range([0, this.width]);
this.y = d3Scale.scaleLinear().range([this.height, 0]);
this.x.domain(d3Array.extent(STOCKS, (d) => d.date ));
this.y.domain(d3Array.extent(STOCKS, (d) => d.value ));
}

private drawAxis() {

this.svg.append('g')
.attr('class', 'axis axis--x')
.attr('transform', 'translate(0,' + this.height + ')')
.call(d3Axis.axisBottom(this.x));

this.svg.append('g')
.attr('class', 'axis axis--y')
.call(d3Axis.axisLeft(this.y))
.append('text')
.attr('class', 'axis-title')
.attr('transform', 'rotate(-90)')
.attr('y', 6)
.attr('dy', '.71em')
.style('text-anchor', 'end')
.text('Price ($)');
}

private drawLine() {
this.line = d3Shape.line()
.x( (d: any) => this.x(d.date) )
.y( (d: any) => this.y(d.value) );

this.svg.append('path')
.datum(STOCKS)
.attr('class', 'line')
.attr('d', this.line);
}

}
5 changes: 5 additions & 0 deletions src/app/02_multi_series_line_chart/multi-series.component.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.line {
fill: none;
stroke: steelblue;
stroke-width: 1.5px;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h2>{{ title }}</h2>
<svg width="960" height="500"></svg>
Loading

0 comments on commit 4661efa

Please sign in to comment.