import pmwc from "./chart_specs/partial_match_weights.json"; import waterfall from "./chart_specs/waterfall.json"; function applyPMWCDomainRange(chart_spec) { const colorConfig = { condition: { test: "datum.activityStatus !== 'Activated partial match weight'", value: "#BBB", }, field: "comparison_name", type: "nominal", legend: null, scale: { domain: [ "Prior", "probability_two_random_records_match", "first_name", "surname", "postcode", "gender", "Final score", ], range: [ "#1f77b4", "#1f77b4", "#ff7f0e", "#2ca02c", "#d62728", "#9467bd", "#17becf", ], }, }; chart_spec.vconcat[0].encoding.color = colorConfig; chart_spec.vconcat[1].encoding.color = colorConfig; chart_spec.vconcat[0].transform.push({ calculate: "datum.bar_is_active === true ? 'Activated partial match weight' : 'Other partial match weights'", as: "activityStatus", }); chart_spec.vconcat[1].transform.push({ calculate: "datum.bar_is_active === true ? 'Activated partial match weight' : 'Other partial match weights'", as: "activityStatus", }); } export function partial_match_weights_chart( data?: Array>, highlight?: boolean ): typeof pmwc { const newPmwc = JSON.parse(JSON.stringify(pmwc)); if (data) { newPmwc.datasets.mydata = data; } if (highlight) { applyPMWCDomainRange(newPmwc); } return newPmwc; } function applyWaterfallDomainRange(chart_spec) { const colorConfig = { field: "column_name", type: "nominal", legend: null, scale: { domain: [ "Prior", "probability_two_random_records_match", "first_name", "surname", "postcode", "gender", "Final score", ], range: [ "#1f77b4", "#1f77b4", "#ff7f0e", "#2ca02c", "#d62728", "#9467bd", "#17becf", ], }, }; chart_spec.layer[0].layer[1]["encoding"]["color"] = colorConfig; if (chart_spec.layer[0].layer[1].encoding.opacity) { delete chart_spec.layer[0].layer[1].encoding.opacity; } } export function waterfall_chart( data?: Array>, highlight?: boolean ): typeof waterfall { const newWaterfall = JSON.parse(JSON.stringify(waterfall)); if (data) { newWaterfall.datasets.mydata = data; } if (highlight) { applyWaterfallDomainRange(newWaterfall); } return newWaterfall; }