I've just wrote a mixin supposed to display an #2x icon version for retina display.
First, here is an example of an icon name :
images/icon/close-black.png
images/icon/close-black#2x.png
Here is the mixin :
#mixin background-image-retina($type, $file, $color, $ext) {
background-image: url('src/assets/images/' + $type + '/' + $file + '-' + $color + '.' + $ext);
#media only screen and (-webkit-min-device-pixel-ratio: 2),
only screen and (-moz-min-device-pixel-ratio: 2),
only screen and (-o-min-device-pixel-ratio: 2/1),
only screen and (min-device-pixel-ratio: 2),
only screen and (min-resolution: 192dpi),
only screen and (min-resolution: 2dppx){
& {
background-image: url('src/assets/images/' + $type + '/' + $file + '-' + $color + '#2x.' + $type);
}
}
}
So I call my mixin :
#include background-image-retina(icon, close, black, png);
And here the result, and here is the problem :
background-image: url(src/assets/images/icon/close-#000.png);
My question :
Does anyone know how to specify the icon color without compiling it in an actual HEX color?
Thanks for your help!
A/W
[EDIT: SOLUTION FOUND]
To avoid color-like names compilation in your mixin, just add quotation marks around it.
black -> #000
"black" -> black
I think you might have an old version of SASS. Surrounding colors in strings is fine, but it's unnecessary. Also if you interpolate the value, even in older versions, I think it will fix your issue; plus it's shorter and easier to follow. I made you a sassmeister with both; comparing interpolated and non-interpolated variables in a newer version of SASS. But here's basically what I'm saying:
#mixin background-image-retina($type, $file, $color, $ext) {
background-image: url('src/assets/images/#{$type}/#{$file}-#{$color}.#{$ext}');
#media only screen and (whatevs) {
& {
background-image: url('src/assets/images/#{$type}/#{$file}-#{$color}#2x.#{$type}');
}
}
}
.hey { #include background-image-retina(icon, close, black, png); }
Related
I have many spans that are one next to each other and I'd like to add some linear-gradient effect - so the first one has background-color: $a, the last one background-color: $b and the spans between the "transition color from $a to $b". If I'm not making any sense, this image will help you:
I tried with lighten(), but it only uses one color.
Here's the current SCSS:
$starting_color: #177DEF;
$ending_color: #2FF0D5;
$elements: 51;
#for $i from 0 to $elements {
span:nth-child(#{$i}) {
height: random(260) + px;
background-color: lighten($starting_color, $i);
}
}
Whole fiddle on Codepen
How can I create this "effect"? Possible with some step parameter (step count = all spans)
This is quite lengthy, but it works:
//$blue: #177DEF;
$firstR: 23;
$firstG: 239;
$firstB: 125;
$blue: rgb(23, 125, 239);
//$green: #2FF0D5;
$secondR: 47;
$secondG: 240;
$secondB: 213;
$green: rgb(47, 240, 213);
body{
background-color: #000;
}
#panel {
font-size: 0;
}
span {
font-size: 16px;
display: inline-block;
vertical-align: bottom;
width: 10px;
&:not(:first-of-type) {
margin-left: 2px;
}
}
$elements: 51;
$redDiv: ($firstR - $secondR) / $elements;
#if $redDiv < 0 {
$redDiv: $redDiv * -1
}
$greenDiv: ($firstG - $secondG) / $elements;
#if $greenDiv < 0 {
$greenDiv: $greenDiv * -1
}
$blueDiv: ($firstB - $secondB) / $elements;
#if $blueDiv < 0 {
$blueDiv: $blueDiv * -1
}
#for $i from 0 to $elements {
$redValue: $redDiv * $i;
$greenValue: $greenDiv * $i;
$blueValue: $blueDiv * $i;
span:nth-child(#{$i}) {
height: random(260) + px;
background-color: rgb($firstR + $redValue, $firstG + $greenValue, $firstB + $blueValue);
}
}
I converted the hexadecimal values to RGB here, then made separate variables for each red, green, blue value in both colors.
Subtract the second value from the first then divide by how many elements (this gives you the amount of change needed each iteration).
Make sure the values aren't negative with #if.
Calculate the change by multiplying by $i and then add/subtract that change depending upon which value was lesser (first or second). If first value is less then $first + $value, if second value is less then $first - $value.
This was the only part that needs to be changed depending on the colors, the rest will work for any RGB value.
Codepen: http://codepen.io/anon/pen/ezpmXJ
There seems to be a couple of different projects with this goal, with different levels of completion. I have just done a quick search, but that was my first impression. So I thought I should ask, anyone who has tested some different options? What was your experience?
I use SVG with Haxe and was a smoth experience, first I create all my svg's with inkscape and then manipulate it with jquery extern so you have something like this
var width:Int = seatmap.innerWidth();
var vsvg:SVGElement = cast(new JQuery("#seatmap").find("svg")[0],
SVGElement);
var height:String = vsvg.getAttribute("height");
if (height > 1200) {
vsvg.setAttribute('viewBox', "0 0 1200 "+ height);
}else if (width <= 1200 && width > 1024) {
vsvg.setAttribute('viewBox', "0 0 1500 "+ height);
} else if (width <= 1024) {
vsvg.setAttribute('viewBox', "0 0 1900 "+ height);
}
also you can change attributes on the fly
new JQuery("#xxx-" + aaa.bb).attr("fill-opacity","1");
new JQuery("#aax-" + aaa.bb).attr("fill","#ff0");
You could use the Rafael.js and D3.js externs for haxe to render content on the fly, working with the javascript externs is the same as javascript but you have strong types and avoid the javascript weirdness.
Hope this helps.
I have a bunch of images, with different resolution.
Also there is a mix of landscape and portrait pictures. I need to resize the images to one resolution (1024x768). If i have a portrait picture, the max height needs to be 768, and my landscape pictures has to have a max width of 1024.
The space that is over, has to be made black.
Right now i use mogrify -resize 1024x768 -verbose *.jpg
I know i can use 1024x!768 , but like i said i'm using different kind of pictures.
My exif information also doesn't contains information about if a picture is landscape or not.
I use ImageMagick for such tasks. When installed, you have the "convert" command, which is very common, and does your task easyly.
You will have to crop the image to get the same aspect ratio, then you can resize the image to get the desired resolution. Example code using nodejs (imagemagick command line tools):
var width = 166;
var height = 117;
var ratio_new = width/height;
var ratio_old = image_file.width_orig/image_file.height_orig;
var pixels_too_much = 0;
var geometry = '';
if (ratio_old > ratio_new)
{
config.debug && console.log ("remove horizontal pixel!");
pixels_too_much = parseInt(image_file.width_orig - (image_file.height_orig * ratio_new))-1;
geometry = parseInt(image_file.height_orig * ratio_new + 0.5) + 'x' + image_file.height_orig;
geometry += "+" + parseInt(pixels_too_much/2) + "+0\!";
}
else if (ratio_old < ratio_new)
{
config.debug && console.log ("remove vertikal pixel");
pixels_too_much = parseInt(image_file.height_orig - (image_file.width_orig / ratio_new));
geometry = image_file.width_orig + 'x' + (image_file.width_orig / ratio_new);
geometry += "+0+" + parseInt(pixels_too_much/2)+"\!";
}
im.convert([image_file.path, '-crop', geometry, '-resize', width + 'x' + height, thumb_path],function(){});
I've got a little text drawing puzzle under Win32. I'm trying to draw some instructions for users of my application at the top of the window.
Please refer to the following window (I've changed the background color on the text so you can see the boundaries)
(source: billy-oneal.com)
I'm currently using DrawTextEx to draw the text to my window, but the problem is that it does not fill the entire RECTangle that I give it. Not drawing that area is just fine, until the window resizes:
(source: billy-oneal.com)
When the text is re wrapped due to the window sizing, because DrawTextEx doesn't clear it's background, these artifacts are leftover.
I tried using FillRect to fill in the area behind the text drawing call, which does eliminate the visual artifacts, but then causes the text to flicker constantly, as it is completely erased and then completely redrawn to the display.
Any ideas on how one might get the area not containing text to be drawn with the background color?
EDIT: I'd like to avoid having to double buffer the form if at app possible.
EDIT2: I solved the problem by only redrawing the text when I detect that the wrapping changes during a resize.
Use double buffering?
Draw everything to a bitmap and draw the bitmap to the window. Flickering is commonly a double buffering issue.
There are many possible solutions and without seeing your code, it's hard to tell which method would be best so I'd suggest taking a look at this article on flicker free drawing
SetBkMode + SetBkColor ?
Well since nobody seems to know what to do about it, I implemented it this way:
std::vector<std::wstring> wrapString(HDC hDC, const std::wstring& text, const RECT& targetRect, HFONT font)
{
std::vector<std::wstring> result;
RECT targetRectangle;
CopyRect(&targetRectangle, &targetRect);
//Calculate the width of the bounding rectangle.
int maxWidth = targetRectangle.right - targetRectangle.left;
//Draw the lines one at a time
std::wstring currentLine;
for(std::wstring::const_iterator it = text.begin(); it != text.end(); currentLine.push_back(*it), it++)
{
if(*it == L'\r' || *it == L'\n')
{ //Hard return
while(it != text.end() && (*it == L'\r' || *it == L'\n')) it++;
result.push_back(currentLine);
currentLine.clear();
}
else
{ //Check for soft return
SIZE sizeStruct;
GetTextExtentPoint32(hDC, currentLine.c_str(), static_cast<int>(currentLine.length()), &sizeStruct);
if (sizeStruct.cx > maxWidth)
{
std::wstring::size_type lineLength = currentLine.find_last_of(L' ');
if (lineLength == currentLine.npos)
{ //Word is longer than a line.
for(;it != text.end() && !iswspace(*it);it++) currentLine.push_back(*it);
}
else
{ //Clip word to line.
//Backtrack our scan of the source text.
it -= currentLine.length() - lineLength - 1;
//Remove the clipped word
currentLine.erase(lineLength);
}
result.push_back(currentLine);
currentLine.clear();
}
}
}
//Last remaining text.
result.push_back(currentLine);
return result;
}
void DrawInstructionsWithFilledBackground(HDC hDC, const std::wstring& text, RECT& targetRectangle, HFONT font, COLORREF backgroundColor)
{
//Set up our background color.
int dcIdx = SaveDC(hDC);
HBRUSH backgroundBrush = CreateSolidBrush(backgroundColor);
SelectObject(hDC, backgroundBrush);
SelectObject(hDC, font);
SetBkColor(hDC, backgroundColor);
std::vector<std::wstring> lines(wrapString(hDC, text, targetRectangle, font));
for(std::vector<std::wstring>::const_iterator it = lines.begin(); it!=lines.end(); it++)
{
RECT backgroundRect = targetRectangle;
DrawText(hDC, const_cast<LPWSTR>(it->c_str()), static_cast<int>(it->length()), &backgroundRect, DT_CALCRECT | DT_NOCLIP | DT_SINGLELINE);
backgroundRect.left = backgroundRect.right;
backgroundRect.right = targetRectangle.right;
if (backgroundRect.right >= backgroundRect.left)
FillRect(hDC, &backgroundRect, backgroundBrush);
ExtTextOut(hDC, targetRectangle.left, targetRectangle.top, ETO_OPAQUE, NULL, it->c_str(), static_cast<UINT>(it->length()), NULL);
targetRectangle.top += backgroundRect.bottom - backgroundRect.top;
}
instructionsWrap = lines;
//Restore the DC to it's former glory.
RestoreDC(hDC, dcIdx);
DeleteObject(backgroundBrush);
}
Get/Calculate the rect used by the DrawText call and clip it with something like ExcludeClipRect before calling FillRect
I'm trying to produce a line chart using Flot, but I want the data labels to show up on the chart - meaning, I want the value of each point to appear next to that point. I feel like this should be an option, but can't find it in the API. Am I just missing something, or does someone know a workaround?
Thanks in advance.
Here is how I added the feature, including a pleasant animation effect:
var p = $.plot(...);
$.each(p.getData()[0].data, function(i, el){
var o = p.pointOffset({x: el[0], y: el[1]});
$('<div class="data-point-label">' + el[1] + '</div>').css( {
position: 'absolute',
left: o.left + 4,
top: o.top - 43,
display: 'none'
}).appendTo(p.getPlaceholder()).fadeIn('slow');
});
You can move the position and display css to a stylesheet.
The feature you want is requested here in the Flot Google group. It doesn't look like it was ever implemented (there's nothing in the API about putting any labels inside the chart itself). I think that the answer to your question is that No, it's not possible at this time to show values next to certain points on lines inside the graph.
Ole Larson, head developer on Flot, mentioned that showing labels inside the chart is different than anything else on FLot and that they would have to think about how to extend the API / plot parameters to do it.
That said, you might want to go post a question on the Flot forum or make a suggestion on the bug-tracker for the new feature. Ole Larson is actually really good at getting back to all the questions, bugs, and suggestions himself.
If anyone else is looking for a quick solution, see this plugin:
http://sites.google.com/site/petrsstuff/projects/flotvallab
Looks like the flot-valuelabels plugin is a fork of a previous flot plugin -- but the forked code renders the labels on the canvas. You can see a demo of what this looks like on the plugin's Github wiki page, here (it looks quite pleasing to the eye).
function redrawplot() {
$('.tt1').remove();
var points = plot.getData();
var graphx = $('#placeholder').offset().left;
graphx = graphx + 30; // replace with offset of canvas on graph
var graphy = $('#placeholder').offset().top;
graphy = graphy + 10; // how low you want the label to hang underneath the point
for(var k = 0; k < points.length; k++){
for(var m = 1; m < points[k].data.length-1; m++){
if(points[k].data[m][0] != null && points[k].data[m][1] != null){
if ((points[k].data[m-1][1] < points[k].data[m][1] && points[k].data[m][1] > points[k].data[m+1][1]) && (points[k].data[m-1][1] - points[k].data[m][1] < -50 || points[k].data[m][1] - points[k].data[m+1][1] > 50)) {
showTooltip1(graphx + points[k].xaxis.p2c(points[k].data[m][0]) - 15, graphy + points[k].yaxis.p2c(points[k].data[m][1]) - 35,points[k].data[m][1], points[k].color);
}
if ((points[k].data[m-1][1] > points[k].data[m][1] && points[k].data[m][1] < points[k].data[m+1][1]) && (points[k].data[m-1][1] - points[k].data[m][1] > 50 || points[k].data[m][1] - points[k].data[m+1][1] < -50)) {
showTooltip1(graphx + points[k].xaxis.p2c(points[k].data[m][0]) - 15, graphy + points[k].yaxis.p2c(points[k].data[m][1]) + 2,points[k].data[m][1], points[k].color);
}
}
}
}
}
function showTooltip1(x,y,contents, colour){
$('<div class=tt1 id="value">' + contents + '</div>').css( {
position: 'absolute',
display: 'none',
top: y,
left: x,
'border-style': 'solid',
'border-width': '2px',
'border-color': colour,
'border-radius': '5px',
'background-color': '#ffffff',
color: '#262626',
padding: '0px',
opacity: '1'
}).appendTo("body").fadeIn(200);
}