| 1 |
<?php |
<?php |
| 2 |
|
// $Id$ |
| 3 |
|
|
| 4 |
// Demonstration of how to embed an svg file |
/** |
| 5 |
|
* @file |
| 6 |
|
* The Drawing Demo module. |
| 7 |
|
*/ |
| 8 |
|
|
| 9 |
|
|
| 10 |
|
############################################################################### |
| 11 |
|
######################### DRUPAL HOOK IMPLEMENTATIONS ######################### |
| 12 |
|
############################################################################### |
| 13 |
|
|
| 14 |
|
/* |
| 15 |
|
* Implementation of hook_menu(). |
| 16 |
|
* |
| 17 |
|
* To add more demos, simply add 'Your_Demo' to the $demos array, where |
| 18 |
|
* Your_Demo is the computer-safe title of your demo. The page callback will |
| 19 |
|
* be "drawing_demo_your_demo()", the path will be "drawing_demo/your_demo", |
| 20 |
|
* and the title of the page will be "Demo Your Demo drawing". |
| 21 |
|
* |
| 22 |
|
*/ |
| 23 |
function drawing_demo_menu() { |
function drawing_demo_menu() { |
| 24 |
$items = array(); |
$items = array(); |
| 25 |
$items['drawing_demo'] = array( |
$items['drawing_demo'] = array( |
| 26 |
'title' => 'drawing_demo drawing', |
'title' => 'Drawing demo', |
| 27 |
'page callback' => 'drawing_demo_page', |
'page callback' => '_drawing_demo', |
| 28 |
|
'access arguments' => array('access content'), |
| 29 |
|
); |
| 30 |
|
$demos = array( |
| 31 |
|
'GD', |
| 32 |
|
'SVG', |
| 33 |
|
'graph', |
| 34 |
|
'stackbar', |
| 35 |
|
'pie_chart', |
| 36 |
|
'tagstack', |
| 37 |
|
); |
| 38 |
|
foreach ($demos as $demo) { |
| 39 |
|
$key = strtolower($demo); |
| 40 |
|
$display = str_replace('_', ' ', $demo); |
| 41 |
|
$items['drawing_demo/'. $key] = array( |
| 42 |
|
'title' => 'Demo '. $display .' drawing', |
| 43 |
|
'page callback' => 'drawing_demo_'. $key, |
| 44 |
'access arguments' => array('access content'), |
'access arguments' => array('access content'), |
| 45 |
|
'type' => MENU_CALLBACK, |
| 46 |
); |
); |
| 47 |
$items['graph'] = array( |
} |
| 48 |
'title' => 'graph drawing', |
return $items; |
| 49 |
'page callback' => 'drawing_demo_graph_page', |
} |
| 50 |
'access arguments' => array('access content'), |
|
| 51 |
); |
/* |
| 52 |
$items['stackbar'] = array( |
* Implementation of hook_block(). |
| 53 |
'title' => 'stackbar chart', |
*/ |
| 54 |
'page callback' => 'drawing_demo_stackbar_page', |
function drawing_demo_block($op = 'list', $delta = 0, $edit = array()) { |
| 55 |
'access arguments' => array('access content'), |
if ($op == 'list') { |
| 56 |
); |
$blocks = array( |
| 57 |
$items['pie_chart'] = array( |
'info' => t('Pie chart block'), |
| 58 |
'title' => 'pie chart', |
'weight' => 0, |
| 59 |
'page callback' => 'drawing_demo_pie_chart_page', |
'enabled' => 1, |
| 60 |
'access arguments' => array('access content'), |
'region' => 'left', |
| 61 |
); |
); |
| 62 |
$items['tagstack'] = array( |
return $blocks; |
| 63 |
'title' => 'tagstack', |
} |
| 64 |
'page callback' => 'drawing_demo_tagstack_page', |
elseif ($op == 'view') { |
| 65 |
'access arguments' => array('access content'), |
$blocks = array( |
| 66 |
|
'subject' => t('Pie chart block'), |
| 67 |
|
'content' => drawing_demo_pie_chart(), |
| 68 |
); |
); |
| 69 |
return $items; |
return $blocks; |
| 70 |
|
} |
| 71 |
} |
} |
| 72 |
|
|
| 73 |
function drawing_demo_canvas() { |
|
| 74 |
|
############################################################################### |
| 75 |
|
############################## INTERNAL FUNCTIONS ############################# |
| 76 |
|
############################################################################### |
| 77 |
|
|
| 78 |
|
/** |
| 79 |
|
* Callback for drawing demo menu page. |
| 80 |
|
*/ |
| 81 |
|
function _drawing_demo() { |
| 82 |
|
$list = array(); |
| 83 |
|
$menu = drawing_demo_menu(); |
| 84 |
|
unset($menu['drawing_demo']); |
| 85 |
|
foreach ($menu as $path => $item) { |
| 86 |
|
$list[] = l(t($item['title']), $path); |
| 87 |
|
} |
| 88 |
|
return theme('item_list', $list); |
| 89 |
|
} |
| 90 |
|
|
| 91 |
|
|
| 92 |
|
############################################################################### |
| 93 |
|
############################## DRUPLICON CANVAS ############################### |
| 94 |
|
############################################################################### |
| 95 |
|
|
| 96 |
|
/** |
| 97 |
|
* Drawings in the Drawing API are called canvases, and are built in a similar |
| 98 |
|
* way to forms. This canvas draws the drupal logo known as 'druplicon'. |
| 99 |
|
*/ |
| 100 |
|
function drawing_demo_druplicon_canvas() { |
| 101 |
$canvas = array( |
$canvas = array( |
| 102 |
'#type' => 'canvas', |
'#type' => 'canvas', |
| 103 |
'#height' => '700px', |
'#height' => '450px', |
| 104 |
'#width' => '700px', |
'#width' => '600px', |
| 105 |
); |
); |
|
/*$canvas['drawing_demo'] = array( |
|
|
'#type' => 'file', |
|
|
'#location' => drupal_get_path('module', 'drawing') . '/drawing_demo.vector.svg', |
|
|
'#height' => '800px', |
|
|
'#width' => '700px', |
|
|
);*/ |
|
|
|
|
| 106 |
$canvas['group'] = array( |
$canvas['group'] = array( |
| 107 |
'#type' => 'group', |
'#type' => 'group', |
| 108 |
'#transform' => array( |
'#transform' => array( |
| 109 |
'translate' => array(0, 60), |
'translate' => array(0, 60), |
| 110 |
'scale' => array( 0.5, 0.5), |
'scale' => array(0.5, 0.5), |
| 111 |
), |
), |
| 112 |
); |
); |
|
|
|
| 113 |
$canvas['group']['path2'] = array( |
$canvas['group']['path2'] = array( |
| 114 |
'#type' => 'path', |
'#type' => 'path', |
| 115 |
'#explicit' => TRUE, |
'#explicit' => TRUE, |
| 116 |
'#points' => 'M 449.25,610.5 C 461.25,610.5 474,611.25 483,617.25 C 492,623.25 497.25,636.75 500.25,644.25 C 503.25,651.75 500.25,656.25 494.25,659.25 C 489,662.25 488.25,660.75 483,651 C 477.75,641.25 473.25,631.5 447,631.5 C 420.75,631.5 412.5,640.5 399.75,651 C 387,661.5 382.5,665.25 378,659.25 C 373.5,653.25 375,647.25 383.25,639.75 C 391.5,632.25 405,620.25 417.75,615 C 430.5,609.75 437.25,610.5 449.25,610.5 L 449.25,610.5 z ', |
'#points' => 'M 449.25,610.5 C 461.25,610.5 474,611.25 483,617.25 C 492, |
| 117 |
|
623.25 497.25,636.75 500.25,644.25 C 503.25,651.75 500.25,656.25 494.25, |
| 118 |
|
659.25 C 489,662.25 488.25,660.75 483,651 C 477.75,641.25 473.25, |
| 119 |
|
631.5 447,631.5 C 420.75,631.5 412.5,640.5 399.75,651 C 387,661.5 382.5, |
| 120 |
|
665.25 378,659.25 C 373.5,653.25 375,647.25 383.25,639.75 C 391.5,632.25 405, |
| 121 |
|
620.25 417.75,615 C 430.5,609.75 437.25,610.5 449.25,610.5 L 449.25, |
| 122 |
|
610.5 z ', |
| 123 |
'#fill' => '#ffffff', |
'#fill' => '#ffffff', |
| 124 |
); |
); |
| 125 |
$canvas['group']['path3'] = array( |
$canvas['group']['path3'] = array( |
| 126 |
'#type' => 'path', |
'#type' => 'path', |
| 127 |
'#explicit' => TRUE, |
'#explicit' => TRUE, |
| 128 |
'#points' => 'M 324.75,696 C 339.75,708 362.25,717.75 410.25,717.75 C 458.25,717.75 492,704.25 507,693 C 513.75,687.75 516.75,692.25 517.5,695.25 C 518.25,698.25 519.75,702.75 514.5,708 C 510.75,711.75 476.25,735.75 435.75,739.5 C 395.25,743.25 340.5,745.5 307.5,715.5 C 302.25,710.25 303.75,702.75 307.5,699.75 C 311.25,696.75 314.25,694.5 318.75,694.5 C 323.25,694.5 322.5,694.5 324.75,696 L 324.75,696 z ', |
'#points' => 'M 324.75,696 C 339.75,708 362.25,717.75 410.25, |
| 129 |
|
717.75 C 458.25,717.75 492,704.25 507,693 C 513.75,687.75 516.75, |
| 130 |
|
692.25 517.5,695.25 C 518.25,698.25 519.75,702.75 514.5,708 C 510.75, |
| 131 |
|
711.75 476.25,735.75 435.75,739.5 C 395.25,743.25 340.5,745.5 307.5, |
| 132 |
|
715.5 C 302.25,710.25 303.75,702.75 307.5,699.75 C 311.25,696.75 314.25, |
| 133 |
|
694.5 318.75,694.5 C 323.25,694.5 322.5,694.5 324.75,696 L 324.75,696 z ', |
| 134 |
'#fill' => '#ffffff', |
'#fill' => '#ffffff', |
| 135 |
); |
); |
| 136 |
|
|
| 137 |
$canvas['group']['path7'] = array( |
$canvas['group']['path6'] = array( |
| 138 |
'#type' => 'path', |
'#type' => 'path', |
| 139 |
'#explicit' => TRUE, |
'#explicit' => TRUE, |
| 140 |
'#points' => 'M 316.5,14.25 C 309.75,63.75 294.75,78.75 274.5,94.5 C 240.75,120 207.75,135.75 200.25,139.5 C 180.75,149.25 110.25,188.25 73.5,244.5 C 62.25,261.75 73.5,268.5 75.75,270 C 78,271.5 103.5,274.5 158.25,241.5 C 213,208.5 237,189 267.75,156.75 C 284.25,139.5 286.5,129.75 286.5,125.25 C 286.5,120 282.75,117.75 276.75,116.25 C 273.75,115.5 273,114 276.75,111.75 C 280.5,109.5 296.25,102 300,99 C 303.75,96 321.75,84 322.5,64.5 C 323.25,45 321.75,31.5 316.5,14.25 L 316.5,14.25 z ', |
'#points' => 'M 316.5,15 C 327,45.75 325.5,61.5 325.5,68.25 C 325.5, |
| 141 |
'#fill' => '#ffffff', |
75 321.75,93 309.75,102 C 304.5,105.75 303,108.75 303,109.5 C 303, |
| 142 |
|
112.5 309.75,114.75 309.75,121.5 C 309.75,129.75 306,146.25 266.25, |
| 143 |
|
186 C 226.5,225.75 169.5,261 125.25,282.75 C 81,304.5 60,303 54,292.5 C 48, |
| 144 |
|
282 56.25,258.75 84,228 C 111.75,197.25 199.5,153 199.5,153 L 309,76.5 L 315, |
| 145 |
|
47.25', |
| 146 |
|
'#fill' => '#93c5e4', |
| 147 |
); |
); |
| 148 |
$canvas['group']['path6'] = array( |
$canvas['group']['path7'] = array( |
| 149 |
'#type' => 'path', |
'#type' => 'path', |
| 150 |
'#explicit' => TRUE, |
'#explicit' => TRUE, |
| 151 |
'#points' => 'M 316.5,15 C 327,45.75 325.5,61.5 325.5,68.25 C 325.5,75 321.75,93 309.75,102 C 304.5,105.75 303,108.75 303,109.5 C 303,112.5 309.75,114.75 309.75,121.5 C 309.75,129.75 306,146.25 266.25,186 C 226.5,225.75 169.5,261 125.25,282.75 C 81,304.5 60,303 54,292.5 C 48,282 56.25,258.75 84,228 C 111.75,197.25 199.5,153 199.5,153 L 309,76.5 L 315,47.25', |
'#points' => 'M 316.5,14.25 C 309.75,63.75 294.75,78.75 274.5, |
| 152 |
'#fill' => '#93c5e4', |
94.5 C 240.75,120 207.75,135.75 200.25,139.5 C 180.75,149.25 110.25, |
| 153 |
|
188.25 73.5,244.5 C 62.25,261.75 73.5,268.5 75.75,270 C 78,271.5 103.5, |
| 154 |
|
274.5 158.25,241.5 C 213,208.5 237,189 267.75,156.75 C 284.25,139.5 286.5, |
| 155 |
|
129.75 286.5,125.25 C 286.5,120 282.75,117.75 276.75,116.25 C 273.75, |
| 156 |
|
115.5 273,114 276.75,111.75 C 280.5,109.5 296.25,102 300,99 C 303.75, |
| 157 |
|
96 321.75,84 322.5,64.5 C 323.25,45 321.75,31.5 316.5,14.25 L 316.5, |
| 158 |
|
14.25 z ', |
| 159 |
|
'#fill' => '#ffffff', |
| 160 |
); |
); |
| 161 |
|
|
| 162 |
$canvas['group']['path8'] = array( |
$canvas['group']['path8'] = array( |
| 163 |
'#type' => 'path', |
'#type' => 'path', |
| 164 |
'#explicit' => TRUE, |
'#explicit' => TRUE, |
| 165 |
'#points' => 'M 147.75,559.5 C 148.5,501 203.25,446.25 272.25,445.5 C 360,444.75 420.75,532.5 465,531.75 C 502.5,531 574.5,457.5 609.75,457.5 C 647.25,457.5 657.75,496.5 657.75,519.75 C 657.75,543 650.25,585 632.25,611.25 C 614.25,637.5 603,647.25 582,645.75 C 555,643.5 501,559.5 466.5,558 C 423,556.5 328.5,648.75 254.25,648.75 C 209.25,648.75 195.75,642 180.75,632.25 C 158.25,616.5 147,592.5 147.75,559.5 L 147.75,559.5 z ', |
'#points' => 'M 147.75,559.5 C 148.5,501 203.25,446.25 272.25,445.5 C 360, |
| 166 |
|
444.75 420.75,532.5 465,531.75 C 502.5,531 574.5,457.5 609.75,457.5 C 647.25, |
| 167 |
|
457.5 657.75,496.5 657.75,519.75 C 657.75,543 650.25,585 632.25, |
| 168 |
|
611.25 C 614.25,637.5 603,647.25 582,645.75 C 555,643.5 501,559.5 466.5, |
| 169 |
|
558 C 423,556.5 328.5,648.75 254.25,648.75 C 209.25,648.75 195.75,642 180.75, |
| 170 |
|
632.25 C 158.25,616.5 147,592.5 147.75,559.5 L 147.75,559.5 z ', |
| 171 |
'#fill' => '#ffffff', |
'#fill' => '#ffffff', |
| 172 |
); |
); |
| 173 |
$canvas['group']['path4'] = array( |
$canvas['group']['path4'] = array( |
| 174 |
'#type' => 'path', |
'#type' => 'path', |
| 175 |
'#explicit' => TRUE, |
'#explicit' => TRUE, |
| 176 |
'#points' => 'M 141,639 C 198,638.25 208.5,628.5 258.75,606 C 530.25,484.5 580.5,373.5 590.25,348 C 600,322.5 614.25,281.25 599.25,235.5 C 596.354,226.668 594.244,219.576 592.72,213.87 C 556.641,173.527 520.821,151.513 510,144.75 C 471,120 432.75,110.25 395.25,85.5 C 372,70.5 339.75,32.25 312.75,0 C 307.5,51.75 292.5,73.5 273.75,87.75 C 235.5,117.75 211.5,126.75 178.5,144.75 C 150.75,159.75 0,249 0,442.5 C 0,504.28 16.593,560.861 45.063,609.266 L 52.5,609 C 68.25,623.25 93,639.75 141,639 z ', |
'#points' => 'M 141,639 C 198,638.25 208.5,628.5 258.75,606 C 530.25, |
| 177 |
|
484.5 580.5,373.5 590.25,348 C 600,322.5 614.25,281.25 599.25, |
| 178 |
|
235.5 C 596.354,226.668 594.244,219.576 592.72,213.87 C 556.641, |
| 179 |
|
173.527 520.821,151.513 510,144.75 C 471,120 432.75,110.25 395.25, |
| 180 |
|
85.5 C 372,70.5 339.75,32.25 312.75,0 C 307.5,51.75 292.5,73.5 273.75, |
| 181 |
|
87.75 C 235.5,117.75 211.5,126.75 178.5,144.75 C 150.75,159.75 0, |
| 182 |
|
249 0,442.5 C 0,504.28 16.593,560.861 45.063,609.266 L 52.5, |
| 183 |
|
609 C 68.25,623.25 93,639.75 141,639 z ', |
| 184 |
'#fill' => '#0073ba', |
'#fill' => '#0073ba', |
| 185 |
); |
); |
| 186 |
$canvas['group']['path5'] = array( |
$canvas['group']['path5'] = array( |
| 187 |
'#type' => 'path', |
'#type' => 'path', |
| 188 |
'#explicit' => TRUE, |
'#explicit' => TRUE, |
| 189 |
'#points' => 'M 510,144.75 C 471,120 432.75,110.25 395.25,85.5 C 372,70.5 339.75,32.25 312.75,0 C 307.5,51.75 292.5,73.5 273.75,87.75 C 235.5,117.75 211.5,126.75 178.5,144.75 C 150.75,159.75 0,249 0,442.5 C 0,504.28 16.593,560.861 45.063,609.266 C 105.763,712.467 220.46,778.5 343.5,778.5 C 524.25,778.5 681,647.25 681,448.5 C 681,339.354 636.668,263.012 592.72,213.87 C 556.641,173.527 520.82,151.513 510,144.75 z M 601.164,232.547 C 650.406,294.111 675.375,366.768 675.375,448.5 C 675.375,495.928 666.342,540.73 648.526,581.665 C 631.626,620.496 607.29,654.898 576.193,683.919 C 514.724,741.283 432.086,772.875 343.5,772.875 C 299.674,772.875 256.668,764.504 215.676,747.993 C 175.413,731.776 139.129,708.555 107.833,678.974 C 41.923,616.678 5.625,532.696 5.625,442.5 C 5.625,362.164 31.701,290.78 83.128,230.333 C 122.417,184.153 164.783,158.559 181.175,149.699 C 189.133,145.358 196.598,141.527 203.818,137.822 C 226.448,126.207 247.823,115.236 277.222,92.177 C 292.899,80.263 309.599,61.392 316.711,13.475 C 341.485,42.941 370.233,76.054 392.201,90.227 C 411.701,103.097 431.702,112.115 451.045,120.837 C 469.343,129.087 488.264,137.618 506.987,149.5 C 507.019,149.521 507.689,149.938 507.689,149.938 C 562.421,184.11 591.581,220.566 601.164,232.547 z ', |
'#points' => 'M 510,144.75 C 471,120 432.75,110.25 395.25,85.5 C 372, |
| 190 |
|
70.5 339.75,32.25 312.75,0 C 307.5,51.75 292.5,73.5 273.75,87.75 C 235.5, |
| 191 |
|
117.75 211.5,126.75 178.5,144.75 C 150.75,159.75 0,249 0,442.5 C 0, |
| 192 |
|
504.28 16.593,560.861 45.063,609.266 C 105.763,712.467 220.46,778.5 343.5, |
| 193 |
|
778.5 C 524.25,778.5 681,647.25 681,448.5 C 681,339.354 636.668, |
| 194 |
|
263.012 592.72,213.87 C 556.641,173.527 520.82,151.513 510, |
| 195 |
|
144.75 z M 601.164,232.547 C 650.406,294.111 675.375,366.768 675.375, |
| 196 |
|
448.5 C 675.375,495.928 666.342,540.73 648.526,581.665 C 631.626, |
| 197 |
|
620.496 607.29,654.898 576.193,683.919 C 514.724,741.283 432.086, |
| 198 |
|
772.875 343.5,772.875 C 299.674,772.875 256.668,764.504 215.676, |
| 199 |
|
747.993 C 175.413,731.776 139.129,708.555 107.833,678.974 C 41.923, |
| 200 |
|
616.678 5.625,532.696 5.625,442.5 C 5.625,362.164 31.701,290.78 83.128, |
| 201 |
|
230.333 C 122.417,184.153 164.783,158.559 181.175,149.699 C 189.133, |
| 202 |
|
145.358 196.598,141.527 203.818,137.822 C 226.448,126.207 247.823, |
| 203 |
|
115.236 277.222,92.177 C 292.899,80.263 309.599,61.392 316.711, |
| 204 |
|
13.475 C 341.485,42.941 370.233,76.054 392.201,90.227 C 411.701, |
| 205 |
|
103.097 431.702,112.115 451.045,120.837 C 469.343,129.087 488.264, |
| 206 |
|
137.618 506.987,149.5 C 507.019,149.521 507.689,149.938 507.689, |
| 207 |
|
149.938 C 562.421,184.11 591.581,220.566 601.164,232.547 z ', |
| 208 |
'#fill' => '#004976', |
'#fill' => '#004976', |
| 209 |
); |
); |
| 210 |
$canvas['group']['path9'] = array( |
$canvas['group']['path9'] = array( |
| 211 |
'#type' => 'path', |
'#type' => 'path', |
| 212 |
'#explicit' => TRUE, |
'#explicit' => TRUE, |
| 213 |
'#points' => 'M 599.25,235.5 C 614.25,281.25 600,322.5 590.25,348 C 580.5,373.5 530.25,484.5 258.75,606 C 208.5,628.5 198,638.25 141,639 C 93,639.75 68.25,623.25 52.5,609 L 45.063,609.266 C 105.763,712.467 220.46,778.5 343.5,778.5 C 524.25,778.5 681,647.25 681,448.5 C 681,339.354 636.668,263.012 592.72,213.87 C 594.244,219.576 596.354,226.668 599.25,235.5 z ', |
'#points' => 'M 599.25,235.5 C 614.25,281.25 600,322.5 590.25,348 C 580.5, |
| 214 |
|
373.5 530.25,484.5 258.75,606 C 208.5,628.5 198,638.25 141,639 C 93, |
| 215 |
|
639.75 68.25,623.25 52.5,609 L 45.063,609.266 C 105.763,712.467 220.46, |
| 216 |
|
778.5 343.5,778.5 C 524.25,778.5 681,647.25 681,448.5 C 681,339.354 636.668, |
| 217 |
|
263.012 592.72,213.87 C 594.244,219.576 596.354,226.668 599.25,235.5 z ', |
| 218 |
'#fill' => 'none', |
'#fill' => 'none', |
| 219 |
); |
); |
|
|
|
| 220 |
$canvas['group']['path1'] = array( |
$canvas['group']['path1'] = array( |
| 221 |
'#type' => 'path', |
'#type' => 'path', |
| 222 |
'#explicit' => FALSE, // this is not obligatory |
'#explicit' => FALSE, // this is not obligatory |
| 335 |
); |
); |
| 336 |
$canvas['text1'] = array( |
$canvas['text1'] = array( |
| 337 |
'#type' => 'text', |
'#type' => 'text', |
| 338 |
'#value' => 'This drawing is made by the drawing_demo.module testmodule in the drawing package.', |
'#value' => 'This drawing is defined by the Drawing demo module in the drawing package.', |
| 339 |
'#cx' => 0, |
'#cx' => 0, |
| 340 |
'#cy' => 20, |
'#cy' => 20, |
| 341 |
); |
); |
| 342 |
$canvas['text2'] = array( |
$canvas['text2'] = array( |
| 343 |
'#type' => 'text', |
'#type' => 'text', |
| 344 |
'#value' => 'Render done via the drawing API, including fill and stroke.', |
'#value' => 'Rendering done using the Drawing API, including fill and stroke.', |
| 345 |
'#cx' => 0, |
'#cx' => 0, |
| 346 |
'#cy' => 40, |
'#cy' => 40, |
| 347 |
); |
); |
| 348 |
$canvas['text3'] = array( |
$canvas['text3'] = array( |
| 349 |
'#type' => 'text', |
'#type' => 'text', |
| 350 |
'#value' => 'You have to be cautious with overlapping figures, like drawing_demo, its difficult to find the correct order of elements.', |
'#value' => 'You have to be cautious with overlapping shapes, its difficult to find the correct elements order.', |
| 351 |
'#cx' => 0, |
'#cx' => 0, |
| 352 |
'#cy' => 60, |
'#cy' => 60, |
| 353 |
); |
); |
|
|
|
|
/*$canvas = array_reverse($canvas);*/ |
|
| 354 |
return $canvas; |
return $canvas; |
| 355 |
} |
} |
| 356 |
|
|
| 357 |
/** |
|
| 358 |
* The ID of the canvas is drawing_demo_test_page |
############################################################################### |
| 359 |
*/ |
############################### GD DRAWING DEMO ############################### |
| 360 |
function drawing_demo_test_page() { |
############################################################################### |
| 361 |
$canvas = drawing_demo_canvas(); |
|
| 362 |
return $canvas; |
function drawing_demo_gd() { |
| 363 |
|
return theme('image', drawing_get_canvas('drawing_demo_gd_canvas')); |
| 364 |
} |
} |
| 365 |
function drawing_demo_druplicion_canvases() { |
|
| 366 |
$canvases['drawing_demo_test_page']['callback'] = 'drawing_demo_canvas'; |
function drawing_demo_gd_canvas() { |
| 367 |
return $canvases; |
$canvas = array( |
| 368 |
|
'#type' => 'canvas', |
| 369 |
|
'#height' => '702px', |
| 370 |
|
'#width' => '702px', |
| 371 |
|
'#method' => 'gd', |
| 372 |
|
// '#format' => 'gif', |
| 373 |
|
); |
| 374 |
|
$canvas['rectangle'] = array( |
| 375 |
|
'#type' => 'rectangle', |
| 376 |
|
'#fill' => 'orange', |
| 377 |
|
'#cx' => 8, |
| 378 |
|
'#cy' => 8, |
| 379 |
|
'#height' => 100, |
| 380 |
|
'#width' => 400, |
| 381 |
|
'#stroke' => 'red', |
| 382 |
|
'#opacity' => 0.75, |
| 383 |
|
'#stroke-width' => 4, |
| 384 |
|
); |
| 385 |
|
$canvas['ellipse'] = array( |
| 386 |
|
'#type' => 'ellipse', |
| 387 |
|
'#fill' => 'maroon', |
| 388 |
|
'#cx' => 222, |
| 389 |
|
'#cy' => 222, |
| 390 |
|
'#height' => 70, |
| 391 |
|
'#width' => 70, |
| 392 |
|
'#stroke' => 'blue', |
| 393 |
|
'#stroke-width' => 2, |
| 394 |
|
'#weight' => 100, |
| 395 |
|
); |
| 396 |
|
$canvas['line'] = array( |
| 397 |
|
'#type' => 'line', |
| 398 |
|
'#fill' => 'green', |
| 399 |
|
'#points' => array( |
| 400 |
|
'#cx1' => 40, |
| 401 |
|
'#cy1' => 40, |
| 402 |
|
'#cx2' => 600, |
| 403 |
|
'#cy2' => 600, |
| 404 |
|
), |
| 405 |
|
'#weight' => 1000, |
| 406 |
|
); |
| 407 |
|
return $canvas; |
| 408 |
} |
} |
| 409 |
|
|
| 410 |
function drawing_demo_page() { |
|
| 411 |
drawing_svg_set_header_xhtml(); |
############################################################################### |
| 412 |
$output = drawing_get_canvas('drawing_demo_test_page'); |
############################## SVG DRAWING DEMO ############################### |
| 413 |
|
############################################################################### |
| 414 |
|
|
| 415 |
|
function drawing_demo_svg() { |
| 416 |
|
$output = drawing_get_canvas('drawing_demo_svg_canvas'); |
| 417 |
|
$output .= '<div>'.t('This SVG image was generated using the Drawing SVG toolkit.').'</div>'; |
| 418 |
return $output; |
return $output; |
| 419 |
} |
} |
| 420 |
|
|
| 421 |
function drawing_demo_graph_page() { |
function drawing_demo_svg_canvas() { |
| 422 |
drupal_add_css(drupal_get_path('module', 'drawing_graph') . '/drawing_graph.css'); |
// use the druplicon canvas and force using the svg method. |
| 423 |
drupal_add_js(drupal_get_path('module', 'drawing_graph') . '/drawing_graph.js'); |
$canvas = drawing_demo_druplicon_canvas(); |
| 424 |
drawing_svg_set_header_xhtml(); |
$canvas['#method'] = 'svg'; |
| 425 |
return drawing_get_canvas('drawing_demo_graph_canvas'); |
return $canvas; |
| 426 |
} |
} |
| 427 |
|
|
| 428 |
|
|
| 429 |
|
############################################################################### |
| 430 |
|
############################# GRAPH DRAWING DEMO ############################## |
| 431 |
|
############################################################################### |
| 432 |
|
|
| 433 |
|
function drawing_demo_graph() { |
| 434 |
|
return drawing_get_canvas('drawing_demo_graph_canvas'); |
| 435 |
|
} |
| 436 |
|
|
| 437 |
function drawing_demo_graph_canvases() { |
function drawing_demo_graph_canvases() { |
| 438 |
$canvases['drawing_graph_test']['callback'] = 'drawing_demo_graph_canvas'; |
$canvases['drawing_graph_test']['callback'] = 'drawing_demo_graph_canvas'; |
| 439 |
return $canvases; |
return $canvases; |
| 440 |
} |
} |
| 441 |
|
|
| 442 |
function drawing_demo_graph_canvas() { |
function drawing_demo_graph_canvas() { |
|
|
|
| 443 |
$chart['points'][] = array(0, 0); |
$chart['points'][] = array(0, 0); |
| 444 |
$chart['points'][] = array(40, 90); |
$chart['points'][] = array(40, 90); |
| 445 |
$chart['points'][] = array(80, 90); |
$chart['points'][] = array(80, 90); |
| 457 |
$chart['points'][] = array(560, 170); |
$chart['points'][] = array(560, 170); |
| 458 |
$chart['points'][] = array(600, 190); |
$chart['points'][] = array(600, 190); |
| 459 |
$chart['points'][] = array(640, 130); |
$chart['points'][] = array(640, 130); |
|
|
|
| 460 |
$chart['xlabel'] = 'xlabel'; |
$chart['xlabel'] = 'xlabel'; |
| 461 |
$chart['ylabel'] = 'ylabel'; |
$chart['ylabel'] = 'ylabel'; |
|
|
|
| 462 |
$config['type'] = 'bar'; |
$config['type'] = 'bar'; |
| 463 |
$config['height'] = 400; |
$config['height'] = 400; |
| 464 |
$config['width'] = 700; |
$config['width'] = 700; |
| 465 |
$config['xtics_height'] = 10; |
$config['xtics_height'] = 10; |
| 466 |
$config['ytics_height'] = 10; |
$config['ytics_height'] = 10; |
| 467 |
$config['ytics_stepsize'] = 50; |
$config['ytics_stepsize'] = 50; |
|
|
|
|
|
|
| 468 |
$config['theme'] = array( |
$config['theme'] = array( |
| 469 |
'text' => 'black', |
'text' => 'black', |
| 470 |
'label' => 'black', |
'label' => 'black', |
| 471 |
'fill' => '#0000ff', |
'fill' => '#0000ff', |
| 472 |
); |
); |
|
|
|
| 473 |
return module_invoke('drawing_graph', 'histogram', $chart, $config); |
return module_invoke('drawing_graph', 'histogram', $chart, $config); |
| 474 |
} |
} |
| 475 |
|
|
|
function drawing_demo_block($op = 'list', $delta = 0, $edit = array()) { |
|
|
if($op == 'list') { |
|
|
$blocks = array( |
|
|
'info' => t('Pie chart block'), |
|
|
'weight' => 0, |
|
|
'enabled' => 1, |
|
|
'region' => 'left', |
|
|
); |
|
|
return $blocks; |
|
|
} |
|
|
else if($op == 'view') { |
|
|
$blocks = array( |
|
|
'subject' => t('Pie chart testblock'), |
|
|
'content' => drawing_get_canvas('drawing_demo_pie_chart_canvas') |
|
|
); |
|
|
return $blocks; |
|
|
} |
|
|
} |
|
| 476 |
|
|
| 477 |
function drawing_demo_pie_chart_page() { |
############################################################################### |
| 478 |
/*drawing_svg_set_header_xhtml();*/ |
########################### PIE CHART DRAWING DEMO ############################ |
| 479 |
|
############################################################################### |
| 480 |
|
|
| 481 |
|
function drawing_demo_pie_chart() { |
| 482 |
return drawing_get_canvas('drawing_demo_pie_chart_canvas'); |
return drawing_get_canvas('drawing_demo_pie_chart_canvas'); |
| 483 |
} |
} |
| 484 |
|
|
| 488 |
$chart['points'][] = array(80, 90); |
$chart['points'][] = array(80, 90); |
| 489 |
$chart['points'][] = array(120, 180); |
$chart['points'][] = array(120, 180); |
| 490 |
$chart['points'][] = array(160, 300); |
$chart['points'][] = array(160, 300); |
|
|
|
|
|
|
| 491 |
$config['height'] = 150; |
$config['height'] = 150; |
| 492 |
$config['width'] = 150; |
$config['width'] = 150; |
| 493 |
$config['labels'] = array( |
$config['labels'] = array( |
| 507 |
return module_invoke('drawing_graph', 'piechart', $chart, $config); |
return module_invoke('drawing_graph', 'piechart', $chart, $config); |
| 508 |
} |
} |
| 509 |
|
|
| 510 |
function drawing_demo_stackbar_page() { |
|
| 511 |
drawing_svg_set_header_xhtml(); |
############################################################################### |
| 512 |
|
########################### STACK BAR DRAWING DEMO ############################ |
| 513 |
|
############################################################################### |
| 514 |
|
|
| 515 |
|
function drawing_demo_stackbar() { |
| 516 |
return drawing_get_canvas('drawing_demo_stackbar_canvas'); |
return drawing_get_canvas('drawing_demo_stackbar_canvas'); |
| 517 |
} |
} |
| 518 |
|
|
| 519 |
function drawing_demo_stackbar_canvas() { |
function drawing_demo_stackbar_canvas() { |
| 520 |
$chart = array(); |
$chart = array(); |
| 521 |
$chart['points'][] = array('value1', 5); |
$chart['points'][] = array('value1', 5); |
| 522 |
$chart['points'][] = array('value2', 20); |
$chart['points'][] = array('value2', 20); |
| 523 |
$chart['points'][] = array('value3', 10); |
$chart['points'][] = array('value3', 10); |
| 524 |
$chart['points'][] = array('value4', 30); |
$chart['points'][] = array('value4', 30); |
|
|
|
|
|
|
| 525 |
$config['canvas_height'] = 600; |
$config['canvas_height'] = 600; |
| 526 |
$config['canvas_width'] = 100; |
$config['canvas_width'] = 100; |
| 527 |
$config['height'] = 600; |
$config['height'] = 600; |
| 540 |
return module_invoke('drawing_graph', 'stackbar', $chart, $config); |
return module_invoke('drawing_graph', 'stackbar', $chart, $config); |
| 541 |
} |
} |
| 542 |
|
|
| 543 |
function drawing_demo_tagstack_page() { |
|
| 544 |
|
############################################################################### |
| 545 |
|
########################### TAG STACK DRAWING DEMO ############################ |
| 546 |
|
############################################################################### |
| 547 |
|
|
| 548 |
|
function drawing_demo_tagstack() { |
| 549 |
if (!module_exists('tagadelic')) { |
if (!module_exists('tagadelic')) { |
| 550 |
drupal_set_message(t('You need the !tag module to view this demo.', array('!tag' => l(t('Tagadelic'), 'http://drupal.org/project/tagadelic'))), 'warning'); |
drupal_set_message( |
| 551 |
|
t('You need the !tag module to view this demo.', array( |
| 552 |
|
'!tag' => l(t('Tagadelic'), 'http://drupal.org/project/tagadelic')) |
| 553 |
|
), 'warning'); |
| 554 |
return ''; |
return ''; |
| 555 |
} |
} |
|
drawing_svg_set_header_xhtml(); |
|
| 556 |
return drawing_get_canvas('drawing_demo_tagstack_canvas'); |
return drawing_get_canvas('drawing_demo_tagstack_canvas'); |
| 557 |
} |
} |
| 558 |
|
|
| 575 |
'fill_5' => '#aaaaff', |
'fill_5' => '#aaaaff', |
| 576 |
'fill_6' => '#ddddff', |
'fill_6' => '#ddddff', |
| 577 |
); |
); |
|
|
|
| 578 |
$data = module_invoke('tagadelic', 'get_weighted_tags', array(1,5)); |
$data = module_invoke('tagadelic', 'get_weighted_tags', array(1,5)); |
| 579 |
$chart = array(); |
$chart = array(); |
| 580 |
$n = 0; |
$n = 0; |
| 584 |
} |
} |
| 585 |
return module_invoke('drawing_graph', 'piechart', $chart, $config); |
return module_invoke('drawing_graph', 'piechart', $chart, $config); |
| 586 |
} |
} |
|
|
|