I am making a visualization using the D3 javascript library. I would like to create tooltips for some of the elements of the visualization and and my client wants them to look like a 'paper snippets/post-its'. Initially I created plain DIV's for the tooltips using some nice CSS tricks to create the desired appearance. (inspired by this tutorial)
I would like to use encapsulate the tooltips into the SVG foreignObject-element so its better fits to the visualization and I can manipulate them easily. (e.g. zooming/panning) So my question is : how to get the proper size of the DIV, which lies inside the foreignObject-element, so I can set the size of the foreignObject-element accurately ? Especially when using margin/padding/shadow ....
I figured it out by using .getBoundingClientRect() but I do not know if this is the best way.
Here is a code-example :
var body = d3.select("body");
var svg = body.append("svg");
var tooltipContainer = svg.append("svg:g");
var html = tooltipContainer.append("foreignObject")
var div = html.append("xhtml:div")
.attr('class', 'paper-tooltip')
.html("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec eu enim quam. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec eu enim quam. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec eu enim quam. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec eu enim quam. ");
var bcr = div[0][0].getBoundingClientRect();
html.attr('x', 50)
.attr('y', 50)
.attr('width', bcr.width)
.attr('height', bcr.height);
svg.call(d3.behavior.zoom().on('zoom', redrawOnZoom));
function redrawOnZoom(){
tooltipContainer.attr('transform', 'translate(' + d3.event.translate + ')' + ' scale(' + d3.event.scale + ')');
};
Here is a working jsFiddle example : http://jsfiddle.net/jhe8Y/1/
EDIT:
I realized, that for different shadow-box settings the .getBoundingClientRect() will not work. i also realized that with my first solution the .getBoundingClientRect() returns too-large size, especially on the right size.
So I tried another way by using the jQuerys .outerWidth(true)/.outerHeight(true) and computing the shadow size manually. This seems to work fine, but it feels just terribly to do something like that.
Is there any other way how to get the exact size of a DIV with all it's components ?
Updated jsFiddle is here : http://jsfiddle.net/jhe8Y/3/
You don't need to scale it up and down. There is no real use of it, right? Then you can set both foreignObject height and width to 1, and via CSS set foreignObject { overflow: visible; }.
I've struggled with this before and I've found that the easiest thing to do is just rely on Bootstrap's Tooltip.
E.g.
// title: this is what gets shown as the title in the tooltip
d3.select('svg').attr('title','This is my tooltip title');
// content: this will show up as the content if you go for
// popovers instead .
d3.select('svg').attr('data-content','This is some content');
// set the options – read more on the Bootstrap page linked to above
$('svg').popover({
'trigger':'hover'
,'container': 'body'
,'placement': 'top'
,'white-space': 'nowrap'
,'html':'true' // preserve html formatting
});
It boils down to, adding title and data-content attributes to whatever svg element you're interested in adding tootltips to. Then, set the content equal to whatever you want. So, in your case, the html would be
<div class='paper-tooltip'>Lorem ipsum dolor sit amet, ... etc etc.</div>
Related:
How do I show a bootstrap tooltip with an SVG object; Question on Stack Overflow
Bootstrap Tooltips
My super-short blog post on it
Related
I am using Angular6.
I have a pre tag with email text. Within this email text are tags like [cid:image001.jpg] which represent an image, using image001.jpg, I can retrieve that specific image from the back-end.
The problem is that I don't know how I can insert a new HTML element from the Typescript file into the pre tag, if this is even possible.
I have tried using a replace() method and replacing the '[cid:image001.jpg]' with '<img ...>' but it (understandably) gets interpreted as a string.
Help would be much appreciated.
Edit:
the positioning of the images is important, the <img> tag should appear where the [cid:image001.jpg] is, for example.
Example email:
Greetings,
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum
vehicula egestas elit viverra auctor. [cid:image001.jpg] Morbi at
nisi vel lorem porta pellentesque ut non urna.
Integer tempor tincidunt viverra. Vivamus ullamcorper et risus ac.
[cid:image002.jpg]
Best regards...
Can you try to pass the image in argument like this:
<img [cid]="pictureUrl">
I fixed this by doing the following, I changed:
<pre> {{emailText}} </pre>
To:
<pre innerHTML="safeHTML(emailText)"> </pre>
Where safeHTML() cleans the text so that scripting is not possible, this is important because it would be very unsafe otherwise.
I'm very new to coding, and am currently teaching myself html/css and i found that my paragraphs weren't centering in the middle of the page. I'd had my headline and sub headline labelled as h1 and h2, so i thought naturally the paragraphs would be the same (even though they had exactly the same declarations), yet when i changed both the elements to just p and brought them both under the same selector it worked. I was wondering if p1/p2 using would cause a lot of problems in the future? (this was before i was learning about ID's and classes, would that be the correct way to differentiate between paragraphs instead?)
please be kind, I've been learning less than a couple weeks:)
p1 and p2 are not valid HTML elements in themselves.
Granted, with HTML5, you can define your own elements where necessary, however this is usually reserved for instances where it makes your markup more semantic, and usually with a front-end framework or such.
With paragraphs, if you must differentiate between them, then I would suggest using classes.
<h1>Heading One</h1>
<h2>Heading Two</h2>
<p class="p1">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean volutpat efficitur magna eget tincidunt.</p>
<p class="p2">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean volutpat efficitur magna eget tincidunt.</p>
Paragraphs are always <p>. Only the header elements have this kind of numbering.
My personal reccomendation would be to use ID's rather than Classes. This is due to the nature of what seem to you want in your question.
ID's are unique - meaning that there can only be one of them per page.
Classes aren't unique - meaning that they can be assigned to multiple objects per page.
<p id="one">This is paragraph one.</p>
<p id="two">This is paragraph two.</p>
Is there any way to text wrapping into two or more columns in HTML only with CSS?
I have continous text with p tags only like this:
<div id="needtowrap">
<p>Lorem ipsum dolor sit amet, ...</p>
<p>Nulla ullamcorper diam arcu, ...</p>
<p>In libero diam, facilisis quis urna nec, ...</p>
<p>Sed varius et mi quis dictum. ...</p>
</div>
I wan to wrap this text into two columns at 50% of the text, like in Microsoft Word or LibreOffice, etc.
It is possible?
See the "column" rule:
http://www.w3schools.com/css/css3_multiple_columns.asp
As you can see, it's a CSS3 rule, and so you might not find browser support as complete as you'd like..
MDN:
https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Using_multi-column_layouts
Breakdown of browser support:
http://caniuse.com/#feat=multicolumn
More reading, examples etc:
http://css-tricks.com/guide-responsive-friendly-css-columns/
(fairly comprehensive)
Multi-column layout in CSS with the columns property and related properties is rather well supported in modern browsers. At the very simplest, you would set just columns: 2 on the div element. In practice, you additionally need vendor prefixed versions for reasonable browser coverage:
#needtowrap {
-webkit-columns: 2;
-moz-columns: 2;
columns: 2;
}
#needtowrap p {
margin: 0;
}
#needtowrap p + p {
text-indent: 1em;
}
<div id="needtowrap">
<p>Lorem ipsum dolor sit amet, ...
Well we need some real content too.
Otherwise this looks rather dull.</p>
<p>Nulla ullamcorper diam arcu, ...
And some more text to make this look like a paragragh.</p>
<p>In libero diam, facilisis quis urna nec, ...
By the way, fake Latin is not good fill text.
It behaves differently from the texts you will really use.</p>
<p>Sed varius et mi quis dictum. ...
But I digress.</p>
</div>
The example uses ”literary paragraph” formatting: instead of default vertical spacing between paragraphs, the first line of each paragraph except the first one is indented a bit. In multi-column rendering, this works much better than the default p formatting (which reflects defaults of office automation software rather than typographic traditions).
There are many other things to consider. As a rule, multi-column text usually looks much better when justified on both sides. This in turn makes hyphenation more or less a necessity.
How can I display negative numbers in right to left textbox, with the minus on the left of the number?
Current state: 1-
Desired state: -1
On your textbox you just need to reset the direction, and align the text to the right:
BODY {
direction: rtl;
}
#test {
direction: ltr;
text-align: right
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div>
Lorem ipsum dolor sit amet consectetuer adipiscing elit. Lorem ipsum dolor sit amet consectetuer adipiscing elit. Lorem ipsum dolor sit amet consectetuer adipiscing elit. Lorem ipsum dolor sit amet consectetuer adipiscing elit.<br />
<input type="text" id="test" value="-109309" />
</div>
This is a general issue with RTL/LTR when it comes to contexts in UI.
Short answer: The best approach is to dedicate numerical inputs and string inputs to separate textboxes. Numbers for most RTL languages (not all, beware!) are LTR, and strings are RTL, and splitting the context allows you to define your inputs properly.
Example -
Place: <input type="text" dir="rtl" />
Temperature: <input type="number" dir="ltr" />
Note that W3C recommends setting the language in the html markup rather than the CSS, which is also better for accessibility and screen readers. Adding a lang="" attribute is also recommended, if possible.
There are several good reasons to split textboxes for strings and numbers separately when possible, especially for RTL/LTR:
This is usually a good UX decision, because it makes it clear to your user what they are expected to type.
You get a clear distinction in your code (or whatever analyzes the form fields) about what is a string and what is a numberical input, for whatever calculations or display concerns.
When you display the results, you can make sure the number and text are displayed correctly (using <span dir="ltr">...</span> or dir="rtl" when relevant)
Defining an input as numerical allows mobile devices to load the number pad rather than the full keyboard, which is a bonus for UX.
I know this question is several years old, but I hope this can help with the new considerations (and some technology updates since then, especially mobile) to anyone interested in supporting RTL or mixed directions in their forms.
I am in the middle of a web app and we're just about to start with a cache-layer that features memcache and disk-based cache.
We just questioned ourself - what level/amount of formatting should we use on the stored cache data?
Let say that we have a database table called articles. Articles table have a number of columns including headline and content.
If we we're about to store this as an array, it would look like this:
array (
'headline' => 'Brilliant news - sunshine all week',
'content' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis a
semper mi. Aenean rutrum ultrices mauris sed dictum. ');
Or, the pre-formatted HTML version:
<div class="article">
<h1>Brilliant news - sunshine all week</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis a
semper mi. Aenean rutrum ultrices mauris sed dictum. </p>
</div>
Pros and cons
Obviously, the pre-formatted html version increases the size of each cached datablock, since it includes a number of html tags. Also, there will be some headache included if the data were about to be formatted in different ways (I don't think that we will do this though). The option for that is of course to instead store multiple versions of each article in the cache.
So, what's common sense to do in our case? Let the HTML be rendered each time based upon the array that are retrieved from memcache, or just output the pre-formatted html?
I think it all depends on performance you need but I would use array version as it give possibility to play with content before rendering. Also building HTML having content is usually quite cheap when compared to getting content itself.