JQVMAP Country Coloring - colors

I am using JQVMAP at here. When I have a country that has members I desire to change that country's color without mousing over it, as the map is displayed.
I am using the following sql to get the countries and the number of their members. My question is what do I do, once I have a country, to change that countries map color? All countries will have the same color.
$result=mysql_query("SELECT COUNT(profile3.organizations) total_org, LEFT(countryCODEconversions.Code, 2) FROM profile3, countryCODEconversions WHERE TRIM(MID(countryCODEconversions.Code, 4, 147)) = profile3.country GROUP by profile3.country");
//if(mysql_num_rows($result)>0){
$counter = "";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC))
{
foreach ($line as $value) {
$counter += 1;
$value = stripslashes($value);
if ($counter == 1){$total = nl2br($value);}
if ($counter == 2){
$counter = 0;
$countryCode = strtolower($value);
?>
gdpOrgData['<?=$countryCode?>']=("<?=$total?>");
<?

Normaly, after loading the map you can set the color of countries that need a different color like this:
jQuery(document).ready(function() {
jQuery('#vmap').vectorMap('set', 'colors', {lt: '#8c9622',
sv: '#8c9622',
yr: '#8c9622'});
});
You could use PHP to generate the list in this script. Just make sure to load it after the map is loaded.
I hope this points you in the correct direction.

Related

ObjectListView / TreeListView: Alternate background color by expandable section

I have a TreeListView control where each root item is expandable, containing an arbitrary number of subnodes. The background color should alternate only at the root level so that all subnodes are of the same background color. If I use a RowFormatter it works as long as it's not sorted by clicking the header.
private void FormatRow(OLVListItem item)
{
var node = (BaseNode)item.RowObject;
var root = node.GetRoot();
if (root == null) return;
var alternate = Model.GetNodeIndex(root) % 2 == 1;
item.BackColor = alternate ? Color.FromArgb(240, 240, 240) : Color.White;
}
How do I get the object's ACTUAL index in the tree, not the index in the underlying data?

Unable to print background colors while writing to Excel

I am trying to generate a background color randomly and print the Excel
field using that color. I put all the colors in an array and generated a
random number to get an element randomly. This part is done but the
"add_format( bg_color => $color ) isn't working as no color is printed
when using 'write' function with $format specified.
If i try a fixed value like 'add_format( bg_color => 'red' )' rather than
a $color, then the excel is printed with red color. But the 'add_format(
bg_color => "$color" ) doesn't seem to work.
sub random_color_select {
my #colors= ("blue","brown","cyan","gray", "green", "lime", "yellow") ;
my $random = int(rand(10));
return "$colors[$random]\n";
}
sub print_excel {
my $color = &random_color_select();
my $format = $workbook_mtr->add_format();
my %hash1= ("bg_color" => "$color");
$format->set_bg_color($hash1{bg_color});
//No color is printed using below line
$worksheet->write("A${row_mem}", "mod", $format);
}
Expect the output excel file to have different color each time run the
script but no color is printed as background.
One of the issues with your code is:
$random = int(rand(10));
Unless you have 10 colours in the array, it will sometimes return a null value.
Much better to use the length of the array as #ysth commented.
#!/usr/bin/perl
use strict;
use warnings;
use Spreadsheet::WriteExcel;
use 5.014;
main();
sub main
{
my $workbook = Spreadsheet::WriteExcel->new('background_colour_test.xls');
my $worksheet = $workbook->add_worksheet();
## get random colour
my $color = &random_color_select();
say "Colour is ".$color;
# Add and define a format
my $format = $workbook->add_format("bg_color" => $color);
my $col = 0;
my $row = 0;
$worksheet->write($row, $col, 'Cell with Background color', $format);
$row++;
$worksheet->write($row, $col, 'Cell without background color');
}
sub random_color_select
{
my #colors= ("blue","brown","cyan","gray", "green", "lime", "yellow");
my $random_color = int(rand(#colors));
return $colors[$random_color];
}
exit;

Is it possible to detect unique colours inside an SVG?

I want to access all the colours that an SVG may be using. I've played with convert, but would like some direction on how to figure out the unique colours that an SVG may contain.
This is the PHP code I've written to talk to convert, to try and determine whether a bitmap contains colours, however it is very limited:
/**
* containsColor
*
* #see https://www.imagemagick.org/discourse-server/viewtopic.php?t=19580&start=15
* #see https://superuser.com/questions/508472/how-to-recognize-black-and-white-images
* #see https://www.imagemagick.org/discourse-server/viewtopic.php?t=19580
* #access public
* #static
* #param string $path
* #return bool
*/
public static function containsColor(string $path): bool
{
$commands = array(
'convert ' .
($path) .' ' .
'-format "%[colorspace]" info:'
);
$command = implode(' && ', $commands);
$response = exec($command);
$color = strtolower($response) !== 'gray';
return $color;
}
If we review Format and Print Image Properties document, we should be able to identify the unique color count with -format %k.
public static function containsColor(string $path): int
{
$commands = array(
'convert ' .
($path) .' ' .
'-format "%k" info:'
);
$command = implode(' && ', $commands);
$response = exec($command);
return (int)$response;
}
If you want to evaluate all colors used by the SVG post render, you can use -unique-colors operator.
convert input.svg -depth 8 -unique-colors txt:-
Which will output something that can easily be parsed by PHP.
# ImageMagick pixel enumeration: 403,1,65535,srgba
0,0: (0,0,0,65535) #000000FF black
1,0: (257,0,0,65535) #010000FF srgba(1,0,0,1)
2,0: (257,257,257,65535) #010101FF srgba(1,1,1,1)
3,0: (257,257,0,65535) #010100FF srgba(1,1,0,1)
4,0: (514,257,0,65535) #020100FF srgba(2,1,0,1)
5,0: (771,771,771,65535) #030303FF grey1
...
Remember that SVG is really just XML, so it may be possible to load it into a DOMDocument class, and use DOMXPath to extract color attributes. But as correctly mentioned in the comments, you would not be able to identify CSS3 filters, or advanced color rendering & mixing.
Update with working example
public static function containsColor(string $input) : bool
{
$pixelInfoList = [];
exec(sprintf('convert "%s" -depth 8 -alpha Off --colors 255 -unique-colors txt:-', $input), $pixelInfoList);
// ... Insert error handling here ...
for($index = 1; $index < count($pixelInfoList); $index++) {
preg_match('/\((\d+),(\d+),(\d+)\)/', $pixelInfoList[$index], $colorParts);
if ($colorParts[1] == $colorParts[2] && $colorParts[2] == $colorParts[3]) {
// Color is gray. Do nothing?
} else {
// Non-gray color. Stop search, and return.
return true;
}
}
return false;
}
Not perfect, but a start.
This works be evaluating the color channels outputted by txt:-. If the red, green, and blue channels are the same, we can state it's a gray color & continue to the next line, else we can state a non-gray color exists & stop the iterations. I'm also taking the library of using -alpha Off -colors 255 to through out additional data.
YMMV
This probably won't help you, because you seem to want to use this for a server application, but it might help others with the same question.
If you're using Inkscape, you can also just export as .gpl.
File > Save a Copy : GIMP Palette (*.gpl)
This will, however, not save all the colors that are displayed within a gradient, only those that are actually used in the file.

define Frontend Layouts for page trees

I'm using the field Frontend-Layout at my TYPO3 7.6-Backend. Because my website will have four different departments with different colours in frontend.
So I'm using:
TCEFORM {
pages {
layout {
altLabels {
0 = [ blue]
1 = [ orange ]
2 = [ green]
3 = [ yellow]
}
}
}
} ### TCEFORM
At my FLUIDTEMPLATE I'll wrap an <div>-wrapper, to set my different languages globally at my stylesheet. f.e. div.wrap.blue { background-color:blue;}
<div class="wrap
{f:if(condition:'{data.layout} == 0',then:'blue')}
{f:if(condition:'{data.layout} == 1',then:'orange')}
{f:if(condition:'{data.layout} == 2',then:'green')}
{f:if(condition:'{data.layout} == 3',then:'yellow')}">
...
This works perfect for me.
But how can I slide (or inherit) the frontend-layout-info from my parent-page to the subpages on my pagetree? I don't want to choose the frontend layout in page properties everytime, if I will add a new page into my pagetree. This must be working automatically. Is this possible? With slide?
For example
*ROOT
+ parent blue
~~ sub blue 1 /* these pages also have frontend layout 0 */
~~ sub blue 2
+ parent orange
~~ sub orange 1
+ parent green
...
+ parent yellow
...
Thebks for your opinion or tips ..
I don't think it's dead simple to set the {data.layout} layout recursively without manipulating the database. I have three 'solutions' coming to mind to solve your problem:
1) Create four Backend Layouts that you can select for your current and childpages. (Basically rinse and repeat what you have done for your first backend layout)
2) Using your layout modes you could try setting a body class using typoscript like so (i did not test this):
page.bodyTag >
page.bodyTagCObject = TEXT
page.bodyTagCObject.field = data.layout
page.bodyTagCObject.wrap = <body class="color-|">
3) Use a similar typoscript but update the value using typoscript conditions such as [pidInRootline]
page.bodyTag >
page.bodyTagCObject = TEXT
page.bodyTagCObject.wrap = <body class="blue">
[PIDinRootline = 1]
page.bodyTagCObject.wrap = <body class="orange">
[global]
[PIDinRootline = 2]
page.bodyTagCObject.wrap = <body class="green">
[global]
# and so on
I had your same problem and this typoscript worked fine for me,
the result is what you wanted to reach.
as you can see the 20.10 object is used when frontend layout is set on the page, while the 20.20 object is used when frontend layout is not set and takes it in slide mode:
page {
bodyTagCObject >
bodyTagCObject = COA
bodyTagCObject {
stdWrap.noTrimWrap = |<body |>|
20 = COA
20 {
wrap = class="|"
10 = TEXT
10 {
if.isTrue.data = page:layout
data = page:layout
noTrimWrap = |page-layout-| |
}
20 = TEXT
20 {
if.isFalse.data = page:layout
data = levelfield:-2, layout, slide
noTrimWrap = |page-layout-|
}
}
}
}
I hope I have been helpfull.

Typo3 list the content of all child-pages as content of the parent page

As the title says, I need to list the content of all child-pages on the parent-page, after its own content. Or the thing I really need is, one page with content and and a menu which links to the different headers of the content. e.g. athe parent-page with content:
**Parent Head**
parent text
*first subhead*
first subtext
*second subhead*
second subtext
and the menu should look like:
Parent
-first subhead
-second subhead
I thought it would be easier if the parent-page "collects" the content of the child-pages.
The other solution was, that the child-pages would be links to extern URLs, to the specific c-IDs of the different contents of the parent-page. But I think this isn't that easy for the website owner, who doesn't know anything about where he can find the right c-ID in the web-page-source-code.
So how would You make that? Or how can I realize the thing with the child-page-content?
EDIT: Have a solution now. Just have to fix, that the submenu will be displayed without childpages.
Here is the code:
temp.contentnav = CONTENT
temp.contentnav {
table = tt_content
select {
pidInList = 7
orderBy = sorting
where = colPos=0
languageField=sys_language_uid
}
renderObj = TEXT
renderObj {
field = header
wrap= <li>|</li>
typolink.parameter.field=pid
typolink.parameter.dataWrap=|#{field:uid}
typolink.ATagParams = class="linkClass"
if.isTrue.field=header
}
wrap = <ul id="submenuClass"> | </ul>
}
page.10.marks.MENU.2.NO.after.cObject < temp.contentnav
Try something like this
temp.pageIds = HMENU
temp.pageIds.entryLevel = 1
temp.pageIds.1 = TMENU
temp.pageIds.1 {
NO.stdWrap.field = uid
NO.allWrap = |,
NO.doNotLinkIt = 1
}
lib.container = CONTENT
lib.container.table = tt_content
lib.container.select {
pidInList.cObject < temp.pageIds
}
There is a content element "Menu/Sitemap" with has an option to render subpages with content.
If you want to do it via TypoScript, render the menu, and then replace the menu items with content of them.
# Pseudocode on menuitem
# assuming you are using css_styled_content
1.allStdWrap.cObject < styles.content.get
# Set pid for CONTENT object from styles.content.get to the uid of the page
# which gets rendered
1.allStdWrap.cObject.select.pidInList.data = uid
Can't provide you with an working snippets atm.

Resources