1212// See the License for the specific language governing permissions and
1313// limitations under the License.
1414
15+ /**
16+ * Chart option builder utilities.
17+ *
18+ * These functions build ECharts option objects with a consistent structure.
19+ * Theme colors are NOT included here - EChartView applies theme colors
20+ * automatically by reading CSS variables from the DOM element.
21+ */
22+
1523import type { EChartsCoreOption } from 'echarts/core' ;
16- import { getChartThemeColors } from './chart_theme' ;
1724
1825/**
1926 * Configuration for an axis in a chart.
@@ -48,35 +55,28 @@ export interface BrushConfig {
4855
4956/**
5057 * Build an axis option from config.
51- * Explicitly includes theme colors because ECharts doesn't deep merge
52- * option objects with theme objects - setting axisLabel overrides the theme's
53- * axisLabel entirely, so we must include colors here.
58+ * Theme colors are applied by EChartView, so we omit color settings here.
5459 */
5560export function buildAxisOption (
5661 config : AxisConfig ,
5762 isXAxis : boolean ,
5863) : Record < string , unknown > {
59- const theme = getChartThemeColors ( ) ;
6064 const axis : Record < string , unknown > = {
6165 type : config . type ,
6266 name : config . name ,
6367 nameLocation : isXAxis ? ( 'middle' as const ) : ( 'end' as const ) ,
6468 nameGap : config . nameGap ?? ( isXAxis ? 25 : 10 ) ,
65- nameTextStyle : { fontSize : 11 , color : theme . textColor } ,
69+ nameTextStyle : { fontSize : 11 } ,
6670 axisLabel : {
6771 fontSize : 10 ,
68- color : theme . textColor ,
6972 ...( config . formatter !== undefined && { formatter : config . formatter } ) ,
7073 ...( config . labelOverflow !== undefined && {
7174 overflow : config . labelOverflow ,
7275 } ) ,
7376 ...( config . labelWidth !== undefined && { width : config . labelWidth } ) ,
7477 } ,
75- axisTick : { lineStyle : { color : theme . borderColor } } ,
76- axisLine : { lineStyle : { color : theme . borderColor } } ,
7778 splitLine : {
7879 show : config . showSplitLine ?? false ,
79- lineStyle : { color : theme . borderColor } ,
8080 } ,
8181 } ;
8282
@@ -100,7 +100,7 @@ export function buildAxisOption(
100100}
101101
102102/**
103- * Build a themed grid option.
103+ * Build a grid option.
104104 */
105105export function buildGridOption ( opts ?: {
106106 top ?: number ;
@@ -119,28 +119,23 @@ export function buildGridOption(opts?: {
119119}
120120
121121/**
122- * Build a themed tooltip option.
123- * Explicitly includes theme colors so tooltips adapt when the theme changes .
122+ * Build a tooltip option.
123+ * Theme colors are applied by EChartView .
124124 * Extra options are merged in (e.g. trigger, formatter).
125125 */
126126export function buildTooltipOption (
127127 extra ?: Record < string , unknown > ,
128128) : Record < string , unknown > {
129- const theme = getChartThemeColors ( ) ;
130129 return {
131- backgroundColor : theme . backgroundColor ,
132- borderColor : theme . borderColor ,
133- textStyle : { color : theme . textColor } ,
134130 ...extra ,
135131 } ;
136132}
137133
138134/**
139135 * Build a brush configuration.
140- * Uses accent color from theme (ECharts doesn't theme brush colors) .
136+ * Theme colors are applied by EChartView .
141137 */
142138export function buildBrushOption ( config : BrushConfig ) : Record < string , unknown > {
143- const theme = getChartThemeColors ( ) ;
144139 return {
145140 ...( config . xAxisIndex !== undefined && { xAxisIndex : config . xAxisIndex } ) ,
146141 ...( config . yAxisIndex !== undefined && { yAxisIndex : config . yAxisIndex } ) ,
@@ -149,7 +144,6 @@ export function buildBrushOption(config: BrushConfig): Record<string, unknown> {
149144 brushStyle : {
150145 borderWidth : 1 ,
151146 color : 'rgba(0, 0, 0, 0.1)' ,
152- borderColor : theme . accentColor ,
153147 } ,
154148 throttleType : 'debounce' as const ,
155149 throttleDelay : 100 ,
@@ -158,13 +152,11 @@ export function buildBrushOption(config: BrushConfig): Record<string, unknown> {
158152
159153/**
160154 * Build a legend option.
161- * Explicitly includes theme colors because ECharts doesn't deep merge
162- * option objects with theme objects.
155+ * Theme colors are applied by EChartView.
163156 */
164157export function buildLegendOption (
165158 position : 'top' | 'right' = 'top' ,
166159) : Record < string , unknown > {
167- const theme = getChartThemeColors ( ) ;
168160 if ( position === 'right' ) {
169161 return {
170162 show : true ,
@@ -178,7 +170,6 @@ export function buildLegendOption(
178170 width : 120 ,
179171 overflow : 'truncate' ,
180172 ellipsis : '\u2026' ,
181- color : theme . textColor ,
182173 } ,
183174 tooltip : { show : true } ,
184175 pageButtonPosition : 'end' ,
@@ -187,17 +178,16 @@ export function buildLegendOption(
187178 return {
188179 show : true ,
189180 top : 0 ,
190- textStyle : { fontSize : 10 , color : theme . textColor } ,
181+ textStyle : { fontSize : 10 } ,
191182 } ;
192183}
193184
194185/**
195186 * Build a complete base chart option with grid, axes, and optional
196187 * tooltip/brush/legend. Charts add their own `series` on top.
197188 *
198- * The `color` array (series colors) and tooltip theme colors are included
199- * so that charts update automatically when the Mithril component re-renders
200- * after a theme change — without needing to reinitialize the ECharts instance.
189+ * Theme colors (series colors, text colors, etc.) are applied by EChartView
190+ * which reads CSS variables from the DOM element.
201191 */
202192export function buildChartOption ( config : {
203193 readonly grid ?: Parameters < typeof buildGridOption > [ 0 ] ;
@@ -208,11 +198,9 @@ export function buildChartOption(config: {
208198 readonly legend ?: Record < string , unknown > ;
209199} ) : EChartsCoreOption {
210200 const { grid, xAxis, yAxis, tooltip, brush, legend} = config ;
211- const theme = getChartThemeColors ( ) ;
212201
213202 const option : Record < string , unknown > = {
214203 animation : false ,
215- color : [ ...theme . chartColors ] ,
216204 grid : buildGridOption ( grid ) ,
217205 xAxis : buildAxisOption ( xAxis , true ) ,
218206 yAxis : buildAxisOption ( yAxis , false ) ,
0 commit comments