001/*
002 * Copyright (c) 2002-2010 The Regents of the University of California.
003 * All rights reserved.
004 *
005 * '$Author: welker $'
006 * '$Date: 2010-05-06 05:21:26 +0000 (Thu, 06 May 2010) $' 
007 * '$Revision: 24234 $'
008 * 
009 * Permission is hereby granted, without written agreement and without
010 * license or royalty fees, to use, copy, modify, and distribute this
011 * software and its documentation for any purpose, provided that the above
012 * copyright notice and the following two paragraphs appear in all copies
013 * of this software.
014 *
015 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
016 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
017 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
018 * THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
019 * SUCH DAMAGE.
020 *
021 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
022 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
024 * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
025 * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
026 * ENHANCEMENTS, OR MODIFICATIONS.
027 *
028 */
029
030package org.geon;
031
032import java.awt.geom.Point2D;
033import java.io.FileWriter;
034import java.io.PrintWriter;
035
036//////////////////////////////////////////////////////////////////////////
037////TernaryDiagram
038/**
039 * This actor reads a string and outputs an array of coordinates and a string of
040 * region.
041 * 
042 * @author Efrat Jaeger
043 * @version $Id: TernaryDiagram.java 24234 2010-05-06 05:21:26Z welker $
044 * @since Ptolemy II 3.0.2
045 */
046public class TernaryDiagram {
047
048        // parameters for the diagram size
049        final public static double width = 420;
050        final public static double height = 700;
051        final public static double leftPadding = 40;
052        final public static double rightPadding = 40;
053        final public static double diagramWidth = width - leftPadding
054                        - rightPadding;
055        final public static double triangleDiagramHeight = (diagramWidth * Math
056                        .sin(Math.PI / 3));
057        final public static double diagramHeight = triangleDiagramHeight * 2;
058        final public static double bottomPadding = 80;
059        final public static double topPadding = height - diagramHeight
060                        - bottomPadding;
061
062        public static boolean fourVertices = false;
063
064        private static String getSVGHeader(String topVertex, String leftVertex,
065                        String rightVertex, String bottomVertex) {
066
067                // get header and scripts
068                String svg = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" standalone=\"no\"?>\n";
069                svg += "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 20010904//EN\"\n";
070                svg += "      \"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\">\n";
071
072                svg += "<svg xmlns=\"http://www.w3.org/2000/svg\"\n"
073                                + "     xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"
074                                + "     width='" + width + "' height='" + height + "'"
075                                + ">\n\n";// not sure about the height..
076
077                svg += "<script type=\"text/ecmascript\">\n\n";
078
079                svg += "<![CDATA[\n";
080
081                svg += "     function show(tid) {\n";
082                svg += "         if (lastMsg != null) {\n";
083                svg += "            lastMsg.setAttribute(\"visibility\", \"hidden\");\n";
084                svg += "         }\n";
085                svg += "         obj = svgDocument.getElementById(tid);\n";
086                svg += "         obj.setAttribute(\"visibility\", \"visible\");\n";
087                svg += "         obj.setAttribute(\"fill\", \"navy\");\n";
088                svg += "         obj = svgDocument.getElementById(tid+\"Polygon\");\n";
089                svg += "         obj.setAttribute(\"fill\", \"#5f7f8f\");\n";
090                svg += "     }\n";
091
092                svg += "     function unshow(tid) {\n";
093                svg += "         obj = svgDocument.getElementById(tid);\n";
094                svg += "         obj.setAttribute(\"visibility\", \"hidden\");\n";
095                svg += "         obj = svgDocument.getElementById(tid+\"Polygon\");\n";
096                svg += "         obj.setAttribute(\"fill\", \"white\");\n";
097                svg += "         if (lastMsg != null) {\n";
098                svg += "            lastMsg.setAttribute(\"fill\", \"brown\");\n";
099                svg += "            lastMsg.setAttribute(\"visibility\", \"visible\");\n";
100                svg += "         }\n";
101                svg += "     }\n";
102
103                svg += "     var lastCircle;\n";
104                svg += "     var lastMsg; \n";
105
106                svg += "// ]]>\n\n";
107                svg += "</script>\n\n";
108
109                String top = (topVertex != null) ? topVertex : "NULL";
110                String left = (leftVertex != null) ? leftVertex : "NULL";
111                String right = (rightVertex != null) ? rightVertex : "NULL";
112                String bot = (bottomVertex != null) ? bottomVertex : "NULL";
113
114                svg += "<text id='properties' visibility = 'hidden' ";
115                svg += "properties='top " + top + " left " + left + " right " + right
116                                + " bot " + bot + " ";
117                svg += "leftPadding " + leftPadding + " topPadding " + topPadding
118                                + " diagramWidth " + diagramWidth + " ";
119                svg += "triangleDiagramHeight " + triangleDiagramHeight + "' />\n";
120
121                svg += "<rect x='0' y='0' rx='5' ry='5' width='" + width + "' height='"
122                                + height + "' fill='#f4f4f4' />\n";
123
124                // draw labels
125                if (topVertex != null) {
126                        svg += "<text x='"
127                                        + (width / 2 - 15)
128                                        + "' y='"
129                                        + (topPadding - 10)
130                                        + "' style='font-weight:bold; font-size: 12pt; font-family: serif; ' >"
131                                        + topVertex + "</text>\n";
132                }
133
134                if (leftVertex != null) {
135                        svg += "<text x='"
136                                        + (leftPadding - 30)
137                                        + "' y='"
138                                        + (height - (bottomPadding + triangleDiagramHeight))
139                                        + "' style='font-weight:bold; font-size: 12pt; font-family: serif; ' >"
140                                        + leftVertex + "</text>\n";
141                }
142
143                if (rightVertex != null) {
144                        svg += "<text x='"
145                                        + (width - rightPadding + 5)
146                                        + "' y='"
147                                        + (height - (bottomPadding + triangleDiagramHeight))
148                                        + "' style='font-weight:bold; font-size: 12pt; font-family: serif; ' >"
149                                        + rightVertex + "</text>\n";
150                }
151
152                if (bottomVertex != null) {
153                        svg += "<text x='"
154                                        + (width / 2 - 15)
155                                        + "' y='"
156                                        + (height - bottomPadding + 15)
157                                        + "' style='font-weight:bold; font-size: 12pt; font-family: serif; ' >"
158                                        + bottomVertex + "</text>\n";
159                        fourVertices = true;
160                }
161
162                return svg;
163        }
164
165        private static String getSVGFooter() {
166                String svg = "</svg>\n";
167                return svg;
168        }
169
170        private static String getLabelInSVG(String label, String msg) {
171                double textY = (fourVertices) ? (height - bottomPadding + 20) : (height
172                                - bottomPadding + 20 - triangleDiagramHeight);
173                String svg = "<text id='"
174                                + label
175                                + "' x='"
176                                + (width / 2)
177                                + "' y='"
178                                + textY
179                                + "' fill='brown' text-anchor='middle' visibility='hidden' "
180                                + "style='font-weight:bold; font-size: 12pt; font-family: serif; ' >\n";
181                svg += msg;
182                svg += "</text>\n";
183                return svg;
184        }
185
186        public static String getPlagPxOlDiagraminSVG() {
187
188                String svg = getSVGHeader("Plag", "Px", "Ol", null);
189
190                // draw top triangle
191                double y1 = topPadding + triangleDiagramHeight / 10;
192                double x1 = (width / 2)
193                                - (Math.tan(Math.PI / 6) * triangleDiagramHeight / 10);
194                double x2 = (width / 2)
195                                + (Math.tan(Math.PI / 6) * triangleDiagramHeight / 10);
196                svg += "<polygon id='anorthositePolygon' points='" + x1 + "," + y1
197                                + " " + x2 + "," + y1 + " " + (width / 2) + "," + topPadding
198                                + "'";
199                svg += " onmouseover='show(\"anorthosite\")' onmouseout='unshow(\"anorthosite\")' ";
200                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
201                svg += getLabelInSVG("anorthosite", "anorthosite");
202
203                // draw bottom polygon
204                double y2 = topPadding + triangleDiagramHeight * 9 / 10;
205                double x3 = (width / 2)
206                                - (Math.tan(Math.PI / 6) * triangleDiagramHeight * 9 / 10);
207                double x4 = (width / 2)
208                                + (Math.tan(Math.PI / 6) * triangleDiagramHeight * 9 / 10);
209                double x5 = (x1 + x2) / 2;
210                svg += "<polygon id='ultramaficPolygon' points='" + (leftPadding) + ","
211                                + (topPadding + triangleDiagramHeight) + " " + x3 + "," + y2
212                                + " " + x4 + "," + y2 + " " + (width - rightPadding) + ","
213                                + (topPadding + triangleDiagramHeight) + "'";
214                svg += " onmouseover='show(\"ultramafic\")' onmouseout='unshow(\"ultramafic\")' ";
215                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
216                svg += getLabelInSVG("ultramafic", "ultramafic");
217
218                // draw the left polygon
219                svg += "<polygon id='noritePolygon' points='" + x1 + "," + y1 + " "
220                                + x5 + "," + y1 + " " + (x3 + x5 - x1) + "," + y2 + " " + x3
221                                + "," + y2 + "'";
222                svg += " onmouseover='show(\"norite\")' onmouseout='unshow(\"norite\")' ";
223                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
224                svg += getLabelInSVG("norite", "norite");
225
226                // draw the right polygon
227                svg += "<polygon id='troctolitePolygon' points='" + x5 + "," + y1 + " "
228                                + x2 + "," + y1 + " " + x4 + "," + y2 + " " + (x4 - x5 + x1)
229                                + "," + y2 + "'";
230                svg += " onmouseover='show(\"troctolite\")' onmouseout='unshow(\"troctolite\")' ";
231                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
232                svg += getLabelInSVG("troctolite", "troctolite");
233
234                // draw the center polygon
235                svg += "<polygon id='gabbroPolygon' points='" + x5 + "," + y1 + " "
236                                + (x3 + x5 - x1) + "," + y2 + " " + (x4 - x5 + x1) + "," + y2
237                                + "'";
238                svg += " onmouseover='show(\"gabbro\")' onmouseout='unshow(\"gabbro\")' ";
239                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
240                svg += getLabelInSVG("gabbro", "gabbro");
241
242                svg += getSVGFooter();
243                return svg;
244
245        }
246
247        public static String getPlagPxHblDiagraminSVG() {
248
249                String svg = getSVGHeader("Plag", "Px", "Hbl", null);
250
251                // draw top triangle
252                double y1 = topPadding + triangleDiagramHeight / 10;
253                double x1 = (width / 2)
254                                - (Math.tan(Math.PI / 6) * triangleDiagramHeight / 10);
255                double x2 = (width / 2)
256                                + (Math.tan(Math.PI / 6) * triangleDiagramHeight / 10);
257                svg += "<polygon id='anorthositePolygon' points='" + x1 + "," + y1
258                                + " " + x2 + "," + y1 + " " + (width / 2) + "," + topPadding
259                                + "'";
260                svg += " onmouseover='show(\"anorthosite\")' onmouseout='unshow(\"anorthosite\")' ";
261                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
262                svg += getLabelInSVG("anorthosite", "anorthosite");
263
264                // draw the left polygon
265                double y2 = topPadding + triangleDiagramHeight * 9 / 10;
266                double x3 = (width / 2)
267                                - (Math.tan(Math.PI / 6) * triangleDiagramHeight * 9 / 10);
268                double x4 = (width / 2)
269                                + (Math.tan(Math.PI / 6) * triangleDiagramHeight * 9 / 10);
270                double x5 = (x1 + x2) / 2;
271                svg += "<polygon id='noritePolygon' points='" + x1 + "," + y1 + " "
272                                + x5 + "," + y1 + " " + (x3 + x5 - x1) + "," + y2 + " " + x3
273                                + "," + y2 + "'";
274                svg += " onmouseover='show(\"norite\")' onmouseout='unshow(\"norite\")' ";
275                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
276                svg += getLabelInSVG("norite", "norite");
277
278                // draw the right polygon
279                svg += "<polygon id='hornblendePolygon' points='" + x5 + "," + y1 + " "
280                                + x2 + "," + y1 + " " + x4 + "," + y2 + " " + (x4 - x5 + x1)
281                                + "," + y2 + "'";
282                svg += " onmouseover='show(\"hornblende\")' onmouseout='unshow(\"hornblende\")' ";
283                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
284                svg += getLabelInSVG("hornblende", "hornblendite gabbro");
285
286                // draw the center polygon
287                svg += "<polygon id='gabbroPolygon' points='" + x5 + "," + y1 + " "
288                                + (x3 + x5 - x1) + "," + y2 + " " + (x4 - x5 + x1) + "," + y2
289                                + "'";
290                svg += " onmouseover='show(\"gabbro\")' onmouseout='unshow(\"gabbro\")' ";
291                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
292                svg += getLabelInSVG("gabbro", "gabbro");
293
294                // draw bottom1 polygon
295                svg += "<polygon id='pyroxenitePolygon' points='" + x3 + "," + y2 + " "
296                                + leftPadding + "," + (topPadding + triangleDiagramHeight)
297                                + " " + (leftPadding + (x2 - x1)) + ","
298                                + (topPadding + triangleDiagramHeight) + "'";
299                svg += " onmouseover='show(\"pyroxenite\")' onmouseout='unshow(\"pyroxenite\")' ";
300                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
301                svg += getLabelInSVG("pyroxenite", "pyroxenite");
302
303                // bottom2
304                svg += "<polygon id='hblpyroxenitePolygon' points='" + x3 + "," + y2
305                                + " " + (leftPadding + (x2 - x1)) + ","
306                                + (topPadding + triangleDiagramHeight) + " "
307                                + (leftPadding + diagramWidth / 2) + ","
308                                + (topPadding + triangleDiagramHeight) + " "
309                                + (leftPadding + diagramWidth / 2) + "," + y2 + "'";
310                svg += " onmouseover='show(\"hblpyroxenite\")' onmouseout='unshow(\"hblpyroxenite\")' ";
311                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
312                svg += getLabelInSVG("hblpyroxenite", "hornblende pyroxenite");
313
314                // pyroxenite-hornblendite
315                svg += "<polygon id='pxhblPolygon' points='"
316                                + (leftPadding + diagramWidth / 2) + ","
317                                + (topPadding + triangleDiagramHeight) + " "
318                                + (leftPadding + diagramWidth / 2) + "," + y2 + " " + x4 + ","
319                                + y2 + " " + (width - rightPadding - (x2 - x1)) + ","
320                                + (topPadding + triangleDiagramHeight) + "'";
321                svg += " onmouseover='show(\"pxhbl\")' onmouseout='unshow(\"pxhbl\")' ";
322                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
323                svg += getLabelInSVG("pxhbl", "pyroxenite hornblendite");
324
325                // hornblendite
326                svg += "<polygon id='hornblenditePolygon' points='"
327                                + (width - rightPadding - (x2 - x1)) + ","
328                                + (topPadding + triangleDiagramHeight) + " " + x4 + "," + y2
329                                + " " + (width - rightPadding) + ","
330                                + (topPadding + triangleDiagramHeight) + "'";
331                svg += " onmouseover='show(\"hornblendite\")' onmouseout='unshow(\"hornblendite\")' ";
332                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
333                svg += getLabelInSVG("hornblendite", "hornblendite");
334
335                svg += getSVGFooter();
336                return svg;
337
338        }
339
340        public static String getPlagOpxCpxDiagraminSVG() {
341
342                String svg = getSVGHeader("Plag", "Opx", "Cpx", null);
343
344                // draw top triangle
345                double y1 = topPadding + triangleDiagramHeight / 10;
346                double x1 = (width / 2)
347                                - (Math.tan(Math.PI / 6) * triangleDiagramHeight / 10);
348                double x2 = (width / 2)
349                                + (Math.tan(Math.PI / 6) * triangleDiagramHeight / 10);
350                svg += "<polygon id='anorthositePolygon' points='" + x1 + "," + y1
351                                + " " + x2 + "," + y1 + " " + (width / 2) + "," + topPadding
352                                + "'";
353                svg += " onmouseover='show(\"anorthosite\")' onmouseout='unshow(\"anorthosite\")' ";
354                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
355                svg += getLabelInSVG("anorthosite", "anorthosite");
356
357                // draw bottom polygon
358                double y2 = topPadding + triangleDiagramHeight * 9 / 10;
359                double x3 = (width / 2)
360                                - (Math.tan(Math.PI / 6) * triangleDiagramHeight * 9 / 10);
361                double x4 = (width / 2)
362                                + (Math.tan(Math.PI / 6) * triangleDiagramHeight * 9 / 10);
363                double x5 = (x1 + x2) / 2;
364                svg += "<polygon id='ultramaficPolygon' points='" + (leftPadding) + ","
365                                + (topPadding + triangleDiagramHeight) + " " + x3 + "," + y2
366                                + " " + x4 + "," + y2 + " " + (width - rightPadding) + ","
367                                + (topPadding + triangleDiagramHeight) + "'";
368                svg += " onmouseover='show(\"ultramafic\")' onmouseout='unshow(\"ultramafic\")' ";
369                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
370                svg += getLabelInSVG("ultramafic", "pyroxenite");
371
372                // draw the left polygon
373                svg += "<polygon id='noritePolygon' points='" + x1 + "," + y1 + " "
374                                + x5 + "," + y1 + " " + (x3 + x5 - x1) + "," + y2 + " " + x3
375                                + "," + y2 + "'";
376                svg += " onmouseover='show(\"norite\")' onmouseout='unshow(\"norite\")' ";
377                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
378                svg += getLabelInSVG("norite", "norite");
379
380                // draw the right polygon
381                svg += "<polygon id='troctolitePolygon' points='" + x5 + "," + y1 + " "
382                                + x2 + "," + y1 + " " + x4 + "," + y2 + " " + (x4 - x5 + x1)
383                                + "," + y2 + "'";
384                svg += " onmouseover='show(\"troctolite\")' onmouseout='unshow(\"troctolite\")' ";
385                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
386                svg += getLabelInSVG("troctolite", "gabbro");
387
388                // draw the center1 polygon
389                svg += "<polygon id='clinopyroxenePolygon' points='" + x5 + "," + y1
390                                + " " + (x3 + x5 - x1) + "," + y2 + " " + (width / 2) + ","
391                                + y2 + "'";
392                svg += " onmouseover='show(\"clinopyroxene\")' onmouseout='unshow(\"clinopyroxene\")' ";
393                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
394                svg += getLabelInSVG("clinopyroxene", "clinopyroxene norite");
395
396                // draw the center2 polygon
397                svg += "<polygon id='orthopyroxenePolygon' points='" + x5 + "," + y1
398                                + " " + (width / 2) + "," + y2 + " " + (x4 - x5 + x1) + ","
399                                + y2 + "'";
400                svg += " onmouseover='show(\"orthopyroxene\")' onmouseout='unshow(\"orthopyroxene\")' ";
401                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
402                svg += getLabelInSVG("orthopyroxene", "orthopyroxene gabbro");
403
404                svg += getSVGFooter();
405                return svg;
406
407        }
408
409        public static String getQAPFDiagraminSVG() {
410
411                String svg = getSVGHeader("Q", "A", "P", "F");
412                // top half
413                // draw top triangle
414                double y1 = topPadding + triangleDiagramHeight / 10;
415                double x1 = (width / 2)
416                                - (Math.tan(Math.PI / 6) * triangleDiagramHeight / 10);
417                double x2 = (width / 2)
418                                + (Math.tan(Math.PI / 6) * triangleDiagramHeight / 10);
419                svg += "<polygon id='quartzolitePolygon' points='" + x1 + "," + y1
420                                + " " + x2 + "," + y1 + " " + (width / 2) + "," + topPadding
421                                + "'";
422                svg += " onmouseover='show(\"quartzolite\")' onmouseout='unshow(\"quartzolite\")' ";
423                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
424                svg += getLabelInSVG("quartzolite", "quartzolite");
425
426                // draw second top polygon
427                double y2 = topPadding + triangleDiagramHeight * 4 / 10;
428                double x3 = (width / 2)
429                                - (Math.tan(Math.PI / 6) * triangleDiagramHeight * 4 / 10);
430                double x4 = (width / 2)
431                                + (Math.tan(Math.PI / 6) * triangleDiagramHeight * 4 / 10);
432                svg += "<polygon id='quartzrichPolygon' points='" + x1 + "," + y1 + " "
433                                + x2 + "," + y1 + " " + x4 + "," + y2 + " " + x3 + "," + y2
434                                + "'";
435                svg += " onmouseover='show(\"quartzrich\")' onmouseout='unshow(\"quartzrich\")' ";
436                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
437                svg += getLabelInSVG("quartzrich", "quartz rich granitic");
438
439                // draw third level polygons
440                double y3 = topPadding + triangleDiagramHeight * 8 / 10;
441                double level2length = 2 * (Math.tan(Math.PI / 6)
442                                * triangleDiagramHeight * 4 / 10);
443                double x5 = x3 + level2length / 10;
444                double x6 = x5 + level2length / 4;
445                double x8 = x4 - level2length / 10;
446                double x7 = x8 - level2length / 4;
447                double level3length = (Math.tan(Math.PI / 6) * triangleDiagramHeight
448                                * 8 / 10) * 2;
449                double x9 = (width / 2)
450                                - (Math.tan(Math.PI / 6) * triangleDiagramHeight * 8 / 10);
451                double x10 = x9 + level3length / 10;
452                double x11 = x10 + level3length / 4;
453                double x14 = (width / 2)
454                                + (Math.tan(Math.PI / 6) * triangleDiagramHeight * 8 / 10);
455                double x13 = x14 - level3length / 10;
456                double x12 = x13 - level3length / 4;
457
458                // leftmost polygon
459                svg += "<polygon id='alkfeldgranitePolygon' points='" + x3 + "," + y2
460                                + " " + x5 + "," + y2 + " " + x10 + "," + y3 + " " + x9 + ","
461                                + y3 + "'";
462                svg += " onmouseover='show(\"alkfeldgranite\")' onmouseout='unshow(\"alkfeldgranite\")' ";
463                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
464                svg += getLabelInSVG("alkfeldgranite", "alkali feldspar granite");
465
466                // second leftmost polygon
467                svg += "<polygon id='syenogranitePolygon' points='" + x5 + "," + y2
468                                + " " + x6 + "," + y2 + " " + x11 + "," + y3 + " " + x10 + ","
469                                + y3 + "'";
470                svg += " onmouseover='show(\"syenogranite\")' onmouseout='unshow(\"syenogranite\")' ";
471                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
472                svg += getLabelInSVG("syenogranite", "syeno granite");
473
474                // center polygon
475                svg += "<polygon id='monzogranitePolygon' points='" + x6 + "," + y2
476                                + " " + x7 + "," + y2 + " " + x12 + "," + y3 + " " + x11 + ","
477                                + y3 + "'";
478                svg += " onmouseover='show(\"monzogranite\")' onmouseout='unshow(\"monzogranite\")' ";
479                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
480                svg += getLabelInSVG("monzogranite", "monzo granite");
481
482                // second rightmost polygon
483                svg += "<polygon id='granodioritePolygon' points='" + x7 + "," + y2
484                                + " " + x8 + "," + y2 + " " + x13 + "," + y3 + " " + x12 + ","
485                                + y3 + "'";
486                svg += " onmouseover='show(\"granodiorite\")' onmouseout='unshow(\"granodiorite\")' ";
487                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
488                svg += getLabelInSVG("granodiorite", "granodiorite");
489
490                // rightmost polygon
491                svg += "<polygon id='tonalitePolygon' points='" + x8 + "," + y2 + " "
492                                + x4 + "," + y2 + " " + x14 + "," + y3 + " " + x13 + "," + y3
493                                + "'";
494                svg += " onmouseover='show(\"tonalite\")' onmouseout='unshow(\"tonalite\")' ";
495                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
496                svg += getLabelInSVG("tonalite", "tonalite");
497
498                // draw fourth level polygons
499                double y4 = topPadding + triangleDiagramHeight * 19 / 20;
500                double level4length = 2 * (Math.tan(Math.PI / 6)
501                                * triangleDiagramHeight * 19 / 20);
502                double x15 = (width / 2)
503                                - (Math.tan(Math.PI / 6) * triangleDiagramHeight * 19 / 20);
504                double x16 = x15 + level4length / 10;
505                double x17 = x16 + level4length / 4;
506                double x20 = (width / 2)
507                                + (Math.tan(Math.PI / 6) * triangleDiagramHeight * 19 / 20);
508                double x19 = x20 - level4length / 10;
509                double x18 = x19 - level4length / 4;
510
511                // leftmost polygon
512                svg += "<polygon id='qrzalkfeldsyenitePolygon' points='" + x9 + ","
513                                + y3 + " " + x10 + "," + y3 + " " + x16 + "," + y4 + " " + x15
514                                + "," + y4 + "'";
515                svg += " onmouseover='show(\"qrzalkfeldsyenite\")' onmouseout='unshow(\"qrzalkfeldsyenite\")' ";
516                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
517                svg += getLabelInSVG("qrzalkfeldsyenite",
518                                "quartz alkali feldspar syenite");
519
520                // second leftmost polygon
521                svg += "<polygon id='quartzsyenitePolygon' points='" + x10 + "," + y3
522                                + " " + x11 + "," + y3 + " " + x17 + "," + y4 + " " + x16 + ","
523                                + y4 + "'";
524                svg += " onmouseover='show(\"quartzsyenite\")' onmouseout='unshow(\"quartzsyenite\")' ";
525                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
526                svg += getLabelInSVG("quartzsyenite", "quartz syenite");
527
528                // center polygon
529                svg += "<polygon id='quartzmonzonitePolygon' points='" + x11 + "," + y3
530                                + " " + x12 + "," + y3 + " " + x18 + "," + y4 + " " + x17 + ","
531                                + y4 + "'";
532                svg += " onmouseover='show(\"quartzmonzonite\")' onmouseout='unshow(\"quartzmonzonite\")' ";
533                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
534                svg += getLabelInSVG("quartzmonzonite", "quartz monzonite");
535
536                // second rightmost polygon
537                svg += "<polygon id='quartzmonzoPolygon' points='" + x12 + "," + y3
538                                + " " + x13 + "," + y3 + " " + x19 + "," + y4 + " " + x18 + ","
539                                + y4 + "'";
540                svg += " onmouseover='show(\"quartzmonzo\")' onmouseout='unshow(\"quartzmonzo\")' ";
541                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
542                svg += getLabelInSVG("quartzmonzo",
543                                "quartz monzodiorite quartz monzogabbro");
544
545                // rightmost polygon
546                svg += "<polygon id='quartzPolygon' points='" + x13 + "," + y3 + " "
547                                + x14 + "," + y3 + " " + x20 + "," + y4 + " " + x19 + "," + y4
548                                + "'";
549                svg += " onmouseover='show(\"quartz\")' onmouseout='unshow(\"quartz\")' ";
550                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
551                svg += getLabelInSVG("quartz",
552                                "quartz diorite quartz gabbro quartz anorthosite");
553
554                // draw fifth level polygons
555                double y5 = topPadding + triangleDiagramHeight;
556                double level5length = 2 * (Math.tan(Math.PI / 6) * triangleDiagramHeight);
557                double b1 = (width / 2)
558                                - (Math.tan(Math.PI / 6) * triangleDiagramHeight);
559                double b2 = b1 + level5length / 10;
560                double b3 = b2 + level5length / 4;
561                double b6 = (width / 2)
562                                + (Math.tan(Math.PI / 6) * triangleDiagramHeight);
563                double b5 = b6 - level5length / 10;
564                double b4 = b5 - level5length / 4;
565
566                // leftmost polygon
567                svg += "<polygon id='alkfeldsyenitePolygon' points='" + x15 + "," + y4
568                                + " " + x16 + "," + y4 + " " + b2 + "," + y5 + " " + b1 + ","
569                                + y5 + "'";
570                svg += " onmouseover='show(\"alkfeldsyenite\")' onmouseout='unshow(\"alkfeldsyenite\")' ";
571                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
572                svg += getLabelInSVG("alkfeldsyenite", "alkali feldspar syenite");
573
574                // second leftmost polygon
575                svg += "<polygon id='syenitePolygon' points='" + x16 + "," + y4 + " "
576                                + x17 + "," + y4 + " " + b3 + "," + y5 + " " + b2 + "," + y5
577                                + "'";
578                svg += " onmouseover='show(\"syenite\")' onmouseout='unshow(\"syenite\")' ";
579                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
580                svg += getLabelInSVG("syenite", "syenite");
581
582                // center polygon
583                svg += "<polygon id='monzonitePolygon' points='" + x17 + "," + y4 + " "
584                                + x18 + "," + y4 + " " + b4 + "," + y5 + " " + b3 + "," + y5
585                                + "'";
586                svg += " onmouseover='show(\"monzonite\")' onmouseout='unshow(\"monzonite\")' ";
587                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
588                svg += getLabelInSVG("monzonite", "monzonite");
589
590                // second rightmost polygon
591                svg += "<polygon id='monzoPolygon' points='" + x18 + "," + y4 + " "
592                                + x19 + "," + y4 + " " + b5 + "," + y5 + " " + b4 + "," + y5
593                                + "'";
594                svg += " onmouseover='show(\"monzo\")' onmouseout='unshow(\"monzo\")' ";
595                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
596                svg += getLabelInSVG("monzo", "monzodiorite monzogabbro");
597
598                // rightmost polygon
599                svg += "<polygon id='diogabanorthPolygon' points='" + x19 + "," + y4
600                                + " " + x20 + "," + y4 + " " + b6 + "," + y5 + " " + b5 + ","
601                                + y5 + "'";
602                svg += " onmouseover='show(\"diogabanorth\")' onmouseout='unshow(\"diogabanorth\")' ";
603                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
604                svg += getLabelInSVG("diogabanorth", "diorite gabbro anorthosite");
605
606                // bottom half
607                // draw third level polygons
608                double y6 = topPadding + triangleDiagramHeight * 11 / 10;
609                double level6length = 2 * (Math.tan(Math.PI / 6)
610                                * triangleDiagramHeight * 9 / 10);
611                double b7 = (width / 2)
612                                - (Math.tan(Math.PI / 6) * triangleDiagramHeight * 9 / 10);
613                double b8 = b7 + level5length / 10;
614                double b9 = b8 + level5length / 4;
615                double b12 = (width / 2)
616                                + (Math.tan(Math.PI / 6) * triangleDiagramHeight * 9 / 10);
617                double b11 = b12 - level5length / 10;
618                double b10 = b11 - level5length / 4;
619
620                // leftmost polygon
621                svg += "<polygon id='foidbearalkfeldsyenitePolygon' points='" + b1
622                                + "," + y5 + " " + b2 + "," + y5 + " " + b8 + "," + y6 + " "
623                                + b7 + "," + y6 + "'";
624                svg += " onmouseover='show(\"foidbearalkfeldsyenite\")' onmouseout='unshow(\"foidbearalkfeldsyenite\")' ";
625                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
626                svg += getLabelInSVG("foidbearalkfeldsyenite",
627                                "foid bearing alkali feldspar syenite");
628
629                // second leftmost polygon
630                svg += "<polygon id='foidbearsyenitePolygon' points='" + b2 + "," + y5
631                                + " " + b3 + "," + y5 + " " + b9 + "," + y6 + " " + b8 + ","
632                                + y6 + "'";
633                svg += " onmouseover='show(\"foidbearsyenite\")' onmouseout='unshow(\"foidbearsyenite\")' ";
634                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
635                svg += getLabelInSVG("foidbearsyenite", "foid bearing syenite");
636
637                // center polygon
638                svg += "<polygon id='foidbearmonzonitePolygon' points='" + b3 + ","
639                                + y5 + " " + b4 + "," + y5 + " " + b10 + "," + y6 + " " + b9
640                                + "," + y6 + "'";
641                svg += " onmouseover='show(\"foidbearmonzonite\")' onmouseout='unshow(\"foidbearmonzonite\")' ";
642                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
643                svg += getLabelInSVG("foidbearmonzonite", "foid bearing monzonite");
644
645                // second rightmost polygon
646                svg += "<polygon id='foidbearmonzoPolygon' points='" + b4 + "," + y5
647                                + " " + b5 + "," + y5 + " " + b11 + "," + y6 + " " + b10 + ","
648                                + y6 + "'";
649                svg += " onmouseover='show(\"foidbearmonzo\")' onmouseout='unshow(\"foidbearmonzo\")' ";
650                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
651                svg += getLabelInSVG("foidbearmonzo",
652                                "foid bearing monzodiorite foid bearing monzogabbro");
653
654                // rightmost polygon
655                svg += "<polygon id='foidbeardiogabanorthPolygon' points='" + b5 + ","
656                                + y5 + " " + b6 + "," + y5 + " " + b12 + "," + y6 + " " + b11
657                                + "," + y6 + "'";
658                svg += " onmouseover='show(\"foidbeardiogabanorth\")' onmouseout='unshow(\"foidbeardiogabanorth\")' ";
659                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
660                svg += getLabelInSVG("foidbeardiogabanorth",
661                                "foid bearing diorite foid bearing gabbro foid bearing anorthosite");
662
663                // draw third level polygons
664                double y7 = topPadding + triangleDiagramHeight * 16 / 10;
665
666                // leftmost polygon
667                svg += "<polygon id='foidsyenitePolygon' points='" + b7 + "," + y6
668                                + " " + b8 + "," + y6 + " " + x5 + "," + y7 + " " + x3 + ","
669                                + y7 + "'";
670                svg += " onmouseover='show(\"foidsyenite\")' onmouseout='unshow(\"foidsyenite\")' ";
671                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
672                svg += getLabelInSVG("foidsyenite", "foid syenite");
673
674                // second leftmost polygon
675                svg += "<polygon id='foidmonzosyenitePolygon' points='" + b8 + "," + y6
676                                + " " + (width / 2) + "," + y6 + " " + (width / 2) + "," + y7
677                                + " " + x5 + "," + y7 + "'";
678                svg += " onmouseover='show(\"foidmonzosyenite\")' onmouseout='unshow(\"foidmonzosyenite\")' ";
679                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
680                svg += getLabelInSVG("foidmonzosyenite", "foidmonzo syenite");
681
682                // second rightmost polygon
683                svg += "<polygon id='foidmonzoPolygon' points='" + (width / 2) + ","
684                                + y6 + " " + b11 + "," + y6 + " " + x8 + "," + y7 + " "
685                                + (width / 2) + "," + y7 + "'";
686                svg += " onmouseover='show(\"foidmonzo\")' onmouseout='unshow(\"foidmonzo\")' ";
687                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
688                svg += getLabelInSVG("foidmonzo", "foid monzosyenite foid gabbro");
689
690                // rightmost polygon
691                svg += "<polygon id='foiddiogabPolygon' points='" + b11 + "," + y6
692                                + " " + b12 + "," + y6 + " " + x4 + "," + y7 + " " + x8 + ","
693                                + y7 + "'";
694                svg += " onmouseover='show(\"foiddiogab\")' onmouseout='unshow(\"foiddiogab\")' ";
695                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
696                svg += getLabelInSVG("foiddiogab", "foid diorite foid gabbro");
697
698                // draw bottom triangle.
699                double ybot = topPadding + diagramHeight;
700
701                svg += "<polygon id='foidolitePolygon' points='" + x3 + "," + y7 + " "
702                                + x4 + "," + y7 + " " + (width / 2) + "," + ybot + "'";
703                svg += " onmouseover='show(\"foidolite\")' onmouseout='unshow(\"foidolite\")' ";
704                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
705                svg += getLabelInSVG("foidolite", "foidolite");
706
707                svg += getSVGFooter();
708                return svg;
709
710        }
711
712        public static String getOlOpxCpxDiagraminSVG() {
713
714                String svg = getSVGHeader("Ol", "Opx", "Cpx", null);
715
716                // top half
717                // draw top triangle
718                double y1 = topPadding + triangleDiagramHeight / 10;
719                double x1 = (width / 2)
720                                - (Math.tan(Math.PI / 6) * triangleDiagramHeight / 10);
721                double x2 = (width / 2)
722                                + (Math.tan(Math.PI / 6) * triangleDiagramHeight / 10);
723                svg += "<polygon id='dunitePolygon' points='" + x1 + "," + y1 + " "
724                                + x2 + "," + y1 + " " + (width / 2) + "," + topPadding + "'";
725                svg += " onmouseover='show(\"dunite\")' onmouseout='unshow(\"dunite\")' ";
726                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
727                svg += getLabelInSVG("dunite", "dunite");
728
729                // draw the left polygon
730                double y2 = topPadding + triangleDiagramHeight * 6 / 10;
731                double x3 = (width / 2)
732                                - (Math.tan(Math.PI / 6) * triangleDiagramHeight * 6 / 10);
733                double x4 = (width / 2)
734                                + (Math.tan(Math.PI / 6) * triangleDiagramHeight * 6 / 10);
735                double x5 = (x1 + x2) / 2;
736                svg += "<polygon id='harzburitePolygon' points='" + x1 + "," + y1 + " "
737                                + x5 + "," + y1 + " " + (x3 + x5 - x1) + "," + y2 + " " + x3
738                                + "," + y2 + "'";
739                svg += " onmouseover='show(\"harzburite\")' onmouseout='unshow(\"harzburite\")' ";
740                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
741                svg += getLabelInSVG("harzburite", "harzburite");
742
743                // draw the right polygon
744                svg += "<polygon id='wehrlitePolygon' points='" + x5 + "," + y1 + " "
745                                + x2 + "," + y1 + " " + x4 + "," + y2 + " " + (x4 - x5 + x1)
746                                + "," + y2 + "'";
747                svg += " onmouseover='show(\"wehrlite\")' onmouseout='unshow(\"wehrlite\")' ";
748                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
749                svg += getLabelInSVG("wehrlite", "wehrlite");
750
751                // draw the center polygon
752                svg += "<polygon id='lherzolitePolygon' points='" + x5 + "," + y1 + " "
753                                + (x3 + x5 - x1) + "," + y2 + " " + (x4 - x5 + x1) + "," + y2
754                                + "'";
755                svg += " onmouseover='show(\"lherzolite\")' onmouseout='unshow(\"lherzolite\")' ";
756                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
757                svg += getLabelInSVG("lherzolite", "lherzolite");
758
759                // bottom half
760                // draw bottom left polygon
761                double y3 = topPadding + triangleDiagramHeight * 9 / 10;
762                double x6 = (width / 2)
763                                - (Math.tan(Math.PI / 6) * triangleDiagramHeight * 9 / 10);
764                double x7 = (width / 2)
765                                + (Math.tan(Math.PI / 6) * triangleDiagramHeight * 9 / 10);
766
767                svg += "<polygon id='pyroxenitePolygon' points='" + x3 + "," + y2 + " "
768                                + leftPadding + "," + (topPadding + triangleDiagramHeight)
769                                + " " + (leftPadding + (x2 - x1)) + ","
770                                + (topPadding + triangleDiagramHeight) + "'";
771                svg += " onmouseover='show(\"pyroxenite\")' onmouseout='unshow(\"pyroxenite\")' ";
772                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
773                svg += getLabelInSVG("pyroxenite", "pyroxenite");
774
775                // bottom right polygon
776                svg += "<polygon id='hblpyroxenitePolygon' points='" + x3 + "," + y2
777                                + " " + (leftPadding + (x2 - x1)) + ","
778                                + (topPadding + triangleDiagramHeight) + " "
779                                + (leftPadding + diagramWidth / 2) + ","
780                                + (topPadding + triangleDiagramHeight) + " "
781                                + (leftPadding + diagramWidth / 2) + "," + y2 + "'";
782                svg += " onmouseover='show(\"hblpyroxenite\")' onmouseout='unshow(\"hblpyroxenite\")' ";
783                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
784                svg += getLabelInSVG("hblpyroxenite", "hornblende pyroxenite");
785
786                // pyroxenite-hornblendite
787                svg += "<polygon id='pxhblPolygon' points='"
788                                + (leftPadding + diagramWidth / 2) + ","
789                                + (topPadding + triangleDiagramHeight) + " "
790                                + (leftPadding + diagramWidth / 2) + "," + y2 + " " + x4 + ","
791                                + y2 + " " + (width - rightPadding - (x2 - x1)) + ","
792                                + (topPadding + triangleDiagramHeight) + "'";
793                svg += " onmouseover='show(\"pxhbl\")' onmouseout='unshow(\"pxhbl\")' ";
794                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
795                svg += getLabelInSVG("pxhbl", "pyroxenite hornblendite");
796
797                // hornblendite
798                svg += "<polygon id='hornblenditePolygon' points='"
799                                + (width - rightPadding - (x2 - x1)) + ","
800                                + (topPadding + triangleDiagramHeight) + " " + x4 + "," + y2
801                                + " " + (width - rightPadding) + ","
802                                + (topPadding + triangleDiagramHeight) + "'";
803                svg += " onmouseover='show(\"hornblendite\")' onmouseout='unshow(\"hornblendite\")' ";
804                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
805                svg += getLabelInSVG("hornblendite", "hornblendite");
806
807                svg += getSVGFooter();
808                return svg;
809
810        }
811
812        public static String getZrTid100Srd2DiagraminSVG() {
813                Point2D.Double p;
814                String svg = getSVGHeader("Ti/100", "Zr", "Sr/2", null);
815
816                svg += "<polygon id='Zr-Ti/100-Sr/2' points='"
817                                + (leftPadding + diagramWidth / 2) + "," + topPadding + " "
818                                + leftPadding + "," + (topPadding + triangleDiagramHeight)
819                                + " " + (leftPadding + diagramWidth) + ","
820                                + (topPadding + triangleDiagramHeight) + "'";
821                svg += " onmouseover='show(\"Zr-Ti/100-Sr/2 \")' onmouseout='unshow(\"Zr-Ti/100-Sr/2 \")' ";
822                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
823
824                p = getPoint(leftPadding, topPadding, diagramWidth,
825                                triangleDiagramHeight, 33, 45, 22);
826                double y1 = p.getY();
827                double x1 = p.getX();
828
829                p = getPoint(leftPadding, topPadding, diagramWidth,
830                                triangleDiagramHeight, 46, 39, 15);
831                double y2 = p.getY();
832                double x2 = p.getX();
833
834                p = getPoint(leftPadding, topPadding, diagramWidth,
835                                triangleDiagramHeight, 54, 32, 14);
836                double y3 = p.getY();
837                double x3 = p.getX();
838
839                p = getPoint(leftPadding, topPadding, diagramWidth,
840                                triangleDiagramHeight, 52, 25, 23);
841                double y4 = p.getY();
842                double x4 = p.getX();
843
844                p = getPoint(leftPadding, topPadding, diagramWidth,
845                                triangleDiagramHeight, 35, 25, 40);
846                double y5 = p.getY();
847                double x5 = p.getX();
848
849                p = getPoint(leftPadding, topPadding, diagramWidth,
850                                triangleDiagramHeight, 27, 32, 41);
851                double y6 = p.getY();
852                double x6 = p.getX();
853
854                p = getPoint(leftPadding, topPadding, diagramWidth,
855                                triangleDiagramHeight, 26, 41, 33);
856                double y7 = p.getY();
857                double x7 = p.getX();
858
859                // right polygon
860                svg += "<polygon id='Ocean-floorCPolygon' points='" + x1 + "," + y1
861                                + " " + x2 + "," + y2 + " " + x3 + "," + y3 + " " + x4 + ","
862                                + y4 + " " + x5 + "," + y5 + " " + x6 + "," + y6 + " " + x7
863                                + "," + y7 + "'";
864                svg += " onmouseover='show(\"Ocean-floor C\")' onmouseout='unshow(\"Ocean-floor C\")' ";
865                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
866                svg += getLabelInSVG("Ocean-floor C", "Ocean-floor C");
867
868                // draw left polygon
869
870                p = getPoint(leftPadding, topPadding, diagramWidth,
871                                triangleDiagramHeight, 20, 18, 62);
872                double y8 = p.getY();
873                double x8 = p.getX();
874
875                p = getPoint(leftPadding, topPadding, diagramWidth,
876                                triangleDiagramHeight, 16, 5, 79);
877                double y9 = p.getY();
878                double x9 = p.getX();
879
880                p = getPoint(leftPadding, topPadding, diagramWidth,
881                                triangleDiagramHeight, 11, 22, 67);
882                double y10 = p.getY();
883                double x10 = p.getX();
884
885                p = getPoint(leftPadding, topPadding, diagramWidth,
886                                triangleDiagramHeight, 15, 35, 50);
887                double y11 = p.getY();
888                double x11 = p.getX();
889
890                svg += "<polygon id='Island-arcAPolygon' points='" + x7 + "," + y7
891                                + " " + x6 + "," + y6 + " " + x5 + "," + y5 + " " + x8 + ","
892                                + y8 + " " + x9 + "," + y9 + " " + x10 + "," + y10 + " " + x11
893                                + "," + y11 + "'";
894                svg += " onmouseover='show(\"Island-arc A\")' onmouseout='unshow(\"Island-arc A\")' ";
895                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
896                svg += getLabelInSVG("Island-arc A", "Island-arc A");
897
898                // draw bottom polygon
899
900                p = getPoint(leftPadding, topPadding, diagramWidth,
901                                triangleDiagramHeight, 52, 11, 37);
902                double y12 = p.getY();
903                double x12 = p.getX();
904
905                p = getPoint(leftPadding, topPadding, diagramWidth,
906                                triangleDiagramHeight, 32, 6, 62);
907                double y13 = p.getY();
908                double x13 = p.getX();
909
910                svg += "<polygon id='Calc-alkaliBPolygon' points='" + x5 + "," + y5
911                                + " " + x4 + "," + y4 + " " + x12 + "," + y12 + " " + x13 + ","
912                                + y13 + " " + x9 + "," + y9 + " " + x8 + "," + y8 + "'";
913                svg += " onmouseover='show(\"Calc-alkali B\")' onmouseout='unshow(\"Calc-alkali B\")' ";
914                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
915                svg += getLabelInSVG("Calc-alkali B", "Calc-alkali B");
916
917                svg += getSVGFooter();
918                return svg;
919
920        }
921
922        public static String getZrTid100Y3DiagraminSVG() {
923                Point2D.Double p;
924                String svg = getSVGHeader("Ti/100", "Zr", "Y*3", null);
925
926                // The main Triangle
927                svg += "<polygon id='Zr-Ti/100-Y*3' points='"
928                                + (leftPadding + diagramWidth / 2) + "," + topPadding + " "
929                                + leftPadding + "," + (topPadding + triangleDiagramHeight)
930                                + " " + (leftPadding + diagramWidth) + ","
931                                + (topPadding + triangleDiagramHeight) + "'";
932                svg += " onmouseover='show(\"Zr-Ti/100-Y*3 \")' onmouseout='unshow(\"Zr-Ti/100-Y*3 \")' ";
933                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
934
935                // Top left polygon
936                p = getPoint(leftPadding, topPadding, diagramWidth,
937                                triangleDiagramHeight, 23, 48, 29);
938                double y1 = p.getY();
939                double x1 = p.getX();
940
941                p = getPoint(leftPadding, topPadding, diagramWidth,
942                                triangleDiagramHeight, 29, 42, 29);
943                double y2 = p.getY();
944                double x2 = p.getX();
945
946                p = getPoint(leftPadding, topPadding, diagramWidth,
947                                triangleDiagramHeight, 44, 30, 26);
948                double y3 = p.getY();
949                double x3 = p.getX();
950
951                p = getPoint(leftPadding, topPadding, diagramWidth,
952                                triangleDiagramHeight, 55, 24, 21);
953                double y4 = p.getY();
954                double x4 = p.getX();
955
956                p = getPoint(leftPadding, topPadding, diagramWidth,
957                                triangleDiagramHeight, 58, 29, 13);
958                double y5 = p.getY();
959                double x5 = p.getX();
960
961                p = getPoint(leftPadding, topPadding, diagramWidth,
962                                triangleDiagramHeight, 37, 50, 13);
963                double y6 = p.getY();
964                double x6 = p.getX();
965
966                svg += "<polygon id='Within-plateDpolygon ' points ='" + x1 + "," + y1
967                                + " " + x2 + "," + y2 + " " + x3 + "," + y3 + " " + x4 + ","
968                                + y4 + " " + x5 + "," + y5 + " " + x6 + "," + y6 + "'";
969                svg += " onmouseover='show(\"Within-plate DD\")' onmouseout='unshow(\"Within-plate DD\")' ";
970                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
971                svg += getLabelInSVG("Within-plate DD", "Within-plate DD");
972
973                // Top right polygon
974                p = getPoint(leftPadding, topPadding, diagramWidth,
975                                triangleDiagramHeight, 23, 48, 29);
976                double y17 = p.getY();
977                double x17 = p.getX();
978
979                p = getPoint(leftPadding, topPadding, diagramWidth,
980                                triangleDiagramHeight, 17, 42, 41);
981                double y18 = p.getY();
982                double x18 = p.getX();
983
984                p = getPoint(leftPadding, topPadding, diagramWidth,
985                                triangleDiagramHeight, 27, 28, 45);
986                double y19 = p.getY();
987                double x19 = p.getX();
988
989                p = getPoint(leftPadding, topPadding, diagramWidth,
990                                triangleDiagramHeight, 29, 42, 29);
991                double y20 = p.getY();
992                double x20 = p.getX();
993
994                svg += "<polygon id='Island-arcA' points ='" + x17 + "," + y17 + " "
995                                + x18 + "," + y18 + " " + x19 + "," + y19 + " " + x20 + ","
996                                + y20 + "'";
997
998                svg += " onmouseover='show(\"Islandic-arc A\")' onmouseout='unshow(\"Islandic-arc A\")' ";
999                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
1000                svg += getLabelInSVG("Islandic-arc A", "Islandic-arc A");
1001
1002                // central polygon
1003                p = getPoint(leftPadding, topPadding, diagramWidth,
1004                                triangleDiagramHeight, 27, 28, 45);
1005                double y13 = p.getY();
1006                double x13 = p.getX();
1007
1008                p = getPoint(leftPadding, topPadding, diagramWidth,
1009                                triangleDiagramHeight, 29, 42, 29);
1010                double y14 = p.getY();
1011                double x14 = p.getX();
1012
1013                p = getPoint(leftPadding, topPadding, diagramWidth,
1014                                triangleDiagramHeight, 44, 30, 26);
1015                double y15 = p.getY();
1016                double x15 = p.getX();
1017
1018                p = getPoint(leftPadding, topPadding, diagramWidth,
1019                                triangleDiagramHeight, 39, 20, 41);
1020                double y16 = p.getY();
1021                double x16 = p.getX();
1022
1023                svg += "<polygon id='Ocean-floorB' points ='" + x13 + "," + y13 + " "
1024                                + x14 + "," + y14 + " " + x15 + "," + y15 + " " + x16 + ","
1025                                + y16 + "'";
1026
1027                svg += " onmouseover='show(\"Ocean-floor B\")' onmouseout='unshow(\"Ocean-floor B\")' ";
1028                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
1029                svg += getLabelInSVG("Ocean-floor B", "Ocean-floor B");
1030
1031                // bottom right polygon
1032                p = getPoint(leftPadding, topPadding, diagramWidth,
1033                                triangleDiagramHeight, 44, 30, 26);
1034                double y7 = p.getY();
1035                double x7 = p.getX();
1036
1037                p = getPoint(leftPadding, topPadding, diagramWidth,
1038                                triangleDiagramHeight, 39, 20, 41);
1039                double y8 = p.getY();
1040                double x8 = p.getX();
1041
1042                p = getPoint(leftPadding, topPadding, diagramWidth,
1043                                triangleDiagramHeight, 54, 11, 35);
1044                double y9 = p.getY();
1045                double x9 = p.getX();
1046
1047                p = getPoint(leftPadding, topPadding, diagramWidth,
1048                                triangleDiagramHeight, 60, 12, 28);
1049                double y10 = p.getY();
1050                double x10 = p.getX();
1051
1052                p = getPoint(leftPadding, topPadding, diagramWidth,
1053                                triangleDiagramHeight, 61, 17, 22);
1054                double y11 = p.getY();
1055                double x11 = p.getX();
1056
1057                p = getPoint(leftPadding, topPadding, diagramWidth,
1058                                triangleDiagramHeight, 55, 24, 21);
1059                double y12 = p.getY();
1060                double x12 = p.getX();
1061
1062                svg += "<polygon id='Calc-alkaliBC' points ='" + x7 + "," + y7 + " "
1063                                + x8 + "," + y8 + " " + x9 + "," + y9 + " " + x10 + "," + y10
1064                                + " " + x11 + "," + y11 + " " + x12 + "," + y12 + "'";
1065
1066                svg += " onmouseover='show(\"Calc-alkali B,C\")' onmouseout='unshow(\"Calc-alkali B,C\")' ";
1067                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
1068                svg += getLabelInSVG("Calc-alkali B,C", "Calc-alkali B,C");
1069
1070                svg += getSVGFooter();
1071                return svg;
1072
1073        }
1074
1075        public static String getThHfd3TaDiagraminSVG() {
1076                Point2D.Double p;
1077                String svg = getSVGHeader("Hf/3", "Th", "Ta", null);
1078
1079                // The main Triangle
1080                svg += "<polygon id='Th-Hf/3-Ta' points='"
1081                                + (leftPadding + diagramWidth / 2) + "," + topPadding + " "
1082                                + leftPadding + "," + (topPadding + triangleDiagramHeight)
1083                                + " " + (leftPadding + diagramWidth) + ","
1084                                + (topPadding + triangleDiagramHeight) + "'";
1085                svg += " onmouseover='show(\"Th-Hf/3-Ta \")' onmouseout='unshow(\"Th-Hf/3-Ta \")' ";
1086                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
1087
1088                System.out.println("Hf = {" + (leftPadding + diagramWidth / 2) + " , "
1089                                + topPadding + "}");
1090                System.out.println("Th = {" + leftPadding + " , "
1091                                + (topPadding + triangleDiagramHeight) + "}");
1092
1093                // Top right polygon
1094                p = getPoint(leftPadding, topPadding, diagramWidth,
1095                                triangleDiagramHeight, 3, 88, 9);
1096                double y1 = p.getY();
1097                double x1 = p.getX();
1098
1099                p = getPoint(leftPadding, topPadding, diagramWidth,
1100                                triangleDiagramHeight, 15, 77, 8);
1101                double y2 = p.getY();
1102                double x2 = p.getX();
1103
1104                p = getPoint(leftPadding, topPadding, diagramWidth,
1105                                triangleDiagramHeight, 35, 46, 19);
1106                double y3 = p.getY();
1107                double x3 = p.getX();
1108
1109                p = getPoint(leftPadding, topPadding, diagramWidth,
1110                                triangleDiagramHeight, 7, 65, 28);
1111                double y4 = p.getY();
1112                double x4 = p.getX();
1113
1114                svg += "<polygon id='N-MORBpolygon' points ='" + x1 + "," + y1 + " "
1115                                + x2 + "," + y2 + " " + x3 + "," + y3 + " " + x4 + "," + y4
1116                                + "'";
1117                svg += " onmouseover='show(\"N-MORB\")' onmouseout='unshow(\"N-MORB\")' ";
1118                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
1119                svg += getLabelInSVG("N-MORB", "N-MORB");
1120
1121                // Top right polygon
1122                p = getPoint(leftPadding, topPadding, diagramWidth,
1123                                triangleDiagramHeight, 7, 65, 28);
1124                double y5 = p.getY();
1125                double x5 = p.getX();
1126
1127                p = getPoint(leftPadding, topPadding, diagramWidth,
1128                                triangleDiagramHeight, 35, 46, 19);
1129                double y6 = p.getY();
1130                double x6 = p.getX();
1131
1132                p = getPoint(leftPadding, topPadding, diagramWidth,
1133                                triangleDiagramHeight, 54, 25, 21);
1134                double y7 = p.getY();
1135                double x7 = p.getX();
1136
1137                p = getPoint(leftPadding, topPadding, diagramWidth,
1138                                triangleDiagramHeight, 57, 20, 23);
1139                double y8 = p.getY();
1140                double x8 = p.getX();
1141
1142                p = getPoint(leftPadding, topPadding, diagramWidth,
1143                                triangleDiagramHeight, 26, 34, 40);
1144                double y9 = p.getY();
1145                double x9 = p.getX();
1146
1147                p = getPoint(leftPadding, topPadding, diagramWidth,
1148                                triangleDiagramHeight, 13, 42, 45);
1149                double y10 = p.getY();
1150                double x10 = p.getX();
1151
1152                p = getPoint(leftPadding, topPadding, diagramWidth,
1153                                triangleDiagramHeight, 5, 55, 40);
1154                double y11 = p.getY();
1155                double x11 = p.getX();
1156
1157                svg += "<polygon id='E-MORB' points ='" + x5 + "," + y5 + " " + x6
1158                                + "," + y6 + " " + x7 + "," + y7 + " " + x8 + "," + y8 + " "
1159                                + x9 + "," + y9 + " " + x10 + "," + y10 + " " + x11 + "," + y11
1160                                + "'";
1161
1162                svg += " onmouseover='show(\"E-MORB\")' onmouseout='unshow(\"E-MORB\")' ";
1163                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
1164                svg += getLabelInSVG("E-MORB", "E-MORB");
1165
1166                // bottom polygon
1167                p = getPoint(leftPadding, topPadding, diagramWidth,
1168                                triangleDiagramHeight, 26, 34, 40);
1169                y11 = p.getY();
1170                x11 = p.getX();
1171
1172                p = getPoint(leftPadding, topPadding, diagramWidth,
1173                                triangleDiagramHeight, 57, 20, 23);
1174                double y12 = p.getY();
1175                double x12 = p.getX();
1176
1177                p = getPoint(leftPadding, topPadding, diagramWidth,
1178                                triangleDiagramHeight, 63, 8, 29);
1179                double y13 = p.getY();
1180                double x13 = p.getX();
1181
1182                p = getPoint(leftPadding, topPadding, diagramWidth,
1183                                triangleDiagramHeight, 40, 12, 48);
1184                double y14 = p.getY();
1185                double x14 = p.getX();
1186
1187                p = getPoint(leftPadding, topPadding, diagramWidth,
1188                                triangleDiagramHeight, 32, 20, 48);
1189                double y15 = p.getY();
1190                double x15 = p.getX();
1191
1192                svg += "<polygon id='OIB-Rift' points ='" + x11 + "," + y11 + " " + x12
1193                                + "," + y12 + " " + x13 + "," + y13 + " " + x14 + "," + y14
1194                                + " " + x15 + "," + y15 + "'";
1195
1196                svg += " onmouseover='show(\"OIB(Rift)\")' onmouseout='unshow(\"OIB(Rift)\")' ";
1197                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
1198                svg += getLabelInSVG("OIB(Rift)", "OIB(Rift)");
1199
1200                // bottom right polygon
1201                p = getPoint(leftPadding, topPadding, diagramWidth,
1202                                triangleDiagramHeight, 15, 85, 0);
1203                double y16 = p.getY();
1204                double x16 = p.getX();
1205
1206                System.out.println("problemPoint = {" + x16 + " , " + y16 + "}");
1207
1208                p = getPoint(leftPadding, topPadding, diagramWidth,
1209                                triangleDiagramHeight, 15, 77, 8);
1210                double y17 = p.getY();
1211                double x17 = p.getX();
1212
1213                p = getPoint(leftPadding, topPadding, diagramWidth,
1214                                triangleDiagramHeight, 23, 64, 13);
1215                double y18 = p.getY();
1216                double x18 = p.getX();
1217
1218                p = getPoint(leftPadding, topPadding, diagramWidth,
1219                                triangleDiagramHeight, 55, 25, 20);
1220                double y19 = p.getY();
1221                double x19 = p.getX();
1222
1223                p = getPoint(leftPadding, topPadding, diagramWidth,
1224                                triangleDiagramHeight, 95, 0, 5);
1225                double y20 = p.getY();
1226                double x20 = p.getX();
1227
1228                p = getPoint(leftPadding, topPadding, diagramWidth,
1229                                triangleDiagramHeight, 100, 0, 0);
1230                double y21 = p.getY();
1231                double x21 = p.getX();
1232
1233                System.out.println("Th = {" + x21 + " , " + y21 + "}");
1234
1235                svg += "<polygon id='Arc-basalts' points ='" + x16 + "," + y16 + " "
1236                                + x17 + "," + y17 + " " + x18 + "," + y18 + " " + x19 + ","
1237                                + y19 + " " + x20 + "," + y20 + " " + x21 + "," + y21 + "'";
1238
1239                svg += " onmouseover='show(\"Arc-basalts\")' onmouseout='unshow(\"Arc-basalts\")' ";
1240                svg += " fill='white' style='stroke: black; stroke-width: 0.4; ' />\n";
1241                svg += getLabelInSVG("Arc-basalts", "Arc-basalts");
1242
1243                svg += getSVGFooter();
1244                return svg;
1245
1246        }
1247
1248        public static Point2D.Double getPoint(double leftPadding,
1249                        double topPadding, double diagramWidth, double diagramHeight,
1250                        double zr, double ti, double sr) {
1251                double X = 0, Y = 0;
1252
1253                double sum = zr + ti + sr;
1254
1255                X = sr / sum;
1256                Y = ti / sum;
1257
1258                double x1 = leftPadding + (X * diagramWidth);
1259                double y1 = topPadding + diagramHeight;
1260
1261                double y0 = topPadding + ((1 - Y) * diagramHeight);
1262                double x0 = x1 + (y1 - y0) / (Math.tan(Math.PI / 6)); // divide by
1263                                                                                                                                // tan(30)
1264                                                                                                                                // instead of
1265                                                                                                                                // sin(30)?
1266
1267                // System.out.println("x1 = " + x1 + " , y1 = " + y1 + " , x0 = " + x0 +
1268                // " , y0 = " + y0);
1269
1270                return new Point2D.Double(x0, y0);
1271
1272        }
1273
1274        static public void main(String args[]) throws Exception {
1275                // fourVertices = false;
1276
1277                fourVertices = true;
1278                String svg1 = getQAPFDiagraminSVG();
1279                PrintWriter pw1 = new PrintWriter(new FileWriter(
1280                                "C:/projects/kepler/lib/testdata/geon/QAPF.svg"));
1281                pw1.println(svg1);
1282                pw1.close();
1283                /*
1284                 * fourVertices = false; String svg2 = getThHfd3TaDiagraminSVG();
1285                 * PrintWriter pw2 = new PrintWriter(new
1286                 * FileWriter("ternarydiagrams/ThHfd3Ta.svg")); pw2.println(svg2);
1287                 * pw2.close();
1288                 */
1289        }
1290
1291}