(spec, scope)
| 148461 | return ref(scope.add(Overlap(params))); |
| 148462 | } |
| 148463 | function parseLegend(spec, scope) { |
| 148464 | const config = scope.config.legend, encode = spec.encode || {}, _ = lookup(spec, config), legendEncode = encode.legend || {}, name = legendEncode.name || undefined, interactive2 = legendEncode.interactive, style = legendEncode.style, scales = {}; |
| 148465 | let scale6 = 0, entryLayout, params, children; // resolve scales and 'canonical' scale name |
| 148466 | LegendScales.forEach((s)=>spec[s] ? (scales[s] = spec[s], scale6 = scale6 || spec[s]) : 0); |
| 148467 | if (!scale6) (0, _vegaUtil.error)("Missing valid scale for legend."); // resolve legend type (symbol, gradient, or discrete gradient) |
| 148468 | const type = legendType(spec, scope.scaleType(scale6)); // single-element data source for legend group |
| 148469 | const datum = { |
| 148470 | title: spec.title != null, |
| 148471 | scales: scales, |
| 148472 | type: type, |
| 148473 | vgrad: type !== "symbol" && _.isVertical() |
| 148474 | }; |
| 148475 | const dataRef = ref(scope.add(Collect(null, [ |
| 148476 | datum |
| 148477 | ]))); // encoding properties for legend entry sub-group |
| 148478 | const entryEncode = { |
| 148479 | enter: { |
| 148480 | x: { |
| 148481 | value: 0 |
| 148482 | }, |
| 148483 | y: { |
| 148484 | value: 0 |
| 148485 | } |
| 148486 | } |
| 148487 | }; // data source for legend values |
| 148488 | const entryRef = ref(scope.add(LegendEntries(params = { |
| 148489 | type: type, |
| 148490 | scale: scope.scaleRef(scale6), |
| 148491 | count: scope.objectProperty(_("tickCount")), |
| 148492 | limit: scope.property(_("symbolLimit")), |
| 148493 | values: scope.objectProperty(spec.values), |
| 148494 | minstep: scope.property(spec.tickMinStep), |
| 148495 | formatType: scope.property(spec.formatType), |
| 148496 | formatSpecifier: scope.property(spec.format) |
| 148497 | }))); // continuous gradient legend |
| 148498 | if (type === Gradient) { |
| 148499 | children = [ |
| 148500 | legendGradient(spec, scale6, config, encode.gradient), |
| 148501 | legendGradientLabels(spec, config, encode.labels, entryRef) |
| 148502 | ]; // adjust default tick count based on the gradient length |
| 148503 | params.count = params.count || scope.signalRef(`max(2,2*floor((${deref(_.gradientLength())})/100))`); |
| 148504 | } else if (type === Discrete) children = [ |
| 148505 | legendGradientDiscrete(spec, scale6, config, encode.gradient, entryRef), |
| 148506 | legendGradientLabels(spec, config, encode.labels, entryRef) |
| 148507 | ]; |
| 148508 | else { |
| 148509 | // determine legend symbol group layout |
| 148510 | entryLayout = legendSymbolLayout(spec, config); |
| 148511 | children = [ |
| 148512 | legendSymbolGroups(spec, config, encode, entryRef, deref(entryLayout.columns)) |
| 148513 | ]; // pass symbol size information to legend entry generator |
| 148514 | params.size = sizeExpression(spec, scope, children[0].marks); |
| 148515 | } // generate legend marks |
| 148516 | children = [ |
| 148517 | guideGroup({ |
| 148518 | role: LegendEntryRole, |
| 148519 | from: dataRef, |
| 148520 | encode: entryEncode, |
no test coverage detected