|
| 1 | +/* |
| 2 | + * Copyright 2025 Adobe. All rights reserved. |
| 3 | + * This file is licensed to you under the Apache License, Version 2.0 (the "License"); |
| 4 | + * you may not use this file except in compliance with the License. You may obtain a copy |
| 5 | + * of the License at http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | + * |
| 7 | + * Unless required by applicable law or agreed to in writing, software distributed under |
| 8 | + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS |
| 9 | + * OF ANY KIND, either express or implied. See the License for the specific language |
| 10 | + * governing permissions and limitations under the License. |
| 11 | + */ |
| 12 | +import { BaseLegendLayout, Config } from 'vega'; |
| 13 | + |
| 14 | +import { |
| 15 | + DEFAULT_BACKGROUND_COLOR, |
| 16 | + DEFAULT_FONT_COLOR, |
| 17 | + DEFAULT_FONT_SIZE, |
| 18 | + DEFAULT_LEGEND_COLUMN_PADDING, |
| 19 | + DEFAULT_LEGEND_LABEL_LIMIT, |
| 20 | + DEFAULT_LEGEND_SYMBOL_SIZE, |
| 21 | + DEFAULT_SYMBOL_SIZE, |
| 22 | + DEFAULT_SYMBOL_STROKE_WIDTH, |
| 23 | + ROUNDED_SQUARE_PATH, |
| 24 | +} from '@spectrum-charts/constants'; |
| 25 | + |
| 26 | +import { categorical16 } from './categoricalColorPalette'; |
| 27 | +import { divergentOrangeYellowSeafoam15 } from './divergingColorPalette'; |
| 28 | +import { sequentialViridis16 } from './sequentialColorPalette'; |
| 29 | +import { spectrum2Colors } from './spectrum2Colors'; |
| 30 | +import { ADOBE_CLEAN_FONT } from './spectrumTheme'; |
| 31 | +import { getS2ColorValue } from './utils'; |
| 32 | + |
| 33 | +export function getSpectrum2VegaConfig(colorScheme: 'light' | 'dark'): Config { |
| 34 | + const FONT_COLOR = getS2ColorValue(DEFAULT_FONT_COLOR, colorScheme); |
| 35 | + const { |
| 36 | + 'blue-400': blue400, |
| 37 | + 'gray-300': gray300, |
| 38 | + 'gray-700': gray700, |
| 39 | + 'gray-800': gray800, |
| 40 | + } = spectrum2Colors[colorScheme]; |
| 41 | + const horizontalLegendLayout: BaseLegendLayout = { |
| 42 | + anchor: 'middle', |
| 43 | + direction: 'horizontal', |
| 44 | + center: true, |
| 45 | + offset: 24, |
| 46 | + bounds: 'full', |
| 47 | + margin: 48, |
| 48 | + }; |
| 49 | + const verticalLegendLayout: BaseLegendLayout = { |
| 50 | + anchor: 'middle', |
| 51 | + direction: 'vertical', |
| 52 | + center: false, |
| 53 | + offset: 24, |
| 54 | + bounds: 'full', |
| 55 | + margin: 24, |
| 56 | + }; |
| 57 | + |
| 58 | + const defaultColor = spectrum2Colors[colorScheme]['categorical-100']; |
| 59 | + |
| 60 | + return { |
| 61 | + axis: { |
| 62 | + bandPosition: 0.5, |
| 63 | + domain: false, |
| 64 | + domainWidth: 1, |
| 65 | + domainColor: gray800, |
| 66 | + gridColor: gray300, |
| 67 | + labelFont: ADOBE_CLEAN_FONT, |
| 68 | + labelFontSize: DEFAULT_FONT_SIZE, |
| 69 | + labelFontWeight: 'normal', |
| 70 | + labelPadding: 8, |
| 71 | + labelOverlap: true, |
| 72 | + labelColor: FONT_COLOR, |
| 73 | + ticks: false, |
| 74 | + tickColor: gray300, |
| 75 | + tickRound: true, |
| 76 | + tickSize: 8, |
| 77 | + tickCap: 'round', |
| 78 | + tickWidth: 1, |
| 79 | + titleAnchor: 'middle', |
| 80 | + titleColor: FONT_COLOR, |
| 81 | + titleFont: ADOBE_CLEAN_FONT, |
| 82 | + titleFontSize: DEFAULT_FONT_SIZE, |
| 83 | + titleFontWeight: 'bold', |
| 84 | + titlePadding: 16, |
| 85 | + }, |
| 86 | + range: { |
| 87 | + category: categorical16, |
| 88 | + diverging: divergentOrangeYellowSeafoam15, |
| 89 | + ordinal: categorical16, |
| 90 | + ramp: sequentialViridis16, |
| 91 | + }, |
| 92 | + background: DEFAULT_BACKGROUND_COLOR, |
| 93 | + legend: { |
| 94 | + columnPadding: DEFAULT_LEGEND_COLUMN_PADDING, |
| 95 | + labelColor: FONT_COLOR, |
| 96 | + labelFont: ADOBE_CLEAN_FONT, |
| 97 | + labelFontSize: DEFAULT_FONT_SIZE, |
| 98 | + labelFontWeight: 'normal', |
| 99 | + labelLimit: DEFAULT_LEGEND_LABEL_LIMIT, |
| 100 | + layout: { |
| 101 | + bottom: horizontalLegendLayout, |
| 102 | + top: horizontalLegendLayout, |
| 103 | + left: verticalLegendLayout, |
| 104 | + right: verticalLegendLayout, |
| 105 | + }, |
| 106 | + rowPadding: 8, |
| 107 | + symbolSize: DEFAULT_LEGEND_SYMBOL_SIZE, |
| 108 | + symbolType: ROUNDED_SQUARE_PATH, |
| 109 | + symbolStrokeColor: gray700, |
| 110 | + titleColor: FONT_COLOR, |
| 111 | + titleFont: ADOBE_CLEAN_FONT, |
| 112 | + titleFontSize: DEFAULT_FONT_SIZE, |
| 113 | + titlePadding: 8, |
| 114 | + }, |
| 115 | + arc: { |
| 116 | + fill: defaultColor, |
| 117 | + }, |
| 118 | + area: { |
| 119 | + fill: defaultColor, |
| 120 | + opacity: 0.8, |
| 121 | + }, |
| 122 | + line: { |
| 123 | + strokeWidth: 1.5, |
| 124 | + stroke: defaultColor, |
| 125 | + }, |
| 126 | + path: { |
| 127 | + stroke: defaultColor, |
| 128 | + }, |
| 129 | + rect: { |
| 130 | + strokeWidth: 0, |
| 131 | + stroke: blue400, |
| 132 | + fill: defaultColor, |
| 133 | + }, |
| 134 | + rule: { |
| 135 | + stroke: gray800, |
| 136 | + strokeWidth: 1, |
| 137 | + }, |
| 138 | + shape: { |
| 139 | + stroke: defaultColor, |
| 140 | + }, |
| 141 | + symbol: { |
| 142 | + strokeWidth: DEFAULT_SYMBOL_STROKE_WIDTH, |
| 143 | + size: DEFAULT_SYMBOL_SIZE, |
| 144 | + fill: defaultColor, |
| 145 | + }, |
| 146 | + text: { |
| 147 | + fill: FONT_COLOR, |
| 148 | + font: ADOBE_CLEAN_FONT, |
| 149 | + fontSize: DEFAULT_FONT_SIZE, |
| 150 | + }, |
| 151 | + title: { |
| 152 | + offset: 10, |
| 153 | + font: ADOBE_CLEAN_FONT, |
| 154 | + fontSize: 18, |
| 155 | + color: FONT_COLOR, |
| 156 | + }, |
| 157 | + autosize: { |
| 158 | + type: 'fit', |
| 159 | + contains: 'padding', |
| 160 | + resize: true, |
| 161 | + }, |
| 162 | + }; |
| 163 | +} |
0 commit comments