Public
Edited
Feb 28, 2023
Fork of import test
Insert cell
Insert cell
import {chart, config, globals} from "@maxwalts/interactive-chart"
Insert cell
{

// One option for config is to clear the default config with `.length = 0` or `.pop()` and then push entire
// objects. This approach only works for config options that are iterable (i.e. `lines` is a list of line objects)
config.lines.length = 0;
config.lines.push(
{
label: 'S',
id: '2',
labelSize: "14px",
point1: [0, 0],
point2: [70, 90],
color: globals.colors.supplyRed,
width: 4,
moveX: true,
moveY: true,
drawOriginLine: true
})
config.lines.push(
{
label: 'D',
id: '1', // new attribute ID. This must be a string without spaces or other special characters.
labelSize: "14px",
point1: [10, 20],
point2: [80, 10],
color: globals.colors.demandBlue,
width: 4,
moveX: true,
moveY: false,
drawOriginLine: true
},
)

/* one option for config is drilling down to the target attribute and editing it directly */
d3.select('#givenLine_1').style('stroke-width', 8)
config.lines[1].width = 8; // this changes the second line we just defined.
config.header.title = "Supply and Demand";

config.intersectionPoints.pop()
config.intersectionPoints.push(
{
label: "Equilibrium",
labels: ["D", "S"],
isPrimary: true,

drawHorizontalDropline: true,
drawVerticalDropline: true,

verticalLabelOffset: [0, 0],
verticalLabelColor: 'black',

labelFormat: ".0f", // format according to 'd3-format' spec https://github.com/d3/d3-format

horizontalLabelOffset: [0, 0],
horizontalLabelColor: 'black',

drawVerticalMeasureLine: true,
drawHorizontalMeasureLine: false

})

// Example of changing Axis config
config.xAxisScale.title.html = `<p class="axisTitle"> <b> New title </b> </p>`;
config.yAxisScale.tickValues =[10, 20, 30, 40, 50];
config.yAxisScale.tickFormat = [10, 20, 30, 40, 50];
console.log(config);
config.xAxisScale.domain=[0,1000];
console.log(config);



}

Insert cell
chart
Insert cell
/*--- other important notes ---*/
{

// console log an element to see all its attribites
console.log("lines", config.lines);
// you can add your own attributes.

// look at the entire DOM tree
console.log(chart)
// you can also select elements and their attributes with d3.select
// console.log(d3.select("#givenLine_2").attr('y1')) // selecting an id
const title = d3.select('text.headerTitle') // selecting with a element & class name
// title.style('color', 'yellow')
}
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more