github.com/hernad/nomad@v1.6.112/ui/app/components/chart-primitives/area.js (about) 1 /** 2 * Copyright (c) HashiCorp, Inc. 3 * SPDX-License-Identifier: MPL-2.0 4 */ 5 6 import Component from '@glimmer/component'; 7 import { assert } from '@ember/debug'; 8 import { default as d3Shape, area, line } from 'd3-shape'; 9 import uniquely from 'nomad-ui/utils/properties/uniquely'; 10 11 export default class ChartPrimitiveArea extends Component { 12 get colorClass() { 13 if (this.args.colorClass) return this.args.colorClass; 14 if (this.args.colorScale && this.args.index != null) 15 return `${this.args.colorScale} ${this.args.colorScale}-${ 16 this.args.index + 1 17 }`; 18 return 'is-primary'; 19 } 20 21 @uniquely('area-mask') maskId; 22 @uniquely('area-fill') fillId; 23 24 get curveMethod() { 25 const mappings = { 26 linear: 'curveLinear', 27 stepAfter: 'curveStepAfter', 28 }; 29 assert( 30 `Provided curve "${this.curve}" is not an allowed curve type`, 31 mappings[this.args.curve] 32 ); 33 return mappings[this.args.curve]; 34 } 35 36 get line() { 37 const { xScale, yScale, xProp, yProp } = this.args; 38 39 const builder = line() 40 .curve(d3Shape[this.curveMethod]) 41 .defined((d) => d[yProp] != null) 42 .x((d) => xScale(d[xProp])) 43 .y((d) => yScale(d[yProp])); 44 45 return builder(this.args.data); 46 } 47 48 get area() { 49 const { xScale, yScale, xProp, yProp } = this.args; 50 51 const builder = area() 52 .curve(d3Shape[this.curveMethod]) 53 .defined((d) => d[yProp] != null) 54 .x((d) => xScale(d[xProp])) 55 .y0(yScale(0)) 56 .y1((d) => yScale(d[yProp])); 57 58 return builder(this.args.data); 59 } 60 }