How to use svelte to vertical fly in and out element - svelte-3

I'm trying to animate the tag. I want to make it fly from top to it's current position and and out to fly from it's current position to top.
<script>
import { fly } from 'svelte/transition'
let state = true
function toggle(){
state = !state
}
</script>
<div style="margin-top:4rem;padding:2rem;background:lightgray">
{#if state}
<a transition:fly="{{ y: 200, duration: 250 }}"
on:click={toggle} href="#/link1">
link1
</a>
{:else}
<a transition:fly="{{ y: 200, duration: 250 }}"
on:click={toggle} href="#/link2">
link2
</a>
{/if}
</div>
I didn't understand quite well how transitions and animations work. In this case even if y it's 200 it goes on x axis.
Here is a link to the svelte repl

Transitions in Svelte are done using CSS, in the case of fly this is through the use of the transform property. This is a property that can only be applied to transformable elements, you could read the specification or take as rule of thumb that only block level elements can be transformed. An anchor tag <a> is by default not a block but an inline element.
You can solve your problem by adding styling making the <a> tags block level either by setting display: block or display: inline-block.

Related

Angular Material vertical percentage space

How can I make one div to take certain percent of parent space verically?See the code below:
<div layout="column">
<div id="div1" flex="70%"></div>
<div id="div2" flex="30%"></div>
</div>
I want to make div1 70% height and div2 30% height of parent div. But it does not work. Div 1 and div 2 collapsed. But if the parent layout is row, it works fine---div1 takes 70% percent space horizontally.
I think you need to make the following modifications:
Specify a "height" to your outside div. This could be a percentage or pixels.
Do not use the % sign with the flex attribute
See this codepen: http://codepen.io/sebastiengiroux/pen/jPovxG
<div layout="column" style="height: 100%;">
<div id="div1" flex="70" style="background-color:red;"></div>
<div id="div2" flex="30" style="background-color:blue;"></div>
</div>
If you look into Layout docs https://material.angularjs.org/latest/layout/introduction
there is this statement that I think is relevant to your problem.
The flex attribute value is restricted to 33, 66, and multiples of five.
For example: flex="5", flex="20", flex="33", flex="50", flex="66", flex="75", ....
So I guess if you use allowed values, you can achieve results that you need. For example using 66 and 33.

Highcharts width exceeds container div on first load

I'm using Highcharts with jQuery Mobile.
I have an area graph being drawn within a jQM data-role="content" container and within that container I have the following divs:
<div style="padding-top: 5px; padding-bottom: 10px; position: relative; width: 100%;">
<div id="hg_graph" style="width: 100%"></div>
</div>
My highcharts graph is a basic graph taken from one of their examples where I have not set the chart width property.
On the first load the graph exceeds the width of the containing divs, but when I resize the browser it snaps to the appropriate width.
How can I make it so that the width of it is right on first page load and not just on resize?
I've reviewed similar posts on stack overflow and none of the solutions seem to work.
UPDATES
I've identified the problem is that the dynamically generated <rect> tag by Highcharts is taking the full width of the browser window on page load and not taking it from the containiner div width at all. Here's the html generated when I inspect:
<rect rx="5" ry="5" fill="#FFFFFF" x="0" y="0" **width="1920"** height="200"></rect>
I tried to reproduce in JSFiddle, but it seems to work fine there, which really has me stumped. Here's my JSFiddle code: http://jsfiddle.net/meandnotyou/rMXnY
To call chart.reflow() helped me.
Docs: http://api.highcharts.com/highcharts#Chart.reflow
this works like magic
put in your css file following
.highcharts-container {
width:100% !important;
height:100% !important;
}
I have the same problem, in my case had a graph of highchart that it is shown after click a button. I put $(window).resize(); after show event and it solved the problem correctly. I hope you serve.
Set width of the chart. That's the only option that worked for me.
chart: {
type: 'line',
width: 835
},
Define the highcharts inside the document ready:
<div style="width:50%" id="charts">
and the script:
$(document).ready(function(){
$(#chart).highcharts(){
...
});
)};
Hope it works ;)
I had a similar issue with centering the highcharts graph it gave. It would center and size correctly for some resolutions but not all. When it didn't, I had the exact same symptoms you're describing here.
I fixed it by attaching/overriding additional css to the highcharts default.
so in a custom css file, adding
.highcharts-container{
/** Rules it should follow **/
}
should fix your issue. Assuming that your div "hg=graph" has nothing but highcharts.
For those using angular and custom-built components, remember to define a dimensioned display in css (such as block or flex) for the host element.
And when the chart container has padding, you might find this indispensable:
html
<chart (load)="saveInstance($event.context)">
...
</chart>
ts
saveInstance(chartInstance: any) {
this.chart = chartInstance;
setTimeout(() => {
this.chart.reflow();
}, 0);
}
Otherwise the chart will bleed past the container on load and get its correct width only at next browser reflow (eg. when you start to resize window).
The best way is to call chart.reflow in render event function documentation;
Highcharts.stockChart( 'chartContainer', {
chart: {
events: {
render: function() {
this.reflow();
}
},
zoomType: 'x',
...
},
and remember to set min-width to zero and overflow to hidden in chart container.
#chartContainter {
min-width: 0;
overflow: hidden;
}
I just ran into the same problem today - not on mobile, but with a window sized small on first page load. When the page loads, the chart is hidden, then after some selections on the page, we create the chart. We have set a min-width and max-width for the container in css, but not a width.
When the chart is being created, it needs to determine the dimensions to create the SVG . Since the chart is hidden, it cant get the dimensions properly so the code clones the chart container, positions it off-screen and appends it to the body so that it can determine the height/width.
Since the width is not set, the cloned div tries to take as much space as it can - up to the max-width that I had set. The SVG elements are created using that width, but added to the chart container div which currently is smaller (based on the size of the screen). The result is that the chart extends past the container div's boundaries.
After the chart has rendered the first time, the on-screen dimensions are known and the clone function is not called. This means that any window resizes, or reloading of the chart data cause the chart to size correctly.
I got around this initial-load problem by overriding the Highcharts function cloneRenderTo which clones the div to get dimensions:
(function (H) {
// encapsulated variables
var ABSOLUTE = 'absolute';
/**
* override cloneRenderTo to get the first chart display to fit in a smaller container based on the viewport size
*/
H.Chart.prototype.cloneRenderTo = function (revert) {
var clone = this.renderToClone,
container = this.container;
// Destroy the clone and bring the container back to the real renderTo div
if (revert) {
if (clone) {
this.renderTo.appendChild(container);
H.discardElement(clone);
delete this.renderToClone;
}
// Set up the clone
} else {
if (container && container.parentNode === this.renderTo) {
this.renderTo.removeChild(container); // do not clone this
}
this.renderToClone = clone = this.renderTo.cloneNode(0);
H.css(clone, {
position: ABSOLUTE,
top: '-9999px',
display: 'block' // #833
});
if (clone.style.setProperty) { // #2631
clone.style.setProperty('display', 'block', 'important');
}
doc.body.appendChild(clone);
//SA: constrain cloned element to width of parent element
if (clone.clientWidth > this.renderTo.parentElement.clientWidth){
clone.style.width = '' + this.renderTo.parentElement.clientWidth + 'px';
}
if (container) {
clone.appendChild(container);
}
}
}
})(Highcharts);
I saved this function in a separate script file that loads after the Highchart.js script has loaded.
try and encapsulate the highchart generation inside a pageshow event
$(document).on("pageshow", "#hg_graph", function() {...});
I resolved this problem (for my case) by ensuring that the containing UI elements render before the chart, allowing Highcharts to calculate the correct width.
For example:
Before:
var renderChart = function(){
...
};
renderChart();
After:
var renderChart = function(){
...
};
setTimeout(renderChart, 0);
I have been having this issue too, and the .highcharts-container css solution wasn't working for me. I managed to solve it for my case by splitting out an ng-class condition (which was setting different widths for the container div) into separate divs.
eg, this
<div ng-class="condition?'col-12':'col-6'">
<chart></chart>
</div>
into
<div ng-show="condition" class="col-12">
<chart></chart>
</div>
<div ng-show="!condition" class="col-6">
<chart></chart>
</div>
I couldn't really tell you why it worked though. I'm guessing the ng-class takes longer to calculate the container width and so highcharts renders first with an undefined width? Hopefully this helps someone anyway.
I also have the same issue in my app where i am using angular
and i also using ngCloak directive which i have removed as i don't need it
after doing this my problem is solved.
I have just seen that sometimes there are several issues going on at the same time.
If it happens the height exceed the expected heigh:
SCSS style:
.parent_container{
position:relative;
.highcharts-container{position: absolute; width:100% !important;height:100% !important;}
}
If the width exceeds the container (bigger than what's supposed to) or does not resize properly to smaller one:
let element = $("#"+id);
element.highcharts({...});
// For some reason it exceeds the div height.
// Trick done to reflow the graph.
setTimeout(()=>{
element.highcharts().reflow();
}, 100 );
The last one happened to me when destroying the chart and creating a new one... the new one was coming with width extra size.
I have been also bump into this issue. both affected in desktop and mobile view of the chart.
In my case i have a Chart that update the series color depending on min or max.After updating the points, the highcharts width exceeds container div on its first load.
To fix that, what i did is add chart.reflow(); after the update of points.
CODE:
//First declare the chart
var chart = $('#TopPlayer').highcharts();
//Set the min and max
var min = chart.series[0].dataMin; //Top Losser
var max = chart.series[0].dataMax; //Top Winner
for (var i = 0; i < chart.series[0].points.length; i++) {
if (chart.series[0].points[i].y === max) {
chart.series[0].points[i].update({
color: 'GREEN',
});
}
if (chart.series[0].points[i].y === min) {
chart.series[0].points[i].update({
color: 'RED',
});
}
}
// redraw the chart after updating the points
chart.reflow();
Hope this helps to those who has the same issue like me. :)
Here's a solution that worked for me ! The charts were working fine for a while and then after a feature they started exceeding their container. Turns out it was the defer attribute on the script in the head of my application.
Try removing defer on your javascript tags:
<script defer src="script.js"></script>
to
<script src="script.js"></script>
Or moving my stylesheet link higher in the head also seemed to fix it but it's a less reliable solution..
This may have been introduced since the OP in 2013, but you should be able to set height with chart.height (https://api.highcharts.com/highcharts/chart.height)
options: {
chart: {
type: 'bar',
height: window.innerHeight + 'px',
},
title: {
text: 'Top 10 Users',
},
subtitle: {
text: 'by scores',
},
This is a web based solution, but I would expect you could cater it to jQuery.mobile
None of the answers helped me. I dynamically change chart data and the top answer solution ruins the animations and causes a jump in the chart position.
The workaround that I finally came up with was to set some padding for the chart wrapper element (in my case some part of the chart to left was hidden, so I gave some left padding), and then set the chart main element overflow property to visible. It works and the animations are just fine. You may need some experimenting with padding value to get it perfectly displayed.
<div class="chart-wrapper">
<!-- high charts main element here -->
</div>
and the style
.chart-wrapper{
padding-left: 20px;
}
.chart-wrapper > div:first-child{
overflow: visible !important;
}
for me, I set chart width:
$('#container').highcharts({
chart: {
backgroundColor: 'white',
**width:3000**,
..... }
and in html set overflow:auto
<div id="container" style="**width:100%;overflow:auto**;" ></div>
I struggled with this for way too long, and found a solution that works for me. A little bit of background on my setup:
The highcharts chart was loading on a tab on my website that is not visible upon logging into the site.
When switching to that tab, the chart was well outside the div.
So, I attached a unique ID to that particular tab, we'll call it tab5, and then bound a click function that forced - and this is the important part - the <svg> element within the container div to 100% using jQuery:
$('#tab5').bind('click', function() {
$('#container_div svg').width('100%');
});
...and my sanity has been restored. For the moment.
Please add width:100% to chart container.
Hope this will resolve overflow:hidden related issue.
classname{min-height:450px;width: 100%;}

Highcharts tooltip is hidden behind other charts

When putting multiple charts tooltips from upper charts are hidden behind others.
I found some tips on how to it but nothing helped.
Is there anyway to keep tooltips on top of charts?
The example is here: http://jsfiddle.net/Zw3uM/
Thanks a lot!
This is pure html : Any div element loaded after ( meaning appearing after on the html page) will always be in front.
In order to get the first chart tooltip be in front of the second : load the second in first and set its y position on the page using an absolute or relative position in css :
I've change their order, putting the container2 in first in html:
<div id="container2" style="height: 200px"></div>
<div id="container1" style="height: 200px"></div>
Then set the position of container2 to be under the first one (thanks to the top style attribute) :
div[id="container2"] {
position:absolute;
top:200px;
}
Here is the result : http://jsfiddle.net/Zw3uM/3/
You can use tooltip pisitioner:
http://api.highcharts.com/highcharts#tooltip.positioner
The problem is due to each highchart container having its own stacking context. This is because the highcharts-container has both position: relative and z-index: 0 (css dynamically applied by the highcharts library).
So the z-index of the tooltip has meaning only in its parent highchart container.
To fix this we need to override the (z-index: 0) rule for the highcharts-container using the following:
.highcharts-container
{
z-index: auto !important;
...
}
This way all hightcharts-containers & their children would share the same stacking context and their z-indices would apply the desired effect.
You can check the fix here: http://jsfiddle.net/w5bLo1cw/4/

Why does the height of the content area of an inline element larger than the value specified by font-size?

In a document like:
<p class="wrapper">
<span class="ref">
<span class="text">English</span>
</p>
the following rules are applied:
.wrapper {
background:green;
position:relative;
padding-left:20px;
font-family:Times;
}
.text {
line-height:1;
background:blue;
font-size:80px;
}
.ref {
position:absolute;
left:5px;
width:10px;
height:80px;
background:black;
}
In Chrome (Version 22.0.1229.79) or IE9, the background of the span element containing 'English' seems to have a height larger than font-size, yet in Firefox (13.0.1) the height equals font-size. (See the output)
Can anybody explain this?
I thought the height of the content area would have the same value as specified by font-size.
Here's a diagram showing the various reference lines available when rendering text:
As you can see, there are many choices. It seems like Firefox is using a different baseline than Chrome/IE when rendering.

CSS, HTML: How can i make the div or <p> width dynamic as the text line increses/decreses

There is a line of text inside a <div></div> or inside <p></p>.
The text length changes when clicking some links.
If the text length decreases the div or p will decrease.
If the text length increases the div or p will increase.
How can i do this ?
The problem is the div or p width looks fixed and the length of text is 30% of that div or p.
The div or p has a background color. So whole div or p is colored. But what i'm trying to do is to color the portion of background of div or p, the portion that contains text of line.
Wrap the text in a <span></span> and style that instead?
It sounds to me like you're struggling with the difference between an inline and block level element, but forget about that a second and let's get to what you want. Without seeing your code... an easy way to fix that is to make your block level elements p and div float to the left. From what you've said, this should be close to what you want (check the jsFiddle).
div {
float:left;
background:red;
}
Ok, so what is a block level element? A div and p are block level elements. As per the Mozilla Developer Network "Their most significant characteristic is that they typically are formatted with a line break before and after the element (thereby creating a stand-alone block of content)." This is why with default styling it expands to the entire line. This sounds like exactly what you didn't want. Where as a span will shrink down to fit just the content that it contains.
If you want a more complicated "real-world" example, I've thrown together this jsFiddle that might help you down your path.
Ah, you're doing Rails! Ok, here's your real answer. Just check to see if the flash[:notice] exists before displaying it to the screen.
<% if flash[:notice] %>
<p class="customnotice"><%= flash[:notice] %></p>
<% end %>

Resources