driver instanceof ezcGraphGdDriver ) ) { throw new ezcGraphToolsIncompatibleDriverException( $chart->driver, 'ezcGraphGdDriver' ); } $elements = $chart->renderer->getElementReferences(); if ( !count( $elements ) ) { throw new ezcGraphToolsNotRenderedException( $chart ); } $imageMap = sprintf( "\n", $name ); // Iterate over legends elements if ( isset( $elements['legend'] ) ) { foreach ( $elements['legend'] as $objectName => $polygones ) { $url = $elements['legend_url'][$objectName]; if ( empty( $url ) ) { continue; } foreach ( $polygones as $shape => $polygone ) { $coordinateString = ''; foreach ( $polygone as $coordinate ) { $coordinateString .= sprintf( '%d,%d,', $coordinate->x, $coordinate->y ); } $imageMap .= sprintf( "\t\"%s\"\n", substr( $coordinateString, 0, -1 ), $url, $objectName ); } } } // Iterate over data foreach ( $elements['data'] as $dataset => $datapoints ) { foreach ( $datapoints as $datapoint => $polygones ) { $url = $chart->data[$dataset]->url[$datapoint]; if ( empty( $url ) ) { continue; } foreach ( $polygones as $polygon ) { $coordinateString = ''; foreach ( $polygon as $coordinate ) { $coordinateString .= sprintf( '%d,%d,', $coordinate->x, $coordinate->y ); } $imageMap .= sprintf( "\t\"%s\"\n", substr( $coordinateString, 0, -1 ), $url, $datapoint ); } } } return $imageMap . "\n"; } /** * Add links to clickable SVG elements in a chart with SVG driver. * * @param ezcGraphChart $chart * @return void */ public static function linkSvgElements( ezcGraphChart $chart ) { if ( ! ( $chart->driver instanceof ezcGraphSvgDriver ) ) { throw new ezcGraphToolsIncompatibleDriverException( $chart->driver, 'ezcGraphSvgDriver' ); } $fileName = $chart->getRenderedFile(); if ( !$fileName ) { throw new ezcGraphToolsNotRenderedException( $chart ); } $dom = new DOMDocument(); $dom->load( $fileName ); $xpath = new DomXPath( $dom ); $elements = $chart->renderer->getElementReferences(); // Link chart elements foreach ( $elements['data'] as $dataset => $datapoints ) { foreach ( $datapoints as $datapoint => $ids ) { $url = $chart->data[$dataset]->url[$datapoint]; if ( empty( $url ) ) { continue; } foreach ( $ids as $id ) { $element = $xpath->query( '//*[@id = \'' . $id . '\']' )->item( 0 ); $element->setAttribute( 'style', $element->getAttribute( 'style' ) . ' cursor: ' . $chart->driver->options->linkCursor . ';' ); $element->setAttribute( 'onclick', "top.location = '{$url}'" ); } } } // Link legend elements if ( isset( $elements['legend'] ) ) { foreach ( $elements['legend'] as $objectName => $ids ) { $url = $elements['legend_url'][$objectName]; if ( empty( $url ) ) { continue; } foreach ( $ids as $id ) { $element = $xpath->query( '//*[@id = \'' . $id . '\']' )->item( 0 ); $element->setAttribute( 'style', $element->getAttribute( 'style' ) . ' cursor: ' . $chart->driver->options->linkCursor . ';' ); $element->setAttribute( 'onclick', "top.location = '{$url}'" ); } } } $dom->save( $fileName ); } } ?>