@xplortech/apollo-data 0.0.4-draft.64ed229 → 0.0.4-draft.f74ef02
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/apollo-data/apollo-data.esm.js +1 -1
- package/dist/apollo-data/p-2nuV5Vny.js +1 -0
- package/dist/apollo-data/p-4ac3c97c.entry.js +1 -0
- package/dist/apollo-data/p-BWkrM8dc.js +11 -0
- package/dist/apollo-data/p-b7471c12.entry.js +1 -0
- package/dist/apollo-data/p-e518baac.entry.js +1 -0
- package/dist/cjs/apollo-data-bar-chart.cjs.entry.js +314 -0
- package/dist/{esm/apollo-data-bar-chart_3.entry.js → cjs/apollo-data-base-CxVQ-WVP.js} +2 -999
- package/dist/cjs/apollo-data-donut-chart.cjs.entry.js +408 -0
- package/dist/cjs/apollo-data-line-chart_2.cjs.entry.js +534 -0
- package/dist/cjs/apollo-data.cjs.js +1 -1
- package/dist/cjs/constants-B3weDEpc.js +5 -0
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/collection/collection-manifest.json +2 -1
- package/dist/collection/components/apollo-data-scatter/apollo-data-scatter.js +329 -0
- package/dist/collection/examples/apollo-data-scatter.examples.js +94 -0
- package/dist/components/apollo-data-scatter-chart.d.ts +11 -0
- package/dist/components/apollo-data-scatter-chart.js +1 -0
- package/dist/esm/apollo-data-bar-chart.entry.js +312 -0
- package/dist/{cjs/apollo-data-bar-chart_3.cjs.entry.js → esm/apollo-data-base-BWkrM8dc.js} +1 -1004
- package/dist/esm/apollo-data-donut-chart.entry.js +406 -0
- package/dist/esm/apollo-data-line-chart_2.entry.js +531 -0
- package/dist/esm/apollo-data.js +1 -1
- package/dist/esm/constants-2nuV5Vny.js +3 -0
- package/dist/esm/loader.js +1 -1
- package/dist/types/components/apollo-data-scatter/apollo-data-scatter.d.ts +329 -0
- package/dist/types/components.d.ts +55 -0
- package/dist/types/examples/apollo-data-scatter.examples.d.ts +11 -0
- package/package.json +1 -1
- package/src/examples/apollo-data-scatter.examples.ts +109 -0
- package/dist/apollo-data/p-725550f2.entry.js +0 -11
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as e,g as a,h as t,H as n}from"./p-Bb2nY-Tf.js";import{A as l}from"./p-BWkrM8dc.js";const r=class extends l{constructor(a){super(),e(this,a)}get el(){return a(this)}adData=[];adSpec={};categories;dataValues;totalRevenue;chartColors;defaultChartColors=["#4d1ab2","#f99170","#e550c8","#ffd563","#8857fa","#52ebba","#bf1d78","#31cff8"];defaultCenterText="Total Revenue";async componentDidRender(){await this.renderChart()}async getViewData(e,a){const t=e;return this.chartColors=a?.colorSet?a.colorSet:this.defaultChartColors,this.categories=t.map((e=>e.category)),this.dataValues=t.map(((e,a)=>({...e,order:a+1}))),this.totalRevenue=Math.round(100*t.reduce(((e,a)=>e+a.value),0))/100,{$schema:"https://vega.github.io/schema/vega/v5.json",description:"Donut chart with correctly placed percentage labels and exploded 'Other' slices on hover",height:250,signals:[{name:"containerW",update:"min(containerSize()[0], 400)"},{name:"centerX",update:"containerW / 2"},{name:"centerY",update:"250 / 2"},{name:"radius",update:"min(containerW, 250) / 2 - 20"},{name:"categoryDisplay",value:null,on:[{events:{type:"mouseover",markname:"mainArc"},update:"datum.category"},{events:{type:"mouseover",markname:"mainArcLabel"},update:"datum.category"},{events:{type:"mouseout",markname:"mainArc"},update:"null"},{events:{type:"mouseout",markname:"mainArcLabel"},update:"null"},{events:{type:"mouseover",markname:"innerArc"},update:"null"},{events:{type:"mouseover",markname:"outerArc"},update:"null"},{events:{type:"mouseover",markname:"otherArc"},update:"datum.category"},{events:{type:"mouseout",markname:"otherArc"},update:"null"}]},{name:"displayText",update:`categoryDisplay && length(categoryDisplay) > 18 ? (lastindexof(categoryDisplay, ' ') > 0 ? slice(categoryDisplay, 0, lastindexof(categoryDisplay, ' ')) + '\\n' + slice(categoryDisplay, lastindexof(categoryDisplay, ' ') + 1) : categoryDisplay) : categoryDisplay || '${a?.centerText?a.centerText:this.defaultCenterText}'`},{name:"hoveredCategory",value:null,on:[{events:{type:"mouseover",markname:"mainArc"},update:"datum.category"},{events:{type:"mouseover",markname:"mainArcLabel"},update:"datum.category"},{events:{type:"mouseover",markname:"outerArc"},update:"null"},{events:{type:"mouseover",markname:"innerArc"},update:"null"},{events:{type:"mouseout",markname:"innerArc"},update:"null"}]},{name:"hoveredValue",value:null,on:[{events:{type:"mouseover",markname:"mainArc"},update:"datum.value"},{events:{type:"mouseover",markname:"mainArcLabel"},update:"datum.value"},{events:{type:"mouseout",markname:"mainArc"},update:"null"},{events:{type:"mouseover",markname:"otherArc"},update:"datum.value"},{events:{type:"mouseout",markname:"otherArc"},update:"null"}]}],width:{signal:"containerW"},data:[{name:"table",values:this.dataValues,transform:[{type:"joinaggregate",fields:["value"],ops:["sum"],as:["total"]},{type:"formula",as:"percent",expr:"datum.value / datum.total"},{type:"collect",sort:{field:"order",order:"descending"}},{type:"pie",field:"value",as:["startAngle","endAngle"]},{type:"formula",as:"midAngle",expr:"((datum.startAngle + datum.endAngle) + 9.418) / 2"},{type:"formula",as:"labelX",expr:"centerX + (radius * 1.2 * cos(datum.midAngle))"},{type:"formula",as:"labelY",expr:"centerY + (radius * 1.2 * sin(datum.midAngle))"},{type:"formula",as:"percentLabel",expr:`format(datum.value / ${this.totalRevenue} * 100, '.1f') + '%'`}]},{name:"defaultCenterText",values:[{category:a?.centerText?a.centerText:this.defaultCenterText,value:this.totalRevenue,order:4}],transform:[{type:"filter",expr:"hoveredCategory === null"},{type:"formula",as:"textDisplay",expr:`'${a?.prefix??"$"}' + format(floor(datum.value), ',') + '${a?.suffix??""}' `}]}],scales:[{name:"mainColor",type:"ordinal",domain:this.categories,range:this.chartColors}],legends:[{fill:"mainColor",orient:"bottom",direction:"horizontal",columns:2,title:"",padding:10,symbolType:"square",symbolSize:100,labelFontSize:12,labelColor:"#6A6D7D",rowPadding:8}],marks:[{type:"rule",name:"labelLines",from:{data:"table"},encode:{enter:{stroke:{value:"black"},strokeWidth:{value:1},x:{signal:"centerX + (radius * 0.9) * cos(datum.midAngle)"},y:{signal:"centerY + (radius * 0.9) * sin(datum.midAngle)"},x2:{signal:"datum.labelX - 12 * cos(datum.midAngle)"},y2:{signal:"datum.labelY - 12 * sin(datum.midAngle)"}},update:{opacity:{value:1}}},zindex:5},{type:"arc",name:"mainArc",from:{data:"table"},encode:{enter:{fill:{scale:"mainColor",field:"category"},x:{signal:"centerX"},y:{signal:"centerY"},startAngle:{field:"startAngle"},endAngle:{field:"endAngle"},innerRadius:{signal:"radius * 0.5"},outerRadius:{signal:"radius * 0.9"},padAngle:{value:.03},cornerRadius:{value:1}}},interactive:!0},{type:"arc",name:"innerArc",from:{data:"table"},encode:{enter:{fill:{value:"transparent"},x:{signal:"centerX"},y:{signal:"centerY"},startAngle:{field:"startAngle"},endAngle:{field:"endAngle"},innerRadius:{signal:"radius * 0.4"},outerRadius:{signal:"radius * 0.5"},padAngle:{value:.03},cornerRadius:{value:1}}},zindex:1},{type:"arc",name:"outerArc",from:{data:"table"},encode:{enter:{fill:{value:"transparent"},x:{signal:"centerX"},y:{signal:"centerY"},startAngle:{field:"startAngle"},endAngle:{field:"endAngle"},innerRadius:{signal:"radius * 0.91"},outerRadius:{signal:"radius * 1.30"}}},zindex:1},{type:"text",name:"mainArcLabel",from:{data:"table"},encode:{enter:{text:{field:"percentLabel"},align:{value:"center"},baseline:{value:"middle"},fill:{value:"#302D3B"},fontSize:{value:10},x:{field:"labelX"},y:{field:"labelY"},font:{value:"apple-system, system-ui, 'Segoe UI', Arial, Helvetica, Roboto, sans-serif"},fontWeight:600}}},{type:"text",encode:{enter:{text:{value:"$850,000"},x:{signal:"centerX"},y:{signal:"centerY"},align:{value:"center"},baseline:{value:"middle"},fontSize:{value:16},fontWeight:{value:"bold"},fill:{value:"#302D3B"},font:{value:"apple-system, system-ui, 'Segoe UI', Arial, Helvetica, Roboto, sans-serif"}},update:{text:{signal:`hoveredValue ? '${a?.prefix??"$"}' + format(floor(hoveredValue), ',') + '${a?.suffix??""}' : '${a?.prefix??"$"}' + format(floor(${this.totalRevenue??1}), ',') + '${a?.suffix??""}'`}}}},{type:"text",encode:{enter:{x:{signal:"centerX"},y:{signal:"centerY + 15"},align:{value:"center"},baseline:{value:"middle"},fontSize:{value:10},fill:{value:"#6A6D7D"},font:{value:"apple-system, system-ui, 'Segoe UI', Arial, Helvetica, Roboto, sans-serif"},fontWeight:400,limit:{value:100},lineBreak:{value:"\\n"}},update:{text:{signal:"displayText"}}}}]}}render(){return t(n,{key:"fb26a6b02b83b0ce64a8301149b66f5d09a4a7b4"},t("div",{key:"fc08cdc3c0c0fda7f7c13149532eb61f511aa035",id:"container",style:{width:"100%",height:"100%"}}))}};export{r as apollo_data_donut_chart}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as e,g as a,h as t,H as l}from"./p-Bb2nY-Tf.js";import{A as n}from"./p-BWkrM8dc.js";import{C as i}from"./p-2nuV5Vny.js";const o="apple-system, system-ui, 'Segoe UI', Arial, Helvetica, Roboto, sans-serif",r=class extends n{constructor(a){super(),e(this,a)}get el(){return a(this)}adData=[];adSpec=null;static tooltipStylesInjected=!1;componentDidLoad(){this.injectTooltipStyles()}async componentDidRender(){await this.renderChart()}injectTooltipStyles(){if(r.tooltipStylesInjected)return;const e="apollo-data-line-tooltip-styles";if(document.getElementById(e))return void(r.tooltipStylesInjected=!0);const a=document.createElement("style");a.id=e,a.textContent="\n #vg-tooltip-element {\n background-color: #ffffff;\n border: 1px solid #e1e2e8;\n border-radius: 0.25rem;\n box-shadow: 0 4px 6px -1px rgba(48, 45, 59, 0.1), 0 2px 4px -1px rgba(48, 45, 59, 0.05);\n font-family: apple-system, system-ui, 'Segoe UI', Arial, Helvetica, Roboto, sans-serif;\n font-weight: 500;\n padding: 0.25rem 0.75rem;\n pointer-events: none;\n text-align: center;\n transform: translateY(20%);\n white-space: pre;\n z-index: 999999999;\n }\n\n #vg-tooltip-element table tr td.key {\n color: #6a6d7d;\n text-align: center;\n }\n\n #vg-tooltip-element table tr td.value {\n text-align: center;\n }\n\n #vg-tooltip-element.dark-theme {\n background-color: #292632;\n border: 1px solid #6a6d7d;\n box-shadow: 0 4px 6px -1px rgba(48, 45, 59, 0.1), 0 2px 4px -1px rgba(48, 45, 59, 0.5);\n color: #ffffff;\n }\n\n #vg-tooltip-element::after {\n border-color: rgba(255, 255, 255, 0.95) transparent transparent transparent;\n border-style: solid;\n border-width: 9px;\n bottom: -17px;\n content: '';\n left: 50%;\n position: absolute;\n transform: translateX(-50%);\n }\n ",document.head.appendChild(a),r.tooltipStylesInjected=!0}async getViewData(e,a){if(!a)throw new Error("adSpec is required for apollo-data-line-chart");const{tooltipPrefix:t="",currencySymbol:l=""}=a;if(!e||0===e.length)throw new Error("Data is required for apollo-data-line-chart");const n=Array.from(new Set(e.map((e=>e.category)))),r=[...new Set(e.map((e=>e.xValue)))].sort(((e,a)=>e-a)),s=a?.colorSet??i,d=r.map((a=>{const t=e.find((e=>e.xValue===a));return{xValue:a,displayLabel:null!=t?.xLabel?t.xLabel:String(a)}})),u=t?".2f":".0f",c=t?l:"",f=a.pointStyle??"circle",p=function(e){switch(e){case"dashed":return[6,4];case"dotted":return[2,2];default:return[]}}(a.lineStyle??"solid"),m=[{name:"raw",values:e},{name:"xLabelData",values:d}];n.forEach(((e,a)=>{m.push({name:`series_${a}`,source:"raw",transform:[{type:"filter",expr:`datum.category === ${JSON.stringify(e)}`},{type:"collect",sort:{field:"xValue"}}]})}));const y=n.map(((e,a)=>({type:"line",from:{data:`series_${a}`},encode:{enter:{x:{scale:"x",field:"xValue"},y:{scale:"y",field:"yValue"},stroke:{value:s[a%s.length]},strokeWidth:{value:2},interpolate:{value:"monotone"},...p.length>0?{strokeDash:{value:p}}:{}}}})));return{$schema:"https://vega.github.io/schema/vega/v5.json",config:{text:{fill:"#6a6d7d",font:o,labelFontSize:12,labelFontWeight:400},axis:{labelColor:"#6a6d7d",titleColor:"#6a6d7d",labelFont:o,titleFont:o,titleFontWeight:400},legend:{labelColor:"#6a6d7d",titleColor:"#6a6d7d",labelFont:o,titleFont:o,labelFontSize:12,labelLimit:95},title:{color:"#6a6d7d",font:o,labelFontSize:12,labelFontWeight:400}},height:250,autosize:{type:"fit-x",contains:"padding",resize:!0},signals:[{name:"containerW",update:"max(containerSize()[0], 400)"},{name:"legendColumns",update:"ceil(containerW / 140)"}],width:{signal:"containerW"},data:m,scales:[{name:"x",type:"point",domain:r,range:"width",padding:.5},{name:"xLabels",type:"ordinal",domain:{data:"xLabelData",field:"xValue"},range:{data:"xLabelData",field:"displayLabel"}},{name:"y",type:"linear",domain:{data:"raw",field:"yValue"},nice:!0,zero:!0,range:"height"},{name:"color",type:"ordinal",domain:n,range:a?.colorSet??i}],axes:[{orient:"bottom",scale:"x",title:a?.xAxisTitle,labelPadding:12,titlePadding:12,labelAngle:-90,labelAlign:"right",labelBaseline:"middle",tickSize:3,labelFontSize:12,titleFontSize:14,ticks:!1,domain:!1,encode:{labels:{update:{text:{signal:"scale('xLabels', datum.value)"}}}}},{orient:"left",scale:"y",title:a?.yAxisTitle||"",format:",.0f",grid:!0,tickCount:6,labelFontSize:12,titleFontSize:14,ticks:!1,domain:!1,tickBand:"extent",labelPadding:10}],legends:[{stroke:"color",orient:"bottom",direction:"horizontal",columns:{signal:"legendColumns"},title:null,symbolType:"stroke",symbolStrokeWidth:3,rowPadding:8,symbolOffset:-35,symbolSize:100,labelOffset:8,labelLimit:95}],marks:[...y,{type:"symbol",from:{data:"raw"},encode:{enter:{x:{scale:"x",field:"xValue"},y:{scale:"y",field:"yValue"},fill:{scale:"color",field:"category"},size:{value:50},shape:{value:f},tooltip:{signal:`(datum.xLabel != null ? datum.xLabel : format(datum.xValue, ',.0f')) + ' · ' + datum.category + ': ' + (datum.yLabel != null ? datum.yLabel : '${c}' + format(datum.yValue, ',${u}'))`}}}}]}}render(){return t(l,{key:"7799f01536f212d7a06da08c1e463d8529c5bf21"},t("div",{key:"25463f10bbc0f5443c35ab03b5b53164d9ad1efd",id:"container",style:{width:"100%",height:"100%"}}))}},s=class extends n{constructor(a){super(),e(this,a)}get el(){return a(this)}adData=[];adSpec={};async componentDidRender(){await this.renderChart()}DEFAULT_POINT_STYLE={shape:"circle",opacity:1,color:"blue",size:1};async getViewData(e,a){const t=e.map((e=>{const t={};return Object.keys(this.DEFAULT_POINT_STYLE).forEach((l=>{t[l]=e.pointStyle?.[l]??e?.[l]??a.categoryPointStyleMap?.[e.category]?.[l]??a.defaultPointStyle?.[l]??this.DEFAULT_POINT_STYLE[l]})),{category:e.category,xValue:e.xValue,yValue:e.yValue,color:t.color,shape:t.shape,opacity:t.opacity}})),l="auto"===a?.tooltip?"category":"none";return{$schema:"https://vega.github.io/schema/vega/v6.json",description:"A scatter plot with null values visualized along the axes.",width:450,height:450,padding:5,autosize:{type:"fit",resize:!0},signals:[{name:"nullSize",value:8},{name:"nullGap",update:"nullSize + 10"}],data:[{name:"source",values:t},{name:"valid",source:"source",transform:[{type:"filter",expr:"datum.xValue != null && datum.yValue != null"}]},{name:"nullXY",source:"source",transform:[{type:"filter",expr:"datum.xValue == null && datum.yValue == null"},{type:"aggregate"}]},{name:"nullY",source:"source",transform:[{type:"filter",expr:"datum.xValue != null && datum.yValue == null"}]},{name:"nullX",source:"source",transform:[{type:"filter",expr:"datum.xValue == null && datum.yValue != null"}]}],scales:[{name:"xscale",type:"linear",range:[{signal:"nullGap"},{signal:"width"}],nice:!0,domain:{data:"valid",field:"xValue"}},{name:"yscale",type:"linear",range:[{signal:"height - nullGap"},0],nice:!0,domain:{data:"valid",field:"yValue"}}],axes:[{orient:"bottom",scale:"xscale",offset:5,format:"s",title:a?.xAxisTitle||"X Value"},{orient:"left",scale:"yscale",offset:5,format:"s",title:a?.yAxisTitle||"Y Value"}],marks:[{type:"symbol",from:{data:"valid"},encode:{enter:{size:{value:50},tooltip:{field:l}},update:{x:{scale:"xscale",field:"xValue"},y:{scale:"yscale",field:"yValue"},fill:{field:"color"},fillOpacity:{field:"opacity"},shape:{field:"shape"},zindex:{value:0}},hover:{fill:{value:"firebrick"},fillOpacity:{value:1},zindex:{value:1}}}},{type:"symbol",from:{data:"nullY"},encode:{enter:{size:{value:50},tooltip:{field:l}},update:{x:{scale:"xscale",field:"xValue"},y:{signal:"height - nullSize/2"},fill:{value:"#aaa"},fillOpacity:{value:.2}},hover:{fill:{value:"firebrick"},fillOpacity:{value:1}}}},{type:"symbol",from:{data:"nullX"},encode:{enter:{size:{value:50},tooltip:{field:"name"}},update:{x:{signal:"nullSize/2"},y:{scale:"yscale",field:"yValue"},fill:{value:"#aaa"},fillOpacity:{value:.2},zindex:{value:0}},hover:{fill:{value:"firebrick"},fillOpacity:{value:1},zindex:{value:1}}}},{type:"text",interactive:!1,from:{data:"nullXY"},encode:{update:{x:{signal:"nullSize",offset:-4},y:{signal:"height",offset:13},text:{signal:"datum.count + ' null'"},align:{value:"right"},baseline:{value:"top"},fill:{value:"#999"},fontSize:{value:9}}}}]}}render(){return t(l,{key:"60005ab926b0153b3e31729a69f5a64cf6558085"},t("div",{key:"820de3e0ddbbc2650b9764e279d87531338e72e3",id:"container",style:{width:"100%",height:"100%"}}))}};export{r as apollo_data_line_chart,s as apollo_data_scatter_chart}
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var index = require('./index-Cl7HgRm0.js');
|
|
4
|
+
var apolloDataBase = require('./apollo-data-base-CxVQ-WVP.js');
|
|
5
|
+
var constants = require('./constants-B3weDEpc.js');
|
|
6
|
+
|
|
7
|
+
const FONT_FAMILY = "apple-system, system-ui, 'Segoe UI', Arial, Helvetica, Roboto, sans-serif";
|
|
8
|
+
const ApolloDataBarChart = class extends apolloDataBase.ApolloBase {
|
|
9
|
+
constructor(hostRef) {
|
|
10
|
+
super();
|
|
11
|
+
index.registerInstance(this, hostRef);
|
|
12
|
+
}
|
|
13
|
+
get el() { return index.getElement(this); }
|
|
14
|
+
adData = [];
|
|
15
|
+
adSpec = null;
|
|
16
|
+
static tooltipStylesInjected = false;
|
|
17
|
+
componentDidLoad() {
|
|
18
|
+
this.injectTooltipStyles();
|
|
19
|
+
}
|
|
20
|
+
async componentDidRender() {
|
|
21
|
+
await this.renderChart();
|
|
22
|
+
}
|
|
23
|
+
injectTooltipStyles() {
|
|
24
|
+
if (ApolloDataBarChart.tooltipStylesInjected) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const styleId = 'apollo-data-bar-tooltip-styles';
|
|
28
|
+
if (document.getElementById(styleId)) {
|
|
29
|
+
ApolloDataBarChart.tooltipStylesInjected = true;
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const style = document.createElement('style');
|
|
33
|
+
style.id = styleId;
|
|
34
|
+
style.textContent = `
|
|
35
|
+
#vg-tooltip-element {
|
|
36
|
+
background-color: #ffffff;
|
|
37
|
+
border: 1px solid #e1e2e8;
|
|
38
|
+
border-radius: 0.25rem;
|
|
39
|
+
box-shadow: 0 4px 6px -1px rgba(48, 45, 59, 0.1), 0 2px 4px -1px rgba(48, 45, 59, 0.05);
|
|
40
|
+
font-family: apple-system, system-ui, 'Segoe UI', Arial, Helvetica, Roboto, sans-serif;
|
|
41
|
+
font-weight: 500;
|
|
42
|
+
padding: 0.25rem 0.75rem;
|
|
43
|
+
pointer-events: none;
|
|
44
|
+
text-align: center;
|
|
45
|
+
transform: translateY(20%);
|
|
46
|
+
white-space: pre;
|
|
47
|
+
z-index: 999999999;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
#vg-tooltip-element table tr td.key {
|
|
51
|
+
color: #6a6d7d;
|
|
52
|
+
text-align: center;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
#vg-tooltip-element table tr td.value {
|
|
56
|
+
text-align: center;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
#vg-tooltip-element.dark-theme {
|
|
60
|
+
background-color: #292632;
|
|
61
|
+
border: 1px solid #6a6d7d;
|
|
62
|
+
box-shadow: 0 4px 6px -1px rgba(48, 45, 59, 0.1), 0 2px 4px -1px rgba(48, 45, 59, 0.5);
|
|
63
|
+
color: #ffffff;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
#vg-tooltip-element::after {
|
|
67
|
+
border-color: rgba(255, 255, 255, 0.95) transparent transparent transparent;
|
|
68
|
+
border-style: solid;
|
|
69
|
+
border-width: 9px;
|
|
70
|
+
bottom: -17px;
|
|
71
|
+
content: '';
|
|
72
|
+
left: 50%;
|
|
73
|
+
position: absolute;
|
|
74
|
+
transform: translateX(-50%);
|
|
75
|
+
}
|
|
76
|
+
`;
|
|
77
|
+
document.head.appendChild(style);
|
|
78
|
+
ApolloDataBarChart.tooltipStylesInjected = true;
|
|
79
|
+
}
|
|
80
|
+
// @ts-ignore
|
|
81
|
+
async getViewData(data, spec) {
|
|
82
|
+
if (!spec) {
|
|
83
|
+
throw new Error('adSpec is required for apollo-data-bar-chart');
|
|
84
|
+
}
|
|
85
|
+
const { tooltipPrefix = '', currencySymbol = '' } = spec;
|
|
86
|
+
if (!data || data.length === 0) {
|
|
87
|
+
throw new Error('Data is required for apollo-data-bar-chart');
|
|
88
|
+
}
|
|
89
|
+
const uniqueCategories = Array.from(new Set(data.map(item => item.category)));
|
|
90
|
+
const formatNumber = tooltipPrefix ? '.2f' : '.0f';
|
|
91
|
+
const currencyPrefix = tooltipPrefix ? currencySymbol : '';
|
|
92
|
+
return {
|
|
93
|
+
$schema: 'https://vega.github.io/schema/vega/v5.json',
|
|
94
|
+
config: {
|
|
95
|
+
text: {
|
|
96
|
+
fill: '#6a6d7d',
|
|
97
|
+
font: FONT_FAMILY,
|
|
98
|
+
labelFontSize: 12,
|
|
99
|
+
labelFontWeight: 400,
|
|
100
|
+
},
|
|
101
|
+
axis: {
|
|
102
|
+
labelColor: '#6a6d7d',
|
|
103
|
+
titleColor: '#6a6d7d',
|
|
104
|
+
labelFont: FONT_FAMILY,
|
|
105
|
+
titleFont: FONT_FAMILY,
|
|
106
|
+
titleFontWeight: 400,
|
|
107
|
+
},
|
|
108
|
+
legend: {
|
|
109
|
+
labelColor: '#6a6d7d',
|
|
110
|
+
titleColor: '#6a6d7d',
|
|
111
|
+
labelFont: FONT_FAMILY,
|
|
112
|
+
titleFont: FONT_FAMILY,
|
|
113
|
+
labelFontSize: 12,
|
|
114
|
+
labelLimit: 95,
|
|
115
|
+
},
|
|
116
|
+
title: {
|
|
117
|
+
color: '#6a6d7d',
|
|
118
|
+
font: FONT_FAMILY,
|
|
119
|
+
labelFontSize: 12,
|
|
120
|
+
labelFontWeight: 400,
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
height: 250,
|
|
124
|
+
autosize: { type: 'fit-x', contains: 'padding', resize: true },
|
|
125
|
+
signals: [
|
|
126
|
+
{
|
|
127
|
+
name: 'containerW',
|
|
128
|
+
update: 'max(containerSize()[0], 400)',
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
name: 'legendColumns',
|
|
132
|
+
update: 'ceil(containerW / 140)',
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
name: 'hoveredPeriod',
|
|
136
|
+
value: null,
|
|
137
|
+
on: [
|
|
138
|
+
{ events: 'rect:mouseover', update: 'datum.period' },
|
|
139
|
+
{ events: 'rect:mouseout', update: 'null' },
|
|
140
|
+
],
|
|
141
|
+
},
|
|
142
|
+
],
|
|
143
|
+
width: { signal: 'containerW' },
|
|
144
|
+
data: [
|
|
145
|
+
{
|
|
146
|
+
name: 'raw',
|
|
147
|
+
values: data,
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
name: 'periodTotals',
|
|
151
|
+
source: 'raw',
|
|
152
|
+
transform: [
|
|
153
|
+
{
|
|
154
|
+
type: 'aggregate',
|
|
155
|
+
groupby: ['periodId'],
|
|
156
|
+
fields: ['value'],
|
|
157
|
+
ops: ['sum'],
|
|
158
|
+
as: ['total'],
|
|
159
|
+
},
|
|
160
|
+
],
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
name: 'table',
|
|
164
|
+
source: 'raw',
|
|
165
|
+
transform: [
|
|
166
|
+
{
|
|
167
|
+
type: 'lookup',
|
|
168
|
+
from: 'periodTotals',
|
|
169
|
+
key: 'periodId',
|
|
170
|
+
fields: ['periodId'],
|
|
171
|
+
values: ['total'],
|
|
172
|
+
as: ['total'],
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
type: 'stack',
|
|
176
|
+
groupby: ['periodId'],
|
|
177
|
+
sort: { field: 'category' },
|
|
178
|
+
field: 'value',
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
type: 'formula',
|
|
182
|
+
as: 'periodId',
|
|
183
|
+
expr: 'datum.periodId',
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
type: 'formula',
|
|
187
|
+
as: 'labelOnly',
|
|
188
|
+
expr: 'datum.label',
|
|
189
|
+
},
|
|
190
|
+
],
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
name: 'periodLabels',
|
|
194
|
+
source: 'raw',
|
|
195
|
+
transform: [
|
|
196
|
+
{
|
|
197
|
+
type: 'aggregate',
|
|
198
|
+
groupby: ['periodId', 'label'],
|
|
199
|
+
},
|
|
200
|
+
],
|
|
201
|
+
},
|
|
202
|
+
],
|
|
203
|
+
scales: [
|
|
204
|
+
{
|
|
205
|
+
name: 'x',
|
|
206
|
+
type: 'band',
|
|
207
|
+
domain: { data: 'table', field: 'periodId' },
|
|
208
|
+
range: 'width',
|
|
209
|
+
paddingInner: 0.35,
|
|
210
|
+
paddingOuter: 0.02,
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
name: 'xLabels',
|
|
214
|
+
type: 'ordinal',
|
|
215
|
+
domain: { data: 'periodLabels', field: 'periodId' },
|
|
216
|
+
range: { data: 'periodLabels', field: 'label' },
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
name: 'y',
|
|
220
|
+
type: 'linear',
|
|
221
|
+
domain: { data: 'table', field: 'y1' },
|
|
222
|
+
nice: true,
|
|
223
|
+
zero: true,
|
|
224
|
+
range: 'height',
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
name: 'color',
|
|
228
|
+
type: 'ordinal',
|
|
229
|
+
domain: uniqueCategories,
|
|
230
|
+
range: spec?.colorSet ?? constants.CHART_COLORS,
|
|
231
|
+
},
|
|
232
|
+
],
|
|
233
|
+
axes: [
|
|
234
|
+
{
|
|
235
|
+
orient: 'bottom',
|
|
236
|
+
scale: 'x',
|
|
237
|
+
title: spec?.xAxisTitle,
|
|
238
|
+
labelPadding: 12,
|
|
239
|
+
titlePadding: 12,
|
|
240
|
+
labelAngle: -90,
|
|
241
|
+
labelAlign: 'right',
|
|
242
|
+
labelBaseline: 'middle',
|
|
243
|
+
tickSize: 3,
|
|
244
|
+
labelFontSize: 12,
|
|
245
|
+
titleFontSize: 14,
|
|
246
|
+
ticks: false,
|
|
247
|
+
domain: false,
|
|
248
|
+
encode: {
|
|
249
|
+
labels: {
|
|
250
|
+
update: {
|
|
251
|
+
text: { signal: "scale('xLabels', datum.value)" },
|
|
252
|
+
},
|
|
253
|
+
},
|
|
254
|
+
},
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
orient: 'left',
|
|
258
|
+
scale: 'y',
|
|
259
|
+
title: spec?.yAxisTitle || '',
|
|
260
|
+
format: ',.0f',
|
|
261
|
+
grid: true,
|
|
262
|
+
tickCount: 6,
|
|
263
|
+
labelFontSize: 12,
|
|
264
|
+
titleFontSize: 14,
|
|
265
|
+
ticks: false,
|
|
266
|
+
domain: false,
|
|
267
|
+
tickBand: 'extent',
|
|
268
|
+
labelPadding: 10,
|
|
269
|
+
},
|
|
270
|
+
],
|
|
271
|
+
legends: [
|
|
272
|
+
{
|
|
273
|
+
fill: 'color',
|
|
274
|
+
orient: 'bottom',
|
|
275
|
+
direction: 'horizontal',
|
|
276
|
+
columns: { signal: 'legendColumns' },
|
|
277
|
+
title: null,
|
|
278
|
+
symbolType: 'square',
|
|
279
|
+
rowPadding: 8,
|
|
280
|
+
symbolOffset: -35,
|
|
281
|
+
symbolSize: 100,
|
|
282
|
+
labelOffset: 8,
|
|
283
|
+
labelLimit: 95,
|
|
284
|
+
},
|
|
285
|
+
],
|
|
286
|
+
marks: [
|
|
287
|
+
{
|
|
288
|
+
type: 'rect',
|
|
289
|
+
from: { data: 'table' },
|
|
290
|
+
encode: {
|
|
291
|
+
enter: {
|
|
292
|
+
x: { scale: 'x', field: 'periodId' },
|
|
293
|
+
width: { scale: 'x', band: 1 },
|
|
294
|
+
y: { scale: 'y', field: 'y1' },
|
|
295
|
+
y2: { scale: 'y', field: 'y0' },
|
|
296
|
+
fill: { scale: 'color', field: 'category' },
|
|
297
|
+
tooltip: {
|
|
298
|
+
signal: `datum.category + ': ${currencyPrefix}' + format(datum.value, ',${formatNumber}') + '\\nTotal: ${currencyPrefix}' + format(datum.total, ',${formatNumber}')`,
|
|
299
|
+
},
|
|
300
|
+
},
|
|
301
|
+
update: {
|
|
302
|
+
opacity: [{ test: 'hoveredPeriod && datum.period !== hoveredPeriod', value: 0.2 }, { value: 1 }],
|
|
303
|
+
},
|
|
304
|
+
},
|
|
305
|
+
},
|
|
306
|
+
],
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
render() {
|
|
310
|
+
return (index.h(index.Host, { key: '86ed2e74e5abd57e684a93bc9cf6a014b3ed081c' }, index.h("div", { key: '96e5f7dd2dfa6a104ca709d1399308a86041c2f3', id: "container", style: { width: '100%', height: '100%' } })));
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
exports.apollo_data_bar_chart = ApolloDataBarChart;
|