I'm trying to animate an element at the :leave transition and I'm a bit baffled by its behaviour.
trigger('inOut', [
transition(':enter', [
style({'max-height': '0'}),
animate(250, style({'max-height': '150px'}))
], { params: { maxHeight: '150px'}}),
So I would expect my element being animated to have a max-height of 15px set at the final frame of the animation... and left there! I can see the max-height being animated but then at the end its removed and the element scales to whatever height fits its content. Struggling to imagine how this is useful, am I doing something wrong?
Update - Resolved it with this
trigger('inOut', [
state('void', style({'max-height': '0'})),
state('*', style({'max-height': '{{maxHeight}}'}), { params: { maxHeight: '0px'}}),
transition(':enter', animate(300)),
transition(':leave', animate(250))
]),
A way to solve this is to use a state for the end of the animation and (#animation.done) to trigger this state.
Here is a StackBlitz example.
app.component.html
<div [#routeAnimations]="state" (#routeAnimations.done)="onDone($event)" class="animate-div">
</div>
app.component.ts
import { trigger, style, state, animate, transition } from '#angular/animations';
#Component({
animations: [
trigger('routeAnimations', [
state('done', style({
maxHeight: '150px'
})),
transition(':enter', [
style({ 'max-height': '0' }),
animate(1000, style({ 'max-height': '150px' }))
], { params: { maxHeight: '150px' } })
])
]
})
export class AppComponent {
state = '';
onDone(event) {
this.state = 'done';
}
}
Related
I am trying to build a custom shape - a diamond that stays centered over the text in its label (bonus if we can make the shape expand as the label changes).
Right now, I am transforming a rectangle by 45 degrees to create the diamond. Problem is this seems to rotate around to top left corner and not the center point.
How can I make JointJS rotate this shape around it's center? Or is there a better way to accomplish this?
Here is a JSFiddle.
http://jsfiddle.net/dfqpbLyn/3/
var baseRhombus = joint.shapes.standard.Rectangle.define('crt.BaseRhombus',
{
attrs: {
label: {
textAnchor: 'middle',
textVerticalAnchor: 'middle',
fontSize: 25,
text: 'Test'
},
body: {
strokeWidth: 1,
stroke: 'green',
fill: 'gray',
//transform-origin: center center,
transform: 'rotate(45, center, center)',
}
}
},
{
markup:
[
{
tagName: 'rect',
selector: 'body'
},
{
tagName: 'text',
selector: 'label'
}
]
},
{
initialize: function (width, height, x, y) {
var newElement = new this({
id: 'g1',
position: {x:x, y:y},
size: {width: width, height: height},
//position: { x: x, y: y },
});
return newElement;
}
}
);
var baseRhombus = joint.shapes.crt.BaseRhombus.initialize(250, 250, 60, 50);
Thanks!
Will
Figured it out. Used
transform: 'rotate(45, 50, 50) on the body of my element, but calculated the transform origin based on the current width and height of the element. The documentation around transform was a bit difficult to find but once I found an example of it in use it became clear.
I am using ngx-admin template. Right now i am trying to create a modal that will open on a button click. I am trying to show a form in the modal window but on clicking, the modal does open but it does not show me the form and i get this error
No component factory found for EmailInstructorsComponent. Did you add it to #NgModule.entryComponents?
I am using lazy laoding and most of the modules have been added in the declaration of a shared.module file to avoid the erros during production.
I tried to look at other links too that were available on the stackoverflow but none of them refered to modal-windows/dialogs that's why i had to create this separate thread
classes-and-students.module.ts file
const ENTRY_COMPONENTS = [
EmailInstructorsComponent
];
#NgModule({
imports: [
ClassesAndStudentsRoutingModule,
NbCardModule,
Ng2SmartTableModule,
NbAlertModule,
SharedModule,
CKEditorModule
],
declarations: [
ClassesAndStudentsComponent,
...routedComponents,
InstructorbiddingComponent,
EmailInstructorsComponent,
],
entryComponents: [
...ENTRY_COMPONENTS
],
providers: [
NewsService,
],
})
export class ClassesandStudentsModule { }
instructorbidding.component.ts file
#Component({
selector: 'ngx-instructorbidding',
templateUrl: 'instructorbidding.component.html',
styleUrls: ['instructorbidding.component.scss']
})
export class InstructorbiddingComponent {
#ViewChild('contentTemplate', { static: true }) contentTemplate: TemplateRef<any>;
#ViewChild('disabledEsc', { read: TemplateRef, static: true }) disabledEscTemplate: TemplateRef<HTMLElement>;
constructor(private windowService: NbWindowService) { }
openWindowForm(contentTemplate) {
this.windowService.open(EmailInstructorsComponent, { title: 'Window'});
}
}
email-instructors.component.ts file
#Component({
selector: 'ngx-email-instructors',
templateUrl: './email-instructors.component.html',
styleUrls: ['./email-instructors.component.scss']
})
export class EmailInstructorsComponent {
constructor(public windowRef: NbWindowRef) {
}
close() {
this.windowRef.close();
}
}
email-instructors.component.html file
<form class="form">
<label for="subject">Subject:</label>
<input nbInput id="subject" type="text">
<label class="text-label" for="text">Text:</label>
<textarea nbInput id="text"></textarea>
</form>
I am not sure what mistake i am making so please help me out by pointing out my mistake
Try to change your code like this to see if it work
const ENTRY_COMPONENTS = [
EmailInstructorsComponent
];
#NgModule({
imports: [
ClassesAndStudentsRoutingModule,
NbCardModule,
Ng2SmartTableModule,
NbAlertModule,
SharedModule,
CKEditorModule
],
declarations: [
ClassesAndStudentsComponent,
...routedComponents,
InstructorbiddingComponent,
EmailInstructorsComponent,
],
entryComponents: [
ENTRY_COMPONENTS
],
providers: [
NewsService,
],
})
export class ClassesandStudentsModule { }
Trying to focus() on a treeview node in this plunker using an ElementRef. I commented the two lines at the bottom cause they don't work.
Here's the plunker for the code listing below:
https://plnkr.co/edit/aUnechu6glXk5CMFsMex?p=preview
import { Component, ElementRef, ViewChild } from '#angular/core';
#Component({
selector: 'my-app',
template: `
<kendo-treeview
#treeview
[nodes]="data"
textField="text"
kendoTreeViewCheckable
kendoTreeViewExpandable
kendoTreeViewSelectable
kendoTreeViewHierarchyBinding
childrenField="items">
</kendo-treeview>
`
})
export export class AppComponent {
#ViewChild("treeview") treeview: ElementRef;
public data: any[] = [
{
text: "Furniture", items: [
{ text: "Tables & Chairs" },
{ text: "Sofas" },
{ text: "Occasional Furniture" }
]
},
{
text: "Decor", items: [
{ text: "Bed Linen" },
{ text: "Curtains & Blinds" },
{ text: "Carpets" }
]
}
];
//let tree = this.treeview.nativeElement;
//this.treeview.focus('0');
}
And the focus() method as per their docs and sample here:
https://www.telerik.com/kendo-angular-ui/components/treeview/api/TreeViewComponent/#toc-focus
How can I focus() programmatically within my component code, as opposed to the click() event posted in their docs ?
The code needs to be executed inside one of Angular's lifecycle hooks or from a method. We need either a ngAfterViewInit or a custom AppComponent.focus() method that ViewChild has time to instantiate the TreeView instance:
ngAfterViewInit(){
//XXX: this.treeview is the TreeViewComponent instance set by ViewChild decorator
this.treeview.focus('1');
}
I have a validateConnection event within which I have a lot of conditions. Now on one of these conditions, I want to add a custom label to the link that gets created. How do I do this within validateConnection
You can try this:
prepare a 'placeholder' for the future label - it creates a label without text:
new joint.dia.Link({
labels: [
{ position: 0.5 }
]
}),
Then in the validateConnection set the label text value throught the attr
validateConnection: function(cellViewS, magnetS, cellViewT, magnetT, end, linkView) {
if (cellViewT) {
linkView.model.prop('labels/0/attrs/text/text', cellViewT.model.attr('text/text'));
} else {
linkView.model.prop('labels/0/attrs/text/text', '')
}
}
https://jsfiddle.net/vtalas/hxbfo0m4/
joint.dia.Link({
labels: [
{ position: 0.5, attrs: { text: { text: 'test' } } }
]
I need to put some additional labels on my charts, so I'm using shapes. Here is the result:
http://jsfiddle.net/z3n3qobm/91/
But I need to align the circles from the example with the labels of the X-axis. The chart must be responsive and the total of labels depends from the database.
I have a function that generates the initial position of the shapes in '%', but it misaligns when I change the window's size.
I did some calculations, but when the chart resizes it doesn't keep a fixed proportion.
Someone have an idea how to use shapes at the same position of the X-axis labels?
Unfortunately ZingChart does not provide a way to scale shapes and labels based on sizing. Hooks are available to position labels on nodes, but not on scale items themselves.
Now there I do have a solution to your issue, but just to be clear this is more of a hack utilizing tricks with ZingChart and multiple charts. I removed the shapes in your chart and decided to replicate those circles utilizing a second chart.
The main goal of this was to utilize a scatter chart, modify the look of each scatter node to replicate what you are trying to achieve, and to hide all the superficial items that were unnecessary (scales, removed plotarea margins). Do note that I'm using a mixed chart, one series for the scatter chart, and another for a dummy bar chart to force the scales to match how the chart above is displayed.
http://jsfiddle.net/mikeschultz/q6arebsu/1/
(Snippet below incase the jsfiddle is deleted in the future).
This can be also accomplished by combining the two charts into a single graphset, but I find working with separate charts is more flexible.
var myData = {
"graphset":[
{
"globals":{
"overflow":"visible"
},
"plot":{
"animation":{
"effect":"ANIMATION_EXPAND_BOTTOM",
"sequence":null,
"speed":10
},
"aspect":"jumped"
},
"plotarea": {
"margin-bottom": 30
},
"type":"mixed",
"series":[
{
"type":"bar",
"values":[46,46,53,50],
"background-color":"#5e36e6",
"value-box":{
"placement":"bottom-in",
"rules":[
{
"rule":"%v==0",
"visible":false
}
],
"thousands-separator":".",
"font-color":"#fff"
},
"palette":0
},
{
"type":"bar",
"values":[52,53,61,58],
"background-color":"#0099cd",
"value-box":{
"placement":"top",
"rules":[
{
"rule":"%v==0",
"visible":false
}
],
"thousands-separator":".",
"font-color":"#fff"
},
"palette":1
},
{
"type":"line",
"values":[150,105,399,159],
"marker":{
"size":0,
"border-width":0,
"background-color":"transparent"
},
"line-color":"#99cc33",
"line-width":3,
"value-box":{
"placement":"top",
"rules":[
{
"rule":"%v==0",
"visible":false
}
],
"thousands-separator":"."
},
"palette":2
}
],
"background-color":"#3F0767",
"scale-x":{
"tick":{
"alpha":0
},
"zooming":false,
"labels":["AB","CDE","FG","HI JKL"],
"line-width":0,
"zoom-to":null
},
"scale-y":{
"guide":{
"alpha":0.25,
"line-style":"solid",
"line-color":"#5a3b77"
},
"short":true,
"tick":{
"alpha":0
},
"line-width":0
},
"scroll-x":false
},
]
};
zingchart.render({
id : 'myChart',
data : myData,
height: 400
});
var bubbleConfig = {
type: 'mixed',
backgroundColor:"#3F0767",
scaleX: {
visible: false
},
scaleY: {
visible: false
},
plotarea: {
marginTop : 0,
marginBottom: 0,
maskTolerance: [0,0]
},
plot: {
marker: {
size: 30,
borderColor: '#371876',
borderWidth: 3,
backgroundColor: 'transparent'
},
tooltip: {
visible: false
}
},
scaleY: {
values: "0:2:1",
visible: false
},
series: [
{
type:'scatter',
values: [
[0,1],
[1,1],
[2,1],
[3,1]
],
valueBox: {
visible: true,
text: 'foobar',
fontColor: '#fff',
fontSize: '15px',
fontWeight: 'normal',
placement: 'over',
rules: [
{
rule: '%i == 0',
text: '35%'
},
{
rule: '%i == 1',
text: '51%'
},
{
rule: '%i == 2',
text: '15%'
},
{
rule: '%i == 3',
text: '36%'
}
]
}
},
{
type:'bar',
values: []
}
]
}
zingchart.render({
id : 'myBubbles',
data : bubbleConfig,
height: 80
});
<html>
<head>
<script src="http://cdn.zingchart.com/zingchart.min.js"></script>
</head>
<body>
<div id="myChart"></div>
<div id='myBubbles'></div>
</body>
</html>