Initial
This commit is contained in:
75
lcp-visualize.php
Normal file
75
lcp-visualize.php
Normal file
@ -0,0 +1,75 @@
|
||||
<?php
|
||||
/**
|
||||
* Plugin Name: LCP Visualize
|
||||
* Description: Data visualization blocks using D3.js
|
||||
* Version: 1.0.0
|
||||
* Author: LCP
|
||||
*/
|
||||
|
||||
if (!defined('ABSPATH')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
function lcp_visualize_register_blocks() {
|
||||
if (!function_exists('register_block_type')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$asset_file = include(plugin_dir_path(__FILE__) . 'blocks/bar-graph/build/index.asset.php');
|
||||
|
||||
wp_register_style(
|
||||
'ag-grid',
|
||||
'https://unpkg.com/ag-grid-community/dist/styles/ag-grid.css',
|
||||
[],
|
||||
'27.1.0'
|
||||
);
|
||||
|
||||
wp_register_style(
|
||||
'ag-grid-theme',
|
||||
'https://unpkg.com/ag-grid-community/dist/styles/ag-theme-balham.css',
|
||||
[],
|
||||
'27.1.0'
|
||||
);
|
||||
|
||||
wp_register_style(
|
||||
'lcp-bar-graph-editor',
|
||||
plugins_url('blocks/bar-graph/build/index.css', __FILE__),
|
||||
[],
|
||||
$asset_file['version']
|
||||
);
|
||||
|
||||
wp_register_script(
|
||||
'lcp-bar-graph',
|
||||
plugins_url('blocks/bar-graph/build/index.js', __FILE__),
|
||||
$asset_file['dependencies'],
|
||||
$asset_file['version']
|
||||
);
|
||||
|
||||
register_block_type('lcp/bar-graph', array(
|
||||
'editor_script' => 'lcp-bar-graph',
|
||||
'editor_style' => ['ag-grid', 'ag-grid-theme', 'lcp-bar-graph-editor'],
|
||||
'render_callback' => 'render_block_lcp_bar_graph'
|
||||
));
|
||||
}
|
||||
add_action('init', 'lcp_visualize_register_blocks');
|
||||
|
||||
function render_block_lcp_bar_graph($attributes) {
|
||||
wp_enqueue_style('ag-grid');
|
||||
wp_enqueue_style('ag-grid-theme');
|
||||
wp_enqueue_style('lcp-bar-graph-editor');
|
||||
|
||||
$wrapper_attributes = get_block_wrapper_attributes([
|
||||
'class' => 'wp-block-lcp-bar-graph'
|
||||
]);
|
||||
|
||||
$chart_data = $attributes['chartData'] ?? [];
|
||||
$chart_data_json = wp_json_encode($chart_data);
|
||||
|
||||
ob_start();
|
||||
?>
|
||||
<div <?php echo $wrapper_attributes; ?>>
|
||||
<div class="lcp-bar-graph-container" data-chart='<?php echo esc_attr($chart_data_json); ?>'></div>
|
||||
</div>
|
||||
<?php
|
||||
return ob_get_clean();
|
||||
}
|
||||
Reference in New Issue
Block a user