UNPKG

mstr-viz

Version:

A new dev tool for creating custom visualizations

80 lines (65 loc) 2.99 kB
import properties from "./properties.js"; import { PROPERTIES_ENUM } from "./enums"; mstrmojo.requiresCls("mstrmojo.customviz.CustomVisEnums"); const $CustomVisEnums = mstrmojo.customviz.CustomVisEnums; /** * Fires after changes in the format panel and applies changes to the properties * @param {object} host * @param {string} propertyKey * @param {any} value */ const apply = (host, propertyKey, value) => { if (properties.indexOf(propertyKey) < 0) return; let unifiedProperty = JSON.parse(host.getProperty("unifiedProperty")); const notRefresh = { callback: () => {}, }; let useDefaultPropertySave = true; const preventDefaultPropertySave = () => { useDefaultPropertySave = false; }; const isLegendProperty = propertyKey === PROPERTIES_ENUM.SHOW_LEGEND || propertyKey === PROPERTIES_ENUM.LEGEND_FONT_FAMILY || propertyKey === PROPERTIES_ENUM.LEGEND_FONT_STYLE || propertyKey === PROPERTIES_ENUM.LEGEND_FONT_SIZE || propertyKey === PROPERTIES_ENUM.LEGEND_FONT_COLOR; let legendValueSet = host.getLegendProperties(); switch (propertyKey) { case PROPERTIES_ENUM.SHOW_LEGEND: //The value indicates whether to hide the hidable layout legendValueSet[$CustomVisEnums.ENUM_LEGEND_PROPS.SHOW_LEGEND] = !value; host.savePropertyAndUpdateWidget($CustomVisEnums.LEGEND_PROPERTY_SET, legendValueSet); break; case PROPERTIES_ENUM.LEGEND_FONT_FAMILY: legendValueSet[$CustomVisEnums.ENUM_LEGEND_PROPS.LEGEND_FONT_FAMILY] = value; host.savePropertyAndUpdateWidget($CustomVisEnums.LEGEND_PROPERTY_SET, legendValueSet); break; case PROPERTIES_ENUM.LEGEND_FONT_STYLE: legendValueSet[$CustomVisEnums.ENUM_LEGEND_PROPS.LEGEND_FONT_WEIGHT] = value[0]; legendValueSet[$CustomVisEnums.ENUM_LEGEND_PROPS.LEGEND_FONT_ITALIC] = value[1]; legendValueSet[$CustomVisEnums.ENUM_LEGEND_PROPS.LEGEND_FONT_UNDERLINE] = value[2]; legendValueSet[$CustomVisEnums.ENUM_LEGEND_PROPS.LEGEND_FONT_LINE_THROUGH] = value[3]; host.savePropertyAndUpdateWidget($CustomVisEnums.LEGEND_PROPERTY_SET, legendValueSet); break; case PROPERTIES_ENUM.LEGEND_FONT_SIZE: legendValueSet[$CustomVisEnums.ENUM_LEGEND_PROPS.LEGEND_FONT_SIZE] = value + 'pt'; host.savePropertyAndUpdateWidget($CustomVisEnums.LEGEND_PROPERTY_SET, legendValueSet); break; case PROPERTIES_ENUM.LEGEND_FONT_COLOR: legendValueSet[$CustomVisEnums.ENUM_LEGEND_PROPS.LEGEND_FONT_COLOR] = value; host.savePropertyAndUpdateWidget($CustomVisEnums.LEGEND_PROPERTY_SET, legendValueSet); break; default: break; } if (useDefaultPropertySave) { unifiedProperty = { ...unifiedProperty, [propertyKey]: value }; host.savePropertyAndUpdateWidgetAsync( "unifiedProperty", JSON.stringify(unifiedProperty), isLegendProperty ? undefined : notRefresh ); } if (!isLegendProperty) { host.plot(unifiedProperty); } }; export default apply;