Converting values to fit in an Image - php

I have to read out some values from a database and create a line diagram with it.
The values i get from the database are the time in ms(going up to 72000) for the x-axis, and a value between 0 and 10 for the y-axis.
How do I get the values ranging from 0 to 72000 into the picture which has to have a width of 800px and how do use the complete 600px of the y-axis with the 0-10 values?

Related

Get calculated height of a PHPSpreadsheet row

I'm trying to get the calculated height of a row in PHPSpreadsheet but whenever I do something like
$spreadsheet->getActiveSheet()->getRowDimension($row)->getRowHeight();
I always get a -1 value which is correct based on their documentation as that is the default value. I need to get the calculated height in pt though as I need to do some calculations. I have a cell that is set to wrap text, and spans multiple lines. Anyone knows how to get the calculated height of a row?
-1 is the value of auto height. Means the value will calculated automatically. If you need a number of height. I would suggest to calc the height over the value of the cell. You must do following: Find newlines in the content and multiply them with 12.75 pts (standard height). Some informations you can find here to.

PHPExcel get cell from x and y

I'm making a program and i'm using PHPExcel. Inside the program you can select width and height. (width is the green row, and blue is the height)
All the white numbers are prices.
Lets say i insert 1400 width and 1600 height. the price should be 640. How can i achieve this?
The easiest option is to find which column contains 1400 in Row 1 (D in your example), and which row contains 1600 in column A (5 in your example), and then use that to read the value at that cell (D5)
A somewhat cleverer way is to use an Excel Formula:
=INDIRECT(CONCATENATE(SUBSTITUTE(ADDRESS(1,MATCH(1400,A1:E1,0),4),1,""),MATCH(1600,A1:A17,0)))
substituting the appropriate lookup values for 1400 and 1600, and adjusting the MATCH ranges to the full size for your width and height lookups.... In MS Excel itself, you could use row and column ranges (A:A) and (1:1), but the PHPExcel calculation engine won't handle row and column ranges correctly, but it will work with cell ranges
As an explanation for the above formula:
MATCH(1400,A1:E1,0)
Does a lookup for value 1400 in the cell range A1:E1 (looking for a match for your width). The returned value for MATCH() is a numeric offset in that row for the column where it is found. In this case, it will return 4.
SUBSTITUTE(ADDRESS(1,<4>,4),1,"")
Converts the column number to a column letter... e.g converts 4 to D. if your range didn't start at A, then you'd have to add an offset to get the correct letter
MATCH(1600,A1:A17,0)
Similar to the previous MATCH, but this time searching in your heights column range (A1:A17) for the value 1600. It will return the offset within that range where it finds the value. Again, if your range doesn't start in row 1, then you'd need to add an offset. In your case, it will return 5.
CONCATENATE(<D>,<5>)
Concatenates the calculated column and row values together to give a cell address (D5)
INDIRECT(<D5>)
Reads the value at the cell address that we've calculated (D5) giving the value 640

Break table if height is greater than value

I'm working on a script that generates a PHP table containing some values from a MySQL database. The script will be displayed on a TV, so I need to break it if its height is greater than 1280 (I've got this value by completing it with values 'till it fits perfect, then I've used jQuery alert to display its height) and I will use jquery.cycle.all plugin to create a slideshow from the tables.
My solution was to use a PHP variable and increment it on each generated then if I have let's say 13 rows, it echoes </table><table>, but the cells must have an exact width so it may add a new line of text (if I have a longer text) on a cell and the table will have more than 1280px height.
Does anybody have any idea about how I can solve this?
Possible solutions:
Use the css overflow: hidden to prevent content going to the next line and just hide it
Use javascript to iterate over each row, calculate the height of the row and remove rows if the total height exceeds 1280px.
Use PHP to calculate the length of the text in actual px and how many rows would be used, but that is quite complex.

PCharts labeling X-axis

Would it be possible to just label the x axis by the minimum value and the maximum value instead of having values inbetween?
More info on what I'm graphing:
I have a large dataset of dates that I am graphing. Currently I am scaling it to a scale of 0-100 to graph it. I just want to label 0 as the lowest date and 100 as the highest date.
Look at setFixedScale()
$Test->setFixedScale(0,100,1);
That will show 0 as the min and then 100 as the max

logic of color variance

http://dribbble.com/colors/1a15a1?percent=5&variance=50
I understand the color minimum slider--you would count the color of each pixel, then create a ratio for a particular color based on the total pixels of the image (10 blue:100 total) = 10% blue.
But what's the logic behind the color variance slider? Looking at the RGB values of these colors http://en.wikipedia.org/wiki/Web_colors#X11_color_names some patterns are apparent, but imagining a sql table full of pictures and their pixel data, anyone have an idea on how to calculate variance?
I too think you are right for the color minimum. Color variance is easy too. If you select a small variance you will get images with a small count of colors used on it. Logically 0% variance must bring an image of a single color only.
I don't think you have to store pixels at all, logically for storing a new image it goes like this:
Read image file
Find how many different color there are in it
Store image path and number of different colors on it.
Then on retriving the image would go like this:
Ask the user what variance he likes
Let's say variance = 60%
Read distinct maximum numbers of colors for an image
MaxColors = 100% (let's say max=18 colors per image)
Turn 60% to integer
18 = 100%
x = 60% then
18*60=100*x then 100*x=1080 then x=10.8
Make 10.8 round so it becomes x=11
Retrieve from database all images that have 11 or more colors on them
Display these images as the result
So no need to store any pixel at all, just a single integer that indicates how many colors consist of an image.

Categories