Skip to content

Commit 0580582

Browse files
Fix ChartJS library detection and remove debug logging
- Fixed bug in frame.js where library dropdown was always reset to first option - Now only changes value if current selection is disabled or empty - This allows ChartJS selection to persist when clicking chart types - Added chart_library to visualizerAI localization for AI assistant - Properly passes ChartJS vs Google Charts to AI - AI now generates correct configuration format for each library - Removed all debugging console.log and error_log statements - Cleaned up browser console output - Kept error_log for actual error conditions - Updated welcome message to show chart library name 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 5e5e522 commit 0580582

4 files changed

Lines changed: 10 additions & 53 deletions

File tree

classes/Visualizer/Module/AI.php

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ public function suppressAjaxWarnings() {
7272
* @return void
7373
*/
7474
public function generateConfiguration() {
75-
error_log( 'Visualizer AI: generateConfiguration called' );
76-
7775
// Verify nonce
7876
if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'visualizer-ai-generate' ) ) {
7977
error_log( 'Visualizer AI: Invalid nonce' );
@@ -93,31 +91,19 @@ public function generateConfiguration() {
9391
$chat_history = isset( $_POST['chat_history'] ) ? json_decode( stripslashes( $_POST['chat_history'] ), true ) : array();
9492
$current_config = isset( $_POST['current_config'] ) ? sanitize_textarea_field( $_POST['current_config'] ) : '';
9593

96-
error_log( '=== Visualizer AI Request ===' );
97-
error_log( 'Visualizer AI: Model: ' . $model );
98-
error_log( 'Visualizer AI: Prompt: ' . $prompt );
99-
error_log( 'Visualizer AI: Chart Type: ' . $chart_type );
100-
error_log( 'Visualizer AI: Chart Library RAW from POST: ' . ( isset( $_POST['chart_library'] ) ? $_POST['chart_library'] : 'NOT SET' ) );
101-
error_log( 'Visualizer AI: Chart Library (sanitized): ' . $chart_library );
102-
error_log( 'Visualizer AI: Chart Library (lowercase check): ' . strtolower( $chart_library ) );
103-
error_log( 'Visualizer AI: Is ChartJS?: ' . ( strtolower( $chart_library ) === 'chartjs' ? 'YES' : 'NO' ) );
104-
error_log( 'Visualizer AI: Chat History Items: ' . count( $chat_history ) );
105-
10694
if ( empty( $prompt ) ) {
10795
error_log( 'Visualizer AI: Empty prompt' );
10896
wp_send_json_error( array( 'message' => esc_html__( 'Please provide a prompt.', 'visualizer' ) ) );
10997
}
11098

11199
// Generate configuration based on selected model
112-
error_log( 'Visualizer AI: Calling AI model' );
113100
$result = $this->_callAIModel( $model, $prompt, $chart_type, $chart_library, $chat_history, $current_config );
114101

115102
if ( is_wp_error( $result ) ) {
116103
error_log( 'Visualizer AI: Error: ' . $result->get_error_message() );
117104
wp_send_json_error( array( 'message' => $result->get_error_message() ) );
118105
}
119106

120-
error_log( 'Visualizer AI: Success' );
121107
wp_send_json_success( $result );
122108
}
123109

@@ -137,8 +123,6 @@ public function analyzeChartImage() {
137123
}
138124
ob_start();
139125

140-
error_log( 'Visualizer AI: analyzeChartImage called' );
141-
142126
// Verify nonce
143127
if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'visualizer-ai-image' ) ) {
144128
error_log( 'Visualizer AI: Invalid nonce' );
@@ -222,13 +206,10 @@ private function _callAIModel( $model, $prompt, $chart_type, $chart_library = 'G
222206
* @return string The system prompt.
223207
*/
224208
private function _createSystemPrompt( $chart_type, $chart_library = 'Google Charts' ) {
225-
error_log( 'Creating system prompt for library: ' . $chart_library . ' (lowercase: ' . strtolower( $chart_library ) . ')' );
226-
227209
$chart_options = $this->_getChartTypeOptions( $chart_type, $chart_library );
228210
$library_name = strtolower( $chart_library ) === 'chartjs' ? 'Chart.js' : 'Google Charts';
229211

230212
if ( strtolower( $chart_library ) === 'chartjs' ) {
231-
error_log( 'Using ChartJS prompt!' );
232213
return 'You are a helpful Chart.js (ChartJS) v3+ API expert assistant. You help users customize their ' . $chart_type . ' charts through conversation.
233214
234215
IMPORTANT CHARTJS STRUCTURE:
@@ -271,7 +252,6 @@ private function _createSystemPrompt( $chart_type, $chart_library = 'Google Char
271252
Remember: Be conversational, provide context, and only include the properties that need to change!';
272253
}
273254

274-
error_log( 'Using Google Charts prompt!' );
275255
return 'You are a helpful ' . $library_name . ' API expert assistant. You help users customize their ' . $chart_type . ' charts through conversation.
276256
277257
IMPORTANT INSTRUCTIONS:
@@ -481,8 +461,6 @@ private function _getChartJSOptions( $chart_type ) {
481461
* @return array<string, mixed>|WP_Error The response with message and optional configuration.
482462
*/
483463
private function _callOpenAI( $prompt, $chart_type, $chart_library = 'Google Charts', $chat_history = array(), $current_config = '' ) {
484-
error_log( 'Visualizer AI: Calling OpenAI API' );
485-
486464
$api_key = get_option( 'visualizer_openai_api_key', '' );
487465

488466
if ( empty( $api_key ) ) {

classes/Visualizer/Module/Chart.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -925,11 +925,6 @@ private function _handleDataAndSettingsPage() {
925925
)
926926
);
927927

928-
error_log( 'Localizing visualizerAI for ai-config script' );
929-
error_log( 'Chart type: ' . $data['type'] );
930-
error_log( 'Chart library from $data: ' . ( isset( $data['library'] ) ? $data['library'] : 'NOT SET' ) );
931-
error_log( 'Full $data keys: ' . implode( ', ', array_keys( $data ) ) );
932-
933928
wp_localize_script(
934929
'visualizer-ai-config',
935930
'visualizerAI',
@@ -979,8 +974,6 @@ private function _handleTypesPage() {
979974
if ( $_SERVER['REQUEST_METHOD'] === 'POST' && wp_verify_nonce( filter_input( INPUT_POST, 'nonce' ), 'visualizer-upload-data' ) ) {
980975
$type = filter_input( INPUT_POST, 'type' );
981976
$library = filter_input( INPUT_POST, 'chart-library' );
982-
error_log( 'Visualizer: Type received: ' . $type );
983-
error_log( 'Visualizer: Library received: ' . $library );
984977
if ( Visualizer_Module_Admin::checkChartStatus( $type ) ) {
985978
if ( empty( $library ) ) {
986979
// library cannot be empty.
@@ -1010,25 +1003,17 @@ private function _handleTypesPage() {
10101003
Visualizer_Module_Utility::set_defaults( $this->_chart );
10111004

10121005
// redirect to next tab
1013-
// changed by Ash/Upwork
1014-
error_log( 'Visualizer: Redirecting to settings tab' );
10151006
$redirect_url = esc_url_raw( add_query_arg( 'tab', 'settings' ) );
1016-
error_log( 'Visualizer: Redirect URL: ' . $redirect_url );
10171007
wp_redirect( $redirect_url );
10181008
exit;
10191009
} else {
1020-
error_log( 'Visualizer: checkChartStatus returned false for type: ' . $type );
10211010
echo '<div style="padding: 20px; color: red;">';
10221011
echo '<h2>Error: Invalid Chart Type</h2>';
10231012
echo '<p>The selected chart type is not available.</p>';
10241013
echo '<p><a href="javascript:history.back()">Go Back</a></p>';
10251014
echo '</div>';
10261015
return;
10271016
}
1028-
} else {
1029-
if ( $_SERVER['REQUEST_METHOD'] === 'POST' ) {
1030-
error_log( 'Visualizer: POST request but nonce verification failed' );
1031-
}
10321017
}
10331018
$render = new Visualizer_Render_Page_Types();
10341019
$render->type = get_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true );

js/ai-config.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,7 @@
55
var currentConfig = null;
66

77
$(document).ready(function() {
8-
console.log('Visualizer AI Config loaded');
9-
108
if (typeof visualizerAI !== 'undefined') {
11-
console.log('visualizerAI data:', visualizerAI);
12-
console.log('Chart Library:', visualizerAI.chart_library);
13-
console.log('Chart Type:', visualizerAI.chart_type);
14-
159
// Show welcome message with animation
1610
var libraryName = visualizerAI.chart_library && visualizerAI.chart_library.toLowerCase() === 'chartjs' ? 'Chart.js' : 'Google Charts';
1711
setTimeout(function() {
@@ -82,8 +76,6 @@
8276
var prompt = $('#visualizer-ai-prompt').val().trim();
8377
var model = $('.visualizer-ai-model-select').val();
8478

85-
console.log('Sending message:', prompt);
86-
8779
if (!prompt) {
8880
return;
8981
}
@@ -112,15 +104,11 @@
112104
current_config: currentManualConfig
113105
};
114106

115-
console.log('Request data:', requestData);
116-
console.log('Sending chart_library:', requestData.chart_library);
117-
118107
$.ajax({
119108
url: visualizerAI.ajaxurl,
120109
type: 'POST',
121110
data: requestData,
122111
success: function(response) {
123-
console.log('Response:', response);
124112
$('.visualizer-ai-loading').hide();
125113
$('#visualizer-ai-send-message').prop('disabled', false);
126114

@@ -134,7 +122,6 @@
134122
if (data.configuration) {
135123
currentConfig = data.configuration;
136124

137-
console.log('Configuration received - auto-applying');
138125
addConfigPreview(data.configuration);
139126

140127
// Auto-apply immediately
@@ -294,8 +281,6 @@
294281
// Also trigger on the name selector that preview.js uses
295282
$('textarea[name="manual"]').trigger('change');
296283
$('textarea[name="manual"]').trigger('keyup');
297-
298-
console.log('Triggered preview update events');
299284
}, 100);
300285

301286
// Don't scroll if we're auto-applying

js/frame.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,16 @@
276276
$('select.viz-select-library option[value="' + $lib + '"]').removeClass('disabled').removeAttr('disabled');
277277
$('select.viz-select-library option[value="' + $lib + '"] .premium-label').remove();
278278
});
279-
$('select.viz-select-library').val( $('select.viz-select-library option:not(.disabled)').val() );
279+
280+
// Only change the selected value if the current selection is disabled or empty
281+
var $select = $('select.viz-select-library');
282+
var currentVal = $select.val();
283+
var $currentOption = $select.find('option[value="' + currentVal + '"]');
284+
285+
// If current value is empty, disabled, or not in the enabled list, change to first enabled option
286+
if (!currentVal || $currentOption.hasClass('disabled') || $currentOption.attr('disabled')) {
287+
$select.val( $select.find('option:not(.disabled)').val() );
288+
}
280289
}
281290

282291
function init_permissions(){

0 commit comments

Comments
 (0)