-
Notifications
You must be signed in to change notification settings - Fork 81
D3 external as script #71
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| <div>Hello {{ name }}</div> | ||
| <input type="text" [value]="name" (input)="name = $event.target.value"/> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we need an actual example app. I'll ask in the GDE channel to see if we can get something good |
||
| <div class="d3-chart-container" #chart><svg><g></g></svg></div> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,4 +9,10 @@ html { | |
| color: $example-red; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| .d3-chart-container { | ||
| overflow-x: hidden; | ||
| width: 500px; | ||
| height: 500px; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,30 @@ | ||
| import {Component, NgModule} from '@angular/core'; | ||
| import {Component, ElementRef, NgModule, ViewChild} from '@angular/core'; | ||
|
|
||
| import {msg} from '../lib/file'; | ||
|
|
||
| @Component({ | ||
| selector: 'hello-world-app', | ||
| template: ` | ||
| <div>Hello {{ name }}</div> | ||
| <input type="text" [value]="name" (input)="name = $event.target.value"/> | ||
| `, | ||
| templateUrl: 'hello-world.component.html', | ||
| styleUrls: ['./hello-world-styles.css'] | ||
| }) | ||
| export class HelloWorldComponent { | ||
| name: string = msg; | ||
| @ViewChild('chart') public chartContainer: ElementRef; | ||
| private chart: any; | ||
|
|
||
| ngAfterViewInit() { | ||
| const element = this.chartContainer.nativeElement; | ||
|
|
||
| this.chart = d3.select(element) | ||
| .select('svg') | ||
| .attr('width', element.offsetWidth) | ||
| .attr('height', element.offsetWidth) | ||
| .select('g') | ||
| .append('circle') | ||
| .attr('class', 'node') | ||
| .attr('cy', 10) | ||
| .attr('cx', 10) | ||
| .attr('r', 10) | ||
| .style('stroke', 'gray'); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import * as _d3 from 'd3'; | ||
|
|
||
| // External libraries that are included as scripts such as D3 are declared as globals | ||
| // here with their appropriate types. This typings files is compiled into | ||
| // any ts_library or ng_module that requires these types and it makes them available | ||
| // as global variables that are properly typed in typescript. | ||
| declare global { | ||
| const d3: typeof _d3; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like this is the opposite of what we want, long-term -- we want users to import d3 if they use it, so that taze can add the proper dependency when needed.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alex and I both agree that we need another example with d3 imported properly. This example is the only way that works at the moment with where ts_devserver and the rollup_bundle production bundler is at right now. Getting it to work with an import will require changes to both and needs to some thought.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @evmar my understanding is that some libraries are documented such that developers expect to import them, but some are only accessible via globals. I think ABC needs to demonstrate both ways? If we only document how to use ES imports then I think some libraries would be unusable? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the typings usually match how the library works, so you only need a shim thing like here when you're using the library in a way contrary to its intended use.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @gregmagolan I'm hesitant to merge this if the intended use of d3 is to import it.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know of one off the top of my head. I'll think about it. |
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should clean this up - can be in a later PR. the ts_devserver should have an option that allows us to serve additional rootdirs, I think this is already present but maybe not wired up?