@@ -41,7 +41,7 @@ import moment from 'moment/min/moment-with-locales'
4141import { logAvailableSharedResources , logProvidedSharedResources } from '../../np.Shared/src/index.js'
4242import { getSummariesSettings } from './summaryHelpers.js'
4343import type { SummariesConfig } from './summarySettings.js'
44- import { tailwindToHsl } from '@helpers/colors'
44+ import { colorToModernSpecWithOpacity } from '@helpers/colors'
4545import { clo , JSP , logDebug , logError , logInfo , logTimer , logWarn } from '@helpers/dev'
4646import { showHTMLV2 , type HtmlWindowOptions } from '@helpers/HTMLView'
4747import { COMPLETED_TASK_TYPES } from '@helpers/utils'
@@ -56,8 +56,6 @@ const chartJsLocalPath = './chart.umd.min.js'
5656
5757// =====================================================================
5858// CONFIGURATION CONSTANTS
59- // TODO: Shift to plugin.json
60- // TODO: Remove timeline toggle
6159// =====================================================================
6260
6361/**
@@ -70,7 +68,7 @@ const chartJsLocalPath = './chart.umd.min.js'
7068
7169// // Yes/No habits tracked with [x] completed checkboxes (add or remove as needed)
7270// // Format in daily notes: [x] Exercise or - [x] Exercise
73- // // TODO: If not tag/mention then treat this way; otherwise take from .progressYesNo
71+ // // If not tag/mention then treat this way; otherwise take from .progressYesNo
7472// yesNoHabits: [
7573// '#pray',
7674// '#stretches',
@@ -117,80 +115,8 @@ const chartJsLocalPath = './chart.umd.min.js'
117115// =====================================================================
118116
119117/**
120- * Convert any CSS color to rgba with specified opacity
121- * Supports: #RGB, #RRGGBB, #RRGGBBAA, named colors (red, blue), hsl(), rgb(), rgba()
122- * @param {string } color - CSS color value
123- * @param {number } opacity - Opacity value between 0 and 1 (default: 0.3)
124- * @returns {string } RGBA color string
125- */
126- function colorToRgba ( colorIn : string , opacity : number = 0.3 ) : string {
127- let color = colorIn . trim ( )
128-
129- // First convert Tailwind color names to hsl(), as we had that function already
130- if ( / ^ \w + - \d + $ / . test ( color ) ) {
131- color = tailwindToHsl ( color )
132- }
133-
134- // If already rgba() or rgb() or hsl(), add opacity if needed
135- if ( color . startsWith ( 'rgb(' ) || color . startsWith ( 'hsl(' ) ) {
136- // Convert rgb() or hsl() to rgba() or hsla() with opacity
137- return color
138- . replace ( 'rgb(' , `rgba(` )
139- . replace ( ')' , `, ${ opacity } )` )
140- . replace ( 'hsl(' , `hsla(` )
141- . replace ( ')' , `, ${ opacity } )` )
142- }
143-
144- // If already rgba() or hsla(), return as-is
145- if ( color . startsWith ( 'rgba(' ) || color . startsWith ( 'hsla(' ) ) {
146- return color
147- }
148-
149- // Handle hex colors (#RGB, #RRGGBB, #RRGGBBAA)
150- if ( color . startsWith ( '#' ) ) {
151- let hex = color . substring ( 1 )
152-
153- // Expand shorthand #RGB to #RRGGBB
154- if ( hex . length === 3 ) {
155- hex = hex [ 0 ] + hex [ 0 ] + hex [ 1 ] + hex [ 1 ] + hex [ 2 ] + hex [ 2 ]
156- }
157-
158- // Parse RGB values
159- const r = parseInt ( hex . substring ( 0 , 2 ) , 16 )
160- const g = parseInt ( hex . substring ( 2 , 4 ) , 16 )
161- const b = parseInt ( hex . substring ( 4 , 6 ) , 16 )
162-
163- // Check if alpha channel is present (#RRGGBBAA)
164- if ( hex . length === 8 ) {
165- const a = parseInt ( hex . substring ( 6 , 8 ) , 16 ) / 255
166- return `rgba(${ r } , ${ g } , ${ b } , ${ a } )`
167- }
168-
169- return `rgba(${ r } , ${ g } , ${ b } , ${ opacity } )`
170- }
171-
172- // For named colors (red, blue, etc.), wrap in rgba with opacity
173- // This works because CSS will interpret it correctly
174- return `rgba(${ color } , ${ opacity } )`
175- }
176-
177- /**
178- * Normalize color input - add # to hex if missing, or return as-is for other formats
179- * @param {string } color - Color input from user
180- * @returns {string } Normalized color
181- */
182- // function normalizeColor(color: string): string {
183- // color = color.trim()
184- // // If it looks like hex without #, add it
185- // if (/^[0-9A-Fa-f]{3}$|^[0-9A-Fa-f]{6}$|^[0-9A-Fa-f]{8}$/.test(color)) {
186- // return '#' + color
187- // }
188- // // Return as-is for named colors, rgb(), hsl(), etc.
189- // return color
190- // }
191-
192- /**
193- * Load custom colors from plugin settings (single chartColors key, comma-separated).
118+ * Load custom colors from plugin settings (single chartColors key, comma-separated).
119+ * Supports: #RGB, #RRGGBB, #RRGGBBAA, named CSS colors (e.g. red, blue), tailwind colors (amber-200, blue-500, etc.), hsl(), rgb(), rgba()
194120 * @returns {Array } Array of color objects with border, bg, and name properties
195121 */
196122async function loadCustomColors ( ) : Promise < Array < { border : string , bg : string , name : string } >> {
@@ -221,14 +147,13 @@ async function loadCustomColors(): Promise<Array<{ border: string, bg: string, n
221147 }
222148
223149 const colors = colorStrings . map ( userColor => {
224- const normalizedColor = userColor . toLowerCase ( )
225150 return {
226- border : normalizedColor ,
227- bg : colorToRgba ( userColor , 0.4 ) ,
228- name : normalizedColor
151+ border : colorToModernSpecWithOpacity ( userColor ) ,
152+ bg : colorToModernSpecWithOpacity ( userColor , 0.5 ) ,
153+ name : userColor
229154 }
230155 } )
231- // clo(colors, 'loadCustomColors :: colors')
156+ // clo(colors, 'loadCustomColors :: colors', 2 )
232157 return colors
233158}
234159// ============================================================================
@@ -798,8 +723,8 @@ function generateYesNoFilterCheckboxes(habits: Array<string>): string {
798723 */
799724function generateYesNoCombinedContainer ( ) : string {
800725 return `
801- <div class="chart-wrapper yesno-combined-wrapper ">
802- <div class="viz-display" id="yesno-combined- heatmap"></div>
726+ <div class="chart-wrapper">
727+ <div class="viz-display yesno-heatmap-section " id="yesno-heatmap-section "></div>
803728 </div>
804729`
805730}
@@ -840,7 +765,7 @@ function generateClientScript(tagData: Object, yesNoData: Object, tags: Array<st
840765 } else {
841766 console.error('Chart Stats: initChartStats not loaded (chartStatsScripts.js)');
842767 }
843- `
768+ `
844769}
845770
846771 // ========================================================================
@@ -907,9 +832,11 @@ async function makeChartSummaryHTML(
907832 ${ chartJsLoaderScript }
908833 <!-- for NotePlan to use -->
909834 <link rel="stylesheet" href="chartStats.css">
835+ <script type="text/javascript" src="chartStatsScripts.js"></script>
836+
910837 <!-- for local development to use -->
911838 <link rel="stylesheet" href="../../jgclark.Summaries/chartStats.css">
912- <script type="text/javascript" src="chartStatsScripts.js"></script>
839+ <script type="text/javascript" src="../../jgclark.Summaries/ chartStatsScripts.js"></script>
913840 <style>${ chartStyleVars } </style>
914841 </head>
915842
0 commit comments