948Part VCase StudiesIt takes a little more work (Free web design)

May 7th, 2008

948Part VCase StudiesIt takes a little more work and trigonometry to get the areas of the triangles. In our code, wemake the job more straightforward by drawing a line from point C to point D, and consideringonly the half of the diagram above that line then at the end, we multiply by two to get thereal area. If we say that the intersection of segments AB and CD is point E, what we eventuallycare about is the area of triangles CAE and DAE. We start by calculating the angles of triangleCDA (whose side lengths are known to us) and, by using that information, determining thelengths of CE, DE, and AE. After we know these lengths, we know the bases and heights, andthe areas of the right triangles CAE and DAE are just 1/2(base height). Listing 48-1 shows code to do this kind of area calculation. Its main public function is circle_intersection_area(), which expects as arguments the radii of two circles and thedistance between them. The simplest case is where the distance is greater than the sum ofthe radii: The circles do not touch; there is no intersection, and the answer is zero. Listing 48-1:trig.php= ($other_1 + $other_2)) || ($other_1 >= ($opposite + $other_2)) || ($other_2 >= ($other_1 + $opposite))) { die( Triangle with impossible side lengths in . angle_given_sides: $opposite, $other_1, $other_2 ); } else { $numerator = ((($other_1 * $other_1) + ($other_2 * $other_2)) - ($opposite * $opposite)); $denominator = 2 * $other_1 * $other_2; return(acos($numerator / $denominator)); } } function area_to_radius ($area) { return (sqrt ($area / M_PI)); } function circle_intersection_area ($radius_left, $radius_right, $distance) { if ($radius_right + $radius_left <= $distance) { return(0); } else { // first, we find the angle measures of a triangle54
We recommend cheap and reliable webhost to host and run your web applications: Coldfusion Web Hosting services.

Java web server - 947Chapter 48Data Visualization with Venn DiagramsNecessary TrigonometryLet s get

May 7th, 2008

947Chapter 48Data Visualization with Venn DiagramsNecessary TrigonometryLet s get the math out of the way first. Unavoidably, because we re talking about circles andareas, we re going to be talking about trigonometry. (As we ve said, though, if you re not inter- ested and are willing to trust us that we have code to calculate the area of circle intersec- tions, please do skip ahead to the section Planning the display, later in this chapter.) The eventual task for our system is to start with three quantities (items in set A, items in setB, and items in the intersection) and produce a diagram containing two circles, with areasproportional to the set sizes, and positioned so that the area of overlap is proportional to thesize of the intersection. For this section, we go in the other direction and calculate intersec- tion area from given circles. Our starting information will be the radii of the two circles andthe distance between their centers. With reference to Figure 48-1, say that our circles have centers at points C and D, respectively, and that we know the radius of the circle on the left (segment CA or segment CB) and theradius of the circle on the right (DA or DB). What we d like to know is the size of that oddlens-shaped object in the middle. Figure 48-1:Area of intersectionThe lens-shaped intersection area is split into two halves by segment AB (not quite halvesbecause the circle sizes may be different), and we can calculate the area of each half indepen- dently. The crucial thing to notice is that the area of each of these half-lenses is the area thatyou get after you subtract the area of a triangle from the area of a pizza-slice-shaped sector ofa circle. The right-hand lens half, for example, has an area equal to the sector of the left-handcircle determined by angle ACB, minus the area of the triangle ACB. So if we can calculate the areas of sectors and triangles, then we are nearly done. The area ofa sector is straightforward it s just the area of the circle multiplied by the fraction of thatcircle that the angle of the sector sweeps over. Area of intersecting circlesACDB54
You want to have a cheap webhost for your apache application, then check apache web hosting services.

946Part VCase StudiesIf we re going to offer a (Free web host)

May 6th, 2008

946Part VCase StudiesIf we re going to offer a way to query the database, then it may as well be via a Web form. Sothe end-to-end view of our task is that we start with a Web form and end up with a picture todisplay. Let s start the design by enumerating the things that need to happen for this to comeabout. We ll need to: 1.Generate (or at least present) the Web form itself. 2.Receive the submitted form data and transform it into appropriate SQL queries for submission to the database. 3.Receive results from the SQL queries. 4.Use the SQL results to decide on the locations and sizes of all the elements in ourgraphic. 5.Actually generate the graphic and send it back to the user. All of the code in this chapter should work with either PHP4 or PHP5, but it assumes that yourPHP installation has access to the gdimage library and is configured to produce PNG images. Any version of gdlater than 1.8, bundled or unbundled, should be OK. (See Chapter 42 fordetails of configuration and installation of gd.) Outline of the CodeOur system contains the following code files: .visualization_form.php:This is essentially a hard-coded form that enables the userto choose two different restrictions on the data in our table. The restrictions chosenmap directly to whereclauses loaded from an auxiliary file called query_clauses.php. .db_visualization.php:This code handles the form data sent by visualization_ form.phpand builds three SQL statements: one with only the first where clause, onewith the second whereclause, and a third with both clauses joined by an and. It col- lects resulting three counts and displays the numbers in a graphic by calling functionsloaded from venn.php. .venn.php:This actually produces the Venn diagram graphic and ships it back to theuser. Its primary function takes as input the three amounts (the sizes of the two sets andtheir intersection), decides the sizes and locations of corresponding circles, and does allthe drawing and shading necessary. For the complicated case of sets that actually havean overlapping area, it uses functions loaded from trig.phpto calculate areas. .trig.php:This code actually calculates the intersection area whenever circles overlap. We discuss these code files in reverse order, from the bottom up. By the way, although we likethis example, we don t want to give the impression that you need to do trigonometry to docomputer graphics in PHP, or even vector graphics in PHP. If you want to understand everybit of this example, then you need to go through the trig, but we encourage those who don tcare to skip the next section ( Necessary trigonometry ). The core of the graphics code itselfis in venn.php, and that example code really is important to understand if you want to do gd-based graphics in PHP. Note54
If you are searching for cheap webhost for your web application, please visit MySQL5 Web Hosting services.

Data Visualizationwith Venn DiagramsIn this chapter s case study, (Windows 2003 server web)

May 5th, 2008

Data Visualizationwith Venn DiagramsIn this chapter s case study, we show one way to use PHP to com- bine MySQL databases with graphic images. We build a completesystem that starts with a database and uses the gdlibrary to producea kind of visualization of the data. The portions of the book we drawon for this are: .Part II: We use PHP to interrogate a MySQL database. .Chapter 42 (Graphics): Our end-product is an image producedwith the gdlibrary. .Chapter 27 (Mathematics): We need a bit of trigonometry as wecreate the images. Scaled Venn DiagramsThe visualization we have in mind is something like the Venn diagram. If you ve ever been in an academic setting where set intersection wasbeing discussed, then you ve probably seen these diagrams they rethe circles that may or may not have overlapping portions represent- ing intersections. We say something like the Venn diagram, because scale has no sig- nificance in a traditional Venn diagram. If you want to illustrate thefact that there are people who use both BeOS and Windows, then youmight draw two circles of equal size (representing Windows usersand BeOS users) that happen to have a region of overlap. In our ver- sion, which you might call a scaledor proportionalVenn diagram, thesizes of both circles and intersections matter; the Windows/BeOSexample would become one large circle and one much smaller circle, with an overlap area proportional to the number of people in bothsets. (To see an example of this kind of diagram, please skip ahead toFigure 48-5.) The taskThe job of our code is to start with a database, provide a way to querythat database about sets and their overlap, and then display theresults as a scaled Venn diagram, generated by using the gdlibrary. Asa sample database, we use the pseudosurvey dataset that we used inthe HTML Graphics section of Chapter 42.4848CHAPTER …In This ChapterFrom database toimageScaled Venn diagramsPlanning the displayPutting it all together …
Searching for affordable and reliable webhost to host and run your web applications? Go to our java web server services and you will be pleased.

943Chapter 47Converting Static HTML SitesSummaryPHP (Yahoo web space) books usually assume

May 3rd, 2008

943Chapter 47Converting Static HTML SitesSummaryPHP books usually assume that you are starting a site from scratch but in the real world, another very common scenario is to upgrade an existing static site. PHP and a database canbe used to take large, messy, hard-to-maintain HTML sites and make them dynamic. Thismakes the sites much easier to maintain, because they are assembled by PHP from data in adatabase. Instead of maintaining hundreds of HTML files, you can just work on one templateand let PHP assemble the pages on-the-fly. Before you do any work, you should take the time to assess your site s strategy and map outthe goals you wish to accomplish. You should also gain a clear understanding of your site sstructure and the resources you will need to support your new design. After that, you musttest your new design, create a new database, load data from possibly disparate sources intothe database, and create PHP template pages. Finally, you should assess the performance ofyour new dynamic site and possibly take steps to improve it. …
In case you need quality webspace to host and run your web applications, try our personal web hosting services.

942Part VCase StudiesFinally, take a (Web hosting comparison) look at browser

May 2nd, 2008

942Part VCase StudiesFinally, take a look at browser latency. The best way to do this is to get on a known slowbrowser Internet Explorer 5.1 for Macintosh is supposedly the market leader in this category and actually time how long it takes from the initial request to the moment you seea complete Web page in your browser. Because a lot of this is controlled by the particularbrowser, there s not much you can do except to realize that complicated layouts featuringmassive tables, immense amounts of nonbreaking spaces, and hundreds of transparent single-pixels add to rendering time. CachingBesides the steps mentioned in the preceding section, another way you can make your sitefaster is to use caching. There are many types of caching, but the most important one for Webdevelopers is HTML caching. Many dynamic sites, such as Slashdot and Epinions, are actu- ally serving up mostly static pages that change every few minutes. Without this trick, feworganizations could afford to scale a Web site. The review page in Listing 47-4 is an interesting example, because although we re storing allthe data in a database, the only thing on the whole page that is dynamic is the CommunityRating score. The rest of the page changes only if updates are made to the database records. We could, therefore, easily write out the whole site as a series of static HTML pages with onePHP function embedded in the middle. You re probably thinking, That s nuts! I just went to all that work to turn my static HTML siteinto a dynamic, database-driven one and now you re telling me to go back to staticHTML?!?! But if you think about it, you see a vast difference between a static site that youmaintain by hand and a dynamic site that happens to update itself automatically whenever ameaningful change occurs. This scheme gives you the best of both worlds: the speed and scal- ability of static HTML plus the flexibility and maintainability of a database-driven PHP site. We ve written another code listing that takes all the entries in your database and writes themout to static HTML files. In the middle is a PHP snippet that includes a text file. This text filecontains the Community Rating and is updated by a separate process every hour. You candownload the code for this listing at www.troutworks.com/phpbook/. If you want to make the Community Rating call on this page fully dynamic, instead of takingcached data from a flat file, you can do that too. But you will no longer be able to constructthe entire page as a single heredoc block. The code to accomplish a static page with adynamic code block is available at www.troutworks.com/phpbook/. The code to insert a dynamic PHP block into a static HTML page doesn t look as pretty asaplain HTML page, and you must be very careful about all the quoting and concatenating, but in the end, you have an automatically generated HTML file with chunks of PHP for thedynamic bits. You could schedule this script to run on the command line once a day via a cronjob. (You redefinitely not going to be able to use the Web server module version of PHP for this task.) Oryou could kick it off whenever you add new pages to the Web site. This has another securitybenefit: You do not need to maintain a full database in production but can merely push flatfiles periodically (perhaps via some tool such as rsync), plus maintain a small database withdata only for those fields you want to display dynamically.
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.

Web hosting provider - 941Chapter 47Converting Static HTML SitesPerformance and CachingAt this

May 2nd, 2008

941Chapter 47Converting Static HTML SitesPerformance and CachingAt this stage you should do some performance testing and evaluation. You want to get decentestimates of: .Server latency:How long the code takes your server to produce. .Network latency:How long it takes to get the code down the pipe to you. .Browser latency:How long it takes a browser to completely render the page. You can measure server latency by putting microtime()calls at the beginning and end ofeach page, like this: This duration should average to less than one second on every page. If it s more than one sec- ond per page load, you have an architecture problem. Subseconds of latency are achieved bymuch larger and more complicated sites than yours. Make sure that you test this on a setupsimilar to your production environment a production server can be several times fasterthan a development server, so unacceptable times in development can magically becomeacceptable in production. The reason server latency is particularly bad is that it ends up costing you money to scaleyour site. Because your code hogs processor cycles, threads, database connections, andother resources longer than it should, you need to invest more in hardware than a zippier site with similar features. The cure for this type of performance problem is to simplify yourarchitecture, particularly those features (templates, objects, message catalogs, and so on) that are known to add server latency. Network latency is (insofar as Web developers can affect it) usually a function of how largeyour page is. To test this, you need to save an HTML page and all its attendant graphic files(including ads) and note their combined size. Divide by 40 kilobytes per second (a realisticestimate of the speed of a 56K modem) for a ballpark estimate of how long your data spendson the wire. Heavy pages also cost you money, especially if you pay for metered bandwidth. Your Webservers can t take another request until they finish sending all the data from this one andthe longer it takes, the fewer available threads your Web servers have at any given time. Youcan sometimes finesse the fat-page problem temporarily by looking into transparent pagecompression Apache, for example, can gzipany file before serving it up in a way that istotally invisible to the user but in the long run you just need to make your pages lighter.
Please visit our professional web hosting services to find out about cheap and reliable webhost service that will surely answer all your demands.

940Part VCase StudiesListing 47-4(continued) EOPAGESTR; echo $page_str; ?>

May 1st, 2008

940Part VCase StudiesListing 47-4(continued) EOPAGESTR; echo $page_str; ?> The results of the preceding book review page are shown in Figure 47-3. If you compare this figure with Figure 47-2, it is immediately obvious that we ve simplified theelements somewhat. Inevitably, as you move toward a final layout in actual HTML, you find thatnot everything envisioned by the designer can be easily implemented. In this case, we foundthat the small visual elements such as the title area and Browse By navbar are extremely fid- dly and difficult to lay out decently in HTML without enormous overhead in pixel-level layout. It s difficult to know these things until you actually begin work on a production template. Yourdesigners should be willing to work with you to make small tweaks at this point. Figure 47-3:Templated version of book review page53
We highly recommend you visit web and email hosting services if you need stable and cheap web hosting platform for your web applications.

Web server type - 939Chapter 47Converting Static HTML Sites $review …READ COMPLETE

April 30th, 2008

939Chapter 47Converting Static HTML Sites

$review …READ COMPLETE REVIEW…

What did YOU think?

Read this book? Rate it!

Continued53
We recommend cheap and reliable webhost to host and run your web applications: Coldfusion Web Hosting services.

938Part VCase (Web server hosting) StudiesListing 47-4(continued) Read Reviews Browse by:   

April 30th, 2008

938Part VCase StudiesListing 47-4(continued)

FAQs | Team Trout | Privacy | Advertising | Email Us

Other Reviewed Titles By ThisAuthor
$title_str

Top 5 Most Similar Titles
$similar

Movie versions
$movie

Our rating: $rating
Community rating: $comm_rating

Awards: $award


Searching for affordable and reliable webhost to host and run your web applications? Go to our java web server services and you will be pleased.